2016-01-15 14:58:39 +01:00
|
|
|
/****************************************************************************
|
2015-04-27 15:03:07 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 Brian McGillion and Hugues Delorme
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-04-27 15:03:07 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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:58:39 +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.
|
2015-04-27 15:03:07 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +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.
|
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
|
|
|
|
|
|
|
|
#include "utils_global.h"
|
|
|
|
|
|
2022-03-02 04:12:25 +01:00
|
|
|
#include "filepath.h"
|
|
|
|
|
#include "processenums.h"
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
2015-04-27 15:03:07 +02:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QMutex;
|
|
|
|
|
class QVariant;
|
|
|
|
|
template <typename T>
|
|
|
|
|
class QFutureInterface;
|
|
|
|
|
template <typename T>
|
|
|
|
|
class QFuture;
|
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;
|
|
|
|
|
|
2015-04-27 15:03:07 +02:00
|
|
|
namespace Internal { class ShellCommandPrivate; }
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT ProgressParser
|
|
|
|
|
{
|
|
|
|
|
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;
|
2015-04-27 15:03:07 +02:00
|
|
|
friend class ShellCommand;
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-14 11:00:00 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT ShellCommand 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.
|
|
|
|
|
FullySynchronously = 0x80, // Suppress local event loop (in case UI actions are
|
|
|
|
|
// triggered by file watchers).
|
|
|
|
|
SilentOutput = 0x100, // Suppress user notifications about the output happening.
|
2018-11-14 11:12:57 +02:00
|
|
|
NoFullySync = 0x200, // Avoid fully synchronous execution even in UI thread.
|
2022-07-12 14:09:40 +02:00
|
|
|
SshPasswordPrompt = 0x400, // Disable terminal on UNIX to force graphical prompt.
|
|
|
|
|
ExpectRepoChanges = 0x800, // Expect changes in repository by the command
|
2015-04-27 15:03:07 +02:00
|
|
|
NoOutput = SuppressStdErr | SuppressFailMessage | SuppressCommandLogging
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2021-08-11 10:02:58 +02:00
|
|
|
ShellCommand(const FilePath &workingDirectory, const Environment &environment);
|
2015-06-08 15:04:04 +02:00
|
|
|
~ShellCommand() override;
|
2015-04-27 15:03:07 +02:00
|
|
|
|
|
|
|
|
QString displayName() const;
|
|
|
|
|
void setDisplayName(const QString &name);
|
|
|
|
|
|
2022-07-14 11:00:00 +02:00
|
|
|
const FilePath &defaultWorkingDirectory() const;
|
|
|
|
|
|
|
|
|
|
Environment environment() const;
|
|
|
|
|
void setEnvironment(const Environment &env);
|
|
|
|
|
|
2019-06-07 15:27:50 +02:00
|
|
|
void addJob(const CommandLine &command,
|
2021-08-11 10:02:58 +02:00
|
|
|
const FilePath &workingDirectory = {},
|
2021-05-06 15:54:02 +02:00
|
|
|
const ExitCodeInterpreter &interpreter = {});
|
2019-06-07 15:27:50 +02:00
|
|
|
void addJob(const CommandLine &command, int timeoutS,
|
2021-08-11 10:02:58 +02:00
|
|
|
const FilePath &workingDirectory = {},
|
2021-05-06 15:54:02 +02:00
|
|
|
const ExitCodeInterpreter &interpreter = {});
|
2016-07-04 15:11:50 +02:00
|
|
|
void execute(); // Execute tasks asynchronously!
|
2015-04-27 15:03:07 +02:00
|
|
|
void abort();
|
|
|
|
|
|
|
|
|
|
int defaultTimeoutS() const;
|
|
|
|
|
void setDefaultTimeoutS(int timeout);
|
|
|
|
|
|
|
|
|
|
unsigned flags() const;
|
|
|
|
|
void addFlags(unsigned f);
|
|
|
|
|
|
|
|
|
|
const QVariant &cookie() const;
|
|
|
|
|
void setCookie(const QVariant &cookie);
|
|
|
|
|
|
|
|
|
|
QTextCodec *codec() const;
|
|
|
|
|
void setCodec(QTextCodec *codec);
|
|
|
|
|
|
|
|
|
|
void setProgressParser(ProgressParser *parser);
|
2017-09-07 11:17:27 +02:00
|
|
|
bool hasProgressParser() const;
|
2015-04-27 15:03:07 +02:00
|
|
|
void setProgressiveOutput(bool progressive);
|
|
|
|
|
|
2016-07-04 17:20:23 +02:00
|
|
|
// This is called once per job in a thread.
|
|
|
|
|
// When called from the UI thread it will execute fully synchronously, so no signals will
|
|
|
|
|
// be triggered!
|
2022-07-12 13:34:26 +02:00
|
|
|
void runCommand(QtcProcess &process, const CommandLine &command,
|
|
|
|
|
const FilePath &workingDirectory = {});
|
2015-04-27 15:03:07 +02:00
|
|
|
|
|
|
|
|
void cancel();
|
|
|
|
|
|
2022-07-14 11:00:00 +02:00
|
|
|
void setDisableUnixTerminal();
|
|
|
|
|
int timeoutS() const;
|
|
|
|
|
|
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 &);
|
2018-06-26 07:58:04 +03:00
|
|
|
void started();
|
2022-07-29 12:28:01 +02:00
|
|
|
void finished(bool success, const QVariant &cookie);
|
2015-04-27 15:03:07 +02:00
|
|
|
|
|
|
|
|
void terminate(); // Internal
|
|
|
|
|
|
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
|
|
|
// TODO: remove Utils:: scope when support for Qt5 is dropped (Creator 9.0)
|
|
|
|
|
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:21:33 +02:00
|
|
|
void executedAsync(const QFuture<void> &future);
|
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-07-12 16:19:18 +02:00
|
|
|
FilePath workDirectory(const FilePath &wd) const;
|
2015-04-27 15:03:07 +02:00
|
|
|
void run(QFutureInterface<void> &future);
|
2016-07-04 17:20:23 +02:00
|
|
|
|
|
|
|
|
// Run without a event loop in fully blocking mode. No signals will be delivered.
|
2022-07-12 16:19:18 +02:00
|
|
|
void runFullySynchronous(QtcProcess &proc);
|
2016-07-04 17:20:23 +02:00
|
|
|
// Run with an event loop. Signals will be delivered.
|
2022-07-12 16:19:18 +02:00
|
|
|
void runSynchronous(QtcProcess &proc);
|
2015-04-27 15:03:07 +02:00
|
|
|
|
|
|
|
|
class Internal::ShellCommandPrivate *const d;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Utils
|