From 84f6b8891be0a9254939eb8066983ada85ec7f3d Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 30 Sep 2021 17:30:55 +0200 Subject: [PATCH] Core: ExternalTool: Use FilePath also for executables Change-Id: I6ec914b68ae41f9ee5eb28416c29d0431c5ab880 Reviewed-by: Qt CI Bot Reviewed-by: Eike Ziller --- .../coreplugin/dialogs/externaltoolconfig.cpp | 10 +++---- src/plugins/coreplugin/externaltool.cpp | 29 ++++++++----------- src/plugins/coreplugin/externaltool.h | 6 ++-- .../externaltool/tst_externaltooltest.cpp | 8 ++--- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp index 111fcb13a14..d17d02f51b6 100644 --- a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp +++ b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp @@ -575,11 +575,11 @@ void ExternalToolConfig::updateItem(const QModelIndex &index) if (!tool) return; tool->setDescription(m_ui.description->text()); - QStringList executables = tool->executables(); + FilePaths executables = tool->executables(); if (executables.size() > 0) - executables[0] = m_ui.executable->rawPath(); + executables[0] = m_ui.executable->rawFilePath(); else - executables << m_ui.executable->rawPath(); + executables << m_ui.executable->rawFilePath(); tool->setExecutables(executables); tool->setArguments(m_ui.arguments->text()); tool->setWorkingDirectory(m_ui.workingDirectory->rawFilePath()); @@ -607,8 +607,8 @@ void ExternalToolConfig::showInfoForItem(const QModelIndex &index) } m_ui.infoWidget->setEnabled(true); m_ui.description->setText(tool->description()); - m_ui.executable->setPath(tool->executables().isEmpty() ? QString() - : tool->executables().constFirst()); + m_ui.executable->setFilePath(tool->executables().isEmpty() ? FilePath() + : tool->executables().constFirst()); m_ui.arguments->setText(tool->arguments()); m_ui.workingDirectory->setFilePath(tool->workingDirectory()); m_ui.outputBehavior->setCurrentIndex(int(tool->outputHandling())); diff --git a/src/plugins/coreplugin/externaltool.cpp b/src/plugins/coreplugin/externaltool.cpp index 33368c47971..04ff8c9e0c5 100644 --- a/src/plugins/coreplugin/externaltool.cpp +++ b/src/plugins/coreplugin/externaltool.cpp @@ -154,7 +154,7 @@ int ExternalTool::order() const return m_order; } -QStringList ExternalTool::executables() const +FilePaths ExternalTool::executables() const { return m_executables; } @@ -250,43 +250,36 @@ void ExternalTool::setDescription(const QString &description) m_description = description; } - void ExternalTool::setOutputHandling(OutputHandling handling) { m_outputHandling = handling; } - void ExternalTool::setErrorHandling(OutputHandling handling) { m_errorHandling = handling; } - void ExternalTool::setModifiesCurrentDocument(bool modifies) { m_modifiesCurrentDocument = modifies; } - -void ExternalTool::setExecutables(const QStringList &executables) +void ExternalTool::setExecutables(const FilePaths &executables) { m_executables = executables; } - void ExternalTool::setArguments(const QString &arguments) { m_arguments = arguments; } - void ExternalTool::setInput(const QString &input) { m_input = input; } - void ExternalTool::setWorkingDirectory(const FilePath &workingDirectory) { m_workingDirectory = workingDirectory; @@ -417,7 +410,7 @@ ExternalTool * ExternalTool::createFromXml(const QByteArray &xml, QString *error } while (reader.readNextStartElement()) { if (reader.name() == QLatin1String(kPath)) { - tool->m_executables.append(reader.readElementText()); + tool->m_executables.append(FilePath::fromString(reader.readElementText())); } else if (reader.name() == QLatin1String(kArguments)) { if (!tool->m_arguments.isEmpty()) { reader.raiseError("only one element allowed"); @@ -519,8 +512,8 @@ bool ExternalTool::save(QString *errorMessage) const out.writeAttribute(kOutput, stringForOutputHandling(m_outputHandling)); out.writeAttribute(kError, stringForOutputHandling(m_errorHandling)); out.writeAttribute(kModifiesDocument, QLatin1String(m_modifiesCurrentDocument ? kYes : kNo)); - foreach (const QString &executable, m_executables) - out.writeTextElement(kPath, executable); + for (const FilePath &executable : m_executables) + out.writeTextElement(kPath, executable.toString()); if (!m_arguments.isEmpty()) out.writeTextElement(kArguments, m_arguments); if (!m_input.isEmpty()) @@ -608,11 +601,12 @@ bool ExternalToolRunner::resolve() { // executable - QStringList expandedExecutables; /* for error message */ - foreach (const QString &executable, m_tool->executables()) { - QString expanded = expander->expand(executable); + FilePaths expandedExecutables; /* for error message */ + const FilePaths executables = m_tool->executables(); + for (const FilePath &executable : executables) { + FilePath expanded = expander->expand(executable); expandedExecutables.append(expanded); - m_resolvedExecutable = m_resolvedEnvironment.searchInPath(expanded); + m_resolvedExecutable = m_resolvedEnvironment.searchInPath(expanded.path()); if (!m_resolvedExecutable.isEmpty()) break; } @@ -620,7 +614,8 @@ bool ExternalToolRunner::resolve() m_hasError = true; for (int i = 0; i < expandedExecutables.size(); ++i) { m_errorString += tr("Could not find executable for \"%1\" (expanded \"%2\")") - .arg(m_tool->executables().at(i), expandedExecutables.at(i)); + .arg(m_tool->executables().at(i).toUserOutput(), + expandedExecutables.at(i).toUserOutput()); m_errorString += QLatin1Char('\n'); } if (!m_errorString.isEmpty()) diff --git a/src/plugins/coreplugin/externaltool.h b/src/plugins/coreplugin/externaltool.h index 36e4a22d813..38fc517bd2d 100644 --- a/src/plugins/coreplugin/externaltool.h +++ b/src/plugins/coreplugin/externaltool.h @@ -64,7 +64,7 @@ public: OutputHandling errorHandling() const; bool modifiesCurrentDocument() const; - QStringList executables() const; + Utils::FilePaths executables() const; QString arguments() const; QString input() const; Utils::FilePath workingDirectory() const; @@ -95,7 +95,7 @@ public: void setOutputHandling(OutputHandling handling); void setErrorHandling(OutputHandling handling); void setModifiesCurrentDocument(bool modifies); - void setExecutables(const QStringList &executables); + void setExecutables(const Utils::FilePaths &executables); void setArguments(const QString &arguments); void setInput(const QString &input); void setWorkingDirectory(const Utils::FilePath &workingDirectory); @@ -108,7 +108,7 @@ private: QString m_displayName; QString m_displayCategory; int m_order = -1; - QStringList m_executables; + Utils::FilePaths m_executables; QString m_arguments; QString m_input; Utils::FilePath m_workingDirectory; diff --git a/tests/auto/externaltool/tst_externaltooltest.cpp b/tests/auto/externaltool/tst_externaltooltest.cpp index d47c50465be..e7addf7a10c 100644 --- a/tests/auto/externaltool/tst_externaltooltest.cpp +++ b/tests/auto/externaltool/tst_externaltooltest.cpp @@ -121,8 +121,8 @@ void ExternaltoolTest::testRead1() QCOMPARE(tool->displayCategory(), QString::fromLatin1("Linguist")); QCOMPARE(tool->order(), 1); QCOMPARE(tool->executables().size(), 2); - QCOMPARE(tool->executables().at(0), QString::fromLatin1("%{QT_INSTALL_BINS}/lupdate")); - QCOMPARE(tool->executables().at(1), QString::fromLatin1("lupdate")); + QCOMPARE(tool->executables().at(0), FilePath::fromString("%{QT_INSTALL_BINS}/lupdate")); + QCOMPARE(tool->executables().at(1), FilePath::fromString("lupdate")); QCOMPARE(tool->arguments(), QString::fromLatin1("%{CurrentProjectFilePath}")); QCOMPARE(tool->input(), QString()); QCOMPARE(tool->workingDirectory(), FilePath::fromString("%{CurrentProjectPath}")); @@ -143,7 +143,7 @@ void ExternaltoolTest::testRead2() QCOMPARE(tool->displayCategory(), QString::fromLatin1("Text")); QCOMPARE(tool->order(), -1); QCOMPARE(tool->executables().size(), 1); - QCOMPARE(tool->executables().at(0), QString::fromLatin1("sort")); + QCOMPARE(tool->executables().at(0), FilePath::fromString("sort")); QCOMPARE(tool->arguments(), QString()); QCOMPARE(tool->input(), QString::fromLatin1("%{CurrentSelection}")); QCOMPARE(tool->workingDirectory(), FilePath::fromString("%{CurrentPath}")); @@ -164,7 +164,7 @@ void ExternaltoolTest::testRead3() QCOMPARE(tool->displayCategory(), QString::fromLatin1("Text")); QCOMPARE(tool->order(), -1); QCOMPARE(tool->executables().size(), 1); - QCOMPARE(tool->executables().at(0), QString::fromLatin1("xterm")); + QCOMPARE(tool->executables().at(0), FilePath::fromString("xterm")); QVERIFY(tool->arguments().startsWith(QLatin1String("-geom %{"))); QCOMPARE(tool->input(), QString()); QCOMPARE(tool->workingDirectory(), FilePath::fromString("%{CurrentPath}"));