SshRemoteProcessRunner: Unify API

Make the API more similar to QtcProcess API.
Drop process prefix for getters.

Change-Id: I21b99bb5b11956d923c0e526c08bbea9686e5c95
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2022-02-28 16:12:12 +01:00
parent b7abe6a6ac
commit d3c1632a0f
10 changed files with 36 additions and 36 deletions

View File

@@ -53,7 +53,7 @@ public:
QString m_lastConnectionErrorString; QString m_lastConnectionErrorString;
QProcess::ExitStatus m_exitStatus; QProcess::ExitStatus m_exitStatus;
int m_exitCode; int m_exitCode;
QString m_processErrorString; QString m_errorString;
State m_state; State m_state;
}; };
@@ -86,7 +86,7 @@ void SshRemoteProcessRunner::runInternal(const QString &command,
setState(Connecting); setState(Connecting);
d->m_lastConnectionErrorString.clear(); d->m_lastConnectionErrorString.clear();
d->m_processErrorString.clear(); d->m_errorString.clear();
d->m_exitCode = -1; d->m_exitCode = -1;
d->m_command = command; d->m_command = command;
d->m_connection = SshConnectionManager::acquireConnection(sshParams); d->m_connection = SshConnectionManager::acquireConnection(sshParams);
@@ -146,9 +146,9 @@ void SshRemoteProcessRunner::handleProcessFinished()
{ {
d->m_exitStatus = d->m_process->exitStatus(); d->m_exitStatus = d->m_process->exitStatus();
d->m_exitCode = d->m_process->exitCode(); d->m_exitCode = d->m_process->exitCode();
d->m_processErrorString = d->m_process->errorString(); d->m_errorString = d->m_process->errorString();
setState(Inactive); setState(Inactive);
emit processClosed(d->m_processErrorString); emit processClosed(d->m_errorString);
} }
void SshRemoteProcessRunner::setState(int newState) void SshRemoteProcessRunner::setState(int newState)
@@ -175,26 +175,26 @@ QString SshRemoteProcessRunner::lastConnectionErrorString() const {
return d->m_lastConnectionErrorString; return d->m_lastConnectionErrorString;
} }
bool SshRemoteProcessRunner::isProcessRunning() const bool SshRemoteProcessRunner::isRunning() const
{ {
return d->m_process && d->m_process->isRunning(); return d->m_process && d->m_process->isRunning();
} }
QProcess::ExitStatus SshRemoteProcessRunner::processExitStatus() const QProcess::ExitStatus SshRemoteProcessRunner::exitStatus() const
{ {
QTC_CHECK(!isProcessRunning()); QTC_CHECK(!isRunning());
return d->m_exitStatus; return d->m_exitStatus;
} }
int SshRemoteProcessRunner::processExitCode() const int SshRemoteProcessRunner::exitCode() const
{ {
QTC_CHECK(processExitStatus() == QProcess::NormalExit); QTC_CHECK(exitStatus() == QProcess::NormalExit);
return d->m_exitCode; return d->m_exitCode;
} }
QString SshRemoteProcessRunner::processErrorString() const QString SshRemoteProcessRunner::errorString() const
{ {
return d->m_processErrorString; return d->m_errorString;
} }
QByteArray SshRemoteProcessRunner::readAllStandardOutput() QByteArray SshRemoteProcessRunner::readAllStandardOutput()

View File

@@ -44,11 +44,11 @@ public:
QString lastConnectionErrorString() const; QString lastConnectionErrorString() const;
bool isProcessRunning() const; bool isRunning() const;
void cancel(); void cancel();
QProcess::ExitStatus processExitStatus() const; QProcess::ExitStatus exitStatus() const;
int processExitCode() const; int exitCode() const;
QString processErrorString() const; QString errorString() const;
QByteArray readAllStandardOutput(); QByteArray readAllStandardOutput();
QByteArray readAllStandardError(); QByteArray readAllStandardError();

View File

