2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 Brian McGillion and Hugues Delorme
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2015-04-27 15:03:07 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2015-04-27 15:03:07 +02:00
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
#include "vcsbase_global.h"
|
2015-04-27 15:03:07 +02:00
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
#include <utils/filepath.h>
|
|
|
|
|
#include <utils/processenums.h>
|
2022-03-02 04:12:25 +01:00
|
|
|
|
|
|
|
|
#include <QObject>
|
2015-04-27 15:03:07 +02:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QMutex;
|
|
|
|
|
class QVariant;
|
|
|
|
|
template <typename T>
|
|
|
|
|
class QFuture;
|
2022-08-01 18:35:07 +02:00
|
|
|
template <typename T>
|
|
|
|
|
class QFutureInterface;
|
2022-03-02 04:12:25 +01:00
|
|
|
class QTextCodec;
|
2015-04-27 15:03:07 +02:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
2022-03-02 04:12:25 +01:00
|
|
|
class CommandLine;
|
|
|
|
|
class Environment;
|
|
|
|
|
class QtcProcess;
|
2022-08-01 10:49:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace VcsBase {
|
2022-03-02 04:12:25 +01:00
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
namespace Internal { class VcsCommandPrivate; }
|
2015-04-27 15:03:07 +02:00
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
class VCSBASE_EXPORT ProgressParser
|
2015-04-27 15:03:07 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ProgressParser();
|
|
|
|
|
virtual ~ProgressParser();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void parseProgress(const QString &text) = 0;
|
|
|
|
|
void setProgressAndMaximum(int value, int maximum);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void setFuture(QFutureInterface<void> *future);
|
|
|
|
|
|
|
|
|
|
QFutureInterface<void> *m_future;
|
2018-07-23 10:45:40 +02:00
|
|
|
QMutex *m_futureMutex = nullptr;
|
2022-09-01 17:35:36 +02:00
|
|
|
friend class Internal::VcsCommandPrivate;
|
2015-04-27 15:03:07 +02:00
|
|
|
};
|
|
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
class VCSBASE_EXPORT CommandResult
|
2022-07-29 14:41:15 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CommandResult() = default;
|
2022-08-01 10:49:13 +02:00
|
|
|
CommandResult(const Utils::QtcProcess &process);
|
2022-09-21 08:13:29 +02:00
|
|
|
CommandResult(Utils::ProcessResult result, const QString &exitMessage)
|
|
|
|
|
: m_result(result), m_exitMessage(exitMessage) {}
|
2022-07-29 14:41:15 +02:00
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
Utils::ProcessResult result() const { return m_result; }
|
2022-07-29 14:41:15 +02:00
|
|
|
int exitCode() const { return m_exitCode; }
|
|
|
|
|
QString exitMessage() const { return m_exitMessage; }
|
|
|
|
|
|
|
|
|
|
QString cleanedStdOut() const { return m_cleanedStdOut; }
|
|
|
|
|
QString cleanedStdErr() const { return m_cleanedStdErr; }
|
|
|
|
|
|
|
|
|
|
QByteArray rawStdOut() const { return m_rawStdOut; }
|
|
|
|
|
|
|
|
|
|
private:
|
2022-08-01 10:49:13 +02:00
|
|
|
Utils::ProcessResult m_result = Utils::ProcessResult::StartFailed;
|
2022-07-29 14:41:15 +02:00
|
|
|
int m_exitCode = 0;
|
|
|
|
|
QString m_exitMessage;
|
|
|
|
|
|
|
|
|
|
QString m_cleanedStdOut;
|
|
|
|
|
QString m_cleanedStdErr;
|
|
|
|
|
|
|
|
|
|
QByteArray m_rawStdOut;
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
class VCSBASE_EXPORT VcsCommand final : public QObject
|
2015-04-27 15:03:07 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// Convenience to synchronously run commands
|
|
|
|
|
enum RunFlags {
|
|
|
|
|
ShowStdOut = 0x1, // Show standard output.
|
|
|
|
|
MergeOutputChannels = 0x2, // see QProcess: Merge stderr/stdout.
|
|
|
|
|
SuppressStdErr = 0x4, // Suppress standard error output.
|
|
|
|
|
SuppressFailMessage = 0x8, // No message about command failure.
|
|
|
|
|
SuppressCommandLogging = 0x10, // No command log entry.
|
|
|
|
|
ShowSuccessMessage = 0x20, // Show message about successful completion of command.
|
|
|
|
|
ForceCLocale = 0x40, // Force C-locale for commands whose output is parsed.
|
2022-10-05 11:14:41 +02:00
|
|
|
SilentOutput = 0x80, // Suppress user notifications about the output happening.
|
|
|
|
|
UseEventLoop = 0x100, // Use event loop when executed in UI thread.
|
|
|
|
|
ExpectRepoChanges = 0x200, // Expect changes in repository by the command
|
2015-04-27 15:03:07 +02:00
|
|
|
NoOutput = SuppressStdErr | SuppressFailMessage | SuppressCommandLogging
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
VcsCommand(const Utils::FilePath &workingDirectory, const Utils::Environment &environment);
|
|
|
|
|
~VcsCommand() override;
|
2015-04-27 15:03:07 +02:00
|
|
|
|
|
|
|
|
void setDisplayName(const QString &name);
|
|
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
void addJob(const Utils::CommandLine &command, int timeoutS,
|
|
|
|
|
const Utils::FilePath &workingDirectory = {},
|
|
|
|
|
const Utils::ExitCodeInterpreter &interpreter = {});
|
2022-09-21 07:06:14 +02:00
|
|
|
void start();
|
2015-04-27 15:03:07 +02:00
|
|
|
|
|
|
|
|
void addFlags(unsigned f);
|
|
|
|
|
|
|
|
|
|
void setCodec(QTextCodec *codec);
|
|
|
|
|
|
|
|
|
|
void setProgressParser(ProgressParser *parser);
|
|
|
|
|
void setProgressiveOutput(bool progressive);
|
|
|
|
|
|
2022-08-02 17:28:15 +02:00
|
|
|
CommandResult runCommand(const Utils::CommandLine &command, int timeoutS = 10);
|
2015-04-27 15:03:07 +02:00
|
|
|
void cancel();
|
|
|
|
|
|
2022-09-19 08:27:41 +02:00
|
|
|
QString cleanedStdOut() const;
|
|
|
|
|
QString cleanedStdErr() const;
|
2022-09-19 11:44:07 +02:00
|
|
|
Utils::ProcessResult result() const;
|
2022-09-19 08:27:41 +02:00
|
|
|
|
2015-04-27 15:03:07 +02:00
|
|
|
signals:
|
2015-04-29 12:50:12 +02:00
|
|
|
void stdOutText(const QString &);
|
|
|
|
|
void stdErrText(const QString &);
|
2022-09-19 11:44:07 +02:00
|
|
|
void done();
|
2015-04-27 15:03:07 +02:00
|
|
|
|
2021-06-07 14:27:48 +02:00
|
|
|
void append(const QString &text);
|
|
|
|
|
void appendSilently(const QString &text);
|
|
|
|
|
void appendError(const QString &text);
|
2022-07-11 10:25:50 +02:00
|
|
|
void appendCommand(const Utils::FilePath &workingDirectory, const Utils::CommandLine &command);
|
2021-06-07 14:27:48 +02:00
|
|
|
void appendMessage(const QString &text);
|
|
|
|
|
|
2022-07-13 23:31:40 +02:00
|
|
|
void runCommandFinished(const Utils::FilePath &workingDirectory);
|
2022-07-13 23:21:33 +02:00
|
|
|
|
2015-04-27 15:03:07 +02:00
|
|
|
private:
|
2022-08-01 18:35:07 +02:00
|
|
|
void postRunCommand(const Utils::FilePath &workingDirectory);
|
|
|
|
|
|
2022-08-01 10:49:13 +02:00
|
|
|
class Internal::VcsCommandPrivate *const d;
|
2015-04-27 15:03:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Utils
|