ExtensionSystem: FilePath'ify

Change IPlugin::fileName() and IPlugin::location to use
FilePath instead of QString.

Change-Id: If473ab1e258951735f93221cbd62c505f0727eb2
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-05-07 08:33:02 +02:00
parent aad2f6ecac
commit 657ce51467
20 changed files with 79 additions and 75 deletions

View File

@@ -765,7 +765,7 @@ int main(int argc, char **argv)
// Load
const QStringList pluginPaths = getPluginPaths() + installPluginPaths
+ options.customPluginPaths;
PluginManager::setPluginPaths(pluginPaths);
PluginManager::setPluginPaths(Utils::transform(pluginPaths, &Utils::FilePath::fromUserInput));
QMap<QString, QString> foundAppOptions;
if (pluginArguments.size() > 1) {
QMap<QString, bool> appOptions;

View File

@@ -146,7 +146,7 @@ void PluginDetailsView::update(PluginSpec *spec)
d->vendor->setText(spec->vendor());
d->component->setText(spec->category().isEmpty() ? Tr::tr("None") : spec->category());
d->url->setText(QString::fromLatin1("<a href=\"%1\">%1</a>").arg(spec->url()));
d->location->setText(QDir::toNativeSeparators(spec->filePath()));
d->location->setText(spec->filePath().toUserOutput());
const QString pattern = spec->platformSpecification().pattern();
const QString platform = pattern.isEmpty() ? Tr::tr("All") : pattern;
const QString platformString = Tr::tr("%1 (current: \"%2\")")

View File

@@ -443,7 +443,7 @@ FutureSynchronizer *PluginManager::futureSynchronizer()
\sa setPluginPaths()
*/
QStringList PluginManager::pluginPaths()
FilePaths PluginManager::pluginPaths()
{
return d->pluginPaths;
}
@@ -455,7 +455,7 @@ QStringList PluginManager::pluginPaths()
\sa pluginPaths()
\sa loadPlugins()
*/
void PluginManager::setPluginPaths(const QStringList &paths)
void PluginManager::setPluginPaths(const FilePaths &paths)
{
d->setPluginPaths(paths);
}
@@ -1732,7 +1732,7 @@ void PluginManagerPrivate::loadPlugin(PluginSpec *spec, PluginSpec::State destSt
/*!
\internal
*/
void PluginManagerPrivate::setPluginPaths(const QStringList &paths)
void PluginManagerPrivate::setPluginPaths(const FilePaths &paths)
{
qCDebug(pluginLog) << "Plugin search paths:" << paths;
qCDebug(pluginLog) << "Required IID:" << pluginIID;
@@ -1741,17 +1741,18 @@ void PluginManagerPrivate::setPluginPaths(const QStringList &paths)
readPluginPaths();
}
static const QStringList pluginFiles(const QStringList &pluginPaths)
static const FilePaths pluginFiles(const FilePaths &pluginPaths)
{
QStringList pluginFiles;
QStringList searchPaths = pluginPaths;
FilePaths pluginFiles;
FilePaths searchPaths = pluginPaths;
while (!searchPaths.isEmpty()) {
const QDir dir(searchPaths.takeFirst());
const QFileInfoList files = dir.entryInfoList(QDir::Files | QDir::NoSymLinks);
const QStringList absoluteFilePaths = Utils::transform(files, &QFileInfo::absoluteFilePath);
pluginFiles += Utils::filtered(absoluteFilePaths, [](const QString &path) { return QLibrary::isLibrary(path); });
const QFileInfoList dirs = dir.entryInfoList(QDir::Dirs|QDir::NoDotAndDotDot);
searchPaths += Utils::transform(dirs, &QFileInfo::absoluteFilePath);
const FilePath dir = searchPaths.takeFirst().absoluteFilePath();
const FilePaths files = dir.dirEntries(QDir::Files | QDir::NoSymLinks);
pluginFiles += Utils::filtered(files, [](const FilePath &path) {
return QLibrary::isLibrary(path.toFSPathString());
});
const FilePaths dirs = dir.dirEntries(QDir::Dirs | QDir::NoDotAndDotDot);
searchPaths += dirs;
}
return pluginFiles;
}
@@ -1793,11 +1794,12 @@ void PluginManagerPrivate::readPluginPaths()
QVector<PluginSpec *> newSpecs;
// from the file system
for (const QString &pluginFile : pluginFiles(pluginPaths)) {
for (const FilePath &pluginFile : pluginFiles(pluginPaths)) {
expected_str<PluginSpec *> spec = readCppPluginSpec(pluginFile);
if (!spec) {
qCInfo(pluginLog).noquote()
<< QString("Ignoring plugin \"%1\" because: %2").arg(pluginFile).arg(spec.error());
qCInfo(pluginLog).noquote() << QString("Ignoring plugin \"%1\" because: %2")
.arg(pluginFile.toUserOutput())
.arg(spec.error());
continue;
}
newSpecs.append(*spec);

View File

@@ -6,6 +6,7 @@
#include "extensionsystem_global.h"
#include <aggregation/aggregate.h>
#include <utils/filepath.h>
#include <utils/qtcsettings.h>
#include <QObject>
@@ -69,8 +70,8 @@ public:
static QVector<PluginSpec *> loadQueue();
static void loadPlugins();
static void loadPluginsAtRuntime(const QSet<PluginSpec *> &plugins);
static QStringList pluginPaths();
static void setPluginPaths(const QStringList &paths);
static Utils::FilePaths pluginPaths();
static void setPluginPaths(const Utils::FilePaths &paths);
static QString pluginIID();
static void setPluginIID(const QString &iid);
static const QVector<PluginSpec *> plugins();

View File

@@ -53,7 +53,7 @@ public:
void addPlugins(const QVector<PluginSpec *> &specs);
void shutdown();
void setPluginPaths(const QStringList &paths);
void setPluginPaths(const Utils::FilePaths &paths);
const QVector<ExtensionSystem::PluginSpec *> loadQueue();
void loadPlugin(PluginSpec *spec, PluginSpec::State destState);
void resolveDependencies();
@@ -91,7 +91,7 @@ public:
QHash<QString, QVector<PluginSpec *>> pluginCategories;
QVector<PluginSpec *> pluginSpecs;
std::vector<TestSpec> testSpecs;
QStringList pluginPaths;
Utils::FilePaths pluginPaths;
QString pluginIID;
QVector<QObject *> allObjects; // ### make this a QVector<QPointer<QObject> > > ?
QStringList defaultDisabledPlugins; // Plugins/Ignored from install settings

View File

@@ -201,8 +201,8 @@ public:
QVector<ExtensionSystem::PluginDependency> dependencies;
PluginSpec::PluginArgumentDescriptions argumentDescriptions;
QString location;
QString filePath;
FilePath location;
FilePath filePath;
bool experimental{false};
bool deprecated{false};
@@ -491,7 +491,7 @@ PluginSpec::PluginArgumentDescriptions PluginSpec::argumentDescriptions() const
/*!
Returns the absolute path to the directory containing the plugin.
*/
QString PluginSpec::location() const
FilePath PluginSpec::location() const
{
return d->location;
}
@@ -499,7 +499,7 @@ QString PluginSpec::location() const
/*!
Returns the absolute path to the plugin.
*/
QString PluginSpec::filePath() const
FilePath PluginSpec::filePath() const
{
return d->filePath;
}
@@ -692,19 +692,20 @@ namespace {
\internal
Returns false if the file does not represent a Qt Creator plugin.
*/
expected_str<PluginSpec *> readCppPluginSpec(const QString &fileName)
expected_str<PluginSpec *> readCppPluginSpec(const FilePath &fileName)
{
auto spec = new CppPluginSpec;
QFileInfo fileInfo(fileName);
spec->setLocation(fileInfo.absolutePath());
spec->setFilePath(fileInfo.absoluteFilePath());
const FilePath absPath = fileName.absoluteFilePath();
spec->setLocation(absPath.parentDir());
spec->setFilePath(absPath);
spec->d->loader.emplace();
if (Utils::HostOsInfo::isMacHost())
spec->d->loader->setLoadHints(QLibrary::ExportExternalSymbolsHint);
spec->d->loader->setFileName(fileInfo.absoluteFilePath());
spec->d->loader->setFileName(absPath.toFSPathString());
if (spec->d->loader->fileName().isEmpty())
return make_unexpected(::ExtensionSystem::Tr::tr("Cannot open file"));
@@ -1110,12 +1111,12 @@ void PluginSpec::setState(State state)
d->state = state;
}
void PluginSpec::setLocation(const QString &location)
void PluginSpec::setLocation(const FilePath &location)
{
d->location = location;
}
void PluginSpec::setFilePath(const QString &filePath)
void PluginSpec::setFilePath(const FilePath &filePath)
{
d->filePath = filePath;
}
@@ -1142,8 +1143,7 @@ bool CppPluginSpec::loadLibrary()
return false;
}
if (d->loader && !d->loader->load()) {
setError(QDir::toNativeSeparators(filePath()) + QString::fromLatin1(": ")
+ d->loader->errorString());
setError(filePath().toUserOutput() + QString::fromLatin1(": ") + d->loader->errorString());
return false;
}
auto *pluginObject = d->loader ? qobject_cast<IPlugin *>(d->loader->instance())

View File

@@ -8,6 +8,7 @@
#include "iplugin.h"
#include <utils/expected.h>
#include <utils/filepath.h>
#include <QHash>
#include <QStaticPlugin>
@@ -120,8 +121,8 @@ public:
virtual QJsonObject metaData() const;
virtual PerformanceData &performanceData() const;
virtual PluginArgumentDescriptions argumentDescriptions() const;
virtual QString location() const;
virtual QString filePath() const;
virtual Utils::FilePath location() const;
virtual Utils::FilePath filePath() const;
virtual QStringList arguments() const;
virtual void setArguments(const QStringList &arguments);
virtual void addArgument(const QString &argument);
@@ -160,8 +161,8 @@ protected:
protected:
virtual void setState(State state);
virtual void setLocation(const QString &location);
virtual void setFilePath(const QString &filePath);
virtual void setLocation(const Utils::FilePath &location);
virtual void setFilePath(const Utils::FilePath &filePath);
virtual Utils::expected_str<void> readMetaData(const QJsonObject &metaData);
Utils::expected_str<void> reportError(const QString &error);
@@ -169,14 +170,15 @@ private:
std::unique_ptr<Internal::PluginSpecPrivate> d;
};
EXTENSIONSYSTEM_EXPORT Utils::expected_str<PluginSpec *> readCppPluginSpec(const QString &filePath);
EXTENSIONSYSTEM_EXPORT Utils::expected_str<PluginSpec *> readCppPluginSpec(
const Utils::FilePath &filePath);
EXTENSIONSYSTEM_EXPORT Utils::expected_str<PluginSpec *> readCppPluginSpec(
const QStaticPlugin &plugin);
class EXTENSIONSYSTEM_TEST_EXPORT CppPluginSpec : public PluginSpec
{
friend EXTENSIONSYSTEM_EXPORT Utils::expected_str<PluginSpec *> readCppPluginSpec(
const QString &filePath);
const Utils::FilePath &filePath);
friend EXTENSIONSYSTEM_EXPORT Utils::expected_str<PluginSpec *> readCppPluginSpec(
const QStaticPlugin &plugin);

View File

@@ -119,7 +119,7 @@ public:
toolTip = Tr::tr("Path: %1\nPlugin is disabled by command line argument.");
else
toolTip = Tr::tr("Path: %1");
return toolTip.arg(QDir::toNativeSeparators(m_spec->filePath()));
return toolTip.arg(m_spec->filePath().toUserOutput());
}
if (role == Qt::DecorationRole) {
bool ok = !m_spec->hasError();

View File

@@ -154,7 +154,7 @@ void checkContents(QPromise<ArchiveIssue> &promise, const FilePath &tempDir)
if (promise.isCanceled())
return;
it.next();
expected_str<PluginSpec *> spec = readCppPluginSpec(it.filePath());
expected_str<PluginSpec *> spec = readCppPluginSpec(FilePath::fromUserInput(it.filePath()));
if (spec) {
// Is a Qt Creator plugin. Let's see if we find a Core dependency and check the
// version

View File

@@ -153,7 +153,7 @@ void ExtensionManagerWidget::updateView(const QModelIndex &current,
"of the extensions that are part of pack ") + data.name
: extension->longDescription();
longDescription.replace("\n", "<br/>");
const QString location = isPack ? extension->location() : extension->filePath();
const FilePath location = isPack ? extension->location() : extension->filePath();
QString description = htmlStart;
@@ -217,7 +217,7 @@ void ExtensionManagerWidget::updateView(const QModelIndex &current,
.arg(Tr::tr("Version"))
.arg(extension->version())
.arg(Tr::tr("Location"))
.arg(location));
.arg(location.toUserOutput()));
description.append(htmlEnd);
m_primaryDescription->setText(description);

View File

@@ -135,8 +135,7 @@ expected_str<void> LuaEngine::prepareSetup(
sol::lib::table,
sol::lib::utf8);
const QString searchPath
= (FilePath::fromUserInput(pluginSpec.filePath()).parentDir() / "?.lua").toUserOutput();
const QString searchPath = (pluginSpec.location() / "?.lua").toUserOutput();
lua["package"]["path"] = searchPath.toStdString();
// TODO: only register what the plugin requested

View File

@@ -62,8 +62,8 @@ public:
bool delayedInitialize() final
{
scanForPlugins(transform(PluginManager::pluginPaths(), [](const QString &path) -> FilePath {
return FilePath::fromUserInput(path) / "lua-plugins";
scanForPlugins(transform(PluginManager::pluginPaths(), [](const FilePath &path) {
return path / "lua-plugins";
}));
return true;

View File

@@ -71,8 +71,8 @@ expected_str<LuaPluginSpec *> LuaPluginSpec::create(const FilePath &filePath,
if (!r)
return make_unexpected(r.error());
pluginSpec->setFilePath(filePath.toUserOutput());
pluginSpec->setLocation(filePath.parentDir().toUserOutput());
pluginSpec->setFilePath(filePath);
pluginSpec->setLocation(filePath.parentDir());
pluginSpec->d->pluginScriptPath = filePath;

View File

@@ -584,7 +584,7 @@ FilePaths &JsonWizardFactory::searchPaths()
// add paths from enabled plugin meta data
for (PluginSpec *plugin : PluginManager::plugins()) {
if (plugin->state() == PluginSpec::Running) {
const auto base = FilePath::fromString(plugin->filePath()).parentDir();
const auto base = plugin->location();
const auto values = plugin->metaData().value("JsonWizardPaths").toArray();
for (const QJsonValue &v : values) {
const auto path = FilePath::fromString(v.toString());

View File

@@ -625,11 +625,13 @@ void QmlDesignerPlugin::enforceDelayedInitialize()
return;
// adding default path to item library plugins
const QString postfix = Utils::HostOsInfo::isMacHost() ? QString("/QmlDesigner")
: QString("/qmldesigner");
const QStringList pluginPaths = Utils::transform(ExtensionSystem::PluginManager::pluginPaths(),
[postfix](const QString &p) {
return QString(p + postfix);
const QString postfix = Utils::HostOsInfo::isMacHost()
? QString("QmlDesigner")
: QString("qmldesigner");
const QStringList pluginPaths =
Utils::transform(ExtensionSystem::PluginManager::pluginPaths(),
[postfix](const Utils::FilePath &p) {
return (p / postfix).toFSPathString();
});
#ifndef QDS_USE_PROJECTSTORAGE

View File

@@ -47,9 +47,9 @@ class MyClass11 : public MyClass1
Q_OBJECT
};
static QString pluginFolder(const QLatin1String &folder)
static Utils::FilePath pluginFolder(const QLatin1String &folder)
{
return QLatin1String(PLUGINMANAGER_TESTS_DIR) + QLatin1String("/") + folder;
return Utils::FilePath::fromUserInput(QLatin1String(PLUGINMANAGER_TESTS_DIR)) / folder;
}
void tst_PluginManager::init()
@@ -138,7 +138,7 @@ void tst_PluginManager::getObject()
void tst_PluginManager::circularPlugins()
{
PluginManager::setPluginPaths(QStringList() << pluginFolder(QLatin1String("circularplugins")));
PluginManager::setPluginPaths({pluginFolder(QLatin1String("circularplugins"))});
PluginManager::loadPlugins();
const QVector<PluginSpec *> plugins = PluginManager::plugins();
QCOMPARE(plugins.count(), 3);
@@ -160,7 +160,7 @@ void tst_PluginManager::circularPlugins()
void tst_PluginManager::correctPlugins1()
{
PluginManager::setPluginPaths(QStringList() << pluginFolder(QLatin1String("correctplugins1")));
PluginManager::setPluginPaths({pluginFolder(QLatin1String("correctplugins1"))});
PluginManager::loadPlugins();
bool specError = false;
bool runError = false;

View File

@@ -5,7 +5,7 @@ add_qtc_test(tst_pluginspec
PLUGIN_DIR="${CMAKE_CURRENT_BINARY_DIR}"
PLUGINSPEC_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
DLL_INFIX="$<$<CONFIG:Debug>:d>"
DEPENDS ExtensionSystem
DEPENDS ExtensionSystem Utils
SOURCES
tst_pluginspec.cpp
)

View File

@@ -4,6 +4,8 @@ QtcAutotest {
name: "ExtensionSystem pluginspec autotest"
Depends { name: "Aggregation" }
Depends { name: "ExtensionSystem" }
Depends { name: "Utils" }
Group {
name: "Sources"
files: "tst_pluginspec.cpp"

View File

@@ -14,6 +14,8 @@
using namespace ExtensionSystem;
static const Utils::FilePath PLUGIN_DIR_PATH = Utils::FilePath::fromUserInput(PLUGIN_DIR);
static QJsonObject metaData(const QString &fileName)
{
QFile f(fileName);
@@ -221,14 +223,11 @@ void tst_PluginSpec::experimental()
void tst_PluginSpec::locationAndPath()
{
Utils::expected_str<PluginSpec *> ps = readCppPluginSpec(
QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/")
+ libraryName(QLatin1String("test")));
PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
QVERIFY(ps);
CppPluginSpec *spec = static_cast<CppPluginSpec *>(ps.value());
QCOMPARE(spec->location(), QString(QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin")));
QCOMPARE(spec->filePath(),
QString(QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/")
+ libraryName(QLatin1String("test"))));
QCOMPARE(spec->location(), PLUGIN_DIR_PATH / "testplugin");
QCOMPARE(spec->filePath(), PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
}
void tst_PluginSpec::resolveDependencies()
@@ -272,8 +271,7 @@ void tst_PluginSpec::resolveDependencies()
void tst_PluginSpec::loadLibrary()
{
Utils::expected_str<PluginSpec *> ps = readCppPluginSpec(
QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/")
+ libraryName(QLatin1String("test")));
PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
QVERIFY(ps);
CppPluginSpec *spec = static_cast<CppPluginSpec *>(ps.value());
@@ -292,8 +290,7 @@ void tst_PluginSpec::loadLibrary()
void tst_PluginSpec::initializePlugin()
{
Utils::expected_str<PluginSpec *> ps = readCppPluginSpec(
QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/")
+ libraryName(QLatin1String("test")));
PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
QVERIFY(ps);
CppPluginSpec *spec = static_cast<CppPluginSpec *>(ps.value());
QVERIFY(spec->resolveDependencies(QVector<PluginSpec *>()));
@@ -317,8 +314,7 @@ void tst_PluginSpec::initializePlugin()
void tst_PluginSpec::initializeExtensions()
{
Utils::expected_str<PluginSpec *> ps = readCppPluginSpec(
QLatin1String(PLUGIN_DIR) + QLatin1String("/testplugin/")
+ libraryName(QLatin1String("test")));
PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
QVERIFY(ps);
CppPluginSpec *spec = static_cast<CppPluginSpec *>(ps.value());
QVERIFY(spec->resolveDependencies(QVector<PluginSpec *>()));

View File

@@ -114,7 +114,7 @@ int main(int argc, char *argv[])
QObject::connect(&app, &QCoreApplication::aboutToQuit,
&manager, &ExtensionSystem::PluginManager::shutdown);
PluginDialog dialog;
manager.setPluginPaths(QStringList() << app.applicationDirPath() + "/plugins");
manager.setPluginPaths({FilePath::fromUserInput(app.applicationDirPath()) / "plugins"});
manager.loadPlugins();
dialog.show();
app.exec();