2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-11-10 08:49:19 +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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-11-10 08:49:19 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-02-21 14:57:44 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-11-10 08:49:19 +01:00
|
|
|
|
|
|
|
|
#include "externaltool.h"
|
2011-08-17 12:54:58 +02:00
|
|
|
#include "externaltoolmanager.h"
|
2015-01-12 12:25:52 +02:00
|
|
|
|
2017-08-29 11:48:48 +02:00
|
|
|
#include "icore.h"
|
2015-02-26 13:38:54 +01:00
|
|
|
#include "idocument.h"
|
2015-01-12 12:25:52 +02:00
|
|
|
#include "messagemanager.h"
|
|
|
|
|
#include "documentmanager.h"
|
|
|
|
|
#include "editormanager/editormanager.h"
|
|
|
|
|
#include "editormanager/ieditor.h"
|
2010-12-08 12:08:21 +01:00
|
|
|
|
2011-08-30 15:57:00 +02:00
|
|
|
#include <app/app_version.h>
|
2014-10-13 18:49:44 +02:00
|
|
|
|
2018-07-09 14:11:21 +02:00
|
|
|
#include <utils/algorithm.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2014-10-13 18:49:44 +02:00
|
|
|
#include <utils/macroexpander.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2011-08-17 12:54:58 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QDateTime>
|
2015-01-12 12:25:52 +02:00
|
|
|
#include <QFileInfo>
|
2014-10-15 13:11:46 +02:00
|
|
|
#include <QXmlStreamReader>
|
|
|
|
|
#include <QXmlStreamWriter>
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2014-10-13 18:49:44 +02:00
|
|
|
using namespace Utils;
|
2010-11-10 08:49:19 +01:00
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
2014-10-15 13:11:46 +02:00
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
const char kExternalTool[] = "externaltool";
|
|
|
|
|
const char kId[] = "id";
|
|
|
|
|
const char kDescription[] = "description";
|
|
|
|
|
const char kDisplayName[] = "displayname";
|
|
|
|
|
const char kCategory[] = "category";
|
|
|
|
|
const char kOrder[] = "order";
|
|
|
|
|
const char kExecutable[] = "executable";
|
|
|
|
|
const char kPath[] = "path";
|
|
|
|
|
const char kArguments[] = "arguments";
|
|
|
|
|
const char kInput[] = "input";
|
|
|
|
|
const char kWorkingDirectory[] = "workingdirectory";
|
2018-09-25 13:56:46 +02:00
|
|
|
const char kBaseEnvironmentId[] = "baseEnvironmentId";
|
2015-01-06 16:41:44 +01:00
|
|
|
const char kEnvironment[] = "environment";
|
2014-10-15 13:11:46 +02:00
|
|
|
|
|
|
|
|
const char kXmlLang[] = "xml:lang";
|
|
|
|
|
const char kOutput[] = "output";
|
|
|
|
|
const char kError[] = "error";
|
|
|
|
|
const char kOutputShowInPane[] = "showinpane";
|
|
|
|
|
const char kOutputReplaceSelection[] = "replaceselection";
|
|
|
|
|
const char kOutputIgnore[] = "ignore";
|
|
|
|
|
const char kModifiesDocument[] = "modifiesdocument";
|
|
|
|
|
const char kYes[] = "yes";
|
|
|
|
|
const char kNo[] = "no";
|
|
|
|
|
const char kTrue[] = "true";
|
|
|
|
|
const char kFalse[] = "false";
|
|
|
|
|
|
2010-11-11 15:47:23 +01:00
|
|
|
// #pragma mark -- ExternalTool
|
|
|
|
|
|
2010-11-10 08:49:19 +01:00
|
|
|
ExternalTool::ExternalTool() :
|
2018-09-25 15:51:57 +02:00
|
|
|
m_displayCategory("") // difference between isNull and isEmpty
|
2010-11-10 08:49:19 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 18:26:09 +01:00
|
|
|
ExternalTool::ExternalTool(const ExternalTool *other)
|
|
|
|
|
: m_id(other->m_id),
|
|
|
|
|
m_description(other->m_description),
|
|
|
|
|
m_displayName(other->m_displayName),
|
|
|
|
|
m_displayCategory(other->m_displayCategory),
|
|
|
|
|
m_order(other->m_order),
|
|
|
|
|
m_executables(other->m_executables),
|
|
|
|
|
m_arguments(other->m_arguments),
|
|
|
|
|
m_input(other->m_input),
|
|
|
|
|
m_workingDirectory(other->m_workingDirectory),
|
2018-09-25 13:56:46 +02:00
|
|
|
m_baseEnvironmentProviderId(other->m_baseEnvironmentProviderId),
|
2015-01-06 16:41:44 +01:00
|
|
|
m_environment(other->m_environment),
|
2011-01-06 18:26:09 +01:00
|
|
|
m_outputHandling(other->m_outputHandling),
|
2011-01-21 10:58:06 +01:00
|
|
|
m_errorHandling(other->m_errorHandling),
|
2011-01-24 12:21:42 +01:00
|
|
|
m_modifiesCurrentDocument(other->m_modifiesCurrentDocument),
|
2011-01-24 18:14:30 +01:00
|
|
|
m_fileName(other->m_fileName),
|
2011-02-01 15:55:40 +01:00
|
|
|
m_presetTool(other->m_presetTool)
|
2011-01-06 18:26:09 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 12:28:35 +01:00
|
|
|
ExternalTool &ExternalTool::operator=(const ExternalTool &other)
|
|
|
|
|
{
|
|
|
|
|
m_id = other.m_id;
|
|
|
|
|
m_description = other.m_description;
|
|
|
|
|
m_displayName = other.m_displayName;
|
|
|
|
|
m_displayCategory = other.m_displayCategory;
|
|
|
|
|
m_order = other.m_order;
|
|
|
|
|
m_executables = other.m_executables;
|
|
|
|
|
m_arguments = other.m_arguments;
|
|
|
|
|
m_input = other.m_input;
|
|
|
|
|
m_workingDirectory = other.m_workingDirectory;
|
2015-01-06 16:41:44 +01:00
|
|
|
m_environment = other.m_environment;
|
2011-02-08 12:28:35 +01:00
|
|
|
m_outputHandling = other.m_outputHandling;
|
|
|
|
|
m_errorHandling = other.m_errorHandling;
|
|
|
|
|
m_modifiesCurrentDocument = other.m_modifiesCurrentDocument;
|
|
|
|
|
m_fileName = other.m_fileName;
|
2014-08-04 14:03:41 +02:00
|
|
|
m_presetFileName = other.m_presetFileName;
|
2011-02-08 12:28:35 +01:00
|
|
|
m_presetTool = other.m_presetTool;
|
2011-02-10 10:03:46 +01:00
|
|
|
return *this;
|
2011-02-08 12:28:35 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
ExternalTool::~ExternalTool() = default;
|
2010-12-08 12:08:21 +01:00
|
|
|
|
2010-11-11 14:57:29 +01:00
|
|
|
QString ExternalTool::id() const
|
|
|
|
|
{
|
|
|
|
|
return m_id;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 08:49:19 +01:00
|
|
|
QString ExternalTool::description() const
|
|
|
|
|
{
|
|
|
|
|
return m_description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ExternalTool::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return m_displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ExternalTool::displayCategory() const
|
|
|
|
|
{
|
|
|
|
|
return m_displayCategory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ExternalTool::order() const
|
|
|
|
|
{
|
|
|
|
|
return m_order;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ExternalTool::executables() const
|
|
|
|
|
{
|
|
|
|
|
return m_executables;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ExternalTool::arguments() const
|
|
|
|
|
{
|
|
|
|
|
return m_arguments;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-09 14:57:22 +01:00
|
|
|
QString ExternalTool::input() const
|
|
|
|
|
{
|
|
|
|
|
return m_input;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 08:49:19 +01:00
|
|
|
QString ExternalTool::workingDirectory() const
|
|
|
|
|
{
|
|
|
|
|
return m_workingDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 13:56:46 +02:00
|
|
|
Id ExternalTool::baseEnvironmentProviderId() const
|
|
|
|
|
{
|
|
|
|
|
return m_baseEnvironmentProviderId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Environment ExternalTool::baseEnvironment() const
|
|
|
|
|
{
|
|
|
|
|
if (m_baseEnvironmentProviderId.isValid()) {
|
|
|
|
|
const optional<EnvironmentProvider> provider = EnvironmentProvider::provider(
|
|
|
|
|
m_baseEnvironmentProviderId.name());
|
|
|
|
|
if (provider && provider->environment)
|
|
|
|
|
return provider->environment();
|
|
|
|
|
}
|
|
|
|
|
return Environment::systemEnvironment();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-07 16:51:22 +02:00
|
|
|
EnvironmentItems ExternalTool::environmentUserChanges() const
|
2015-01-06 16:41:44 +01:00
|
|
|
{
|
|
|
|
|
return m_environment;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 08:49:19 +01:00
|
|
|
ExternalTool::OutputHandling ExternalTool::outputHandling() const
|
|
|
|
|
{
|
|
|
|
|
return m_outputHandling;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-08 14:52:53 +01:00
|
|
|
ExternalTool::OutputHandling ExternalTool::errorHandling() const
|
|
|
|
|
{
|
|
|
|
|
return m_errorHandling;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-24 12:21:42 +01:00
|
|
|
bool ExternalTool::modifiesCurrentDocument() const
|
|
|
|
|
{
|
|
|
|
|
return m_modifiesCurrentDocument;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-24 18:14:30 +01:00
|
|
|
void ExternalTool::setFileName(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
m_fileName = fileName;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 15:55:40 +01:00
|
|
|
void ExternalTool::setPreset(QSharedPointer<ExternalTool> preset)
|
2011-01-24 18:14:30 +01:00
|
|
|
{
|
2011-02-01 15:55:40 +01:00
|
|
|
m_presetTool = preset;
|
2011-01-24 18:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ExternalTool::fileName() const
|
|
|
|
|
{
|
|
|
|
|
return m_fileName;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 15:55:40 +01:00
|
|
|
QSharedPointer<ExternalTool> ExternalTool::preset() const
|
2011-01-24 18:14:30 +01:00
|
|
|
{
|
2011-02-01 15:55:40 +01:00
|
|
|
return m_presetTool;
|
2011-01-24 18:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-02 12:35:32 +01:00
|
|
|
void ExternalTool::setId(const QString &id)
|
|
|
|
|
{
|
|
|
|
|
m_id = id;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 10:03:46 +01:00
|
|
|
void ExternalTool::setDisplayCategory(const QString &category)
|
2011-02-02 12:35:32 +01:00
|
|
|
{
|
|
|
|
|
m_displayCategory = category;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-24 15:01:48 +01:00
|
|
|
void ExternalTool::setDisplayName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
m_displayName = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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 QString &workingDirectory)
|
|
|
|
|
{
|
|
|
|
|
m_workingDirectory = workingDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 13:56:46 +02:00
|
|
|
void ExternalTool::setBaseEnvironmentProviderId(Id id)
|
|
|
|
|
{
|
|
|
|
|
m_baseEnvironmentProviderId = id;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-07 16:51:22 +02:00
|
|
|
void ExternalTool::setEnvironmentUserChanges(const EnvironmentItems &items)
|
2015-01-06 16:41:44 +01:00
|
|
|
{
|
|
|
|
|
m_environment = items;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-11 14:26:14 +01:00
|
|
|
static QStringList splitLocale(const QString &locale)
|
2010-11-10 08:49:19 +01:00
|
|
|
{
|
2010-11-11 14:26:14 +01:00
|
|
|
QString value = locale;
|
|
|
|
|
QStringList values;
|
|
|
|
|
if (!value.isEmpty())
|
|
|
|
|
values << value;
|
|
|
|
|
int index = value.indexOf(QLatin1Char('.'));
|
|
|
|
|
if (index >= 0) {
|
|
|
|
|
value = value.left(index);
|
|
|
|
|
if (!value.isEmpty())
|
|
|
|
|
values << value;
|
|
|
|
|
}
|
|
|
|
|
index = value.indexOf(QLatin1Char('_'));
|
|
|
|
|
if (index >= 0) {
|
|
|
|
|
value = value.left(index);
|
|
|
|
|
if (!value.isEmpty())
|
|
|
|
|
values << value;
|
|
|
|
|
}
|
|
|
|
|
return values;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void localizedText(const QStringList &locales, QXmlStreamReader *reader, int *currentLocale, QString *currentText)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(reader);
|
|
|
|
|
Q_ASSERT(currentLocale);
|
|
|
|
|
Q_ASSERT(currentText);
|
2018-09-25 15:51:57 +02:00
|
|
|
if (reader->attributes().hasAttribute(kXmlLang)) {
|
|
|
|
|
int index = locales.indexOf(reader->attributes().value(kXmlLang).toString());
|
2010-11-11 14:26:14 +01:00
|
|
|
if (index >= 0 && (index < *currentLocale || *currentLocale < 0)) {
|
|
|
|
|
*currentText = reader->readElementText();
|
|
|
|
|
*currentLocale = index;
|
|
|
|
|
} else {
|
|
|
|
|
reader->skipCurrentElement();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (*currentLocale < 0 && currentText->isEmpty()) {
|
2011-08-15 12:51:16 +02:00
|
|
|
*currentText = QCoreApplication::translate("Core::Internal::ExternalTool",
|
2013-03-05 11:37:36 +01:00
|
|
|
reader->readElementText().toUtf8().constData(),
|
2014-08-28 17:33:47 +02:00
|
|
|
"");
|
2010-11-11 14:26:14 +01:00
|
|
|
} else {
|
|
|
|
|
reader->skipCurrentElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-28 12:46:58 +01:00
|
|
|
if (currentText->isNull()) // prefer isEmpty over isNull
|
2018-09-25 15:51:57 +02:00
|
|
|
*currentText = "";
|
2010-11-11 14:26:14 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-08 14:52:53 +01:00
|
|
|
static bool parseOutputAttribute(const QString &attribute, QXmlStreamReader *reader, ExternalTool::OutputHandling *value)
|
|
|
|
|
{
|
2020-09-07 12:26:59 +02:00
|
|
|
const auto output = reader->attributes().value(attribute);
|
2020-09-28 17:29:50 +02:00
|
|
|
if (output == QLatin1String(kOutputShowInPane)) {
|
2010-12-08 14:52:53 +01:00
|
|
|
*value = ExternalTool::ShowInPane;
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (output == QLatin1String(kOutputReplaceSelection)) {
|
2010-12-08 14:52:53 +01:00
|
|
|
*value = ExternalTool::ReplaceSelection;
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (output == QLatin1String(kOutputIgnore)) {
|
2010-12-08 14:52:53 +01:00
|
|
|
*value = ExternalTool::Ignore;
|
|
|
|
|
} else {
|
2018-09-25 15:51:57 +02:00
|
|
|
reader->raiseError("Allowed values for output attribute are 'showinpane','replaceselection','ignore'");
|
2010-12-08 14:52:53 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-11 15:47:23 +01:00
|
|
|
ExternalTool * ExternalTool::createFromXml(const QByteArray &xml, QString *errorMessage, const QString &locale)
|
2010-11-11 14:26:14 +01:00
|
|
|
{
|
|
|
|
|
int descriptionLocale = -1;
|
|
|
|
|
int nameLocale = -1;
|
|
|
|
|
int categoryLocale = -1;
|
|
|
|
|
const QStringList &locales = splitLocale(locale);
|
2018-07-21 21:11:46 +02:00
|
|
|
auto tool = new ExternalTool;
|
2010-11-10 08:49:19 +01:00
|
|
|
QXmlStreamReader reader(xml);
|
2010-11-11 14:26:14 +01:00
|
|
|
|
2020-09-28 17:29:50 +02:00
|
|
|
if (!reader.readNextStartElement() || reader.name() != QLatin1String(kExternalTool))
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("Missing start element <externaltool>");
|
|
|
|
|
tool->m_id = reader.attributes().value(kId).toString();
|
2010-11-11 14:57:29 +01:00
|
|
|
if (tool->m_id.isEmpty())
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("Missing or empty id attribute for <externaltool>");
|
2010-11-10 08:49:19 +01:00
|
|
|
while (reader.readNextStartElement()) {
|
2020-09-28 17:29:50 +02:00
|
|
|
if (reader.name() == QLatin1String(kDescription)) {
|
2010-11-11 14:26:14 +01:00
|
|
|
localizedText(locales, &reader, &descriptionLocale, &tool->m_description);
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (reader.name() == QLatin1String(kDisplayName)) {
|
2010-11-11 14:26:14 +01:00
|
|
|
localizedText(locales, &reader, &nameLocale, &tool->m_displayName);
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (reader.name() == QLatin1String(kCategory)) {
|
2010-11-11 14:26:14 +01:00
|
|
|
localizedText(locales, &reader, &categoryLocale, &tool->m_displayCategory);
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (reader.name() == QLatin1String(kOrder)) {
|
2010-11-10 08:49:19 +01:00
|
|
|
if (tool->m_order >= 0) {
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("only one <order> element allowed");
|
2010-11-10 08:49:19 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
bool ok;
|
|
|
|
|
tool->m_order = reader.readElementText().toInt(&ok);
|
|
|
|
|
if (!ok || tool->m_order < 0)
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("<order> element requires non-negative integer value");
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (reader.name() == QLatin1String(kExecutable)) {
|
2018-09-25 15:51:57 +02:00
|
|
|
if (reader.attributes().hasAttribute(kOutput)) {
|
|
|
|
|
if (!parseOutputAttribute(kOutput, &reader, &tool->m_outputHandling))
|
2010-12-08 14:52:53 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2018-09-25 15:51:57 +02:00
|
|
|
if (reader.attributes().hasAttribute(kError)) {
|
|
|
|
|
if (!parseOutputAttribute(kError, &reader, &tool->m_errorHandling))
|
2010-11-10 08:49:19 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2018-09-25 15:51:57 +02:00
|
|
|
if (reader.attributes().hasAttribute(kModifiesDocument)) {
|
2020-09-07 12:26:59 +02:00
|
|
|
const auto value = reader.attributes().value(kModifiesDocument);
|
2020-09-28 17:29:50 +02:00
|
|
|
if (value == QLatin1String(kYes) || value == QLatin1String(kTrue)) {
|
2011-01-24 12:21:42 +01:00
|
|
|
tool->m_modifiesCurrentDocument = true;
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (value == QLatin1String(kNo) || value == QLatin1String(kFalse)) {
|
2011-01-24 12:21:42 +01:00
|
|
|
tool->m_modifiesCurrentDocument = false;
|
|
|
|
|
} else {
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("Allowed values for modifiesdocument attribute are 'yes','true','no','false'");
|
2011-01-24 12:21:42 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-10 08:49:19 +01:00
|
|
|
while (reader.readNextStartElement()) {
|
2020-09-28 17:29:50 +02:00
|
|
|
if (reader.name() == QLatin1String(kPath)) {
|
2010-11-10 08:49:19 +01:00
|
|
|
tool->m_executables.append(reader.readElementText());
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (reader.name() == QLatin1String(kArguments)) {
|
2010-11-10 08:49:19 +01:00
|
|
|
if (!tool->m_arguments.isEmpty()) {
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("only one <arguments> element allowed");
|
2010-11-10 08:49:19 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
tool->m_arguments = reader.readElementText();
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (reader.name() == QLatin1String(kInput)) {
|
2010-12-09 14:57:22 +01:00
|
|
|
if (!tool->m_input.isEmpty()) {
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("only one <input> element allowed");
|
2010-12-09 14:57:22 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
tool->m_input = reader.readElementText();
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (reader.name() == QLatin1String(kWorkingDirectory)) {
|
2010-11-10 08:49:19 +01:00
|
|
|
if (!tool->m_workingDirectory.isEmpty()) {
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("only one <workingdirectory> element allowed");
|
2010-11-10 08:49:19 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
tool->m_workingDirectory = reader.readElementText();
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (reader.name() == QLatin1String(kBaseEnvironmentId)) {
|
2018-09-25 13:56:46 +02:00
|
|
|
if (tool->m_baseEnvironmentProviderId.isValid()) {
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("only one <baseEnvironmentId> element allowed");
|
2018-09-25 13:56:46 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
tool->m_baseEnvironmentProviderId = Id::fromString(reader.readElementText());
|
2020-09-28 17:29:50 +02:00
|
|
|
} else if (reader.name() == QLatin1String(kEnvironment)) {
|
2015-01-06 16:41:44 +01:00
|
|
|
if (!tool->m_environment.isEmpty()) {
|
2018-09-25 15:51:57 +02:00
|
|
|
reader.raiseError("only one <environment> element allowed");
|
2015-01-06 16:41:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
QStringList lines = reader.readElementText().split(QLatin1Char(';'));
|
|
|
|
|
for (auto iter = lines.begin(); iter != lines.end(); ++iter)
|
|
|
|
|
*iter = QString::fromUtf8(QByteArray::fromPercentEncoding(iter->toUtf8()));
|
2015-02-03 23:48:19 +02:00
|
|
|
tool->m_environment = EnvironmentItem::fromStringList(lines);
|
2010-12-08 12:07:06 +01:00
|
|
|
} else {
|
|
|
|
|
reader.raiseError(QString::fromLatin1("Unknown element <%1> as subelement of <%2>").arg(
|
2020-06-19 16:12:42 +02:00
|
|
|
reader.qualifiedName().toString(), QString(kExecutable)));
|
2010-12-08 12:07:06 +01:00
|
|
|
break;
|
2010-11-10 08:49:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
reader.raiseError(QString::fromLatin1("Unknown element <%1>").arg(reader.qualifiedName().toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (reader.hasError()) {
|
|
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = reader.errorString();
|
|
|
|
|
delete tool;
|
2018-07-21 21:11:46 +02:00
|
|
|
return nullptr;
|
2010-11-10 08:49:19 +01:00
|
|
|
}
|
|
|
|
|
return tool;
|
|
|
|
|
}
|
2010-11-11 15:47:23 +01:00
|
|
|
|
2011-02-01 15:55:40 +01:00
|
|
|
ExternalTool * ExternalTool::createFromFile(const QString &fileName, QString *errorMessage, const QString &locale)
|
2011-01-24 18:14:30 +01:00
|
|
|
{
|
2011-03-30 15:15:15 +02:00
|
|
|
QString absFileName = QFileInfo(fileName).absoluteFilePath();
|
2014-10-15 13:11:46 +02:00
|
|
|
FileReader reader;
|
2021-05-18 09:47:07 +02:00
|
|
|
if (!reader.fetch(FilePath::fromString(absFileName), errorMessage))
|
2018-07-21 21:11:46 +02:00
|
|
|
return nullptr;
|
2011-03-30 15:15:15 +02:00
|
|
|
ExternalTool *tool = ExternalTool::createFromXml(reader.data(), errorMessage, locale);
|
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 (!tool)
|
2018-07-21 21:11:46 +02:00
|
|
|
return nullptr;
|
2011-03-30 15:15:15 +02:00
|
|
|
tool->m_fileName = absFileName;
|
2011-01-24 18:14:30 +01:00
|
|
|
return tool;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 15:51:57 +02:00
|
|
|
static QString stringForOutputHandling(ExternalTool::OutputHandling handling)
|
2011-01-24 18:14:30 +01:00
|
|
|
{
|
|
|
|
|
switch (handling) {
|
2013-09-05 18:48:06 +02:00
|
|
|
case ExternalTool::Ignore:
|
2011-01-24 18:14:30 +01:00
|
|
|
return QLatin1String(kOutputIgnore);
|
2013-09-05 18:48:06 +02:00
|
|
|
case ExternalTool::ShowInPane:
|
2011-01-24 18:14:30 +01:00
|
|
|
return QLatin1String(kOutputShowInPane);
|
2013-09-05 18:48:06 +02:00
|
|
|
case ExternalTool::ReplaceSelection:
|
2011-01-24 18:14:30 +01:00
|
|
|
return QLatin1String(kOutputReplaceSelection);
|
|
|
|
|
}
|
2018-09-25 15:51:57 +02:00
|
|
|
return QString();
|
2011-01-24 18:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ExternalTool::save(QString *errorMessage) const
|
|
|
|
|
{
|
|
|
|
|
if (m_fileName.isEmpty())
|
|
|
|
|
return false;
|
2021-05-18 09:47:07 +02:00
|
|
|
FileSaver saver(FilePath::fromString(m_fileName));
|
2011-03-30 15:15:15 +02:00
|
|
|
if (!saver.hasError()) {
|
|
|
|
|
QXmlStreamWriter out(saver.file());
|
|
|
|
|
out.setAutoFormatting(true);
|
2018-09-25 15:51:57 +02:00
|
|
|
out.writeStartDocument("1.0");
|
2017-08-29 11:48:48 +02:00
|
|
|
out.writeComment(QString::fromLatin1("Written on %1 by %2")
|
|
|
|
|
.arg(QDateTime::currentDateTime().toString(), ICore::versionString()));
|
2018-09-25 15:51:57 +02:00
|
|
|
out.writeStartElement(kExternalTool);
|
|
|
|
|
out.writeAttribute(kId, m_id);
|
|
|
|
|
out.writeTextElement(kDescription, m_description);
|
|
|
|
|
out.writeTextElement(kDisplayName, m_displayName);
|
|
|
|
|
out.writeTextElement(kCategory, m_displayCategory);
|
2011-03-30 15:15:15 +02:00
|
|
|
if (m_order != -1)
|
2018-09-25 15:51:57 +02:00
|
|
|
out.writeTextElement(kOrder, QString::number(m_order));
|
2011-03-30 15:15:15 +02:00
|
|
|
|
2018-09-25 15:51:57 +02:00
|
|
|
out.writeStartElement(kExecutable);
|
|
|
|
|
out.writeAttribute(kOutput, stringForOutputHandling(m_outputHandling));
|
|
|
|
|
out.writeAttribute(kError, stringForOutputHandling(m_errorHandling));
|
|
|
|
|
out.writeAttribute(kModifiesDocument, QLatin1String(m_modifiesCurrentDocument ? kYes : kNo));
|
2011-03-30 15:15:15 +02:00
|
|
|
foreach (const QString &executable, m_executables)
|
2018-09-25 15:51:57 +02:00
|
|
|
out.writeTextElement(kPath, executable);
|
2011-03-30 15:15:15 +02:00
|
|
|
if (!m_arguments.isEmpty())
|
2018-09-25 15:51:57 +02:00
|
|
|
out.writeTextElement(kArguments, m_arguments);
|
2011-03-30 15:15:15 +02:00
|
|
|
if (!m_input.isEmpty())
|
2018-09-25 15:51:57 +02:00
|
|
|
out.writeTextElement(kInput, m_input);
|
2011-03-30 15:15:15 +02:00
|
|
|
if (!m_workingDirectory.isEmpty())
|
2018-09-25 15:51:57 +02:00
|
|
|
out.writeTextElement(kWorkingDirectory, m_workingDirectory);
|
2018-09-25 13:56:46 +02:00
|
|
|
if (m_baseEnvironmentProviderId.isValid())
|
|
|
|
|
out.writeTextElement(kBaseEnvironmentId, m_baseEnvironmentProviderId.toString());
|
2015-01-06 16:41:44 +01:00
|
|
|
if (!m_environment.isEmpty()) {
|
2015-02-03 23:48:19 +02:00
|
|
|
QStringList envLines = EnvironmentItem::toStringList(m_environment);
|
2015-01-06 16:41:44 +01:00
|
|
|
for (auto iter = envLines.begin(); iter != envLines.end(); ++iter)
|
|
|
|
|
*iter = QString::fromUtf8(iter->toUtf8().toPercentEncoding());
|
2018-09-25 15:51:57 +02:00
|
|
|
out.writeTextElement(kEnvironment, envLines.join(QLatin1Char(';')));
|
2015-01-06 16:41:44 +01:00
|
|
|
}
|
2011-03-30 15:15:15 +02:00
|
|
|
out.writeEndElement();
|
|
|
|
|
|
|
|
|
|
out.writeEndDocument();
|
|
|
|
|
|
|
|
|
|
saver.setResult(&out);
|
2011-01-24 18:14:30 +01:00
|
|
|
}
|
2011-03-30 15:15:15 +02:00
|
|
|
return saver.finalize(errorMessage);
|
2011-01-24 18:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-25 15:27:13 +01:00
|
|
|
bool ExternalTool::operator==(const ExternalTool &other) const
|
2011-01-21 10:58:06 +01:00
|
|
|
{
|
|
|
|
|
return m_id == other.m_id
|
|
|
|
|
&& m_description == other.m_description
|
|
|
|
|
&& m_displayName == other.m_displayName
|
|
|
|
|
&& m_displayCategory == other.m_displayCategory
|
|
|
|
|
&& m_order == other.m_order
|
|
|
|
|
&& m_executables == other.m_executables
|
|
|
|
|
&& m_arguments == other.m_arguments
|
|
|
|
|
&& m_input == other.m_input
|
|
|
|
|
&& m_workingDirectory == other.m_workingDirectory
|
2018-09-25 13:56:46 +02:00
|
|
|
&& m_baseEnvironmentProviderId == other.m_baseEnvironmentProviderId
|
2015-01-06 16:41:44 +01:00
|
|
|
&& m_environment == other.m_environment
|
2011-01-21 10:58:06 +01:00
|
|
|
&& m_outputHandling == other.m_outputHandling
|
2011-01-24 12:21:42 +01:00
|
|
|
&& m_modifiesCurrentDocument == other.m_modifiesCurrentDocument
|
2011-02-01 15:55:40 +01:00
|
|
|
&& m_errorHandling == other.m_errorHandling
|
|
|
|
|
&& m_fileName == other.m_fileName;
|
2011-01-21 10:58:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-08 12:08:21 +01:00
|
|
|
// #pragma mark -- ExternalToolRunner
|
|
|
|
|
|
|
|
|
|
ExternalToolRunner::ExternalToolRunner(const ExternalTool *tool)
|
2011-01-21 10:58:06 +01:00
|
|
|
: m_tool(new ExternalTool(tool)),
|
2018-07-21 21:11:46 +02:00
|
|
|
m_process(nullptr),
|
2011-03-22 13:37:19 +01:00
|
|
|
m_outputCodec(QTextCodec::codecForLocale()),
|
|
|
|
|
m_hasError(false)
|
2010-12-08 12:08:21 +01:00
|
|
|
{
|
|
|
|
|
run();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
ExternalToolRunner::~ExternalToolRunner()
|
|
|
|
|
{
|
|
|
|
|
if (m_tool)
|
|
|
|
|
delete m_tool;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-22 13:37:19 +01:00
|
|
|
bool ExternalToolRunner::hasError() const
|
|
|
|
|
{
|
|
|
|
|
return m_hasError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ExternalToolRunner::errorString() const
|
|
|
|
|
{
|
|
|
|
|
return m_errorString;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-08 12:08:21 +01:00
|
|
|
bool ExternalToolRunner::resolve()
|
|
|
|
|
{
|
|
|
|
|
if (!m_tool)
|
|
|
|
|
return false;
|
2011-02-25 15:27:13 +01:00
|
|
|
m_resolvedExecutable.clear();
|
|
|
|
|
m_resolvedArguments.clear();
|
|
|
|
|
m_resolvedWorkingDirectory.clear();
|
2018-09-25 13:56:46 +02:00
|
|
|
m_resolvedEnvironment = m_tool->baseEnvironment();
|
2014-10-13 12:49:05 +02:00
|
|
|
|
2014-10-15 13:11:46 +02:00
|
|
|
MacroExpander *expander = globalMacroExpander();
|
2019-05-07 16:51:22 +02:00
|
|
|
EnvironmentItems expandedEnvironment = Utils::transform(
|
|
|
|
|
m_tool->environmentUserChanges(), [expander](const EnvironmentItem &item) {
|
|
|
|
|
return EnvironmentItem(item.name, expander->expand(item.value), item.operation);
|
|
|
|
|
});
|
2018-07-09 14:11:21 +02:00
|
|
|
m_resolvedEnvironment.modify(expandedEnvironment);
|
2015-01-06 16:41:44 +01:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// executable
|
2011-03-22 13:37:19 +01:00
|
|
|
QStringList expandedExecutables; /* for error message */
|
2010-12-08 12:08:21 +01:00
|
|
|
foreach (const QString &executable, m_tool->executables()) {
|
2014-10-15 14:45:31 +02:00
|
|
|
QString expanded = expander->expand(executable);
|
|
|
|
|
expandedExecutables.append(expanded);
|
2015-01-06 16:41:44 +01:00
|
|
|
m_resolvedExecutable = m_resolvedEnvironment.searchInPath(expanded);
|
2011-03-22 13:37:19 +01:00
|
|
|
if (!m_resolvedExecutable.isEmpty())
|
|
|
|
|
break;
|
2010-12-08 12:08:21 +01:00
|
|
|
}
|
2011-03-22 13:37:19 +01:00
|
|
|
if (m_resolvedExecutable.isEmpty()) {
|
|
|
|
|
m_hasError = true;
|
|
|
|
|
for (int i = 0; i < expandedExecutables.size(); ++i) {
|
2014-04-17 14:09:47 +02:00
|
|
|
m_errorString += tr("Could not find executable for \"%1\" (expanded \"%2\")")
|
2018-09-25 15:51:57 +02:00
|
|
|
.arg(m_tool->executables().at(i), expandedExecutables.at(i));
|
2013-10-17 13:48:04 +02:00
|
|
|
m_errorString += QLatin1Char('\n');
|
2011-03-22 13:37:19 +01:00
|
|
|
}
|
|
|
|
|
if (!m_errorString.isEmpty())
|
|
|
|
|
m_errorString.chop(1);
|
2010-12-08 12:08:21 +01:00
|
|
|
return false;
|
2011-03-22 13:37:19 +01:00
|
|
|
}
|
2010-12-08 12:08:21 +01:00
|
|
|
}
|
2014-10-15 14:45:31 +02:00
|
|
|
|
2014-10-21 13:19:38 +02:00
|
|
|
m_resolvedArguments = expander->expandProcessArgs(m_tool->arguments());
|
2014-10-15 14:45:31 +02:00
|
|
|
m_resolvedInput = expander->expand(m_tool->input());
|
|
|
|
|
m_resolvedWorkingDirectory = expander->expand(m_tool->workingDirectory());
|
|
|
|
|
|
2010-12-08 12:08:21 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolRunner::run()
|
|
|
|
|
{
|
|
|
|
|
if (!resolve()) {
|
|
|
|
|
deleteLater();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-01-24 12:21:42 +01:00
|
|
|
if (m_tool->modifiesCurrentDocument()) {
|
2013-07-09 11:52:44 +02:00
|
|
|
if (IDocument *document = EditorManager::currentDocument()) {
|
2014-12-21 21:54:30 +02:00
|
|
|
m_expectedFileName = document->filePath().toString();
|
2014-01-21 13:25:19 +01:00
|
|
|
if (!DocumentManager::saveModifiedDocument(document)) {
|
2010-12-13 18:01:20 +01:00
|
|
|
deleteLater();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-02-14 16:43:51 +01:00
|
|
|
DocumentManager::expectFileChange(m_expectedFileName);
|
2010-12-13 17:35:40 +01:00
|
|
|
}
|
2010-12-13 15:17:33 +01:00
|
|
|
}
|
2014-10-15 13:11:46 +02:00
|
|
|
m_process = new QtcProcess(this);
|
2021-05-14 15:21:54 +02:00
|
|
|
connect(m_process, &QtcProcess::started, this, &ExternalToolRunner::started);
|
|
|
|
|
connect(m_process, &QtcProcess::finished, this, &ExternalToolRunner::finished);
|
|
|
|
|
connect(m_process, &QtcProcess::errorOccurred, this, &ExternalToolRunner::error);
|
|
|
|
|
connect(m_process, &QtcProcess::readyReadStandardOutput,
|
2016-02-02 09:10:54 +02:00
|
|
|
this, &ExternalToolRunner::readStandardOutput);
|
2021-05-14 15:21:54 +02:00
|
|
|
connect(m_process, &QtcProcess::readyReadStandardError,
|
2016-02-02 09:10:54 +02:00
|
|
|
this, &ExternalToolRunner::readStandardError);
|
2010-12-08 12:08:21 +01:00
|
|
|
if (!m_resolvedWorkingDirectory.isEmpty())
|
|
|
|
|
m_process->setWorkingDirectory(m_resolvedWorkingDirectory);
|
2019-06-05 15:35:15 +02:00
|
|
|
const CommandLine cmd{m_resolvedExecutable, m_resolvedArguments, CommandLine::Raw};
|
|
|
|
|
m_process->setCommand(cmd);
|
2015-01-06 16:41:44 +01:00
|
|
|
m_process->setEnvironment(m_resolvedEnvironment);
|
2021-05-17 13:45:01 +02:00
|
|
|
const auto write = m_tool->outputHandling() == ExternalTool::ShowInPane
|
2021-05-18 06:31:54 +02:00
|
|
|
? QOverload<const QString &>::of(MessageManager::writeDisrupting)
|
|
|
|
|
: QOverload<const QString &>::of(MessageManager::writeSilently);
|
2021-05-17 13:45:01 +02:00
|
|
|
write(tr("Starting external tool \"%1\"").arg(cmd.toUserOutput()));
|
2010-12-15 16:48:11 +01:00
|
|
|
m_process->start();
|
2010-12-09 14:57:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolRunner::started()
|
|
|
|
|
{
|
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 (!m_resolvedInput.isEmpty())
|
2010-12-09 14:57:22 +01:00
|
|
|
m_process->write(m_resolvedInput.toLocal8Bit());
|
|
|
|
|
m_process->closeWriteChannel();
|
2010-12-08 12:08:21 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-28 14:48:25 +02:00
|
|
|
void ExternalToolRunner::finished()
|
2010-12-08 12:08:21 +01:00
|
|
|
{
|
2021-05-28 14:48:25 +02:00
|
|
|
if (m_process->result() == QtcProcess::FinishedWithSuccess
|
2013-08-07 13:15:15 +02:00
|
|
|
&& (m_tool->outputHandling() == ExternalTool::ReplaceSelection
|
|
|
|
|
|| m_tool->errorHandling() == ExternalTool::ReplaceSelection)) {
|
2013-09-27 10:44:32 +02:00
|
|
|
ExternalToolManager::emitReplaceSelectionRequested(m_processOutput);
|
2010-12-09 15:53:43 +01:00
|
|
|
}
|
2013-08-07 13:15:15 +02:00
|
|
|
if (m_tool->modifiesCurrentDocument())
|
|
|
|
|
DocumentManager::unexpectFileChange(m_expectedFileName);
|
2021-05-17 13:45:01 +02:00
|
|
|
const auto write = m_tool->outputHandling() == ExternalTool::ShowInPane
|
2021-05-18 06:31:54 +02:00
|
|
|
? QOverload<const QString &>::of(MessageManager::writeFlashing)
|
|
|
|
|
: QOverload<const QString &>::of(MessageManager::writeSilently);
|
2021-05-17 13:45:01 +02:00
|
|
|
write(tr("\"%1\" finished").arg(m_resolvedExecutable.toUserOutput()));
|
2010-12-08 12:08:21 +01:00
|
|
|
deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolRunner::error(QProcess::ProcessError error)
|
|
|
|
|
{
|
2012-01-19 23:23:43 +01:00
|
|
|
if (m_tool->modifiesCurrentDocument())
|
2012-02-14 16:43:51 +01:00
|
|
|
DocumentManager::unexpectFileChange(m_expectedFileName);
|
2010-12-08 12:08:21 +01:00
|
|
|
// TODO inform about errors
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(error)
|
2010-12-08 12:08:21 +01:00
|
|
|
deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolRunner::readStandardOutput()
|
|
|
|
|
{
|
2010-12-08 14:52:53 +01:00
|
|
|
if (m_tool->outputHandling() == ExternalTool::Ignore)
|
|
|
|
|
return;
|
2020-12-01 13:02:12 +01:00
|
|
|
const QByteArray data = m_process->readAllStandardOutput();
|
|
|
|
|
const QString output = m_outputCodec->toUnicode(data.constData(),
|
|
|
|
|
data.length(),
|
|
|
|
|
&m_outputCodecState);
|
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 (m_tool->outputHandling() == ExternalTool::ShowInPane)
|
2020-12-01 13:02:12 +01:00
|
|
|
MessageManager::writeSilently(output);
|
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 if (m_tool->outputHandling() == ExternalTool::ReplaceSelection)
|
2010-12-09 15:53:43 +01:00
|
|
|
m_processOutput.append(output);
|
2010-12-08 12:08:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExternalToolRunner::readStandardError()
|
|
|
|
|
{
|
2010-12-08 14:52:53 +01:00
|
|
|
if (m_tool->errorHandling() == ExternalTool::Ignore)
|
|
|
|
|
return;
|
2020-12-01 13:02:12 +01:00
|
|
|
const QByteArray data = m_process->readAllStandardError();
|
|
|
|
|
const QString output = m_outputCodec->toUnicode(data.constData(),
|
|
|
|
|
data.length(),
|
|
|
|
|
&m_errorCodecState);
|
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 (m_tool->errorHandling() == ExternalTool::ShowInPane)
|
2020-12-01 13:02:12 +01:00
|
|
|
MessageManager::writeSilently(output);
|
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 if (m_tool->errorHandling() == ExternalTool::ReplaceSelection)
|
2010-12-09 15:53:43 +01:00
|
|
|
m_processOutput.append(output);
|
2010-12-08 12:08:21 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 13:11:46 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
} // namespace Core
|