forked from qt-creator/qt-creator
ExtensionSystem: Use Qt 5 plugin metadata instead of .pluginspec files
Change-Id: I2b2c704260c613985a4bda179658ec1f8879e70f Reviewed-by: Christian Kandeler <christian.kandeler@digia.com> Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -32,6 +32,8 @@
|
||||
#include <extensionsystem/pluginmanager_p.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
#include <QMetaObject>
|
||||
#include <QtTest>
|
||||
@@ -39,6 +41,33 @@
|
||||
|
||||
using namespace ExtensionSystem;
|
||||
|
||||
static QJsonObject metaData(const QString &fileName)
|
||||
{
|
||||
QFile f(fileName);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Could not open" << fileName;
|
||||
return QJsonObject();
|
||||
}
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(f.readAll(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Could not parse" << fileName << ":" << error.errorString();
|
||||
return QJsonObject();
|
||||
}
|
||||
return doc.object();
|
||||
}
|
||||
|
||||
static QString libraryName(const QString &basename)
|
||||
{
|
||||
#if defined(Q_OS_OSX)
|
||||
return QLatin1String("lib") + basename + QLatin1String("_debug.dylib");
|
||||
#elif defined(Q_OS_UNIX)
|
||||
return QLatin1String("lib") + basename + QLatin1String(".so");
|
||||
#else
|
||||
return basename + QLatin1String("d.dll");
|
||||
#endif
|
||||
}
|
||||
|
||||
class tst_PluginSpec : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -56,19 +85,36 @@ private slots:
|
||||
void initializePlugin();
|
||||
void initializeExtensions();
|
||||
void init();
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
PluginManager *pm;
|
||||
};
|
||||
|
||||
void tst_PluginSpec::init()
|
||||
{
|
||||
QLoggingCategory::setFilterRules(QLatin1String("qtc.*.debug=false"));
|
||||
QVERIFY(QDir::setCurrent(QLatin1String(PLUGINSPEC_DIR)));
|
||||
}
|
||||
|
||||
void tst_PluginSpec::initTestCase()
|
||||
{
|
||||
pm = new PluginManager;
|
||||
pm->setPluginIID(QLatin1String("plugin"));
|
||||
}
|
||||
|
||||
void tst_PluginSpec::cleanupTestCase()
|
||||
{
|
||||
delete pm;
|
||||
pm = 0;
|
||||
}
|
||||
|
||||
void tst_PluginSpec::read()
|
||||
{
|
||||
Internal::PluginSpecPrivate spec(0);
|
||||
QCOMPARE(spec.state, PluginSpec::Invalid);
|
||||
QVERIFY(spec.read("testspecs/spec1.xml"));
|
||||
QCOMPARE(spec.state, PluginSpec::Read);
|
||||
QVERIFY(spec.readMetaData(metaData("testspecs/spec1.json")));
|
||||
QVERIFY(!spec.hasError);
|
||||
QVERIFY(spec.errorString.isEmpty());
|
||||
QCOMPARE(spec.name, QString("test"));
|
||||
@@ -81,7 +127,7 @@ void tst_PluginSpec::read()
|
||||
QCOMPARE(spec.copyright, QString("(C) 2014 Digia Plc"));
|
||||
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://qt.digi.com"));
|
||||
QCOMPARE(spec.url, QString("http://qt.digia.com"));
|
||||
PluginDependency dep1;
|
||||
dep1.name = QString("SomeOtherPlugin");
|
||||
dep1.version = QString("2.3.0_2");
|
||||
@@ -92,7 +138,7 @@ void tst_PluginSpec::read()
|
||||
|
||||
// test missing compatVersion behavior
|
||||
// and 'required' attribute
|
||||
QVERIFY(spec.read("testspecs/spec2.xml"));
|
||||
QVERIFY(spec.readMetaData(metaData("testspecs/spec2.json")));
|
||||
QCOMPARE(spec.version, QString("3.1.4_10"));
|
||||
QCOMPARE(spec.compatVersion, QString("3.1.4_10"));
|
||||
QCOMPARE(spec.required, true);
|
||||
@@ -102,27 +148,23 @@ void tst_PluginSpec::readError()
|
||||
{
|
||||
Internal::PluginSpecPrivate spec(0);
|
||||
QCOMPARE(spec.state, PluginSpec::Invalid);
|
||||
QVERIFY(!spec.read("non-existing-file.xml"));
|
||||
QVERIFY(!spec.readMetaData(metaData("non-existing-file.json")));
|
||||
QCOMPARE(spec.state, PluginSpec::Invalid);
|
||||
QVERIFY(!spec.hasError);
|
||||
QVERIFY(spec.errorString.isEmpty());
|
||||
QVERIFY(spec.readMetaData(metaData("testspecs/spec_wrong2.json")));
|
||||
QCOMPARE(spec.state, PluginSpec::Invalid);
|
||||
QVERIFY(spec.hasError);
|
||||
QVERIFY(!spec.errorString.isEmpty());
|
||||
QVERIFY(!spec.read("testspecs/spec_wrong1.xml"));
|
||||
QVERIFY(spec.readMetaData(metaData("testspecs/spec_wrong3.json")));
|
||||
QCOMPARE(spec.state, PluginSpec::Invalid);
|
||||
QVERIFY(spec.hasError);
|
||||
QVERIFY(!spec.errorString.isEmpty());
|
||||
QVERIFY(!spec.read("testspecs/spec_wrong2.xml"));
|
||||
QVERIFY(spec.readMetaData(metaData("testspecs/spec_wrong4.json")));
|
||||
QCOMPARE(spec.state, PluginSpec::Invalid);
|
||||
QVERIFY(spec.hasError);
|
||||
QVERIFY(!spec.errorString.isEmpty());
|
||||
QVERIFY(!spec.read("testspecs/spec_wrong3.xml"));
|
||||
QCOMPARE(spec.state, PluginSpec::Invalid);
|
||||
QVERIFY(spec.hasError);
|
||||
QVERIFY(!spec.errorString.isEmpty());
|
||||
QVERIFY(!spec.read("testspecs/spec_wrong4.xml"));
|
||||
QCOMPARE(spec.state, PluginSpec::Invalid);
|
||||
QVERIFY(spec.hasError);
|
||||
QVERIFY(!spec.errorString.isEmpty());
|
||||
QVERIFY(!spec.read("testspecs/spec_wrong5.xml"));
|
||||
QVERIFY(spec.readMetaData(metaData("testspecs/spec_wrong5.json")));
|
||||
QCOMPARE(spec.state, PluginSpec::Invalid);
|
||||
QVERIFY(spec.hasError);
|
||||
QVERIFY(!spec.errorString.isEmpty());
|
||||
@@ -168,7 +210,7 @@ void tst_PluginSpec::versionCompare()
|
||||
void tst_PluginSpec::provides()
|
||||
{
|
||||
Internal::PluginSpecPrivate spec(0);
|
||||
QVERIFY(spec.read("testspecs/simplespec.xml"));
|
||||
QVERIFY(spec.readMetaData(metaData("testspecs/simplespec.json")));
|
||||
QVERIFY(!spec.provides("SomeOtherPlugin", "2.2.3_9"));
|
||||
QVERIFY(!spec.provides("MyPlugin", "2.2.3_10"));
|
||||
QVERIFY(!spec.provides("MyPlugin", "2.2.4"));
|
||||
@@ -193,7 +235,7 @@ void tst_PluginSpec::provides()
|
||||
void tst_PluginSpec::experimental()
|
||||
{
|
||||
Internal::PluginSpecPrivate spec(0);
|
||||
QVERIFY(spec.read("testspecs/simplespec_experimental.xml"));
|
||||
QVERIFY(spec.readMetaData(metaData("testspecs/simplespec_experimental.json")));
|
||||
QCOMPARE(spec.experimental, true);
|
||||
QCOMPARE(spec.enabledInSettings, false);
|
||||
}
|
||||
@@ -201,15 +243,9 @@ void tst_PluginSpec::experimental()
|
||||
void tst_PluginSpec::locationAndPath()
|
||||
{
|
||||
Internal::PluginSpecPrivate spec(0);
|
||||
QVERIFY(spec.read("testspecs/simplespec.xml"));
|
||||
QCOMPARE(spec.location, QString(QDir::currentPath()+"/testspecs"));
|
||||
QCOMPARE(spec.filePath, QString(QDir::currentPath()+"/testspecs/simplespec.xml"));
|
||||
QVERIFY(spec.read("testdir/../testspecs/simplespec.xml"));
|
||||
QCOMPARE(spec.location, QString(QDir::currentPath()+"/testspecs"));
|
||||
QCOMPARE(spec.filePath, QString(QDir::currentPath()+"/testspecs/simplespec.xml"));
|
||||
QVERIFY(spec.read("testdir/spec.xml"));
|
||||
QCOMPARE(spec.location, QString(QDir::currentPath()+"/testdir"));
|
||||
QCOMPARE(spec.filePath, QString(QDir::currentPath()+"/testdir/spec.xml"));
|
||||
QVERIFY(spec.read(QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/") + libraryName(QLatin1String("test"))));
|
||||
QCOMPARE(spec.location, QString(QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin")));
|
||||
QCOMPARE(spec.filePath, QString(QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/") + libraryName(QLatin1String("test"))));
|
||||
}
|
||||
|
||||
void tst_PluginSpec::resolveDependencies()
|
||||
@@ -218,20 +254,33 @@ void tst_PluginSpec::resolveDependencies()
|
||||
PluginSpec *spec1 = Internal::PluginManagerPrivate::createSpec();
|
||||
specs.append(spec1);
|
||||
Internal::PluginSpecPrivate *spec1Priv = Internal::PluginManagerPrivate::privateSpec(spec1);
|
||||
spec1Priv->read("testdependencies/spec1.xml");
|
||||
spec1Priv->readMetaData(metaData("testdependencies/spec1.json"));
|
||||
spec1Priv->state = PluginSpec::Read; // fake read state for plugin resolving
|
||||
|
||||
PluginSpec *spec2 = Internal::PluginManagerPrivate::createSpec();
|
||||
specs.append(spec2);
|
||||
Internal::PluginManagerPrivate::privateSpec(spec2)->read("testdependencies/spec2.xml");
|
||||
Internal::PluginSpecPrivate *spec2Priv = Internal::PluginManagerPrivate::privateSpec(spec2);
|
||||
spec2Priv->readMetaData(metaData("testdependencies/spec2.json"));
|
||||
spec2Priv->state = PluginSpec::Read; // fake read state for plugin resolving
|
||||
|
||||
PluginSpec *spec3 = Internal::PluginManagerPrivate::createSpec();
|
||||
specs.append(spec3);
|
||||
Internal::PluginManagerPrivate::privateSpec(spec3)->read("testdependencies/spec3.xml");
|
||||
Internal::PluginSpecPrivate *spec3Priv = Internal::PluginManagerPrivate::privateSpec(spec3);
|
||||
spec3Priv->readMetaData(metaData("testdependencies/spec3.json"));
|
||||
spec3Priv->state = PluginSpec::Read; // fake read state for plugin resolving
|
||||
|
||||
PluginSpec *spec4 = Internal::PluginManagerPrivate::createSpec();
|
||||
specs.append(spec4);
|
||||
Internal::PluginSpecPrivate *spec4Priv = Internal::PluginManagerPrivate::privateSpec(spec4);
|
||||
spec4Priv->read("testdependencies/spec4.xml");
|
||||
spec4Priv->readMetaData(metaData("testdependencies/spec4.json"));
|
||||
spec4Priv->state = PluginSpec::Read; // fake read state for plugin resolving
|
||||
|
||||
PluginSpec *spec5 = Internal::PluginManagerPrivate::createSpec();
|
||||
specs.append(spec5);
|
||||
Internal::PluginManagerPrivate::privateSpec(spec5)->read("testdependencies/spec5.xml");
|
||||
Internal::PluginSpecPrivate *spec5Priv = Internal::PluginManagerPrivate::privateSpec(spec5);
|
||||
spec5Priv->readMetaData(metaData("testdependencies/spec5.json"));
|
||||
spec5Priv->state = PluginSpec::Read; // fake read state for plugin resolving
|
||||
|
||||
QVERIFY(spec1Priv->resolveDependencies(specs));
|
||||
QCOMPARE(spec1Priv->dependencySpecs.size(), 2);
|
||||
QVERIFY(!spec1Priv->dependencySpecs.key(spec2).name.isEmpty());
|
||||
@@ -246,8 +295,7 @@ void tst_PluginSpec::loadLibrary()
|
||||
{
|
||||
PluginSpec *ps = Internal::PluginManagerPrivate::createSpec();
|
||||
Internal::PluginSpecPrivate *spec = Internal::PluginManagerPrivate::privateSpec(ps);
|
||||
PluginManager *manager = new PluginManager();
|
||||
QVERIFY(spec->read("testplugin/testplugin.xml"));
|
||||
QVERIFY(spec->read(QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/") + libraryName(QLatin1String("test"))));
|
||||
QVERIFY(spec->resolveDependencies(QList<PluginSpec *>()));
|
||||
QVERIFY2(spec->loadLibrary(), qPrintable(spec->errorString));
|
||||
QVERIFY(spec->plugin != 0);
|
||||
@@ -255,14 +303,13 @@ void tst_PluginSpec::loadLibrary()
|
||||
QCOMPARE(spec->state, PluginSpec::Loaded);
|
||||
QVERIFY(!spec->hasError);
|
||||
QCOMPARE(spec->plugin->pluginSpec(), ps);
|
||||
delete manager;
|
||||
delete ps;
|
||||
}
|
||||
|
||||
void tst_PluginSpec::initializePlugin()
|
||||
{
|
||||
Internal::PluginSpecPrivate spec(0);
|
||||
QVERIFY(spec.read("testplugin/testplugin.xml"));
|
||||
QVERIFY(spec.read(QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/") + libraryName(QLatin1String("test"))));
|
||||
QVERIFY(spec.resolveDependencies(QList<PluginSpec *>()));
|
||||
QVERIFY2(spec.loadLibrary(), qPrintable(spec.errorString));
|
||||
bool isInitialized;
|
||||
@@ -280,7 +327,7 @@ void tst_PluginSpec::initializePlugin()
|
||||
void tst_PluginSpec::initializeExtensions()
|
||||
{
|
||||
Internal::PluginSpecPrivate spec(0);
|
||||
QVERIFY(spec.read("testplugin/testplugin.xml"));
|
||||
QVERIFY(spec.read(QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/") + libraryName(QLatin1String("test"))));
|
||||
QVERIFY(spec.resolveDependencies(QList<PluginSpec *>()));
|
||||
QVERIFY2(spec.loadLibrary(), qPrintable(spec.errorString));
|
||||
bool isExtensionsInitialized;
|
||||
|
||||
Reference in New Issue
Block a user