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
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2014-07-15 23:32:11 +03:00
|
|
|
#include <utils/fileutils.h>
|
2015-01-06 16:41:44 +01:00
|
|
|
#include <utils/environment.h>
|
2014-07-15 23:32:11 +03:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
#include <QSharedPointer>
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
|
#include <QMetaType>
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2014-02-11 21:55:42 +02:00
|
|
|
namespace Utils { class QtcProcess; }
|
2010-11-10 08:49:19 +01:00
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-12-08 12:08:21 +01:00
|
|
|
class ExternalTool : public QObject
|
2010-11-10 08:49:19 +01:00
|
|
|
{
|
2010-12-08 12:08:21 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2010-11-10 08:49:19 +01:00
|
|
|
public:
|
|
|
|
|
enum OutputHandling {
|
2010-12-08 14:52:53 +01:00
|
|
|
Ignore,
|
2010-11-10 08:49:19 +01:00
|
|
|
ShowInPane,
|
2011-01-24 12:21:42 +01:00
|
|
|
ReplaceSelection
|
2010-11-10 08:49:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ExternalTool();
|
2011-01-21 10:58:06 +01:00
|
|
|
explicit ExternalTool(const ExternalTool *other);
|
2018-05-07 15:00:03 +02:00
|
|
|
~ExternalTool() override;
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2010-11-11 14:57:29 +01:00
|
|
|
QString id() const;
|
2010-11-10 08:49:19 +01:00
|
|
|
QString description() const;
|
|
|
|
|
QString displayName() const;
|
|
|
|
|
QString displayCategory() const;
|
|
|
|
|
int order() const;
|
|
|
|
|
OutputHandling outputHandling() const;
|
2010-12-08 14:52:53 +01:00
|
|
|
OutputHandling errorHandling() const;
|
2011-01-24 12:21:42 +01:00
|
|
|
bool modifiesCurrentDocument() const;
|
2010-11-10 08:49:19 +01:00
|
|
|
|
|
|
|
|
QStringList executables() const;
|
|
|
|
|
QString arguments() const;
|
2010-12-09 14:57:22 +01:00
|
|
|
QString input() const;
|
2010-11-10 08:49:19 +01:00
|
|
|
QString workingDirectory() const;
|
2015-01-06 16:41:44 +01:00
|
|
|
QList<Utils::EnvironmentItem> environment() const;
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2011-01-24 18:14:30 +01:00
|
|
|
void setFileName(const QString &fileName);
|
2011-02-01 15:55:40 +01:00
|
|
|
void setPreset(QSharedPointer<ExternalTool> preset);
|
2011-01-24 18:14:30 +01:00
|
|
|
QString fileName() const;
|
2011-02-01 15:55:40 +01:00
|
|
|
// all tools that are preset (changed or unchanged) have the original value here:
|
|
|
|
|
QSharedPointer<ExternalTool> preset() const;
|
2011-01-24 18:14:30 +01:00
|
|
|
|
2018-05-07 17:34:42 +02:00
|
|
|
static ExternalTool *createFromXml(const QByteArray &xml, QString *errorMessage = nullptr, const QString &locale = QString());
|
|
|
|
|
static ExternalTool *createFromFile(const QString &fileName, QString *errorMessage = nullptr,
|
2011-02-01 15:55:40 +01:00
|
|
|
const QString &locale = QString());
|
2011-01-24 18:14:30 +01:00
|
|
|
|
2018-05-07 17:34:42 +02:00
|
|
|
bool save(QString *errorMessage = nullptr) const;
|
2010-11-10 08:49:19 +01:00
|
|
|
|
2011-02-25 15:27:13 +01:00
|
|
|
bool operator==(const ExternalTool &other) const;
|
|
|
|
|
bool operator!=(const ExternalTool &other) const { return !((*this) == other); }
|
2011-02-08 12:28:35 +01:00
|
|
|
ExternalTool &operator=(const ExternalTool &other);
|
2011-01-24 15:01:48 +01:00
|
|
|
|
2011-02-02 12:35:32 +01:00
|
|
|
void setId(const QString &id);
|
2011-02-10 10:03:46 +01:00
|
|
|
void setDisplayCategory(const QString &category);
|
2011-01-24 15:01:48 +01:00
|
|
|
void setDisplayName(const QString &name);
|
|
|
|
|
void setDescription(const QString &description);
|
|
|
|
|
void setOutputHandling(OutputHandling handling);
|
|
|
|
|
void setErrorHandling(OutputHandling handling);
|
|
|
|
|
void setModifiesCurrentDocument(bool modifies);
|
|
|
|
|
void setExecutables(const QStringList &executables);
|
|
|
|
|
void setArguments(const QString &arguments);
|
|
|
|
|
void setInput(const QString &input);
|
|
|
|
|
void setWorkingDirectory(const QString &workingDirectory);
|
2015-01-06 16:41:44 +01:00
|
|
|
void setEnvironment(const QList<Utils::EnvironmentItem> &items);
|
2011-01-24 18:14:30 +01:00
|
|
|
|
2010-11-10 08:49:19 +01:00
|
|
|
private:
|
2010-11-11 14:57:29 +01:00
|
|
|
QString m_id;
|
2010-11-10 08:49:19 +01:00
|
|
|
QString m_description;
|
|
|
|
|
QString m_displayName;
|
|
|
|
|
QString m_displayCategory;
|
2018-07-21 21:11:46 +02:00
|
|
|
int m_order = -1;
|
2010-11-10 08:49:19 +01:00
|
|
|
QStringList m_executables;
|
|
|
|
|
QString m_arguments;
|
2010-12-09 14:57:22 +01:00
|
|
|
QString m_input;
|
2010-11-10 08:49:19 +01:00
|
|
|
QString m_workingDirectory;
|
2015-01-06 16:41:44 +01:00
|
|
|
QList<Utils::EnvironmentItem> m_environment;
|
2018-07-21 21:11:46 +02:00
|
|
|
OutputHandling m_outputHandling = ShowInPane;
|
|
|
|
|
OutputHandling m_errorHandling = ShowInPane;
|
|
|
|
|
bool m_modifiesCurrentDocument = false;
|
2011-01-24 12:21:42 +01:00
|
|
|
|
2011-01-24 18:14:30 +01:00
|
|
|
QString m_fileName;
|
|
|
|
|
QString m_presetFileName;
|
2011-02-01 15:55:40 +01:00
|
|
|
QSharedPointer<ExternalTool> m_presetTool;
|
2010-11-10 08:49:19 +01:00
|
|
|
};
|
|
|
|
|
|
2010-12-08 12:08:21 +01:00
|
|
|
class ExternalToolRunner : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
ExternalToolRunner(const ExternalTool *tool);
|
2018-05-07 15:00:03 +02:00
|
|
|
~ExternalToolRunner() override;
|
2010-12-08 12:08:21 +01:00
|
|
|
|
2011-03-22 13:37:19 +01:00
|
|
|
bool hasError() const;
|
|
|
|
|
QString errorString() const;
|
|
|
|
|
|
2016-02-02 09:10:54 +02:00
|
|
|
private:
|
2010-12-09 14:57:22 +01:00
|
|
|
void started();
|
2010-12-13 17:35:40 +01:00
|
|
|
void finished(int exitCode, QProcess::ExitStatus status);
|
2010-12-08 12:08:21 +01:00
|
|
|
void error(QProcess::ProcessError error);
|
|
|
|
|
void readStandardOutput();
|
|
|
|
|
void readStandardError();
|
|
|
|
|
|
|
|
|
|
void run();
|
|
|
|
|
bool resolve();
|
|
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
const ExternalTool *m_tool; // is a copy of the tool that was passed in
|
2014-07-15 23:32:11 +03:00
|
|
|
Utils::FileName m_resolvedExecutable;
|
2010-12-15 16:48:11 +01:00
|
|
|
QString m_resolvedArguments;
|
2010-12-09 14:57:22 +01:00
|
|
|
QString m_resolvedInput;
|
2010-12-08 12:08:21 +01:00
|
|
|
QString m_resolvedWorkingDirectory;
|
2015-01-06 16:41:44 +01:00
|
|
|
Utils::Environment m_resolvedEnvironment;
|
2010-12-15 16:48:11 +01:00
|
|
|
Utils::QtcProcess *m_process;
|
2010-12-08 12:08:21 +01:00
|
|
|
QTextCodec *m_outputCodec;
|
|
|
|
|
QTextCodec::ConverterState m_outputCodecState;
|
|
|
|
|
QTextCodec::ConverterState m_errorCodecState;
|
2010-12-09 15:53:43 +01:00
|
|
|
QString m_processOutput;
|
2010-12-13 17:35:40 +01:00
|
|
|
QString m_expectedFileName;
|
2011-03-22 13:37:19 +01:00
|
|
|
bool m_hasError;
|
|
|
|
|
QString m_errorString;
|
2010-12-08 12:08:21 +01:00
|
|
|
};
|
|
|
|
|
|
2010-12-09 15:53:43 +01:00
|
|
|
} // Internal
|
2010-11-10 08:49:19 +01:00
|
|
|
} // Core
|
|
|
|
|
|
2011-01-06 18:26:09 +01:00
|
|
|
Q_DECLARE_METATYPE(Core::Internal::ExternalTool *)
|