Commit 1062c0ad authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Improve save/restore of buildsteps

 * Inspect the BuildStep::Type enum for key names in fromMap/toMap

Reviewed-by: dt
parent 8ccbd0ec
......@@ -35,6 +35,8 @@
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/buildmanager.h>
#include <QtCore/QMetaEnum>
#include <QtCore/QMetaObject>
#include <QtCore/QProcess>
using namespace ProjectExplorer;
......@@ -59,10 +61,8 @@ IBuildStepFactory *findRestoreFactory(BuildConfiguration *parent, BuildStep::Typ
return 0;
}
const char * const BUILD_STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.BuildStepsCount");
const char * const BUILD_STEPS_PREFIX("ProjectExplorer.BuildConfiguration.BuildStep.");
const char * const CLEAN_STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.CleanStepsCount");
const char * const CLEAN_STEPS_PREFIX("ProjectExplorer.BuildConfiguration.CleanStep.");
const char * const STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.%1StepsCount");
const char * const STEPS_PREFIX("ProjectExplorer.BuildConfiguration.%1Step.");
const char * const CLEAR_SYSTEM_ENVIRONMENT_KEY("ProjectExplorer.BuildConfiguration.ClearSystemEnvironment");
const char * const USER_ENVIRONMENT_CHANGES_KEY("ProjectExplorer.BuildConfiguration.UserEnvironmentChanges");
......@@ -95,12 +95,15 @@ BuildConfiguration::~BuildConfiguration()
QVariantMap BuildConfiguration::toMap() const
{
QVariantMap map(ProjectConfiguration::toMap());
map.insert(QLatin1String(BUILD_STEPS_COUNT_KEY), m_steps[BuildStep::Build].count());
for (int i = 0; i < m_steps[BuildStep::Build].count(); ++i)
map.insert(QString::fromLatin1(BUILD_STEPS_PREFIX) + QString::number(i), m_steps[BuildStep::Build].at(i)->toMap());
map.insert(QLatin1String(CLEAN_STEPS_COUNT_KEY), m_steps[BuildStep::Clean].count());
for (int i = 0; i < m_steps[BuildStep::Clean].count(); ++i)
map.insert(QString::fromLatin1(CLEAN_STEPS_PREFIX) + QString::number(i), m_steps[BuildStep::Clean].at(i)->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));
......@@ -127,48 +130,28 @@ bool BuildConfiguration::fromMap(const QVariantMap &map)
if (!ProjectConfiguration::fromMap(map))
return false;
int maxI(map.value(QLatin1String(BUILD_STEPS_COUNT_KEY), 0).toInt());
if (maxI < 0)
maxI = 0;
for (int i = 0; i < maxI; ++i) {
QVariantMap bsData(map.value(QString::fromLatin1(BUILD_STEPS_PREFIX) + QString::number(i)).toMap());
if (bsData.isEmpty()) {
qWarning() << "No buildstep data found (continuing).";
continue;
}
IBuildStepFactory *factory(findRestoreFactory(this, BuildStep::Build, bsData));
if (!factory) {
qWarning() << "No factory for buildstep found (continuing).";
continue;
}
BuildStep *bs(factory->restore(this, BuildStep::Build, bsData));
if (!bs) {
qWarning() << "Restoration of buildstep failed (continuing).";
continue;
}
insertStep(BuildStep::Build, m_steps[BuildStep::Build].count(), bs);
}
maxI = map.value(QLatin1String(CLEAN_STEPS_COUNT_KEY), 0).toInt();
if (maxI < 0)
maxI = 0;
for (int i = 0; i < maxI; ++i) {
QVariantMap bsData(map.value(QString::fromLatin1(CLEAN_STEPS_PREFIX) + QString::number(i)).toMap());
if (bsData.isEmpty()) {
qWarning() << "No cleanstep data found for (continuing).";
continue;
}
IBuildStepFactory *factory(findRestoreFactory(this, BuildStep::Clean, bsData));
if (!factory) {
qWarning() << "No factory for cleanstep found (continuing).";
continue;
}
BuildStep *bs(factory->restore(this, BuildStep::Clean, bsData));
if (!bs) {
qWarning() << "Restoration of cleanstep failed (continuing).";
continue;
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);
}
insertStep(BuildStep::Clean, m_steps[BuildStep::Clean].count(), bs);
}
m_clearSystemEnvironment = map.value(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY)).toBool();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment