Commit d3aaa769 authored by Daniel Teske's avatar Daniel Teske

PluginManager: Implement -load %plugin% option

This loads a plugin that is disabled by default.

Change-Id: Ibbc9849c417519904fe1e69a46f93a7cc1c7edc8
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@digia.com>
parent 16b60798
......@@ -36,6 +36,7 @@ using namespace ExtensionSystem::Internal;
static const char END_OF_OPTIONS[] = "--";
const char *OptionsParser::NO_LOAD_OPTION = "-noload";
const char *OptionsParser::LOAD_OPTION = "-load";
const char *OptionsParser::TEST_OPTION = "-test";
const char *OptionsParser::PROFILE_OPTION = "-profile";
......@@ -68,6 +69,8 @@ bool OptionsParser::parse()
break;
if (checkForEndOfOptions())
break;
if (checkForLoadOption())
continue;
if (checkForNoLoadOption())
continue;
if (checkForProfilingOption())
......@@ -137,6 +140,26 @@ bool OptionsParser::checkForTestOption()
return true;
}
bool OptionsParser::checkForLoadOption()
{
if (m_currentArg != QLatin1String(LOAD_OPTION))
return false;
if (nextToken(RequiredToken)) {
PluginSpec *spec = m_pmPrivate->pluginByName(m_currentArg);
if (!spec) {
if (m_errorString)
*m_errorString = QCoreApplication::translate("PluginManager",
"The plugin '%1' does not exist.")
.arg(m_currentArg);
m_hasError = true;
} else {
spec->setForceEnabled(true);
m_isDependencyRefreshNeeded = true;
}
}
return true;
}
bool OptionsParser::checkForNoLoadOption()
{
if (m_currentArg != QLatin1String(NO_LOAD_OPTION))
......@@ -149,7 +172,7 @@ bool OptionsParser::checkForNoLoadOption()
"The plugin '%1' does not exist.").arg(m_currentArg);
m_hasError = true;
} else {
m_pmPrivate->disablePluginIndirectly(spec);
spec->setForceDisabled(true);
m_isDependencyRefreshNeeded = true;
}
}
......
......@@ -50,12 +50,14 @@ public:
bool parse();
static const char *NO_LOAD_OPTION;
static const char *LOAD_OPTION;
static const char *TEST_OPTION;
static const char *PROFILE_OPTION;
private:
// return value indicates if the option was processed
// it doesn't indicate success (--> m_hasError)
bool checkForEndOfOptions();
bool checkForLoadOption();
bool checkForNoLoadOption();
bool checkForTestOption();
bool checkForAppOption();
......
......@@ -609,6 +609,9 @@ static inline void formatOption(QTextStream &str,
void PluginManager::formatOptions(QTextStream &str, int optionIndentation, int descriptionIndentation)
{
formatOption(str, QLatin1String(OptionsParser::LOAD_OPTION),
QLatin1String("plugin"), QLatin1String("Load <plugin>"),
optionIndentation, descriptionIndentation);
formatOption(str, QLatin1String(OptionsParser::NO_LOAD_OPTION),
QLatin1String("plugin"), QLatin1String("Do not load <plugin>"),
optionIndentation, descriptionIndentation);
......@@ -1120,7 +1123,7 @@ void PluginManagerPrivate::loadPlugin(PluginSpec *spec, PluginSpec::State destSt
return;
// don't load disabled plugins.
if ((spec->isDisabledIndirectly() || !spec->isEnabledInSettings()) && destState == PluginSpec::Loaded)
if (!spec->isEffectivelyEnabled() && destState == PluginSpec::Loaded)
return;
switch (destState) {
......@@ -1249,6 +1252,11 @@ void PluginManagerPrivate::resolveDependencies()
foreach (PluginSpec *spec, pluginSpecs) {
spec->d->resolveDependencies(pluginSpecs);
}
// Reset disabledIndirectly flag
foreach (PluginSpec *spec, loadQueue())
spec->d->disabledIndirectly = false;
foreach (PluginSpec *spec, loadQueue()) {
spec->d->disableIndirectlyIfDependencyDisabled();
}
......
......@@ -294,16 +294,45 @@ bool PluginSpec::isEnabledInSettings() const
return d->enabledInSettings;
}
/*!
\fn bool PluginSpec::isEffectivelyEnabled() const
Returns if the plugin is loaded at startup.
\see PluginSpec::isEnabled
*/
bool PluginSpec::isEffectivelyEnabled() const
{
return !d->disabledIndirectly
&& (d->enabledInSettings || d->forceEnabled)
&& !d->forceDisabled;
}
/*!
\fn bool PluginSpec::isDisabledIndirectly() const
Returns true if loading was not done due to user unselecting this plugin or its dependencies,
or if command-line parameter -noload was used.
Returns true if loading was not done due to user unselecting this plugin or its dependencies.
*/
bool PluginSpec::isDisabledIndirectly() const
{
return d->disabledIndirectly;
}
/*!
\fn bool PluginSpec::isForceEnabled() const
Returns if the plugin is enabled via the -load option on the command line.
*/
bool PluginSpec::isForceEnabled() const
{
return d->forceEnabled;
}
/*!
\fn bool PluginSpec::isForceDisabled() const
Returns if the plugin is disabled via the -noload option on the command line.
*/
bool PluginSpec::isForceDisabled() const
{
return d->forceDisabled;
}
/*!
\fn QList<PluginDependency> PluginSpec::dependencies() const
The plugin dependencies. This is valid after the PluginSpec::Read state is reached.
......@@ -473,6 +502,8 @@ PluginSpecPrivate::PluginSpecPrivate(PluginSpec *spec)
disabledByDefault(false),
enabledInSettings(true),
disabledIndirectly(false),
forceEnabled(false),
forceDisabled(false),
plugin(0),
state(PluginSpec::Invalid),
hasError(false),
......@@ -544,6 +575,20 @@ void PluginSpec::setDisabledIndirectly(bool value)
d->disabledIndirectly = value;
}
void PluginSpec::setForceEnabled(bool value)
{
d->forceEnabled = value;
if (value)
d->forceDisabled = false;
}
void PluginSpec::setForceDisabled(bool value)
{
if (value)
d->forceEnabled = false;
d->forceDisabled = value;
}
/*!
\fn bool PluginSpecPrivate::reportError(const QString &err)
\internal
......@@ -903,7 +948,7 @@ void PluginSpecPrivate::disableIndirectlyIfDependencyDisabled()
if (it.key().type == PluginDependency::Optional)
continue;
PluginSpec *dependencySpec = it.value();
if (dependencySpec->isDisabledIndirectly() || !dependencySpec->isEnabledInSettings()) {
if (!dependencySpec->isEffectivelyEnabled()) {
disabledIndirectly = true;
break;
}
......
......@@ -93,7 +93,10 @@ public:
bool isExperimental() const;
bool isDisabledByDefault() const;
bool isEnabledInSettings() const;
bool isEffectivelyEnabled() const;
bool isDisabledIndirectly() const;
bool isForceEnabled() const;
bool isForceDisabled() const;
QList<PluginDependency> dependencies() const;
typedef QList<PluginArgumentDescription> PluginArgumentDescriptions;
......@@ -106,6 +109,8 @@ public:
void setEnabled(bool value);
void setDisabledByDefault(bool value);
void setDisabledIndirectly(bool value);
void setForceEnabled(bool value);
void setForceDisabled(bool value);
QStringList arguments() const;
void setArguments(const QStringList &arguments);
......
......@@ -75,6 +75,8 @@ public:
QList<PluginDependency> dependencies;
bool enabledInSettings;
bool disabledIndirectly;
bool forceEnabled;
bool forceDisabled;
QString location;
QString filePath;
......
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