2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: 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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "pluginspec.h"
|
2010-01-11 09:45:20 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "pluginspec_p.h"
|
|
|
|
|
#include "iplugin.h"
|
|
|
|
|
#include "iplugin_p.h"
|
|
|
|
|
#include "pluginmanager.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QXmlStreamReader>
|
|
|
|
|
#include <QRegExp>
|
|
|
|
|
#include <QCoreApplication>
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-02-19 16:30:08 +01:00
|
|
|
#ifdef Q_OS_LINUX
|
2009-04-07 14:08:44 +02:00
|
|
|
// Using the patched version breaks on Fedora 10, KDE4.2.2/Qt4.5.
|
|
|
|
|
# define USE_UNPATCHED_QPLUGINLOADER 1
|
2009-02-19 16:30:08 +01:00
|
|
|
#else
|
|
|
|
|
# define USE_UNPATCHED_QPLUGINLOADER 1
|
|
|
|
|
#endif
|
2009-02-19 15:32:50 +01:00
|
|
|
|
|
|
|
|
#if USE_UNPATCHED_QPLUGINLOADER
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
# include <QPluginLoader>
|
2009-02-19 16:30:08 +01:00
|
|
|
typedef QT_PREPEND_NAMESPACE(QPluginLoader) PluginLoader;
|
2009-02-19 15:32:50 +01:00
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
2009-02-19 16:30:08 +01:00
|
|
|
# include "patchedpluginloader.cpp"
|
|
|
|
|
typedef PatchedPluginLoader PluginLoader;
|
2009-02-19 15:32:50 +01:00
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
|
\class ExtensionSystem::PluginDependency
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The PluginDependency class contains the name and required compatible
|
|
|
|
|
version number of a plugin's dependency.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-06 11:46:55 +02:00
|
|
|
This reflects the data of a dependency tag in the plugin's XML description
|
|
|
|
|
file. The name and version are used to resolve the dependency. That is,
|
|
|
|
|
a plugin with the given name and
|
2008-12-02 12:01:29 +01:00
|
|
|
plugin \c {compatibility version <= dependency version <= plugin version} is searched for.
|
|
|
|
|
|
|
|
|
|
See also ExtensionSystem::IPlugin for more information about plugin dependencies and
|
|
|
|
|
version matching.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\variable ExtensionSystem::PluginDependency::name
|
|
|
|
|
String identifier of the plugin.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\variable ExtensionSystem::PluginDependency::version
|
|
|
|
|
Version string that a plugin must match to fill this dependency.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-01-11 14:01:08 +01:00
|
|
|
/*!
|
|
|
|
|
\variable ExtensionSystem::PluginDependency::type
|
|
|
|
|
Defines whether the dependency is required or optional.
|
|
|
|
|
\sa ExtensionSystem::PluginDependency::Type
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\enum ExtensionSystem::PluginDependency::Type
|
|
|
|
|
Whether the dependency is required or optional.
|
|
|
|
|
\value Required
|
|
|
|
|
Dependency needs to be there.
|
|
|
|
|
\value Optional
|
|
|
|
|
Dependency is not necessarily needed. You need to make sure that
|
|
|
|
|
the plugin is able to load without this dependency installed, so
|
|
|
|
|
for example you may not link to the dependency's library.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
|
\class ExtensionSystem::PluginSpec
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The PluginSpec class contains the information of the plugin's XML
|
|
|
|
|
description file and
|
2008-12-02 12:01:29 +01:00
|
|
|
information about the plugin's current state.
|
|
|
|
|
|
|
|
|
|
The plugin spec is also filled with more information as the plugin
|
2009-06-12 13:07:15 +02:00
|
|
|
goes through its loading process (see PluginSpec::State).
|
2008-12-02 12:01:29 +01:00
|
|
|
If an error occurs, the plugin spec is the place to look for the
|
|
|
|
|
error details.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\enum ExtensionSystem::PluginSpec::State
|
2013-09-06 11:46:55 +02:00
|
|
|
The State enum indicates the states the plugin goes through while
|
|
|
|
|
it is being loaded.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
The state gives a hint on what went wrong in case of an error.
|
|
|
|
|
|
|
|
|
|
\value Invalid
|
2013-09-06 11:46:55 +02:00
|
|
|
Starting point: Even the XML description file was not read.
|
2008-12-02 12:01:29 +01:00
|
|
|
\value Read
|
2013-09-06 11:46:55 +02:00
|
|
|
The XML description file has been successfully read, and its
|
2008-12-02 12:01:29 +01:00
|
|
|
information is available via the PluginSpec.
|
|
|
|
|
\value Resolved
|
|
|
|
|
The dependencies given in the description file have been
|
2013-10-07 13:34:40 +02:00
|
|
|
successfully found, and are available via the dependencySpecs() function.
|
2008-12-02 12:01:29 +01:00
|
|
|
\value Loaded
|
|
|
|
|
The plugin's library is loaded and the plugin instance created
|
|
|
|
|
(available through plugin()).
|
|
|
|
|
\value Initialized
|
2013-10-07 13:34:40 +02:00
|
|
|
The plugin instance's IPlugin::initialize() function has been called
|
2008-12-02 12:01:29 +01:00
|
|
|
and returned a success value.
|
|
|
|
|
\value Running
|
|
|
|
|
The plugin's dependencies are successfully initialized and
|
|
|
|
|
extensionsInitialized has been called. The loading process is
|
|
|
|
|
complete.
|
|
|
|
|
\value Stopped
|
2013-10-07 13:34:40 +02:00
|
|
|
The plugin has been shut down, i.e. the plugin's IPlugin::aboutToShutdown() function has been called.
|
2008-12-02 12:01:29 +01:00
|
|
|
\value Deleted
|
|
|
|
|
The plugin instance has been deleted.
|
|
|
|
|
*/
|
2011-01-11 14:01:08 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace ExtensionSystem;
|
|
|
|
|
using namespace ExtensionSystem::Internal;
|
|
|
|
|
|
2011-01-11 14:01:08 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
uint ExtensionSystem::qHash(const ExtensionSystem::PluginDependency &value)
|
|
|
|
|
{
|
|
|
|
|
return qHash(value.name);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2011-01-11 14:01:08 +01:00
|
|
|
bool PluginDependency::operator==(const PluginDependency &other) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-11 14:01:08 +01:00
|
|
|
return name == other.name && version == other.version && type == other.type;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
PluginSpec::PluginSpec()
|
|
|
|
|
: d(new PluginSpecPrivate(this))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
PluginSpec::~PluginSpec()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
d = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
The plugin name. This is valid after the PluginSpec::Read state is reached.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::name() const
|
|
|
|
|
{
|
|
|
|
|
return d->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
The plugin version. This is valid after the PluginSpec::Read state is reached.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::version() const
|
|
|
|
|
{
|
|
|
|
|
return d->version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
The plugin compatibility version. This is valid after the PluginSpec::Read state is reached.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::compatVersion() const
|
|
|
|
|
{
|
|
|
|
|
return d->compatVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
The plugin vendor. This is valid after the PluginSpec::Read state is reached.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::vendor() const
|
|
|
|
|
{
|
|
|
|
|
return d->vendor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
The plugin copyright. This is valid after the PluginSpec::Read state is reached.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::copyright() const
|
|
|
|
|
{
|
|
|
|
|
return d->copyright;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
The plugin license. This is valid after the PluginSpec::Read state is reached.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::license() const
|
|
|
|
|
{
|
|
|
|
|
return d->license;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
The plugin description. This is valid after the PluginSpec::Read state is reached.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::description() const
|
|
|
|
|
{
|
|
|
|
|
return d->description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
The plugin URL where you can find more information about the plugin.
|
|
|
|
|
This is valid after the PluginSpec::Read state is reached.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
QString PluginSpec::url() const
|
|
|
|
|
{
|
|
|
|
|
return d->url;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 16:02:23 +01:00
|
|
|
/*!
|
|
|
|
|
The category that the plugin belongs to. Categories are groups of plugins which allow for keeping them together in the UI.
|
|
|
|
|
Returns an empty string if the plugin does not belong to a category.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::category() const
|
|
|
|
|
{
|
|
|
|
|
return d->category;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-28 16:29:08 +02:00
|
|
|
/*!
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 16:02:23 +01:00
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Returns whether the plugin has its experimental flag set.
|
2010-03-30 16:54:29 +02:00
|
|
|
*/
|
|
|
|
|
bool PluginSpec::isExperimental() const
|
|
|
|
|
{
|
|
|
|
|
return d->experimental;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 14:46:29 +02:00
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Returns whether the plugin is disabled by default.
|
2011-10-26 14:46:29 +02:00
|
|
|
This might be because the plugin is experimental, or because
|
|
|
|
|
the plugin manager's settings define it as disabled by default.
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpec::isDisabledByDefault() const
|
|
|
|
|
{
|
|
|
|
|
return d->disabledByDefault;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 16:54:29 +02:00
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Returns whether the plugin should be loaded at startup. True by default.
|
|
|
|
|
|
2013-02-12 13:15:05 +01:00
|
|
|
The user can change it from the Plugin settings.
|
2013-09-06 11:46:55 +02:00
|
|
|
|
|
|
|
|
\note This function returns true even if a plugin is disabled because its
|
|
|
|
|
dependencies were not loaded, or an error occurred during loading it.
|
2010-03-12 16:02:23 +01:00
|
|
|
*/
|
2013-02-12 13:15:05 +01:00
|
|
|
bool PluginSpec::isEnabledInSettings() const
|
2010-03-12 16:02:23 +01:00
|
|
|
{
|
2013-02-12 13:15:05 +01:00
|
|
|
return d->enabledInSettings;
|
2010-03-12 16:02:23 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-12 13:19:15 +01:00
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Returns whether the plugin is loaded at startup.
|
2013-02-12 13:19:15 +01:00
|
|
|
\see PluginSpec::isEnabled
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpec::isEffectivelyEnabled() const
|
|
|
|
|
{
|
2013-08-28 16:29:08 +02:00
|
|
|
if (d->disabledIndirectly
|
|
|
|
|
|| (!d->enabledInSettings && !d->forceEnabled)
|
|
|
|
|
|| d->forceDisabled) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return d->platformSpecification.isEmpty() || d->platformSpecification.exactMatch(PluginManager::platformName());
|
2013-02-12 13:19:15 +01:00
|
|
|
}
|
|
|
|
|
|
2010-05-12 14:34:36 +02:00
|
|
|
/*!
|
2013-02-12 13:19:15 +01:00
|
|
|
Returns true if loading was not done due to user unselecting this plugin or its dependencies.
|
2010-05-12 14:34:36 +02:00
|
|
|
*/
|
|
|
|
|
bool PluginSpec::isDisabledIndirectly() const
|
2010-03-12 16:02:23 +01:00
|
|
|
{
|
2010-05-12 14:34:36 +02:00
|
|
|
return d->disabledIndirectly;
|
2010-03-12 16:02:23 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-12 13:19:15 +01:00
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Returns whether the plugin is enabled via the -load option on the command line.
|
2013-02-12 13:19:15 +01:00
|
|
|
*/
|
|
|
|
|
bool PluginSpec::isForceEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return d->forceEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Returns whether the plugin is disabled via the -noload option on the command line.
|
2013-02-12 13:19:15 +01:00
|
|
|
*/
|
|
|
|
|
bool PluginSpec::isForceDisabled() const
|
|
|
|
|
{
|
|
|
|
|
return d->forceDisabled;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
|
The plugin dependencies. This is valid after the PluginSpec::Read state is reached.
|
|
|
|
|
*/
|
|
|
|
|
QList<PluginDependency> PluginSpec::dependencies() const
|
|
|
|
|
{
|
|
|
|
|
return d->dependencies;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Returns a list of descriptions of command line arguments the plugin processes.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
PluginSpec::PluginArgumentDescriptions PluginSpec::argumentDescriptions() const
|
|
|
|
|
{
|
|
|
|
|
return d->argumentDescriptions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
The absolute path to the directory containing the plugin XML description file
|
2008-12-02 12:01:29 +01:00
|
|
|
this PluginSpec corresponds to.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::location() const
|
|
|
|
|
{
|
|
|
|
|
return d->location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
The absolute path to the plugin XML description file (including the file name)
|
2008-12-02 12:01:29 +01:00
|
|
|
this PluginSpec corresponds to.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::filePath() const
|
|
|
|
|
{
|
|
|
|
|
return d->filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Command line arguments specific to the plugin. Set at startup.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
QStringList PluginSpec::arguments() const
|
|
|
|
|
{
|
|
|
|
|
return d->arguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Sets the command line arguments specific to the plugin to \a arguments.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void PluginSpec::setArguments(const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
d->arguments = arguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Adds \a argument to the command line arguments specific to the plugin.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void PluginSpec::addArgument(const QString &argument)
|
|
|
|
|
{
|
|
|
|
|
d->arguments.push_back(argument);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
The state in which the plugin currently is.
|
|
|
|
|
See the description of the PluginSpec::State enum for details.
|
|
|
|
|
*/
|
|
|
|
|
PluginSpec::State PluginSpec::state() const
|
|
|
|
|
{
|
|
|
|
|
return d->state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Returns whether an error occurred while reading/starting the plugin.
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpec::hasError() const
|
|
|
|
|
{
|
|
|
|
|
return d->hasError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Detailed, possibly multi-line, error description in case of an error.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginSpec::errorString() const
|
|
|
|
|
{
|
|
|
|
|
return d->errorString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 11:46:55 +02:00
|
|
|
Returns whether this plugin can be used to fill in a dependency of the given
|
2008-12-02 12:01:29 +01:00
|
|
|
\a pluginName and \a version.
|
|
|
|
|
|
|
|
|
|
\sa PluginSpec::dependencies()
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpec::provides(const QString &pluginName, const QString &version) const
|
|
|
|
|
{
|
|
|
|
|
return d->provides(pluginName, version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
The corresponding IPlugin instance, if the plugin library has already been successfully loaded,
|
|
|
|
|
i.e. the PluginSpec::Loaded state is reached.
|
|
|
|
|
*/
|
|
|
|
|
IPlugin *PluginSpec::plugin() const
|
|
|
|
|
{
|
|
|
|
|
return d->plugin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Returns the list of dependencies, already resolved to existing plugin specs.
|
|
|
|
|
Valid if PluginSpec::Resolved state is reached.
|
|
|
|
|
|
|
|
|
|
\sa PluginSpec::dependencies()
|
|
|
|
|
*/
|
2011-01-11 14:01:08 +01:00
|
|
|
QHash<PluginDependency, PluginSpec *> PluginSpec::dependencySpecs() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return d->dependencySpecs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//==========PluginSpecPrivate==================
|
|
|
|
|
|
|
|
|
|
namespace {
|
2011-11-02 16:45:13 +01:00
|
|
|
const char PLUGIN[] = "plugin";
|
|
|
|
|
const char PLUGIN_NAME[] = "name";
|
|
|
|
|
const char PLUGIN_VERSION[] = "version";
|
|
|
|
|
const char PLUGIN_COMPATVERSION[] = "compatVersion";
|
|
|
|
|
const char PLUGIN_EXPERIMENTAL[] = "experimental";
|
2013-01-08 11:55:52 +01:00
|
|
|
const char PLUGIN_DISABLED_BY_DEFAULT[] = "disabledByDefault";
|
2011-11-02 16:45:13 +01:00
|
|
|
const char VENDOR[] = "vendor";
|
|
|
|
|
const char COPYRIGHT[] = "copyright";
|
|
|
|
|
const char LICENSE[] = "license";
|
|
|
|
|
const char DESCRIPTION[] = "description";
|
|
|
|
|
const char URL[] = "url";
|
|
|
|
|
const char CATEGORY[] = "category";
|
2013-08-28 16:29:08 +02:00
|
|
|
const char PLATFORM[] = "platform";
|
2011-11-02 16:45:13 +01:00
|
|
|
const char DEPENDENCYLIST[] = "dependencyList";
|
|
|
|
|
const char DEPENDENCY[] = "dependency";
|
|
|
|
|
const char DEPENDENCY_NAME[] = "name";
|
|
|
|
|
const char DEPENDENCY_VERSION[] = "version";
|
|
|
|
|
const char DEPENDENCY_TYPE[] = "type";
|
|
|
|
|
const char DEPENDENCY_TYPE_SOFT[] = "optional";
|
|
|
|
|
const char DEPENDENCY_TYPE_HARD[] = "required";
|
|
|
|
|
const char ARGUMENTLIST[] = "argumentList";
|
|
|
|
|
const char ARGUMENT[] = "argument";
|
|
|
|
|
const char ARGUMENT_NAME[] = "name";
|
|
|
|
|
const char ARGUMENT_PARAMETER[] = "parameter";
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
PluginSpecPrivate::PluginSpecPrivate(PluginSpec *spec)
|
2010-03-12 16:02:23 +01:00
|
|
|
:
|
2011-10-26 14:46:29 +02:00
|
|
|
experimental(false),
|
|
|
|
|
disabledByDefault(false),
|
2013-02-12 13:15:05 +01:00
|
|
|
enabledInSettings(true),
|
2010-05-12 14:34:36 +02:00
|
|
|
disabledIndirectly(false),
|
2013-02-12 13:19:15 +01:00
|
|
|
forceEnabled(false),
|
|
|
|
|
forceDisabled(false),
|
2010-03-12 16:02:23 +01:00
|
|
|
plugin(0),
|
2008-12-02 12:01:29 +01:00
|
|
|
state(PluginSpec::Invalid),
|
|
|
|
|
hasError(false),
|
|
|
|
|
q(spec)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpecPrivate::read(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
name
|
|
|
|
|
= version
|
|
|
|
|
= compatVersion
|
|
|
|
|
= vendor
|
|
|
|
|
= copyright
|
|
|
|
|
= license
|
|
|
|
|
= description
|
|
|
|
|
= url
|
2010-03-12 16:02:23 +01:00
|
|
|
= category
|
2008-12-02 12:01:29 +01:00
|
|
|
= location
|
2012-11-27 22:23:17 +02:00
|
|
|
= QString();
|
2008-12-02 12:01:29 +01:00
|
|
|
state = PluginSpec::Invalid;
|
|
|
|
|
hasError = false;
|
2012-11-27 22:23:17 +02:00
|
|
|
errorString.clear();
|
2008-12-02 12:01:29 +01:00
|
|
|
dependencies.clear();
|
|
|
|
|
QFile file(fileName);
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
2011-06-21 17:07:45 +02:00
|
|
|
return reportError(tr("Cannot open file %1 for reading: %2")
|
2011-03-30 15:15:15 +02:00
|
|
|
.arg(QDir::toNativeSeparators(file.fileName()), file.errorString()));
|
2008-12-02 12:01:29 +01:00
|
|
|
QFileInfo fileInfo(file);
|
|
|
|
|
location = fileInfo.absolutePath();
|
|
|
|
|
filePath = fileInfo.absoluteFilePath();
|
|
|
|
|
QXmlStreamReader reader(&file);
|
|
|
|
|
while (!reader.atEnd()) {
|
|
|
|
|
reader.readNext();
|
|
|
|
|
switch (reader.tokenType()) {
|
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
readPluginSpec(reader);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (reader.hasError())
|
|
|
|
|
return reportError(tr("Error parsing file %1: %2, at line %3, column %4")
|
2011-12-29 20:15:58 +01:00
|
|
|
.arg(QDir::toNativeSeparators(file.fileName()))
|
2008-12-02 12:01:29 +01:00
|
|
|
.arg(reader.errorString())
|
|
|
|
|
.arg(reader.lineNumber())
|
|
|
|
|
.arg(reader.columnNumber()));
|
|
|
|
|
state = PluginSpec::Read;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 14:18:15 +02:00
|
|
|
void PluginSpec::setEnabled(bool value)
|
2010-03-12 16:02:23 +01:00
|
|
|
{
|
2013-02-12 13:15:05 +01:00
|
|
|
d->enabledInSettings = value;
|
2010-03-12 16:02:23 +01:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 14:46:29 +02:00
|
|
|
void PluginSpec::setDisabledByDefault(bool value)
|
|
|
|
|
{
|
|
|
|
|
d->disabledByDefault = value;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 16:29:47 +02:00
|
|
|
void PluginSpec::setDisabledIndirectly(bool value)
|
|
|
|
|
{
|
|
|
|
|
d->disabledIndirectly = value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-12 13:19:15 +01:00
|
|
|
void PluginSpec::setForceEnabled(bool value)
|
|
|
|
|
{
|
|
|
|
|
d->forceEnabled = value;
|
|
|
|
|
if (value)
|
|
|
|
|
d->forceDisabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PluginSpec::setForceDisabled(bool value)
|
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
d->forceEnabled = false;
|
|
|
|
|
d->forceDisabled = value;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpecPrivate::reportError(const QString &err)
|
|
|
|
|
{
|
|
|
|
|
errorString = err;
|
|
|
|
|
hasError = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QString msgAttributeMissing(const char *elt, const char *attribute)
|
|
|
|
|
{
|
2014-04-17 14:09:47 +02:00
|
|
|
return QCoreApplication::translate("PluginSpec", "\"%1\" misses attribute \"%2\"").arg(QLatin1String(elt), QLatin1String(attribute));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QString msgInvalidFormat(const char *content)
|
|
|
|
|
{
|
2014-04-17 14:09:47 +02:00
|
|
|
return QCoreApplication::translate("PluginSpec", "\"%1\" has invalid format").arg(QLatin1String(content));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QString msgInvalidElement(const QString &name)
|
|
|
|
|
{
|
2014-04-17 14:09:47 +02:00
|
|
|
return QCoreApplication::translate("PluginSpec", "Invalid element \"%1\"").arg(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QString msgUnexpectedClosing(const QString &name)
|
|
|
|
|
{
|
2014-04-17 14:09:47 +02:00
|
|
|
return QCoreApplication::translate("PluginSpec", "Unexpected closing element \"%1\"").arg(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QString msgUnexpectedToken()
|
|
|
|
|
{
|
|
|
|
|
return QCoreApplication::translate("PluginSpec", "Unexpected token");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
void PluginSpecPrivate::readPluginSpec(QXmlStreamReader &reader)
|
|
|
|
|
{
|
2013-08-28 14:02:48 +02:00
|
|
|
if (reader.name() != QLatin1String(PLUGIN)) {
|
2014-04-17 14:09:47 +02:00
|
|
|
reader.raiseError(QCoreApplication::translate("PluginSpec", "Expected element \"%1\" as top level element")
|
2012-11-27 22:23:17 +02:00
|
|
|
.arg(QLatin1String(PLUGIN)));
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2012-11-27 22:23:17 +02:00
|
|
|
name = reader.attributes().value(QLatin1String(PLUGIN_NAME)).toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (name.isEmpty()) {
|
|
|
|
|
reader.raiseError(msgAttributeMissing(PLUGIN, PLUGIN_NAME));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-11-27 22:23:17 +02:00
|
|
|
version = reader.attributes().value(QLatin1String(PLUGIN_VERSION)).toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (version.isEmpty()) {
|
|
|
|
|
reader.raiseError(msgAttributeMissing(PLUGIN, PLUGIN_VERSION));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!isValidVersion(version)) {
|
|
|
|
|
reader.raiseError(msgInvalidFormat(PLUGIN_VERSION));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-11-27 22:23:17 +02:00
|
|
|
compatVersion = reader.attributes().value(QLatin1String(PLUGIN_COMPATVERSION)).toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!compatVersion.isEmpty() && !isValidVersion(compatVersion)) {
|
|
|
|
|
reader.raiseError(msgInvalidFormat(PLUGIN_COMPATVERSION));
|
|
|
|
|
return;
|
|
|
|
|
} else if (compatVersion.isEmpty()) {
|
|
|
|
|
compatVersion = version;
|
|
|
|
|
}
|
2013-01-08 11:55:52 +01:00
|
|
|
disabledByDefault = readBooleanValue(reader, PLUGIN_DISABLED_BY_DEFAULT);
|
|
|
|
|
experimental = readBooleanValue(reader, PLUGIN_EXPERIMENTAL);
|
|
|
|
|
if (reader.hasError())
|
2010-03-30 16:54:29 +02:00
|
|
|
return;
|
2013-01-08 11:55:52 +01:00
|
|
|
if (experimental)
|
|
|
|
|
disabledByDefault = true;
|
2013-02-12 13:15:05 +01:00
|
|
|
enabledInSettings = !disabledByDefault;
|
2008-12-02 12:01:29 +01:00
|
|
|
while (!reader.atEnd()) {
|
|
|
|
|
reader.readNext();
|
|
|
|
|
switch (reader.tokenType()) {
|
2013-08-28 14:02:48 +02:00
|
|
|
case QXmlStreamReader::StartElement: {
|
|
|
|
|
const QStringRef element = reader.name();
|
2012-11-27 22:23:17 +02:00
|
|
|
if (element == QLatin1String(VENDOR))
|
2008-12-02 12:01:29 +01:00
|
|
|
vendor = reader.readElementText().trimmed();
|
2012-11-27 22:23:17 +02:00
|
|
|
else if (element == QLatin1String(COPYRIGHT))
|
2008-12-02 12:01:29 +01:00
|
|
|
copyright = reader.readElementText().trimmed();
|
2012-11-27 22:23:17 +02:00
|
|
|
else if (element == QLatin1String(LICENSE))
|
2008-12-02 12:01:29 +01:00
|
|
|
license = reader.readElementText().trimmed();
|
2012-11-27 22:23:17 +02:00
|
|
|
else if (element == QLatin1String(DESCRIPTION))
|
2008-12-02 12:01:29 +01:00
|
|
|
description = reader.readElementText().trimmed();
|
2012-11-27 22:23:17 +02:00
|
|
|
else if (element == QLatin1String(URL))
|
2008-12-02 12:01:29 +01:00
|
|
|
url = reader.readElementText().trimmed();
|
2012-11-27 22:23:17 +02:00
|
|
|
else if (element == QLatin1String(CATEGORY))
|
2010-03-12 16:02:23 +01:00
|
|
|
category = reader.readElementText().trimmed();
|
2013-08-28 16:29:08 +02:00
|
|
|
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))
|
2008-12-02 12:01:29 +01:00
|
|
|
readDependencies(reader);
|
2012-11-27 22:23:17 +02:00
|
|
|
else if (element == QLatin1String(ARGUMENTLIST))
|
2008-12-02 12:01:29 +01:00
|
|
|
readArgumentDescriptions(reader);
|
|
|
|
|
else
|
2013-08-28 14:02:48 +02:00
|
|
|
reader.raiseError(msgInvalidElement(element.toString()));
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
reader.raiseError(msgUnexpectedToken());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
void PluginSpecPrivate::readArgumentDescriptions(QXmlStreamReader &reader)
|
|
|
|
|
{
|
|
|
|
|
while (!reader.atEnd()) {
|
|
|
|
|
reader.readNext();
|
|
|
|
|
switch (reader.tokenType()) {
|
|
|
|
|
case QXmlStreamReader::StartElement:
|
2013-08-28 14:02:48 +02:00
|
|
|
if (reader.name() == QLatin1String(ARGUMENT))
|
2008-12-02 12:01:29 +01:00
|
|
|
readArgumentDescription(reader);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2013-08-28 14:02:48 +02:00
|
|
|
reader.raiseError(msgInvalidElement(reader.name().toString()));
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2013-08-28 14:02:48 +02:00
|
|
|
if (reader.name() == QLatin1String(ARGUMENTLIST))
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
2013-08-28 14:02:48 +02:00
|
|
|
reader.raiseError(msgUnexpectedClosing(reader.name().toString()));
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
reader.raiseError(msgUnexpectedToken());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
void PluginSpecPrivate::readArgumentDescription(QXmlStreamReader &reader)
|
|
|
|
|
{
|
|
|
|
|
PluginArgumentDescription arg;
|
2012-11-27 22:23:17 +02:00
|
|
|
arg.name = reader.attributes().value(QLatin1String(ARGUMENT_NAME)).toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (arg.name.isEmpty()) {
|
|
|
|
|
reader.raiseError(msgAttributeMissing(ARGUMENT, ARGUMENT_NAME));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-11-27 22:23:17 +02:00
|
|
|
arg.parameter = reader.attributes().value(QLatin1String(ARGUMENT_PARAMETER)).toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
arg.description = reader.readElementText();
|
|
|
|
|
if (reader.tokenType() != QXmlStreamReader::EndElement)
|
|
|
|
|
reader.raiseError(msgUnexpectedToken());
|
|
|
|
|
argumentDescriptions.push_back(arg);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-08 11:55:52 +01:00
|
|
|
bool PluginSpecPrivate::readBooleanValue(QXmlStreamReader &reader, const char *key)
|
|
|
|
|
{
|
2013-08-28 14:02:48 +02:00
|
|
|
const QStringRef valueString = reader.attributes().value(QLatin1String(key));
|
2013-01-08 11:55:52 +01:00
|
|
|
const bool isOn = valueString.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0;
|
|
|
|
|
if (!valueString.isEmpty() && !isOn
|
|
|
|
|
&& valueString.compare(QLatin1String("false"), Qt::CaseInsensitive) != 0) {
|
|
|
|
|
reader.raiseError(msgInvalidFormat(key));
|
|
|
|
|
}
|
|
|
|
|
return isOn;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
void PluginSpecPrivate::readDependencies(QXmlStreamReader &reader)
|
|
|
|
|
{
|
|
|
|
|
while (!reader.atEnd()) {
|
|
|
|
|
reader.readNext();
|
|
|
|
|
switch (reader.tokenType()) {
|
|
|
|
|
case QXmlStreamReader::StartElement:
|
2013-08-28 14:02:48 +02:00
|
|
|
if (reader.name() == QLatin1String(DEPENDENCY))
|
2008-12-02 12:01:29 +01:00
|
|
|
readDependencyEntry(reader);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2013-08-28 14:02:48 +02:00
|
|
|
reader.raiseError(msgInvalidElement(reader.name().toString()));
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2013-08-28 14:02:48 +02:00
|
|
|
if (reader.name() == QLatin1String(DEPENDENCYLIST))
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
2013-08-28 14:02:48 +02:00
|
|
|
reader.raiseError(msgUnexpectedClosing(reader.name().toString()));
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
reader.raiseError(msgUnexpectedToken());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
void PluginSpecPrivate::readDependencyEntry(QXmlStreamReader &reader)
|
|
|
|
|
{
|
|
|
|
|
PluginDependency dep;
|
2012-11-27 22:23:17 +02:00
|
|
|
dep.name = reader.attributes().value(QLatin1String(DEPENDENCY_NAME)).toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (dep.name.isEmpty()) {
|
|
|
|
|
reader.raiseError(msgAttributeMissing(DEPENDENCY, DEPENDENCY_NAME));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-11-27 22:23:17 +02:00
|
|
|
dep.version = reader.attributes().value(QLatin1String(DEPENDENCY_VERSION)).toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!dep.version.isEmpty() && !isValidVersion(dep.version)) {
|
|
|
|
|
reader.raiseError(msgInvalidFormat(DEPENDENCY_VERSION));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-01-11 14:01:08 +01:00
|
|
|
dep.type = PluginDependency::Required;
|
2012-11-27 22:23:17 +02:00
|
|
|
if (reader.attributes().hasAttribute(QLatin1String(DEPENDENCY_TYPE))) {
|
2013-08-28 14:02:48 +02:00
|
|
|
const QStringRef typeValue = reader.attributes().value(QLatin1String(DEPENDENCY_TYPE));
|
2011-01-11 14:01:08 +01:00
|
|
|
if (typeValue == QLatin1String(DEPENDENCY_TYPE_HARD)) {
|
|
|
|
|
dep.type = PluginDependency::Required;
|
|
|
|
|
} else if (typeValue == QLatin1String(DEPENDENCY_TYPE_SOFT)) {
|
|
|
|
|
dep.type = PluginDependency::Optional;
|
|
|
|
|
} else {
|
|
|
|
|
reader.raiseError(msgInvalidFormat(DEPENDENCY_TYPE));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
dependencies.append(dep);
|
|
|
|
|
reader.readNext();
|
|
|
|
|
if (reader.tokenType() != QXmlStreamReader::EndElement)
|
|
|
|
|
reader.raiseError(msgUnexpectedToken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpecPrivate::provides(const QString &pluginName, const QString &pluginVersion) const
|
|
|
|
|
{
|
|
|
|
|
if (QString::compare(pluginName, name, Qt::CaseInsensitive) != 0)
|
|
|
|
|
return false;
|
|
|
|
|
return (versionCompare(version, pluginVersion) >= 0) && (versionCompare(compatVersion, pluginVersion) <= 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
QRegExp &PluginSpecPrivate::versionRegExp()
|
|
|
|
|
{
|
2012-11-27 22:23:17 +02:00
|
|
|
static QRegExp reg(QLatin1String("([0-9]+)(?:[.]([0-9]+))?(?:[.]([0-9]+))?(?:_([0-9]+))?"));
|
2008-12-02 12:01:29 +01:00
|
|
|
return reg;
|
|
|
|
|
}
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpecPrivate::isValidVersion(const QString &version)
|
|
|
|
|
{
|
|
|
|
|
return versionRegExp().exactMatch(version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
int PluginSpecPrivate::versionCompare(const QString &version1, const QString &version2)
|
|
|
|
|
{
|
|
|
|
|
QRegExp reg1 = versionRegExp();
|
|
|
|
|
QRegExp reg2 = versionRegExp();
|
|
|
|
|
if (!reg1.exactMatch(version1))
|
|
|
|
|
return 0;
|
|
|
|
|
if (!reg2.exactMatch(version2))
|
|
|
|
|
return 0;
|
|
|
|
|
int number1;
|
|
|
|
|
int number2;
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
number1 = reg1.cap(i+1).toInt();
|
|
|
|
|
number2 = reg2.cap(i+1).toInt();
|
|
|
|
|
if (number1 < number2)
|
|
|
|
|
return -1;
|
|
|
|
|
if (number1 > number2)
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2008-12-11 11:26:42 +01:00
|
|
|
bool PluginSpecPrivate::resolveDependencies(const QList<PluginSpec *> &specs)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
if (hasError)
|
|
|
|
|
return false;
|
|
|
|
|
if (state == PluginSpec::Resolved)
|
|
|
|
|
state = PluginSpec::Read; // Go back, so we just re-resolve the dependencies.
|
|
|
|
|
if (state != PluginSpec::Read) {
|
|
|
|
|
errorString = QCoreApplication::translate("PluginSpec", "Resolving dependencies failed because state != Read");
|
|
|
|
|
hasError = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-01-11 14:01:08 +01:00
|
|
|
QHash<PluginDependency, PluginSpec *> resolvedDependencies;
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (const PluginDependency &dependency, dependencies) {
|
|
|
|
|
PluginSpec *found = 0;
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (PluginSpec *spec, specs) {
|
|
|
|
|
if (spec->provides(dependency.name, dependency.version)) {
|
|
|
|
|
found = spec;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
2011-01-11 14:01:08 +01:00
|
|
|
if (dependency.type == PluginDependency::Required) {
|
|
|
|
|
hasError = true;
|
|
|
|
|
if (!errorString.isEmpty())
|
|
|
|
|
errorString.append(QLatin1Char('\n'));
|
|
|
|
|
errorString.append(QCoreApplication::translate("PluginSpec", "Could not resolve dependency '%1(%2)'")
|
|
|
|
|
.arg(dependency.name).arg(dependency.version));
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2011-01-11 14:01:08 +01:00
|
|
|
resolvedDependencies.insert(dependency, found);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
if (hasError)
|
|
|
|
|
return false;
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
dependencySpecs = resolvedDependencies;
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2010-05-19 16:29:47 +02:00
|
|
|
state = PluginSpec::Resolved;
|
2010-03-12 16:02:23 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 16:29:47 +02:00
|
|
|
void PluginSpecPrivate::disableIndirectlyIfDependencyDisabled()
|
|
|
|
|
{
|
2013-02-12 13:15:05 +01:00
|
|
|
if (!enabledInSettings)
|
2010-05-19 16:29:47 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-09-08 11:13:37 +02:00
|
|
|
if (disabledIndirectly)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-01-11 14:01:08 +01:00
|
|
|
QHashIterator<PluginDependency, PluginSpec *> it(dependencySpecs);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
if (it.key().type == PluginDependency::Optional)
|
|
|
|
|
continue;
|
|
|
|
|
PluginSpec *dependencySpec = it.value();
|
2013-02-12 13:19:15 +01:00
|
|
|
if (!dependencySpec->isEffectivelyEnabled()) {
|
2010-05-19 16:29:47 +02:00
|
|
|
disabledIndirectly = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpecPrivate::loadLibrary()
|
|
|
|
|
{
|
|
|
|
|
if (hasError)
|
|
|
|
|
return false;
|
|
|
|
|
if (state != PluginSpec::Resolved) {
|
|
|
|
|
if (state == PluginSpec::Loaded)
|
|
|
|
|
return true;
|
|
|
|
|
errorString = QCoreApplication::translate("PluginSpec", "Loading the library failed because state != Resolved");
|
|
|
|
|
hasError = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#ifdef QT_NO_DEBUG
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
2012-11-27 22:23:17 +02:00
|
|
|
QString libName = QString::fromLatin1("%1/%2.dll").arg(location).arg(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
#elif defined(Q_OS_MAC)
|
2012-11-27 22:23:17 +02:00
|
|
|
QString libName = QString::fromLatin1("%1/lib%2.dylib").arg(location).arg(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
#else
|
2012-11-27 22:23:17 +02:00
|
|
|
QString libName = QString::fromLatin1("%1/lib%2.so").arg(location).arg(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#else //Q_NO_DEBUG
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
2012-11-27 22:23:17 +02:00
|
|
|
QString libName = QString::fromLatin1("%1/%2d.dll").arg(location).arg(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
#elif defined(Q_OS_MAC)
|
2012-11-27 22:23:17 +02:00
|
|
|
QString libName = QString::fromLatin1("%1/lib%2_debug.dylib").arg(location).arg(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
#else
|
2012-11-27 22:23:17 +02:00
|
|
|
QString libName = QString::fromLatin1("%1/lib%2.so").arg(location).arg(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-02-19 15:32:50 +01:00
|
|
|
PluginLoader loader(libName);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!loader.load()) {
|
|
|
|
|
hasError = true;
|
2009-10-06 17:40:30 +02:00
|
|
|
errorString = QDir::toNativeSeparators(libName)
|
|
|
|
|
+ QString::fromLatin1(": ") + loader.errorString();
|
2008-12-02 12:01:29 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
IPlugin *pluginObject = qobject_cast<IPlugin*>(loader.instance());
|
|
|
|
|
if (!pluginObject) {
|
|
|
|
|
hasError = true;
|
2009-09-29 12:17:37 +02:00
|
|
|
errorString = QCoreApplication::translate("PluginSpec", "Plugin is not valid (does not derive from IPlugin)");
|
2008-12-02 12:01:29 +01:00
|
|
|
loader.unload();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
state = PluginSpec::Loaded;
|
|
|
|
|
plugin = pluginObject;
|
|
|
|
|
plugin->d->pluginSpec = q;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpecPrivate::initializePlugin()
|
|
|
|
|
{
|
|
|
|
|
if (hasError)
|
|
|
|
|
return false;
|
|
|
|
|
if (state != PluginSpec::Loaded) {
|
|
|
|
|
if (state == PluginSpec::Initialized)
|
|
|
|
|
return true;
|
|
|
|
|
errorString = QCoreApplication::translate("PluginSpec", "Initializing the plugin failed because state != Loaded");
|
|
|
|
|
hasError = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!plugin) {
|
|
|
|
|
errorString = QCoreApplication::translate("PluginSpec", "Internal error: have no plugin instance to initialize");
|
|
|
|
|
hasError = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QString err;
|
|
|
|
|
if (!plugin->initialize(arguments, &err)) {
|
|
|
|
|
errorString = QCoreApplication::translate("PluginSpec", "Plugin initialization failed: %1").arg(err);
|
|
|
|
|
hasError = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
state = PluginSpec::Initialized;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpecPrivate::initializeExtensions()
|
|
|
|
|
{
|
|
|
|
|
if (hasError)
|
|
|
|
|
return false;
|
|
|
|
|
if (state != PluginSpec::Initialized) {
|
|
|
|
|
if (state == PluginSpec::Running)
|
|
|
|
|
return true;
|
|
|
|
|
errorString = QCoreApplication::translate("PluginSpec", "Cannot perform extensionsInitialized because state != Initialized");
|
|
|
|
|
hasError = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!plugin) {
|
|
|
|
|
errorString = QCoreApplication::translate("PluginSpec", "Internal error: have no plugin instance to perform extensionsInitialized");
|
|
|
|
|
hasError = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
plugin->extensionsInitialized();
|
|
|
|
|
state = PluginSpec::Running;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-02 10:47:33 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
bool PluginSpecPrivate::delayedInitialize()
|
|
|
|
|
{
|
|
|
|
|
if (hasError)
|
|
|
|
|
return false;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (state != PluginSpec::Running)
|
2012-02-02 10:47:33 +01:00
|
|
|
return false;
|
|
|
|
|
if (!plugin) {
|
|
|
|
|
errorString = QCoreApplication::translate("PluginSpec", "Internal error: have no plugin instance to perform delayedInitialize");
|
|
|
|
|
hasError = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return plugin->delayedInitialize();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2010-07-13 13:36:47 +02:00
|
|
|
IPlugin::ShutdownFlag PluginSpecPrivate::stop()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
if (!plugin)
|
2010-07-13 13:36:47 +02:00
|
|
|
return IPlugin::SynchronousShutdown;
|
2008-12-02 12:01:29 +01:00
|
|
|
state = PluginSpec::Stopped;
|
2010-07-13 13:36:47 +02:00
|
|
|
return plugin->aboutToShutdown();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
void PluginSpecPrivate::kill()
|
|
|
|
|
{
|
|
|
|
|
if (!plugin)
|
|
|
|
|
return;
|
|
|
|
|
delete plugin;
|
|
|
|
|
plugin = 0;
|
|
|
|
|
state = PluginSpec::Deleted;
|
|
|
|
|
}
|