@@ -80,14 +80,14 @@ void SshDeviceProcessList::handleListProcessFinished(const QString &error)
handleProcessError(error); handleProcessError(error);
return; return;
} }
if (d->process.processExitCode() == 0) { if (d->process.exitCode() == 0) {
const QByteArray remoteStdout = d->process.readAllStandardOutput(); const QByteArray remoteStdout = d->process.readAllStandardOutput();
const QString stdoutString const QString stdoutString
= QString::fromUtf8(remoteStdout.data(), remoteStdout.count()); = QString::fromUtf8(remoteStdout.data(), remoteStdout.count());
reportProcessListUpdated(buildProcessList(stdoutString)); reportProcessListUpdated(buildProcessList(stdoutString));
} else { } else {
handleProcessError(tr("Process listing command failed with exit code %1.") handleProcessError(tr("Process listing command failed with exit code %1.")
.arg(d->process.processExitCode())); .arg(d->process.exitCode()));
} }
} }

View File

@@ -201,7 +201,7 @@ void QnxDeployQtLibrariesDialog::handleRemoteProcessCompleted()
if (m_state == CheckingRemoteDirectory) { if (m_state == CheckingRemoteDirectory) {
// Directory exists // Directory exists
if (m_processRunner->processExitCode() == 0) { if (m_processRunner->exitCode() == 0) {
int answer = QMessageBox::question(this, windowTitle(), int answer = QMessageBox::question(this, windowTitle(),
tr("The remote directory \"%1\" already exists. " tr("The remote directory \"%1\" already exists. "
"Deploying to that directory will remove any files " "Deploying to that directory will remove any files "
@@ -217,7 +217,7 @@ void QnxDeployQtLibrariesDialog::handleRemoteProcessCompleted()
startUpload(); startUpload();
} }
} else if (m_state == RemovingRemoteDirectory) { } else if (m_state == RemovingRemoteDirectory) {
QTC_ASSERT(m_processRunner->processExitCode() == 0, return); QTC_ASSERT(m_processRunner->exitCode() == 0, return);
startUpload(); startUpload();
} }

View File

@@ -124,7 +124,7 @@ void QnxDeviceTester::handleVarRunProcessFinished(const QString &error)
QTC_ASSERT(m_state == VarRunTest, return); QTC_ASSERT(m_state == VarRunTest, return);
if (error.isEmpty()) { if (error.isEmpty()) {
if (m_processRunner->processExitCode() == 0) { if (m_processRunner->exitCode() == 0) {
emit progressMessage(tr("Files can be created in /var/run.") + QLatin1Char('\n')); emit progressMessage(tr("Files can be created in /var/run.") + QLatin1Char('\n'));
} else { } else {
emit errorMessage(tr("Files cannot be created in /var/run.") + QLatin1Char('\n')); emit errorMessage(tr("Files cannot be created in /var/run.") + QLatin1Char('\n'));
@@ -156,7 +156,7 @@ void QnxDeviceTester::handleProcessFinished(const QString &error)
const QString command = m_commandsToTest[m_currentCommandIndex]; const QString command = m_commandsToTest[m_currentCommandIndex];
if (error.isEmpty()) { if (error.isEmpty()) {
if (m_processRunner->processExitCode() == 0) { if (m_processRunner->exitCode() == 0) {
emit progressMessage(tr("%1 found.").arg(command) + QLatin1Char('\n')); emit progressMessage(tr("%1 found.").arg(command) + QLatin1Char('\n'));
} else { } else {
emit errorMessage(tr("%1 not found.").arg(command) + QLatin1Char('\n')); emit errorMessage(tr("%1 not found.").arg(command) + QLatin1Char('\n'));

View File

@@ -121,9 +121,9 @@ void RemoteLinuxCustomCommandDeployService::handleProcessClosed(const QString &e
if (!error.isEmpty()) { if (!error.isEmpty()) {
emit errorMessage(tr("Remote process failed: %1").arg(error)); emit errorMessage(tr("Remote process failed: %1").arg(error));
} else if (d->runner->processExitCode() != 0) { } else if (d->runner->exitCode() != 0) {
emit errorMessage(tr("Remote process finished with exit code %1.") emit errorMessage(tr("Remote process finished with exit code %1.")
.arg(d->runner->processExitCode())); .arg(d->runner->exitCode()));
} else { } else {
emit progressMessage(tr("Remote command finished successfully.")); emit progressMessage(tr("Remote command finished successfully."));
} }

View File

@@ -104,7 +104,7 @@ void AbstractRemoteLinuxPackageInstaller::handleInstallationFinished(const QStri
if (!d->isRunning) if (!d->isRunning)
return; return;
if (!error.isEmpty() || d->installer->processExitCode() != 0) if (!error.isEmpty() || d->installer->exitCode() != 0)
emit finished(tr("Installing package failed.")); emit finished(tr("Installing package failed."));
else if (!errorString().isEmpty()) else if (!errorString().isEmpty())
emit finished(errorString()); emit finished(errorString());

View File

@@ -115,10 +115,10 @@ void RemoteLinuxSignalOperation::interruptProcess(const QString &filePath)
void RemoteLinuxSignalOperation::runnerProcessFinished() void RemoteLinuxSignalOperation::runnerProcessFinished()
{ {
m_errorMessage.clear(); m_errorMessage.clear();
if (m_runner->processExitStatus() != QProcess::NormalExit) { if (m_runner->exitStatus() != QProcess::NormalExit) {
m_errorMessage = m_runner->processErrorString(); m_errorMessage = m_runner->errorString();
} else if (m_runner->processExitCode() != 0) { } else if (m_runner->exitCode() != 0) {
m_errorMessage = tr("Exit code is %1. stderr:").arg(m_runner->processExitCode()) m_errorMessage = tr("Exit code is %1. stderr:").arg(m_runner->exitCode())
+ QLatin1Char(' ') + QLatin1Char(' ')
+ QString::fromLatin1(m_runner->readAllStandardError()); + QString::fromLatin1(m_runner->readAllStandardError());
} }

View File

@@ -83,8 +83,8 @@ void SshKeyDeployer::handleConnectionFailure()
void SshKeyDeployer::handleKeyUploadFinished() void SshKeyDeployer::handleKeyUploadFinished()
{ {
const int exitCode = d->deployProcess.processExitCode(); const int exitCode = d->deployProcess.exitCode();
const QString errorMsg = d->deployProcess.processErrorString(); const QString errorMsg = d->deployProcess.errorString();
cleanup(); cleanup();
if (errorMsg.isEmpty() && exitCode == 0) { if (errorMsg.isEmpty() && exitCode == 0) {
emit finishedSuccessfully(); emit finishedSuccessfully();

View File

@@ -259,8 +259,8 @@ void tst_Ssh::remoteProcess()
timer.stop(); timer.stop();
QVERIFY2(runner.lastConnectionErrorString().isEmpty(), QVERIFY2(runner.lastConnectionErrorString().isEmpty(),
qPrintable(runner.lastConnectionErrorString())); qPrintable(runner.lastConnectionErrorString()));
QVERIFY2(runner.processErrorString().isEmpty(), qPrintable(runner.processErrorString())); QVERIFY2(runner.errorString().isEmpty(), qPrintable(runner.errorString()));
QVERIFY(runner.isProcessRunning()); // Event loop exit should have been triggered by started(). QVERIFY(runner.isRunning()); // Event loop exit should have been triggered by started().
QVERIFY2(remoteStdout.isEmpty(), remoteStdout.constData()); QVERIFY2(remoteStdout.isEmpty(), remoteStdout.constData());
QVERIFY2(remoteStderr.isEmpty(), remoteStderr.constData()); QVERIFY2(remoteStderr.isEmpty(), remoteStderr.constData());
@@ -272,14 +272,14 @@ void tst_Ssh::remoteProcess()
loop.exec(); loop.exec();
QVERIFY(timer.isActive()); QVERIFY(timer.isActive());
timer.stop(); timer.stop();
QVERIFY(!runner.isProcessRunning()); QVERIFY(!runner.isRunning());
QVERIFY2(runner.lastConnectionErrorString().isEmpty(), QVERIFY2(runner.lastConnectionErrorString().isEmpty(),
qPrintable(runner.lastConnectionErrorString())); qPrintable(runner.lastConnectionErrorString()));
if (isBlocking) { if (isBlocking) {
QVERIFY(runner.processExitStatus() == QProcess::CrashExit QVERIFY(runner.exitStatus() == QProcess::CrashExit
|| runner.processExitCode() != 0); || runner.exitCode() != 0);
} else { } else {
QCOMPARE(successExpected, runner.processExitCode() == 0); QCOMPARE(successExpected, runner.exitCode() == 0);
} }
QCOMPARE(stdoutExpected, !remoteStdout.isEmpty()); QCOMPARE(stdoutExpected, !remoteStdout.isEmpty());
QCOMPARE(stderrExpected, !remoteStderr.isEmpty()); QCOMPARE(stderrExpected, !remoteStderr.isEmpty());