Commit 1d56d718 authored by Friedemann Kleint's avatar Friedemann Kleint

Add <platform> element to pluginspec-files.

The <platform> element may contain a regular expression
matching the names of the platforms on which the plugin works.

Task-number: QTCREATORBUG-9002
Change-Id: Ic816cfed69a5dd2c4112c976843b9106ba2cbd22
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 54a114e6
......@@ -101,6 +101,10 @@
\row
\o copyright
\o A short copyright notice, like \c{(C) 2007-2008 MyCompany}.
\row
\o platform
\o A regular expression that matches the names of the platforms the plugin works on.
Omitting the tag implies that the plugin is loaded on all platforms.
\row
\o license
\o Possibly multi-line license information about the plugin.
......
......@@ -32,6 +32,7 @@
#include "pluginspec.h"
#include <QDir>
#include <QRegExp>
/*!
\class ExtensionSystem::PluginDetailsView
......@@ -84,6 +85,8 @@ void PluginDetailsView::update(PluginSpec *spec)
m_ui->description->setText(spec->description());
m_ui->copyright->setText(spec->copyright());
m_ui->license->setText(spec->license());
const QRegExp platforms = spec->platformSpecification();
m_ui->platforms->setText(platforms.isEmpty() ? tr("All") : platforms.pattern());
QStringList depStrings;
foreach (const PluginDependency &dep, spec->dependencies()) {
QString depString = dep.name;
......
......@@ -38,6 +38,7 @@
#include <QEventLoop>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QMetaProperty>
#include <QSettings>
#include <QTextStream>
......@@ -45,6 +46,7 @@
#include <QWriteLocker>
#include <QDebug>
#include <QTimer>
#include <QSysInfo>
#ifdef WITH_TESTS
#include <QTest>
......@@ -1329,6 +1331,77 @@ void PluginManagerPrivate::profilingSummary() const
}
}
static inline QString getPlatformName()
{
#if defined(Q_OS_MAC)
QString result = QLatin1String("Mac OS");
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_0)
result += QLatin1String(" 10.") + QString::number(QSysInfo::MacintoshVersion - QSysInfo::MV_10_0);
return result;
#elif defined(Q_OS_UNIX)
QFile osReleaseFile(QLatin1String("/etc/os-release")); // Newer Linuxes
if (osReleaseFile.open(QIODevice::ReadOnly)) {
QString name;
QString version;
forever {
const QByteArray line = osReleaseFile.readLine();
if (line.isEmpty())
break;
if (line.startsWith("NAME=\""))
name = QString::fromLatin1(line.mid(6, line.size() - 8)).trimmed();
if (line.startsWith("VERSION_ID=\""))
version = QString::fromLatin1(line.mid(12, line.size() - 14)).trimmed();
}
if (!name.isEmpty()) {
if (!version.isEmpty())
name += QLatin1Char(' ') + version;
return name;
}
}
QFile issueFile(QLatin1String("/etc/issue")); // Older Linuxes
if (issueFile.open(QIODevice::ReadOnly)) {
QByteArray issue = issueFile.readAll();
const int end = issue.lastIndexOf(" \\n");
if (end >= 0)
issue.truncate(end);
return QString::fromLatin1(issue).trimmed();
}
# ifdef Q_OS_LINUX
return QLatin1String("Linux");
# else
return QLatin1String("Unix");
# endif // Q_OS_LINUX
#elif defined(Q_OS_WIN)
QString result = QLatin1String("Windows");
switch (QSysInfo::WindowsVersion) {
case QSysInfo::WV_XP:
result += QLatin1String(" XP");
break;
case QSysInfo::WV_2003:
result += QLatin1String(" 2003");
break;
case QSysInfo::WV_VISTA:
result += QLatin1String(" Vista");
break;
case QSysInfo::WV_WINDOWS7:
result += QLatin1String(" 7");
break;
default:
break;
}
if (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8)
result += QLatin1String(" 8");
return result;
#endif // Q_OS_WIN
return QLatin1String("Unknown");
}
QString PluginManager::platformName()
{
static const QString result = getPlatformName();
return result;
}
/*!
\brief Retrieves one object with a given name from the object pool.
\sa addObject()
......
......@@ -128,6 +128,8 @@ public:
static void profilingReport(const char *what, const PluginSpec *spec = 0);
static QString platformName();
signals:
void objectAdded(QObject *obj);
void aboutToRemoveObject(QObject *obj);
......
......@@ -252,6 +252,16 @@ QString PluginSpec::category() const
return d->category;
}
/*!
A QRegExp matching the platforms this plugin works on. An empty pattern implies all platforms.
\since 3.0
*/
QRegExp PluginSpec::platformSpecification() const
{
return d->platformSpecification;
}
/*!
Returns if the plugin has its experimental flag set.
*/
......@@ -287,9 +297,12 @@ bool PluginSpec::isEnabledInSettings() const
*/
bool PluginSpec::isEffectivelyEnabled() const
{
return !d->disabledIndirectly
&& (d->enabledInSettings || d->forceEnabled)
&& !d->forceDisabled;
if (d->disabledIndirectly
|| (!d->enabledInSettings && !d->forceEnabled)
|| d->forceDisabled) {
return false;
}
return d->platformSpecification.isEmpty() || d->platformSpecification.exactMatch(PluginManager::platformName());
}
/*!
......@@ -450,6 +463,7 @@ namespace {
const char DESCRIPTION[] = "description";
const char URL[] = "url";
const char CATEGORY[] = "category";
const char PLATFORM[] = "platform";
const char DEPENDENCYLIST[] = "dependencyList";
const char DEPENDENCY[] = "dependency";
const char DEPENDENCY_NAME[] = "name";
......@@ -647,7 +661,16 @@ void PluginSpecPrivate::readPluginSpec(QXmlStreamReader &reader)
url = reader.readElementText().trimmed();
else if (element == QLatin1String(CATEGORY))
category = reader.readElementText().trimmed();
else if (element == QLatin1String(DEPENDENCYLIST))
else if (element == QLatin1String(PLATFORM)) {
const QString platformSpec = reader.readElementText().trimmed();
if (!platformSpec.isEmpty()) {
platformSpecification.setPattern(platformSpec);
if (!platformSpecification.isValid())
reader.raiseError(QLatin1String("Invalid platform specification \"")
+ platformSpec + QLatin1String("\": ")
+ platformSpecification.errorString());
}
} else if (element == QLatin1String(DEPENDENCYLIST))
readDependencies(reader);
else if (element == QLatin1String(ARGUMENTLIST))
readArgumentDescriptions(reader);
......
......@@ -38,6 +38,7 @@
QT_BEGIN_NAMESPACE
class QStringList;
class QRegExp;
QT_END_NAMESPACE
namespace ExtensionSystem {
......@@ -90,6 +91,7 @@ public:
QString description() const;
QString url() const;
QString category() const;
QRegExp platformSpecification() const;
bool isExperimental() const;
bool isDisabledByDefault() const;
bool isEnabledInSettings() const;
......
......@@ -36,6 +36,7 @@
#include <QObject>
#include <QStringList>
#include <QXmlStreamReader>
#include <QRegExp>
namespace ExtensionSystem {
......@@ -72,6 +73,7 @@ public:
QString description;
QString url;
QString category;
QRegExp platformSpecification;
QList<PluginDependency> dependencies;
bool enabledInSettings;
bool disabledIndirectly;
......
......@@ -15,6 +15,9 @@
<xsl:template match="vendor">
"Vendor" : "<xsl:apply-templates/>",
</xsl:template>
<xsl:template match="platform">
"Platform" : "<xsl:apply-templates/>",
</xsl:template>
<xsl:template match="category">
"Category" : "<xsl:apply-templates/>",
</xsl:template>
......
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