2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2021-03-29 09:11:36 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-07-04 11:09:11 +02:00
|
|
|
#include "dockersettings.h"
|
|
|
|
|
|
2022-09-14 16:40:28 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
|
|
|
|
|
2021-03-29 09:11:36 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
|
|
|
|
#include <projectexplorer/devicesupport/idevicefactory.h>
|
|
|
|
|
|
2022-07-04 14:24:51 +02:00
|
|
|
#include <QMutex>
|
|
|
|
|
|
2022-07-13 10:43:31 +02:00
|
|
|
namespace Docker::Internal {
|
2021-03-29 09:11:36 +02:00
|
|
|
|
|
|
|
|
class DockerDeviceData
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-09-14 16:20:02 +02:00
|
|
|
bool operator==(const DockerDeviceData &other) const
|
|
|
|
|
{
|
2022-09-14 16:40:28 +02:00
|
|
|
return imageId == other.imageId && repo == other.repo && tag == other.tag
|
2022-09-14 16:43:39 +02:00
|
|
|
&& useLocalUidGid == other.useLocalUidGid && mounts == other.mounts
|
|
|
|
|
&& keepEntryPoint == other.keepEntryPoint;
|
2022-09-14 16:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 16:40:28 +02:00
|
|
|
bool operator!=(const DockerDeviceData &other) const { return !(*this == other); }
|
2022-09-14 16:20:02 +02:00
|
|
|
|
2022-02-24 10:14:25 +01:00
|
|
|
// Used for "docker run"
|
2022-09-14 16:20:02 +02:00
|
|
|
QString repoAndTag() const
|
|
|
|
|
{
|
|
|
|
|
if (repo == "<none>")
|
|
|
|
|
return imageId;
|
|
|
|
|
|
|
|
|
|
if (tag == "<none>")
|
|
|
|
|
return repo;
|
|
|
|
|
|
|
|
|
|
return repo + ':' + tag;
|
|
|
|
|
}
|
2021-05-31 13:01:49 +02:00
|
|
|
|
2021-03-29 09:11:36 +02:00
|
|
|
QString imageId;
|
|
|
|
|
QString repo;
|
|
|
|
|
QString tag;
|
|
|
|
|
QString size;
|
2021-06-29 10:47:48 +02:00
|
|
|
bool useLocalUidGid = true;
|
2022-09-14 16:40:28 +02:00
|
|
|
QStringList mounts = {Core::DocumentManager::projectsDirectory().toString()};
|
2022-09-14 16:43:39 +02:00
|
|
|
bool keepEntryPoint = false;
|
2021-03-29 09:11:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DockerDevice : public ProjectExplorer::IDevice
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using Ptr = QSharedPointer<DockerDevice>;
|
|
|
|
|
using ConstPtr = QSharedPointer<const DockerDevice>;
|
|
|
|
|
|
2022-07-04 14:24:51 +02:00
|
|
|
explicit DockerDevice(DockerSettings *settings, const DockerDeviceData &data);
|
2021-03-29 09:11:36 +02:00
|
|
|
~DockerDevice();
|
2021-04-29 07:36:34 +02:00
|
|
|
|
2022-07-04 14:24:51 +02:00
|
|
|
void shutdown();
|
|
|
|
|
|
2022-09-14 16:40:28 +02:00
|
|
|
static Ptr create(DockerSettings *settings, const DockerDeviceData &data)
|
|
|
|
|
{
|
|
|
|
|
return Ptr(new DockerDevice(settings, data));
|
|
|
|
|
}
|
2021-03-29 09:11:36 +02:00
|
|
|
|
|
|
|
|
ProjectExplorer::IDeviceWidget *createWidget() override;
|
2022-01-26 13:02:49 +01:00
|
|
|
QList<ProjectExplorer::Task> validate() const override;
|
2021-03-29 09:11:36 +02:00
|
|
|
|
2022-04-28 16:15:46 +02:00
|
|
|
Utils::ProcessInterface *createProcessInterface() const override;
|
|
|
|
|
|
2021-03-29 09:11:36 +02:00
|
|
|
bool canAutoDetectPorts() const override;
|
2022-05-10 12:53:27 +02:00
|
|
|
ProjectExplorer::PortsGatheringMethod portsGatheringMethod() const override;
|
2021-03-29 09:11:36 +02:00
|
|
|
bool canCreateProcessModel() const override { return false; }
|
|
|
|
|
ProjectExplorer::DeviceProcessList *createProcessListModel(QObject *parent) const override;
|
|
|
|
|
bool hasDeviceTester() const override { return false; }
|
|
|
|
|
ProjectExplorer::DeviceTester *createDeviceTester() const override;
|
|
|
|
|
ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const override;
|
|
|
|
|
ProjectExplorer::DeviceEnvironmentFetcher::Ptr environmentFetcher() const override;
|
|
|
|
|
|
2021-04-29 07:36:34 +02:00
|
|
|
Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const override;
|
2021-10-08 10:31:30 +02:00
|
|
|
QString mapToDevicePath(const Utils::FilePath &globalPath) const override;
|
2021-04-29 07:36:34 +02:00
|
|
|
|
2022-05-31 11:16:44 +02:00
|
|
|
Utils::FilePath rootPath() const override;
|
|
|
|
|
|
2021-04-29 07:36:34 +02:00
|
|
|
bool handlesFile(const Utils::FilePath &filePath) const override;
|
|
|
|
|
bool isExecutableFile(const Utils::FilePath &filePath) const override;
|
|
|
|
|
bool isReadableFile(const Utils::FilePath &filePath) const override;
|
2021-06-22 07:09:00 +02:00
|
|
|
bool isWritableFile(const Utils::FilePath &filePath) const override;
|
2021-04-29 07:36:34 +02:00
|
|
|
bool isReadableDirectory(const Utils::FilePath &filePath) const override;
|
|
|
|
|
bool isWritableDirectory(const Utils::FilePath &filePath) const override;
|
2021-07-14 07:41:23 +02:00
|
|
|
bool isFile(const Utils::FilePath &filePath) const override;
|
|
|
|
|
bool isDirectory(const Utils::FilePath &filePath) const override;
|
2021-04-29 07:36:34 +02:00
|
|
|
bool createDirectory(const Utils::FilePath &filePath) const override;
|
2021-06-01 09:40:17 +02:00
|
|
|
bool exists(const Utils::FilePath &filePath) const override;
|
2021-06-29 09:41:53 +02:00
|
|
|
bool ensureExistingFile(const Utils::FilePath &filePath) const override;
|
2021-06-14 08:33:44 +02:00
|
|
|
bool removeFile(const Utils::FilePath &filePath) const override;
|
2021-06-28 15:26:44 +02:00
|
|
|
bool removeRecursively(const Utils::FilePath &filePath) const override;
|
2021-06-14 08:33:44 +02:00
|
|
|
bool copyFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
2021-06-28 13:57:10 +02:00
|
|
|
bool renameFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
2021-06-29 15:57:41 +02:00
|
|
|
Utils::FilePath symLinkTarget(const Utils::FilePath &filePath) const override;
|
2021-12-14 12:15:40 +01:00
|
|
|
void iterateDirectory(const Utils::FilePath &filePath,
|
|
|
|
|
const std::function<bool(const Utils::FilePath &)> &callBack,
|
2022-01-21 12:22:54 +01:00
|
|
|
const Utils::FileFilter &filter) const override;
|
2022-09-09 14:25:36 +02:00
|
|
|
std::optional<QByteArray> fileContents(const Utils::FilePath &filePath,
|
|
|
|
|
qint64 limit,
|
|
|
|
|
qint64 offset) const override;
|
2021-06-15 18:29:51 +02:00
|
|
|
bool writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const override;
|
2021-06-14 08:33:44 +02:00
|
|
|
QDateTime lastModified(const Utils::FilePath &filePath) const override;
|
2021-07-23 12:06:38 +02:00
|
|
|
qint64 fileSize(const Utils::FilePath &filePath) const override;
|
2021-07-23 17:55:25 +02:00
|
|
|
QFileDevice::Permissions permissions(const Utils::FilePath &filePath) const override;
|
2022-09-14 16:40:28 +02:00
|
|
|
bool setPermissions(const Utils::FilePath &filePath,
|
|
|
|
|
QFileDevice::Permissions permissions) const override;
|
|
|
|
|
bool ensureReachable(const Utils::FilePath &other) const override;
|
2021-04-29 07:36:34 +02:00
|
|
|
|
2021-05-26 17:18:40 +02:00
|
|
|
Utils::Environment systemEnvironment() const override;
|
|
|
|
|
|
2022-09-14 16:20:02 +02:00
|
|
|
const DockerDeviceData data() const;
|
|
|
|
|
DockerDeviceData data();
|
|
|
|
|
|
|
|
|
|
void setData(const DockerDeviceData &data);
|
2021-03-29 09:11:36 +02:00
|
|
|
|
2022-01-11 15:57:21 +01:00
|
|
|
void updateContainerAccess() const;
|
2021-07-09 13:18:22 +02:00
|
|
|
void setMounts(const QStringList &mounts) const;
|
2021-03-29 09:11:36 +02:00
|
|
|
|
2021-12-08 12:39:22 +01:00
|
|
|
protected:
|
|
|
|
|
void fromMap(const QVariantMap &map) final;
|
|
|
|
|
QVariantMap toMap() const final;
|
|
|
|
|
|
2021-04-29 07:36:34 +02:00
|
|
|
private:
|
2021-12-14 12:15:40 +01:00
|
|
|
void iterateWithFind(const Utils::FilePath &filePath,
|
|
|
|
|
const std::function<bool(const Utils::FilePath &)> &callBack,
|
2022-01-21 12:22:54 +01:00
|
|
|
const Utils::FileFilter &filter) const;
|
2021-03-29 09:11:36 +02:00
|
|
|
|
2021-05-31 13:01:49 +02:00
|
|
|
void aboutToBeRemoved() const final;
|
|
|
|
|
|
2021-04-29 07:36:34 +02:00
|
|
|
class DockerDevicePrivate *d = nullptr;
|
2022-09-14 16:20:02 +02:00
|
|
|
|
2021-05-18 06:16:25 +02:00
|
|
|
friend class DockerDeviceSetupWizard;
|
2021-05-31 10:10:53 +02:00
|
|
|
friend class DockerDeviceWidget;
|
2021-03-29 09:11:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DockerDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-07-04 14:24:51 +02:00
|
|
|
DockerDeviceFactory(DockerSettings *settings);
|
|
|
|
|
|
|
|
|
|
void shutdownExistingDevices();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QMutex m_deviceListMutex;
|
2022-09-14 16:40:28 +02:00
|
|
|
std::vector<QWeakPointer<DockerDevice>> m_existingDevices;
|
2021-03-29 09:11:36 +02:00
|
|
|
};
|
|
|
|
|
|
2022-09-14 16:40:28 +02:00
|
|
|
} // namespace Docker::Internal
|
2021-03-29 09:11:36 +02:00
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Docker::Internal::DockerDeviceData)
|