Commit 89416bed authored by con's avatar con

Support an "experimental" attribute in plugin specs.

A flag that marks a plugin to be experimental, that should not be loaded
by default.
parent 3319797d
......@@ -48,6 +48,7 @@
#endif
static const char * const C_IGNORED_PLUGINS = "Plugins/Ignored";
static const char * const C_FORCEENABLED_PLUGINS = "Plugins/ForceEnabled";
typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet;
......@@ -624,12 +625,16 @@ void PluginManagerPrivate::writeSettings()
QLatin1String("Nokia"), QLatin1String("QtCreator"));
QStringList tempDisabledPlugins;
QStringList tempForceEnabledPlugins;
foreach(PluginSpec *spec, pluginSpecs) {
if (!spec->isEnabled())
if (!spec->isExperimental() && !spec->isEnabled())
tempDisabledPlugins.append(spec->name());
if (spec->isExperimental() && spec->isEnabled())
tempForceEnabledPlugins.append(spec->name());
}
settings.setValue(QLatin1String(C_IGNORED_PLUGINS), tempDisabledPlugins);
settings.setValue(QLatin1String(C_FORCEENABLED_PLUGINS), tempForceEnabledPlugins);
}
void PluginManagerPrivate::loadSettings()
......@@ -638,6 +643,7 @@ void PluginManagerPrivate::loadSettings()
QLatin1String("Nokia"), QLatin1String("QtCreator"));
disabledPlugins = settings.value(QLatin1String(C_IGNORED_PLUGINS)).toStringList();
forceEnabledPlugins = settings.value(QLatin1String(C_FORCEENABLED_PLUGINS)).toStringList();
}
void PluginManagerPrivate::stopAll()
......@@ -883,7 +889,9 @@ void PluginManagerPrivate::readPluginPaths()
collection = new PluginCollection(spec->category());
pluginCategories.insert(spec->category(), collection);
}
if (disabledPlugins.contains(spec->name()))
if (spec->isExperimental() && forceEnabledPlugins.contains(spec->name()))
spec->setEnabled(true);
if (!spec->isExperimental() && disabledPlugins.contains(spec->name()))
spec->setEnabled(false);
collection->addPlugin(spec);
......
......@@ -80,6 +80,7 @@ public:
QString extension;
QList<QObject *> allObjects; // ### make this a QList<QPointer<QObject> > > ?
QStringList disabledPlugins;
QStringList forceEnabledPlugins;
QStringList arguments;
QScopedPointer<QTime> m_profileTimer;
......
......@@ -237,8 +237,17 @@ QString PluginSpec::category() const
}
/*!
\fn bool PluginSpec::loadOnStartup() const
True if the plugin is loaded at startup. True by default - the user can change it from the Plugin settings.
\fn bool PluginSpec::isExperimental() const
Returns if the plugin has its experimental flag set.
*/
bool PluginSpec::isExperimental() const
{
return d->experimental;
}
/*!
\fn bool PluginSpec::isEnabled() const
Returns if the plugin is loaded at startup. True by default - the user can change it from the Plugin settings.
*/
bool PluginSpec::isEnabled() const
{
......@@ -416,6 +425,7 @@ namespace {
const char * const PLUGIN_NAME = "name";
const char * const PLUGIN_VERSION = "version";
const char * const PLUGIN_COMPATVERSION = "compatVersion";
const char * const PLUGIN_EXPERIMENTAL = "experimental";
const char * const VENDOR = "vendor";
const char * const COPYRIGHT = "copyright";
const char * const LICENSE = "license";
......@@ -569,6 +579,14 @@ void PluginSpecPrivate::readPluginSpec(QXmlStreamReader &reader)
} else if (compatVersion.isEmpty()) {
compatVersion = version;
}
QString experimentalString = reader.attributes().value(PLUGIN_EXPERIMENTAL).toString();
experimental = (experimentalString.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0);
if (!experimentalString.isEmpty() && !experimental
&& experimentalString.compare(QLatin1String("false"), Qt::CaseInsensitive) != 0) {
reader.raiseError(msgInvalidFormat(PLUGIN_EXPERIMENTAL));
return;
}
enabled = !experimental;
while (!reader.atEnd()) {
reader.readNext();
switch (reader.tokenType()) {
......
......@@ -79,6 +79,7 @@ public:
QString description() const;
QString url() const;
QString category() const;
bool isExperimental() const;
bool isEnabled() const;
// true if loading was not done due to user unselecting this plugin or its dependencies
bool isDisabledByDependency() const;
......
......@@ -62,6 +62,7 @@ public:
QString name;
QString version;
QString compatVersion;
bool experimental;
QString vendor;
QString copyright;
QString license;
......
<plugin name="MyPlugin" version="2.2.3_9" compatVersion="2.0.0" experimental="true">
</plugin>
......@@ -49,6 +49,7 @@ private slots:
void isValidVersion();
void versionCompare();
void provides();
void experimental();
void locationAndPath();
void resolveDependencies();
void loadLibrary();
......@@ -67,11 +68,13 @@ void tst_PluginSpec::read()
QCOMPARE(spec.name, QString("test"));
QCOMPARE(spec.version, QString("1.0.1"));
QCOMPARE(spec.compatVersion, QString("1.0.0"));
QCOMPARE(spec.vendor, QString("Trolltech"));
QCOMPARE(spec.copyright, QString("(C) 2007 Trolltech ASA"));
QCOMPARE(spec.experimental, false);
QCOMPARE(spec.enabled, true);
QCOMPARE(spec.vendor, QString("Nokia Corporation"));
QCOMPARE(spec.copyright, QString("(C) 2007 Nokia Corporation"));
QCOMPARE(spec.license, QString("This is a default license bla\nblubbblubb\nend of terms"));
QCOMPARE(spec.description, QString("This plugin is just a test.\n it demonstrates the great use of the plugin spec."));
QCOMPARE(spec.url, QString("http://www.trolltech.com"));
QCOMPARE(spec.url, QString("http://qt.noki.com"));
PluginDependency dep1;
dep1.name = QString("SomeOtherPlugin");
dep1.version = QString("2.3.0_2");
......@@ -178,6 +181,14 @@ void tst_PluginSpec::provides()
QVERIFY(spec.provides("MyPlugin", "2"));
}
void tst_PluginSpec::experimental()
{
Internal::PluginSpecPrivate spec(0);
QVERIFY(spec.read("testspecs/simplespec_experimental.xml"));
QCOMPARE(spec.experimental, true);
QCOMPARE(spec.enabled, false);
}
void tst_PluginSpec::locationAndPath()
{
Internal::PluginSpecPrivate spec(0);
......@@ -194,23 +205,23 @@ void tst_PluginSpec::locationAndPath()
void tst_PluginSpec::resolveDependencies()
{
QSet<PluginSpec *> specs;
QList<PluginSpec *> specs;
PluginSpec *spec1 = Internal::PluginManagerPrivate::createSpec();
specs.insert(spec1);
specs.append(spec1);
Internal::PluginSpecPrivate *spec1Priv = Internal::PluginManagerPrivate::privateSpec(spec1);
spec1Priv->read("testdependencies/spec1.xml");
PluginSpec *spec2 = Internal::PluginManagerPrivate::createSpec();
specs.insert(spec2);
specs.append(spec2);
Internal::PluginManagerPrivate::privateSpec(spec2)->read("testdependencies/spec2.xml");
PluginSpec *spec3 = Internal::PluginManagerPrivate::createSpec();
specs.insert(spec3);
specs.append(spec3);
Internal::PluginManagerPrivate::privateSpec(spec3)->read("testdependencies/spec3.xml");
PluginSpec *spec4 = Internal::PluginManagerPrivate::createSpec();
specs.insert(spec4);
specs.append(spec4);
Internal::PluginSpecPrivate *spec4Priv = Internal::PluginManagerPrivate::privateSpec(spec4);
spec4Priv->read("testdependencies/spec4.xml");
PluginSpec *spec5 = Internal::PluginManagerPrivate::createSpec();
specs.insert(spec5);
specs.append(spec5);
Internal::PluginManagerPrivate::privateSpec(spec5)->read("testdependencies/spec5.xml");
QVERIFY(spec1Priv->resolveDependencies(specs));
QCOMPARE(spec1Priv->dependencySpecs.size(), 2);
......@@ -228,7 +239,7 @@ void tst_PluginSpec::loadLibrary()
Internal::PluginSpecPrivate *spec = Internal::PluginManagerPrivate::privateSpec(ps);
PluginManager *manager = new PluginManager();
QVERIFY(spec->read("testplugin/testplugin.xml"));
QVERIFY(spec->resolveDependencies(QSet<PluginSpec *>()));
QVERIFY(spec->resolveDependencies(QList<PluginSpec *>()));
QVERIFY(spec->loadLibrary());
QVERIFY(qobject_cast<MyPlugin::MyPluginImpl*>(spec->plugin) != 0);
QCOMPARE(spec->state, PluginSpec::Loaded);
......@@ -243,7 +254,7 @@ void tst_PluginSpec::initializePlugin()
Internal::PluginSpecPrivate spec(0);
MyPlugin::MyPluginImpl *impl;
QVERIFY(spec.read("testplugin/testplugin.xml"));
QVERIFY(spec.resolveDependencies(QSet<PluginSpec *>()));
QVERIFY(spec.resolveDependencies(QList<PluginSpec *>()));
QVERIFY(spec.loadLibrary());
impl = qobject_cast<MyPlugin::MyPluginImpl*>(spec.plugin);
QVERIFY(impl != 0);
......@@ -259,7 +270,7 @@ void tst_PluginSpec::initializeExtensions()
Internal::PluginSpecPrivate spec(0);
MyPlugin::MyPluginImpl *impl;
QVERIFY(spec.read("testplugin/testplugin.xml"));
QVERIFY(spec.resolveDependencies(QSet<PluginSpec *>()));
QVERIFY(spec.resolveDependencies(QList<PluginSpec *>()));
QVERIFY(spec.loadLibrary());
impl = qobject_cast<MyPlugin::MyPluginImpl*>(spec.plugin);
QVERIFY(impl != 0);
......
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