forked from qt-creator/qt-creator
Extensionsystem: Allow pluginspecs to customize how they want to check dependencies
Change-Id: I84f3a56160588e4842301f4577f7bfdad96463ca Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -559,18 +559,17 @@ QString PluginSpec::errorString() const
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns whether this plugin can be used to fill in a dependency of the given
|
||||
\a pluginName and \a pluginVersion.
|
||||
Returns whether the plugin \a spec can be used to fill the \a dependency of this plugin.
|
||||
|
||||
\sa PluginSpec::dependencies()
|
||||
*/
|
||||
bool PluginSpec::provides(const QString &pluginName, const QString &pluginVersion) const
|
||||
bool PluginSpec::provides(PluginSpec *spec, const PluginDependency &dependency) const
|
||||
{
|
||||
if (QString::compare(pluginName, name(), Qt::CaseInsensitive) != 0)
|
||||
if (QString::compare(dependency.name, spec->name(), Qt::CaseInsensitive) != 0)
|
||||
return false;
|
||||
|
||||
return (versionCompare(version(), pluginVersion) >= 0)
|
||||
&& (versionCompare(compatVersion(), pluginVersion) <= 0);
|
||||
return (versionCompare(spec->version(), dependency.version) >= 0)
|
||||
&& (versionCompare(spec->compatVersion(), dependency.version) <= 0);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1075,8 +1074,8 @@ bool PluginSpec::resolveDependencies(const PluginSpecs &specs)
|
||||
|
||||
QHash<PluginDependency, PluginSpec *> resolvedDependencies;
|
||||
for (const PluginDependency &dependency : d->dependencies) {
|
||||
PluginSpec *const found = findOrDefault(specs, [&dependency](PluginSpec *spec) {
|
||||
return spec->provides(dependency.name, dependency.version);
|
||||
PluginSpec *const found = findOrDefault(specs, [this, &dependency](PluginSpec *spec) {
|
||||
return provides(spec, dependency);
|
||||
});
|
||||
if (!found) {
|
||||
if (dependency.type == PluginDependency::Required) {
|
||||
|
@@ -36,13 +36,14 @@ class PluginView;
|
||||
|
||||
struct EXTENSIONSYSTEM_EXPORT PluginDependency
|
||||
{
|
||||
enum Type {
|
||||
Required,
|
||||
Optional,
|
||||
Test
|
||||
};
|
||||
enum Type { Required, Optional, Test };
|
||||
|
||||
PluginDependency() : type(Required) {}
|
||||
PluginDependency(const QString &name, const QString &version, Type type = Required)
|
||||
: name(name)
|
||||
, version(version)
|
||||
, type(type)
|
||||
{}
|
||||
|
||||
QString name;
|
||||
QString version;
|
||||
@@ -130,7 +131,7 @@ public:
|
||||
virtual void addArgument(const QString &argument);
|
||||
virtual QHash<PluginDependency, PluginSpec *> dependencySpecs() const;
|
||||
|
||||
virtual bool provides(const QString &pluginName, const QString &pluginVersion) const;
|
||||
virtual bool provides(PluginSpec *spec, const PluginDependency &dependency) const;
|
||||
virtual bool requiresAny(const QSet<PluginSpec *> &plugins) const;
|
||||
virtual PluginSpecs enableDependenciesIndirectly(bool enableTestDependencies);
|
||||
virtual bool resolveDependencies(const PluginSpecs &pluginSpecs);
|
||||
|
@@ -162,7 +162,7 @@ void checkContents(QPromise<ArchiveIssue> &promise, const FilePath &tempDir)
|
||||
[coreplugin](const PluginDependency &d) { return d.name == coreplugin->name(); });
|
||||
if (found == dependencies.constEnd())
|
||||
return;
|
||||
if (coreplugin->provides(found->name, found->version))
|
||||
if ((*spec)->provides(coreplugin, *found))
|
||||
return;
|
||||
promise.addResult(
|
||||
ArchiveIssue{Tr::tr("Plugin requires an incompatible version of %1 (%2).")
|
||||
|
@@ -190,25 +190,25 @@ void tst_PluginSpec::provides()
|
||||
CppPluginSpec spec;
|
||||
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"));
|
||||
QVERIFY(!spec.provides("MyPlugin", "2.3.11_1"));
|
||||
QVERIFY(!spec.provides("MyPlugin", "2.3"));
|
||||
QVERIFY(!spec.provides("MyPlugin", "3.0"));
|
||||
QVERIFY(!spec.provides("MyPlugin", "1.9.9_99"));
|
||||
QVERIFY(!spec.provides("MyPlugin", "1.9"));
|
||||
QVERIFY(!spec.provides("MyPlugin", "0.9"));
|
||||
QVERIFY(!spec.provides("MyPlugin", "1"));
|
||||
QVERIFY(!spec.provides(&spec, {"SomeOtherPlugin", "2.2.3_9"}));
|
||||
QVERIFY(!spec.provides(&spec, {"MyPlugin", "2.2.3_10"}));
|
||||
QVERIFY(!spec.provides(&spec, {"MyPlugin", "2.2.4"}));
|
||||
QVERIFY(!spec.provides(&spec, {"MyPlugin", "2.3.11_1"}));
|
||||
QVERIFY(!spec.provides(&spec, {"MyPlugin", "2.3"}));
|
||||
QVERIFY(!spec.provides(&spec, {"MyPlugin", "3.0"}));
|
||||
QVERIFY(!spec.provides(&spec, {"MyPlugin", "1.9.9_99"}));
|
||||
QVERIFY(!spec.provides(&spec, {"MyPlugin", "1.9"}));
|
||||
QVERIFY(!spec.provides(&spec, {"MyPlugin", "0.9"}));
|
||||
QVERIFY(!spec.provides(&spec, {"MyPlugin", "1"}));
|
||||
|
||||
QVERIFY(spec.provides("myplugin", "2.2.3_9"));
|
||||
QVERIFY(spec.provides("MyPlugin", "2.2.3_9"));
|
||||
QVERIFY(spec.provides("MyPlugin", "2.2.3_8"));
|
||||
QVERIFY(spec.provides("MyPlugin", "2.2.3"));
|
||||
QVERIFY(spec.provides("MyPlugin", "2.2.2"));
|
||||
QVERIFY(spec.provides("MyPlugin", "2.1.2_10"));
|
||||
QVERIFY(spec.provides("MyPlugin", "2.0_10"));
|
||||
QVERIFY(spec.provides("MyPlugin", "2"));
|
||||
QVERIFY(spec.provides(&spec, {"myplugin", "2.2.3_9"}));
|
||||
QVERIFY(spec.provides(&spec, {"MyPlugin", "2.2.3_9"}));
|
||||
QVERIFY(spec.provides(&spec, {"MyPlugin", "2.2.3_8"}));
|
||||
QVERIFY(spec.provides(&spec, {"MyPlugin", "2.2.3"}));
|
||||
QVERIFY(spec.provides(&spec, {"MyPlugin", "2.2.2"}));
|
||||
QVERIFY(spec.provides(&spec, {"MyPlugin", "2.1.2_10"}));
|
||||
QVERIFY(spec.provides(&spec, {"MyPlugin", "2.0_10"}));
|
||||
QVERIFY(spec.provides(&spec, {"MyPlugin", "2"}));
|
||||
}
|
||||
|
||||
void tst_PluginSpec::experimental()
|
||||
|
Reference in New Issue
Block a user