1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #include "processstep.h"
27
28 #include "abstractprocessstep.h"
29 #include "buildconfiguration.h"
30 #include "kit.h"
31 #include "processparameters.h"
32 #include "projectexplorerconstants.h"
33 #include "projectexplorer_export.h"
34 #include "target.h"
35
36 #include <utils/aspects.h>
37 #include <utils/fileutils.h>
38 #include <utils/outputformatter.h>
39
40 using namespace Utils;
41
42 namespace ProjectExplorer {
43 namespace Internal {
44
45 const char PROCESS_COMMAND_KEY[] = "ProjectExplorer.ProcessStep.Command";
46 const char PROCESS_WORKINGDIRECTORY_KEY[] = "ProjectExplorer.ProcessStep.WorkingDirectory";
47 const char PROCESS_ARGUMENTS_KEY[] = "ProjectExplorer.ProcessStep.Arguments";
48
49 class ProcessStep final : public AbstractProcessStep
50 {
51 Q_DECLARE_TR_FUNCTIONS(ProjectExplorer::ProcessStep)
52
53 public:
54 ProcessStep(BuildStepList *bsl, Id id);
55
56 void setupOutputFormatter(OutputFormatter *formatter) final;
57 };
58
ProcessStep(BuildStepList * bsl,Id id)59 ProcessStep::ProcessStep(BuildStepList *bsl, Id id)
60 : AbstractProcessStep(bsl, id)
61 {
62 auto command = addAspect<StringAspect>();
63 command->setSettingsKey(PROCESS_COMMAND_KEY);
64 command->setDisplayStyle(StringAspect::PathChooserDisplay);
65 command->setLabelText(tr("Command:"));
66 command->setExpectedKind(PathChooser::Command);
67 command->setHistoryCompleter("PE.ProcessStepCommand.History");
68
69 auto arguments = addAspect<StringAspect>();
70 arguments->setSettingsKey(PROCESS_ARGUMENTS_KEY);
71 arguments->setDisplayStyle(StringAspect::LineEditDisplay);
72 arguments->setLabelText(tr("Arguments:"));
73
74 auto workingDirectory = addAspect<StringAspect>();
75 workingDirectory->setSettingsKey(PROCESS_WORKINGDIRECTORY_KEY);
76 workingDirectory->setValue(Constants::DEFAULT_WORKING_DIR);
77 workingDirectory->setDisplayStyle(StringAspect::PathChooserDisplay);
78 workingDirectory->setLabelText(tr("Working directory:"));
79 workingDirectory->setExpectedKind(PathChooser::Directory);
80
81 setWorkingDirectoryProvider([this, workingDirectory] {
82 const FilePath workingDir = workingDirectory->filePath();
83 if (workingDir.isEmpty())
84 return FilePath::fromString(fallbackWorkingDirectory());
85 return workingDir;
86 });
87
88 setCommandLineProvider([command, arguments] {
89 return CommandLine{command->filePath(), arguments->value(), CommandLine::Raw};
90 });
91
92 setSummaryUpdater([this] {
93 QString display = displayName();
94 if (display.isEmpty())
95 display = tr("Custom Process Step");
96 ProcessParameters param;
97 setupProcessParameters(¶m);
98 return param.summary(display);
99 });
100
101 addMacroExpander();
102 }
103
setupOutputFormatter(OutputFormatter * formatter)104 void ProcessStep::setupOutputFormatter(OutputFormatter *formatter)
105 {
106 formatter->addLineParsers(kit()->createOutputParsers());
107 AbstractProcessStep::setupOutputFormatter(formatter);
108 }
109
110 // ProcessStepFactory
111
ProcessStepFactory()112 ProcessStepFactory::ProcessStepFactory()
113 {
114 registerStep<ProcessStep>("ProjectExplorer.ProcessStep");
115 //: Default ProcessStep display name
116 setDisplayName(ProcessStep::tr("Custom Process Step"));
117 }
118
119 } // Internal
120 } // ProjectExplorer
121