aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-01-07 15:19:29 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-01-08 11:12:56 +0100
commit5cb8ca29c3815405d41d035f5f4ebb2af326a8ef (patch)
treea31bab609599cab55437c218775a20dae5677a3d
parentbf10bf0331cb3d26e7f5f0bc9333acea1077273e (diff)
Allow importing protected modules with different major versions
This allows QtQuick.Controls 1.x and 2.x imports to co-exist even if they are two different plugins with the same module directive. Change-Id: Idee302439e3c2fd6813ba2f41b69144fbae7902c Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/qml/qml/qqmlengine.cpp2
-rw-r--r--src/qml/qml/qqmlimport.cpp16
-rw-r--r--src/qml/qml/qqmlimport_p.h6
-rw-r--r--src/qml/qml/qqmlmetatype.cpp4
-rw-r--r--src/qml/qml/qqmlmetatype_p.h2
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro1
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/strictModule.2/plugin.cpp61
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/strictModule.2/qmldir2
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/strictModule.2/strictModule.2.pro13
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp21
10 files changed, 113 insertions, 15 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 8f2c554a7e..f8469cce14 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -1999,7 +1999,7 @@ void QQmlEngine::setPluginPathList(const QStringList &paths)
bool QQmlEngine::importPlugin(const QString &filePath, const QString &uri, QList<QQmlError> *errors)
{
Q_D(QQmlEngine);
- return d->importDatabase.importDynamicPlugin(filePath, uri, QString(), errors);
+ return d->importDatabase.importDynamicPlugin(filePath, uri, QString(), -1, errors);
}
/*!
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index cb8764e773..20bc28d886 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -926,7 +926,7 @@ bool QQmlImportsPrivate::importExtension(const QString &qmldirFilePath,
QString resolvedFilePath = database->resolvePlugin(typeLoader, qmldirPath, plugin.path, plugin.name);
if (!resolvedFilePath.isEmpty()) {
dynamicPluginsFound++;
- if (!database->importDynamicPlugin(resolvedFilePath, uri, typeNamespace, errors)) {
+ if (!database->importDynamicPlugin(resolvedFilePath, uri, typeNamespace, vmaj, errors)) {
if (errors) {
// XXX TODO: should we leave the import plugin error alone?
// Here, we pop it off the top and coalesce it into this error's message.
@@ -962,7 +962,7 @@ bool QQmlImportsPrivate::importExtension(const QString &qmldirFilePath,
if (versionUri == metaTagUri.toString()) {
staticPluginsFound++;
QObject *instance = pair.first.instance();
- if (!database->importStaticPlugin(instance, basePath, uri, typeNamespace, errors)) {
+ if (!database->importStaticPlugin(instance, basePath, uri, typeNamespace, vmaj, errors)) {
if (errors) {
QQmlError poppedError = errors->takeFirst();
QQmlError error;
@@ -1811,7 +1811,7 @@ void QQmlImportDatabase::setImportPathList(const QStringList &paths)
\internal
*/
bool QQmlImportDatabase::registerPluginTypes(QObject *instance, const QString &basePath,
- const QString &uri, const QString &typeNamespace, QList<QQmlError> *errors)
+ const QString &uri, const QString &typeNamespace, int vmaj, QList<QQmlError> *errors)
{
if (qmlImportTrace())
qDebug().nospace() << "QQmlImportDatabase::registerPluginTypes: " << uri << " from " << basePath;
@@ -1847,7 +1847,7 @@ bool QQmlImportDatabase::registerPluginTypes(QObject *instance, const QString &b
return false;
}
- if (QQmlMetaType::namespaceContainsRegistrations(typeNamespace)) {
+ if (QQmlMetaType::namespaceContainsRegistrations(typeNamespace, vmaj)) {
// Other modules have already installed to this namespace
if (errors) {
QQmlError error;
@@ -1894,7 +1894,7 @@ bool QQmlImportDatabase::registerPluginTypes(QObject *instance, const QString &b
\internal
*/
bool QQmlImportDatabase::importStaticPlugin(QObject *instance, const QString &basePath,
- const QString &uri, const QString &typeNamespace, QList<QQmlError> *errors)
+ const QString &uri, const QString &typeNamespace, int vmaj, QList<QQmlError> *errors)
{
#ifndef QT_NO_LIBRARY
// Dynamic plugins are differentiated by their filepath. For static plugins we
@@ -1918,7 +1918,7 @@ bool QQmlImportDatabase::importStaticPlugin(QObject *instance, const QString &ba
plugin.loader = 0;
plugins->insert(uniquePluginID, plugin);
- if (!registerPluginTypes(instance, basePath, uri, typeNamespace, errors))
+ if (!registerPluginTypes(instance, basePath, uri, typeNamespace, vmaj, errors))
return false;
}
@@ -1941,7 +1941,7 @@ bool QQmlImportDatabase::importStaticPlugin(QObject *instance, const QString &ba
\internal
*/
bool QQmlImportDatabase::importDynamicPlugin(const QString &filePath, const QString &uri,
- const QString &typeNamespace, QList<QQmlError> *errors)
+ const QString &typeNamespace, int vmaj, QList<QQmlError> *errors)
{
#ifndef QT_NO_LIBRARY
QFileInfo fileInfo(filePath);
@@ -1995,7 +1995,7 @@ bool QQmlImportDatabase::importDynamicPlugin(const QString &filePath, const QStr
plugins->insert(absoluteFilePath, plugin);
// Continue with shared code path for dynamic and static plugins:
- if (!registerPluginTypes(instance, fileInfo.absolutePath(), uri, typeNamespace, errors))
+ if (!registerPluginTypes(instance, fileInfo.absolutePath(), uri, typeNamespace, vmaj, errors))
return false;
}
diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h
index 26eab669bc..353349182e 100644
--- a/src/qml/qml/qqmlimport_p.h
+++ b/src/qml/qml/qqmlimport_p.h
@@ -145,7 +145,7 @@ public:
QQmlImportDatabase(QQmlEngine *);
~QQmlImportDatabase();
- bool importDynamicPlugin(const QString &filePath, const QString &uri, const QString &importNamespace, QList<QQmlError> *errors);
+ bool importDynamicPlugin(const QString &filePath, const QString &uri, const QString &importNamespace, int vmaj, QList<QQmlError> *errors);
QStringList importPathList(PathType type = LocalOrRemote) const;
void setImportPathList(const QStringList &paths);
@@ -165,9 +165,9 @@ private:
const QString &qmldirPath, const QString &qmldirPluginPath,
const QString &baseName);
bool importStaticPlugin(QObject *instance, const QString &basePath, const QString &uri,
- const QString &typeNamespace, QList<QQmlError> *errors);
+ const QString &typeNamespace, int vmaj, QList<QQmlError> *errors);
bool registerPluginTypes(QObject *instance, const QString &basePath,
- const QString &uri, const QString &typeNamespace, QList<QQmlError> *errors);
+ const QString &uri, const QString &typeNamespace, int vmaj, QList<QQmlError> *errors);
void clearDirCache();
struct QmldirCache {
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index d20fe72d09..00fe233124 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -1391,14 +1391,14 @@ bool qmlProtectModule(const char *uri, int majVersion)
return false;
}
-bool QQmlMetaType::namespaceContainsRegistrations(const QString &uri)
+bool QQmlMetaType::namespaceContainsRegistrations(const QString &uri, int majorVersion)
{
QQmlMetaTypeData *data = metaTypeData();
// Has any type previously been installed to this namespace?
QHashedString nameSpace(uri);
foreach (const QQmlType *type, data->types)
- if (type->module() == nameSpace)
+ if (type->module() == nameSpace && type->majorVersion() == majorVersion)
return true;
return false;
diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h
index ac408836fa..2fcd113183 100644
--- a/src/qml/qml/qqmlmetatype_p.h
+++ b/src/qml/qml/qqmlmetatype_p.h
@@ -114,7 +114,7 @@ public:
static const QQmlPrivate::CachedQmlUnit *findCachedCompilationUnit(const QUrl &uri);
- static bool namespaceContainsRegistrations(const QString &);
+ static bool namespaceContainsRegistrations(const QString &, int majorVersion);
static void protectNamespace(const QString &);
diff --git a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro
index 54acabe8eb..b715c6b82e 100644
--- a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro
+++ b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro
@@ -10,6 +10,7 @@ SUBDIRS =\
pluginVersion\
nestedPlugin\
strictModule\
+ strictModule.2\
invalidStrictModule\
nonstrictModule\
preemptiveModule\
diff --git a/tests/auto/qml/qqmlmoduleplugin/strictModule.2/plugin.cpp b/tests/auto/qml/qqmlmoduleplugin/strictModule.2/plugin.cpp
new file mode 100644
index 0000000000..75bcd04462
--- /dev/null
+++ b/tests/auto/qml/qqmlmoduleplugin/strictModule.2/plugin.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QStringList>
+#include <QtQml/qqmlextensionplugin.h>
+#include <QtQml/qqml.h>
+#include <QDebug>
+
+class MyPluginType : public QObject
+{
+ Q_OBJECT
+public:
+ MyPluginType(QObject *parent=0) : QObject(parent) {}
+};
+
+
+class MyPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
+
+public:
+ MyPlugin() {}
+
+ void registerTypes(const char *uri)
+ {
+ Q_ASSERT(QLatin1String(uri) == "org.qtproject.StrictModule");
+ qmlRegisterType<MyPluginType>(uri, 2, 0, "MyPluginType");
+ }
+};
+
+#include "plugin.moc"
diff --git a/tests/auto/qml/qqmlmoduleplugin/strictModule.2/qmldir b/tests/auto/qml/qqmlmoduleplugin/strictModule.2/qmldir
new file mode 100644
index 0000000000..26c408587d
--- /dev/null
+++ b/tests/auto/qml/qqmlmoduleplugin/strictModule.2/qmldir
@@ -0,0 +1,2 @@
+module org.qtproject.StrictModule
+plugin strictModule
diff --git a/tests/auto/qml/qqmlmoduleplugin/strictModule.2/strictModule.2.pro b/tests/auto/qml/qqmlmoduleplugin/strictModule.2/strictModule.2.pro
new file mode 100644
index 0000000000..14f3c59c21
--- /dev/null
+++ b/tests/auto/qml/qqmlmoduleplugin/strictModule.2/strictModule.2.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+CONFIG += plugin
+SOURCES = plugin.cpp
+QT = core qml
+DESTDIR = ../imports/org/qtproject/StrictModule.2
+
+QT += core-private gui-private qml-private
+
+IMPORT_FILES = \
+ qmldir
+
+include (../../../shared/imports.pri)
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp
index 0a8090ab07..6f4382f871 100644
--- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp
+++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp
@@ -508,6 +508,27 @@ void tst_qqmlmoduleplugin::importStrictModule_data()
<< QString()
<< QString();
+ QTest::newRow("two strict modules with different major version")
+ << "import org.qtproject.StrictModule 1.0\n"
+ "import org.qtproject.StrictModule 2.0\n"
+ "MyPluginType {}"
+ << QString()
+ << QString();
+
+ QTest::newRow("old namespaced strict module")
+ << "import org.qtproject.StrictModule 1.0 as Old\n"
+ "import org.qtproject.StrictModule 2.0 as New\n"
+ "Old.MyPluginType {}"
+ << QString()
+ << QString();
+
+ QTest::newRow("new namespaced strict modules")
+ << "import org.qtproject.StrictModule 1.0 as Old\n"
+ "import org.qtproject.StrictModule 2.0 as New\n"
+ "New.MyPluginType {}"
+ << QString()
+ << QString();
+
QTest::newRow("wrong target")
<< "import org.qtproject.InvalidStrictModule 1.0\n"
"MyPluginType {}"