aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qtapplicationmanager/appmanagerdeploypackagestep.cpp
blob: 6263028a6e4bed67fbec5c2db4de0b7c0fa3804e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "appmanagerdeploypackagestep.h"

#include "appmanagerconstants.h"
#include "appmanagerstringaspect.h"
#include "appmanagertargetinformation.h"
#include "appmanagertr.h"

#include <projectexplorer/buildstep.h>
#include <projectexplorer/deployconfiguration.h>
#include <projectexplorer/kitaspects.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/target.h>

#include <remotelinux/remotelinux_constants.h>

#include <utils/filestreamer.h>

using namespace ProjectExplorer;
using namespace RemoteLinux;
using namespace Tasking;
using namespace Utils;

namespace AppManager::Internal {

#define SETTINGSPREFIX "ApplicationManagerPlugin.Deploy.DeployPackageStep."

class AppManagerDeployPackageStep : public BuildStep
{
public:
    AppManagerDeployPackageStep(BuildStepList *bsl, Id id)
        : BuildStep(bsl, id)
    {
        setDisplayName(Tr::tr("Deploy Application Manager package"));

        packageFilePath.setSettingsKey(SETTINGSPREFIX "FilePath");
        packageFilePath.setLabelText(Tr::tr("Package file:"));
        packageFilePath.setEnabler(&customizeStep);

        targetDirectory.setSettingsKey(SETTINGSPREFIX "TargetDirectory");
        targetDirectory.setLabelText(Tr::tr("Target directory:"));
        targetDirectory.setEnabler(&customizeStep);

        const auto updateAspects = [this] {
            if (customizeStep.value())
                return;

            const TargetInformation targetInformation(target());

            packageFilePath.setValue(targetInformation.packageFilePath);
            packageFilePath.setDefaultValue(packageFilePath.value());

            targetDirectory.setValue(targetInformation.runDirectory);
            targetDirectory.setDefaultValue(targetDirectory.value());

            setEnabled(!targetInformation.isBuiltin);
        };

        connect(target(), &Target::activeRunConfigurationChanged, this, updateAspects);
        connect(target(), &Target::activeDeployConfigurationChanged, this, updateAspects);
        connect(target(), &Target::parsingFinished, this, updateAspects);
        connect(target(), &Target::runConfigurationsUpdated, this, updateAspects);
        connect(project(), &Project::displayNameChanged, this, updateAspects);
        connect(&customizeStep, &BaseAspect::changed, this, updateAspects);

        updateAspects();
    }

private:
    bool init() final
    {
        return TargetInformation(target()).isValid();
    }

    GroupItem runRecipe() final
    {
        const auto onSetup = [this](FileStreamer &streamer) {
            const FilePath source = packageFilePath().isEmpty() ?
                                        FilePath::fromString(packageFilePath.defaultValue()) :
                                        packageFilePath();
            const FilePath targetDir = targetDirectory().isEmpty() ?
                                           FilePath::fromString(targetDirectory.defaultValue()) :
                                           targetDirectory();
            const FilePath target = DeviceKitAspect::device(kit())->filePath(targetDir.path())
                                        .pathAppended(source.fileName());
            streamer.setSource(source);
            streamer.setDestination(target);
            emit addOutput("Starting uploading", OutputFormat::NormalMessage);
        };
        const auto onDone = [this](DoneWith result) {
            if (result == DoneWith::Success)
                emit addOutput(Tr::tr("Uploading finished."), OutputFormat::NormalMessage);
            else
                emit addOutput(Tr::tr("Uploading failed."), OutputFormat::ErrorMessage);
        };
        return FileStreamerTask(onSetup, onDone);
    }

    AppManagerCustomizeAspect customizeStep{this};
    FilePathAspect packageFilePath{this};
    FilePathAspect targetDirectory{this};
};

// Factory

class AppManagerDeployPackageStepFactory final : public BuildStepFactory
{
public:
    AppManagerDeployPackageStepFactory()
    {
        registerStep<AppManagerDeployPackageStep>(Constants::DEPLOY_PACKAGE_STEP_ID);
        setDisplayName(Tr::tr("Deploy Application Manager package"));
        setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY);
    }
};

void setupAppManagerDeployPackageStep()
{
   static AppManagerDeployPackageStepFactory theAppManagerDeployPackageStepFactory;
}

} // namespace AppManager::Internal