forked from qt-creator/qt-creator
Refactor deployment
* Add a DeployConfiguration class to hold settings related to deployment. * Add BuildStepsList to hold a list of buildsteps * Update BuildConfiguration to use BuildStepLists instead of manageing lists of buildsteps itself. * Update BuildManager to use BuildStepLists in its interfaces * Fix fallout introduced by API changes * Update .user file to new way of storing settings Task-number: QTCREATORBUG-1427 Task-number: QTCREATORBUG-1428 Task-number: QTCREATORBUG-1811 Task-number: QTCREATORBUG-1930
This commit is contained in:
@@ -29,100 +29,81 @@
|
||||
|
||||
#include "buildconfiguration.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/buildmanager.h>
|
||||
#include "buildmanager.h"
|
||||
#include "buildsteplist.h"
|
||||
#include "projectexplorer.h"
|
||||
#include "projectexplorerconstants.h"
|
||||
#include "target.h"
|
||||
|
||||
#include <QtCore/QMetaEnum>
|
||||
#include <QtCore/QMetaObject>
|
||||
#include <QtCore/QProcess>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace {
|
||||
|
||||
IBuildStepFactory *findCloneFactory(BuildConfiguration *parent, BuildStep::Type type, BuildStep *source)
|
||||
{
|
||||
QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IBuildStepFactory>();
|
||||
foreach(IBuildStepFactory *factory, factories)
|
||||
if (factory->canClone(parent, type, source))
|
||||
return factory;
|
||||
return 0;
|
||||
}
|
||||
|
||||
IBuildStepFactory *findRestoreFactory(BuildConfiguration *parent, BuildStep::Type type, const QVariantMap &map)
|
||||
{
|
||||
QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IBuildStepFactory>();
|
||||
foreach(IBuildStepFactory *factory, factories)
|
||||
if (factory->canRestore(parent, type, map))
|
||||
return factory;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * const STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.%1StepsCount");
|
||||
const char * const STEPS_PREFIX("ProjectExplorer.BuildConfiguration.%1Step.");
|
||||
const char * const BUILD_STEP_LIST_COUNT("ProjectExplorer.BuildConfiguration.BuildStepListCount");
|
||||
const char * const BUILD_STEP_LIST_PREFIX("ProjectExplorer.BuildConfiguration.BuildStepList.");
|
||||
const char * const CLEAR_SYSTEM_ENVIRONMENT_KEY("ProjectExplorer.BuildConfiguration.ClearSystemEnvironment");
|
||||
const char * const USER_ENVIRONMENT_CHANGES_KEY("ProjectExplorer.BuildConfiguration.UserEnvironmentChanges");
|
||||
|
||||
} // namespace
|
||||
|
||||
BuildConfiguration::BuildConfiguration(Target *target, const QString &id) :
|
||||
ProjectConfiguration(id),
|
||||
m_target(target),
|
||||
ProjectConfiguration(target, id),
|
||||
m_clearSystemEnvironment(false)
|
||||
{
|
||||
Q_ASSERT(m_target);
|
||||
Q_ASSERT(target);
|
||||
BuildStepList *bsl = new BuildStepList(this, QLatin1String(Constants::BUILDSTEPS_BUILD));
|
||||
//: Display name of the build build step list. Used as part of the labels in the project window.
|
||||
bsl->setDisplayName(tr("Build"));
|
||||
m_stepLists.append(bsl);
|
||||
bsl = new BuildStepList(this, QLatin1String(Constants::BUILDSTEPS_CLEAN));
|
||||
//: Display name of the clean build step list. Used as part of the labels in the project window.
|
||||
bsl->setDisplayName(tr("Clean"));
|
||||
m_stepLists.append(bsl);
|
||||
}
|
||||
|
||||
BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *source) :
|
||||
ProjectConfiguration(source),
|
||||
m_target(target),
|
||||
ProjectConfiguration(target, source),
|
||||
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
|
||||
m_userEnvironmentChanges(source->m_userEnvironmentChanges)
|
||||
{
|
||||
Q_ASSERT(m_target);
|
||||
Q_ASSERT(target);
|
||||
// Do not clone stepLists here, do that in the derived constructor instead
|
||||
// otherwise BuildStepFactories might reject to set up a BuildStep for us
|
||||
// since we are not yet the derived class!
|
||||
}
|
||||
|
||||
BuildConfiguration::~BuildConfiguration()
|
||||
{ }
|
||||
|
||||
QStringList BuildConfiguration::knownStepLists() const
|
||||
{
|
||||
for (int i = 0; i < BuildStep::LastStepType; ++i) {
|
||||
qDeleteAll(m_steps[i]);
|
||||
}
|
||||
QStringList result;
|
||||
foreach (BuildStepList *list, m_stepLists)
|
||||
result.append(list->id());
|
||||
return result;
|
||||
}
|
||||
|
||||
BuildStepList *BuildConfiguration::stepList(const QString &id) const
|
||||
{
|
||||
foreach (BuildStepList *list, m_stepLists)
|
||||
if (id == list->id())
|
||||
return list;
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariantMap BuildConfiguration::toMap() const
|
||||
{
|
||||
QVariantMap map(ProjectConfiguration::toMap());
|
||||
// Save build steps
|
||||
QMetaEnum typeEnum = BuildStep::staticMetaObject.enumerator(BuildStep::staticMetaObject.indexOfEnumerator("Type"));
|
||||
for (int type = 0; type < BuildStep::LastStepType; ++type) {
|
||||
const QString key(typeEnum.key(type));
|
||||
map.insert(QString::fromLatin1(STEPS_COUNT_KEY).arg(key), m_steps[type].count());
|
||||
for (int step = 0; step < m_steps[type].count(); ++step)
|
||||
map.insert(QString::fromLatin1(STEPS_PREFIX).arg(key) + QString::number(step), m_steps[type].at(step)->toMap());
|
||||
}
|
||||
|
||||
map.insert(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY), m_clearSystemEnvironment);
|
||||
map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), EnvironmentItem::toStringList(m_userEnvironmentChanges));
|
||||
|
||||
return map;
|
||||
}
|
||||
map.insert(QLatin1String(BUILD_STEP_LIST_COUNT), m_stepLists.count());
|
||||
for (int i = 0; i < m_stepLists.count(); ++i)
|
||||
map.insert(QLatin1String(BUILD_STEP_LIST_PREFIX) % QString::number(i), m_stepLists.at(i)->toMap());
|
||||
|
||||
void BuildConfiguration::cloneSteps(BuildConfiguration *source)
|
||||
{
|
||||
Q_ASSERT(source);
|
||||
for (int i = 0; i < BuildStep::LastStepType; ++i) {
|
||||
foreach (BuildStep *originalbs, source->steps(BuildStep::Type(i))) {
|
||||
IBuildStepFactory *factory(findCloneFactory(this, BuildStep::Type(i), originalbs));
|
||||
if (!factory)
|
||||
continue;
|
||||
BuildStep *clonebs(factory->clone(this, BuildStep::Type(i), originalbs));
|
||||
if (clonebs)
|
||||
m_steps[i].append(clonebs);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
bool BuildConfiguration::fromMap(const QVariantMap &map)
|
||||
@@ -130,74 +111,38 @@ bool BuildConfiguration::fromMap(const QVariantMap &map)
|
||||
if (!ProjectConfiguration::fromMap(map))
|
||||
return false;
|
||||
|
||||
QMetaEnum typeEnum = BuildStep::staticMetaObject.enumerator(BuildStep::staticMetaObject.indexOfEnumerator("Type"));
|
||||
for (int type = 0; type < BuildStep::LastStepType; ++type) {
|
||||
const QString key(typeEnum.key(type));
|
||||
int maxSteps = map.value(QString::fromLatin1(STEPS_COUNT_KEY).arg(key), 0).toInt();
|
||||
for (int step = 0; step < maxSteps; ++step) {
|
||||
QVariantMap bsData(map.value(QString::fromLatin1(STEPS_PREFIX).arg(key) + QString::number(step)).toMap());
|
||||
if (bsData.isEmpty()) {
|
||||
qWarning() << "No step data found for" << key << step << "(continuing).";
|
||||
continue;
|
||||
}
|
||||
IBuildStepFactory *factory(findRestoreFactory(this, BuildStep::Type(type), bsData));
|
||||
if (!factory) {
|
||||
qWarning() << "No factory for step" << key << step << "found (continuing).";
|
||||
continue;
|
||||
}
|
||||
BuildStep *bs(factory->restore(this, BuildStep::Type(type), bsData));
|
||||
if (!bs) {
|
||||
qWarning() << "Restoration of step" << key << step << "failed (continuing).";
|
||||
continue;
|
||||
}
|
||||
insertStep(BuildStep::Type(type), m_steps[type].count(), bs);
|
||||
}
|
||||
}
|
||||
|
||||
m_clearSystemEnvironment = map.value(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY)).toBool();
|
||||
m_userEnvironmentChanges = EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
|
||||
|
||||
qDeleteAll(m_stepLists);
|
||||
m_stepLists.clear();
|
||||
|
||||
int maxI = map.value(QLatin1String(BUILD_STEP_LIST_COUNT), 0).toInt();
|
||||
for (int i = 0; i < maxI; ++i) {
|
||||
QVariantMap data = map.value(QLatin1String(BUILD_STEP_LIST_PREFIX) % QString::number(i)).toMap();
|
||||
if (data.isEmpty()) {
|
||||
qWarning() << "No data for build step list" << i << "found!";
|
||||
continue;
|
||||
}
|
||||
BuildStepList *list = new BuildStepList(this, data);
|
||||
if (list->isNull()) {
|
||||
qWarning() << "Failed to restore build step list" << i;
|
||||
delete list;
|
||||
return false;
|
||||
}
|
||||
m_stepLists.append(list);
|
||||
}
|
||||
|
||||
// TODO: We currently assume there to be at least a clean, build and deploy list!
|
||||
Q_ASSERT(knownStepLists().contains(QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_BUILD)));
|
||||
Q_ASSERT(knownStepLists().contains(QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_CLEAN)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<BuildStep *> BuildConfiguration::steps(BuildStep::Type type) const
|
||||
{
|
||||
Q_ASSERT(type >= 0 && type < BuildStep::LastStepType);
|
||||
return m_steps[type];
|
||||
}
|
||||
|
||||
void BuildConfiguration::insertStep(BuildStep::Type type, int position, BuildStep *step)
|
||||
{
|
||||
Q_ASSERT(type >= 0 && type < BuildStep::LastStepType);
|
||||
m_steps[type].insert(position, step);
|
||||
}
|
||||
|
||||
bool BuildConfiguration::removeStep(BuildStep::Type type, int position)
|
||||
{
|
||||
Q_ASSERT(type >= 0 && type < BuildStep::LastStepType);
|
||||
|
||||
ProjectExplorer::BuildManager *bm =
|
||||
ProjectExplorer::ProjectExplorerPlugin::instance()->buildManager();
|
||||
if (bm->isBuilding(m_steps[type].at(position)))
|
||||
return false;
|
||||
|
||||
delete m_steps[type].at(position);
|
||||
m_steps[type].removeAt(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
void BuildConfiguration::moveStepUp(BuildStep::Type type, int position)
|
||||
{
|
||||
Q_ASSERT(type >= 0 && type < BuildStep::LastStepType);
|
||||
if (position <= 0 || m_steps[type].size() <= 1)
|
||||
return;
|
||||
m_steps[type].swap(position - 1, position);
|
||||
|
||||
}
|
||||
|
||||
Target *BuildConfiguration::target() const
|
||||
{
|
||||
return m_target;
|
||||
return static_cast<Target *>(parent());
|
||||
}
|
||||
|
||||
Environment BuildConfiguration::baseEnvironment() const
|
||||
@@ -248,15 +193,23 @@ void BuildConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::
|
||||
emit environmentChanged();
|
||||
}
|
||||
|
||||
void BuildConfiguration::cloneSteps(BuildConfiguration *source)
|
||||
{
|
||||
qDeleteAll(m_stepLists);
|
||||
m_stepLists.clear();
|
||||
foreach (BuildStepList *bsl, source->m_stepLists) {
|
||||
BuildStepList *newBsl = new BuildStepList(this, bsl);
|
||||
m_stepLists.append(newBsl);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
// IBuildConfigurationFactory
|
||||
///
|
||||
|
||||
IBuildConfigurationFactory::IBuildConfigurationFactory(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
IBuildConfigurationFactory::~IBuildConfigurationFactory()
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
Reference in New Issue
Block a user