Commit b3f13f96 authored by hjk's avatar hjk

ProjectExplorer: Move RunWorker priority handling to worker selection

This fixes the temporary regression introduced by 5a848aa1. After
having RunWorker registration in RunControl and RunConfigurationAspect
registration in RunConfiguration, this was effectively the only
remaining code in IRunControlFactory, so this can go now.

Change-Id: I38b51bb00058b90d30f0260660b040f788920008
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent 1646510f
......@@ -1995,17 +1995,6 @@ static RunControlFactory findRunControlFactory(RunConfiguration *config, Core::I
};
}
IRunControlFactory *runControlFactory = ExtensionSystem::PluginManager::getObject<IRunControlFactory>(
[&config, &mode](IRunControlFactory *factory) {
return factory->canRun(config, mode);
});
if (runControlFactory) {
return [runControlFactory](RunConfiguration *rc, Id runMode, QString *errorMessage) {
return runControlFactory->create(rc, runMode, errorMessage);
};
}
return {};
}
......
......@@ -48,7 +48,6 @@ namespace Utils { class ProcessHandle; }
namespace ProjectExplorer {
class RunControl;
class RunConfiguration;
class IRunControlFactory;
class Project;
class Node;
class FolderNode;
......
......@@ -367,7 +367,7 @@ IRunConfigurationAspect *RunConfiguration::extraAspect(Core::Id id) const
A target specific \l RunConfiguration implementation can specify
what information it considers necessary to execute a process
on the target. Target specific) \n IRunControlFactory implementation
on the target. Target specific) \n RunWorker implementation
can use that information either unmodified or tweak it or ignore
it when setting up a RunControl.
......@@ -473,29 +473,6 @@ QList<IRunConfigurationFactory *> IRunConfigurationFactory::find(Target *parent)
});
}
/*!
\class ProjectExplorer::IRunControlFactory
\brief The IRunControlFactory class creates RunControl objects matching a
run configuration.
*/
/*!
\fn RunConfigWidget *ProjectExplorer::IRunConfigurationAspect::createConfigurationWidget()
Returns a widget used to configure this runner. Ownership is transferred to
the caller.
Returns null if @p \a runConfiguration is not suitable for RunControls from this
factory, or no user-accessible
configuration is required.
*/
IRunControlFactory::IRunControlFactory(QObject *parent)
: QObject(parent)
{
}
using WorkerFactories = std::vector<RunControl::WorkerFactory>;
static WorkerFactories &theWorkerFactories()
......@@ -513,37 +490,6 @@ bool RunControl::WorkerFactory::canRun(RunConfiguration *runConfiguration, Core:
return constraint(runConfiguration);
}
bool IRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const
{
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
if (factory.canRun(runConfiguration, runMode))
return true;
};
return false;
}
RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id runMode, QString *)
{
WorkerFactories candidates;
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
if (factory.canRun(runConfiguration, runMode))
candidates.push_back(factory);
}
if (candidates.empty())
return nullptr;
RunControl::WorkerFactory bestFactory = *candidates.begin();
for (const RunControl::WorkerFactory &factory : candidates) {
if (factory.priority > bestFactory.priority)
bestFactory = factory;
}
auto runControl = new RunControl(runConfiguration, runMode);
bestFactory.producer(runControl);
return runControl;
}
/*!
\class ProjectExplorer::RunControl
\brief The RunControl class instances represent one item that is run.
......@@ -558,18 +504,6 @@ RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core:
*/
const char PRIORITY_KEY[] = "RunControlFactoryPriority";
int ProjectExplorer::IRunControlFactory::priority() const
{
return property(PRIORITY_KEY).toInt(); // 0 by default.
}
void IRunControlFactory::setPriority(int priority)
{
setProperty(PRIORITY_KEY, priority);
}
namespace Internal {
enum class RunWorkerState
......@@ -797,12 +731,22 @@ RunWorker *RunControl::createWorker(Core::Id id)
RunControl::WorkerCreator RunControl::producer(RunConfiguration *runConfiguration, Core::Id runMode)
{
for (const auto &factory : theWorkerFactories()) {
if (factory.runMode == runMode
&& (!factory.constraint || factory.constraint(runConfiguration)))
return factory.producer;
WorkerFactories candidates;
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
if (factory.canRun(runConfiguration, runMode))
candidates.push_back(factory);
}
if (candidates.empty())
return {};
RunControl::WorkerFactory bestFactory = *candidates.begin();
for (const RunControl::WorkerFactory &factory : candidates) {
if (factory.priority > bestFactory.priority)
bestFactory = factory;
}
return {};
return bestFactory.producer;
}
void RunControl::addWorkerFactory(const RunControl::WorkerFactory &workerFactory)
......
......@@ -301,20 +301,6 @@ private:
virtual RunConfiguration *doRestore(Target *parent, const QVariantMap &map) = 0;
};
class PROJECTEXPLORER_EXPORT IRunControlFactory : public QObject
{
Q_OBJECT
public:
explicit IRunControlFactory(QObject *parent = nullptr);
virtual bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const;
virtual RunControl *create(RunConfiguration *runConfiguration, Core::Id runMode, QString *errorMessage);
int priority() const;
protected:
void setPriority(int priority); // Higher values will be preferred.
};
class PROJECTEXPLORER_EXPORT RunConfigWidget : public QWidget
{
Q_OBJECT
......
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