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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "processstep.h"
#include "buildstep.h"
#include "project.h"
#include "buildconfiguration.h"
#include <coreplugin/ifile.h>
#include <utils/qtcprocess.h>
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
#include <QtGui/QFileDialog>
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
namespace {
const char * const PROCESS_STEP_ID("ProjectExplorer.ProcessStep");
const char * const PROCESS_COMMAND_KEY("ProjectExplorer.ProcessStep.Command");
const char * const PROCESS_WORKINGDIRECTORY_KEY("ProjectExplorer.ProcessStep.WorkingDirectory");
const char * const PROCESS_ARGUMENTS_KEY("ProjectExplorer.ProcessStep.Arguments");
const char * const PROCESS_ENABLED_KEY("ProjectExplorer.ProcessStep.Enabled");
}
ProcessStep::ProcessStep(BuildStepList *bsl) :
AbstractProcessStep(bsl, QLatin1String(PROCESS_STEP_ID))
{
ctor();
}
ProcessStep::ProcessStep(BuildStepList *bsl, const QString &id) :
AbstractProcessStep(bsl, id)
{
ctor();
}
ProcessStep::ProcessStep(BuildStepList *bsl, ProcessStep *bs) :
AbstractProcessStep(bsl, bs),
m_command(bs->m_command),
m_arguments(bs->m_arguments),
m_workingDirectory(bs->m_workingDirectory),
m_env(bs->m_env),
m_enabled(bs->m_enabled)
{
ctor();
}
void ProcessStep::ctor()
{
//: Default ProcessStep display name
setDefaultDisplayName(tr("Custom Process Step"));
if (m_workingDirectory.isEmpty())
m_workingDirectory = QLatin1String(DEFAULT_WORKING_DIR);
}
ProcessStep::~ProcessStep()
{
}
bool ProcessStep::init()
{
BuildConfiguration *bc = buildConfiguration();
ProcessParameters *pp = processParameters();
pp->setMacroExpander(bc->macroExpander());
pp->setEnvironment(bc->environment());
pp->setWorkingDirectory(workingDirectory());
pp->setCommand(m_command);
pp->setArguments(m_arguments);
AbstractProcessStep::setEnabled(m_enabled);
setOutputParser(bc->createOutputParser());
return AbstractProcessStep::init();
}
void ProcessStep::run(QFutureInterface<bool> & fi)
{
return AbstractProcessStep::run(fi);
}
BuildStepConfigWidget *ProcessStep::createConfigWidget()
{
return new ProcessStepConfigWidget(this);
}
bool ProcessStep::immutable() const
{
return false;
}
QString ProcessStep::command() const
{
return m_command;
}
QString ProcessStep::arguments() const
{
return m_arguments;
}
bool ProcessStep::enabled() const
{
return m_enabled;
}
QString ProcessStep::workingDirectory() const
{
return m_workingDirectory;
}
void ProcessStep::setCommand(const QString &command)
{
m_command = command;
}
void ProcessStep::setArguments(const QString &arguments)
{
m_arguments = arguments;
}
void ProcessStep::setEnabled(bool enabled)
{
m_enabled = enabled;
}
void ProcessStep::setWorkingDirectory(const QString &workingDirectory)
{
if (workingDirectory.isEmpty())
m_workingDirectory = QLatin1String(DEFAULT_WORKING_DIR);
else
m_workingDirectory = workingDirectory;
}
QVariantMap ProcessStep::toMap() const
{
QVariantMap map(AbstractProcessStep::toMap());
map.insert(QLatin1String(PROCESS_COMMAND_KEY), command());
map.insert(QLatin1String(PROCESS_ARGUMENTS_KEY), arguments());
map.insert(QLatin1String(PROCESS_WORKINGDIRECTORY_KEY), workingDirectory());
map.insert(QLatin1String(PROCESS_ENABLED_KEY), enabled());
return map;
}
bool ProcessStep::fromMap(const QVariantMap &map)
{
setCommand(map.value(QLatin1String(PROCESS_COMMAND_KEY)).toString());
setArguments(map.value(QLatin1String(PROCESS_ARGUMENTS_KEY)).toString());
setWorkingDirectory(map.value(QLatin1String(PROCESS_WORKINGDIRECTORY_KEY)).toString());
setEnabled(map.value(QLatin1String(PROCESS_ENABLED_KEY), false).toBool());
return AbstractProcessStep::fromMap(map);
}
//*******
// ProcessStepFactory
//*******
ProcessStepFactory::ProcessStepFactory()
{
}
ProcessStepFactory::~ProcessStepFactory()
{
}
bool ProcessStepFactory::canCreate(BuildStepList *parent, const QString &id) const
{
Q_UNUSED(parent);
return id == QLatin1String(PROCESS_STEP_ID);
}
BuildStep *ProcessStepFactory::create(BuildStepList *parent, const QString &id)
{
if (!canCreate(parent, id))
return 0;
return new ProcessStep(parent);
}
bool ProcessStepFactory::canClone(BuildStepList *parent, BuildStep *bs) const
{
return canCreate(parent, bs->id());
}
BuildStep *ProcessStepFactory::clone(BuildStepList *parent, BuildStep *bs)
{
if (!canClone(parent, bs))
return 0;
return new ProcessStep(parent, static_cast<ProcessStep *>(bs));
}
bool ProcessStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
{
QString id(ProjectExplorer::idFromMap(map));
return canCreate(parent, id);
}
BuildStep *ProcessStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
ProcessStep *bs(new ProcessStep(parent));
if (bs->fromMap(map))
return bs;
delete bs;
return 0;
}
QStringList ProcessStepFactory::availableCreationIds(BuildStepList *parent) const
{
Q_UNUSED(parent);
return QStringList() << QLatin1String(PROCESS_STEP_ID);
}
QString ProcessStepFactory::displayNameForId(const QString &id) const
{
if (id == QLatin1String(PROCESS_STEP_ID))
return ProcessStep::tr("Custom Process Step", "item in combobox");
return QString();
}
//*******
// ProcessStepConfigWidget
//*******
ProcessStepConfigWidget::ProcessStepConfigWidget(ProcessStep *step)
: m_step(step)
{
m_ui.setupUi(this);
m_ui.command->setExpectedKind(Utils::PathChooser::ExistingCommand);
connect(m_ui.command, SIGNAL(changed(QString)),
this, SLOT(commandLineEditTextEdited()));
connect(m_ui.workingDirectory, SIGNAL(changed(QString)),
this, SLOT(workingDirectoryLineEditTextEdited()));
connect(m_ui.commandArgumentsLineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(commandArgumentsLineEditTextEdited()));
connect(m_ui.enabledCheckBox, SIGNAL(clicked(bool)),
this, SLOT(enabledCheckBoxClicked(bool)));
}
void ProcessStepConfigWidget::updateDetails()
{
QString displayName = m_step->displayName();
if (displayName.isEmpty())
displayName = tr("Custom Process Step");
ProcessParameters param;
param.setMacroExpander(m_step->buildConfiguration()->macroExpander());
param.setEnvironment(m_step->buildConfiguration()->environment());
param.setWorkingDirectory(m_step->workingDirectory());
param.setCommand(m_step->command());
param.setArguments(m_step->arguments());
m_summaryText = param.summary(displayName);
if (!m_step->enabled()) {
//: %1 is the custom process step summary
m_summaryText = tr("%1 (disabled)").arg(m_summaryText);
}
emit updateSummary();
}
QString ProcessStepConfigWidget::displayName() const
{
return m_step->displayName();
}
void ProcessStepConfigWidget::init()
{
m_ui.command->setEnvironment(m_step->buildConfiguration()->environment());
m_ui.command->setPath(m_step->command());
m_ui.workingDirectory->setEnvironment(m_step->buildConfiguration()->environment());
m_ui.workingDirectory->setPath(m_step->workingDirectory());
m_ui.commandArgumentsLineEdit->setText(m_step->arguments());
m_ui.enabledCheckBox->setChecked(m_step->enabled());
updateDetails();
}
QString ProcessStepConfigWidget::summaryText() const
{
return m_summaryText;
}
void ProcessStepConfigWidget::commandLineEditTextEdited()
{
m_step->setCommand(m_ui.command->rawPath());
updateDetails();
}
void ProcessStepConfigWidget::workingDirectoryLineEditTextEdited()
{
m_step->setWorkingDirectory(m_ui.workingDirectory->rawPath());
}
void ProcessStepConfigWidget::commandArgumentsLineEditTextEdited()
{
m_step->setArguments(m_ui.commandArgumentsLineEdit->text());
updateDetails();
}
void ProcessStepConfigWidget::enabledCheckBoxClicked(bool)
{
m_step->setEnabled(m_ui.enabledCheckBox->isChecked());
updateDetails();
}
|