Remove Core::ShellCommand

Move the implementation into VcsCommand.
Use Utils::ShellCommand inside coreplugin API.

Change-Id: I74a34057b33832a138b05f1dfa6937565027edb4
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-07-11 11:45:54 +02:00
parent 9891a879aa
commit e793841b4f
17 changed files with 91 additions and 199 deletions

View File

@@ -163,7 +163,7 @@ public:
void vcsAnnotate(const Utils::FilePath &file, int line) final;
void vcsDescribe(const Utils::FilePath &source, const QString &id) final { m_client.view(source.toString(), id); }
Core::ShellCommand *createInitialCheckoutCommand(const QString &url,
ShellCommand *createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs) final;
@@ -924,8 +924,7 @@ void BazaarPluginPrivate::vcsAnnotate(const FilePath &file, int line)
m_client.annotate(file.parentDir(), file.fileName(), QString(), line);
}
Core::ShellCommand *BazaarPluginPrivate::createInitialCheckoutCommand(
const QString &url,
ShellCommand *BazaarPluginPrivate::createInitialCheckoutCommand(const QString &url,
const FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs)

View File

@@ -149,7 +149,6 @@ add_qtc_plugin(Core
progressmanager/progressview.cpp progressmanager/progressview.h
rightpane.cpp rightpane.h
settingsdatabase.cpp settingsdatabase.h
shellcommand.cpp shellcommand.h
sidebar.cpp sidebar.h
sidebarwidget.cpp sidebarwidget.h
statusbarmanager.cpp statusbarmanager.h

View File

@@ -156,8 +156,6 @@ Project {
"rightpane.h",
"settingsdatabase.cpp",
"settingsdatabase.h",
"shellcommand.cpp",
"shellcommand.h",
"sidebar.cpp",
"sidebar.h",
"sidebarwidget.cpp",

View File

@@ -38,9 +38,9 @@
QT_FORWARD_DECLARE_CLASS(QMenu);
namespace Core {
namespace Utils { class ShellCommand; }
class ShellCommand;
namespace Core {
class CORE_EXPORT IVersionControl : public QObject
{
@@ -229,7 +229,7 @@ public:
*
* \a extraArgs are passed on to the command being run.
*/
virtual ShellCommand *createInitialCheckoutCommand(const QString &url,
virtual Utils::ShellCommand *createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs);

View File

@@ -1,72 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 Brian McGillion and Hugues Delorme
** Contact: https://www.qt.io/licensing/
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#include "shellcommand.h"
#include "icore.h"
#include "progressmanager/progressmanager.h"
#include <QFutureInterface>
#include <QFutureWatcher>
using namespace Utils;
namespace Core {
ShellCommand::ShellCommand(const FilePath &workingDirectory, const Environment &environment) :
Utils::ShellCommand(workingDirectory, environment)
{
connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose,
this, &ShellCommand::coreAboutToClose);
}
void ShellCommand::addTask(QFuture<void> &future)
{
const QString name = displayName();
const auto id = Utils::Id::fromString(name + QLatin1String(".action"));
if (hasProgressParser()) {
m_progress = ProgressManager::addTask(future, name, id);
} else {
// add a timed tasked based on timeout
// we cannot access the future interface directly, so we need to create a new one
// with the same lifetime
auto fi = new QFutureInterface<void>();
auto watcher = new QFutureWatcher<void>();
connect(watcher, &QFutureWatcherBase::finished, [fi, watcher] {
fi->reportFinished();
delete fi;
watcher->deleteLater();
});
watcher->setFuture(future);
m_progress = ProgressManager::addTimedTask(*fi, name, id, qMax(2, timeoutS() / 5)/*itsmagic*/);
}
}
void ShellCommand::coreAboutToClose()
{
abort();
}
} // namespace Core

View File

@@ -1,54 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 Brian McGillion and Hugues Delorme
** Contact: https://www.qt.io/licensing/
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include "core_global.h"
#include "progressmanager/futureprogress.h"
#include <utils/shellcommand.h>
#include <QPointer>
namespace Core {
class CORE_EXPORT ShellCommand : public Utils::ShellCommand
{
Q_OBJECT
public:
ShellCommand(const Utils::FilePath &workingDirectory, const Utils::Environment &environment);
protected:
void addTask(QFuture<void> &future) override;
virtual void coreAboutToClose();
private:
QPointer<FutureProgress> m_progress;
};
} // namespace Core

View File

@@ -251,7 +251,7 @@ public:
QString vcsOpenText() const final;
Core::ShellCommand *createInitialCheckoutCommand(const QString &url,
ShellCommand *createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs) final;
@@ -472,7 +472,7 @@ QString CvsPluginPrivate::vcsOpenText() const
return tr("&Edit");
}
Core::ShellCommand *CvsPluginPrivate::createInitialCheckoutCommand(const QString &url,
ShellCommand *CvsPluginPrivate::createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs)

View File

@@ -30,10 +30,10 @@
#include "../gitclient.h"
#include <coreplugin/icore.h>
#include <coreplugin/shellcommand.h>
#include <utils/hostosinfo.h>
#include <utils/qtcprocess.h>
#include <utils/shellcommand.h>
#include <QFile>
#include <QJsonDocument>
@@ -244,8 +244,7 @@ int GerritServer::testConnection()
static GitClient *const client = GitClient::instance();
const QStringList arguments = curlArguments() << (url(RestUrl) + accountUrlC);
QtcProcess proc;
client->vcsFullySynchronousExec(proc, {}, {curlBinary, arguments},
Core::ShellCommand::NoOutput);
client->vcsFullySynchronousExec(proc, {}, {curlBinary, arguments}, ShellCommand::NoOutput);
if (proc.result() == ProcessResult::FinishedWithSuccess) {
QString output = proc.cleanedStdOut();
// Gerrit returns an empty response for /p/qt-creator/a/accounts/self
@@ -345,7 +344,7 @@ bool GerritServer::resolveVersion(const GerritParameters &p, bool forceReload)
if (port)
arguments << p.portFlag << QString::number(port);
arguments << hostArgument() << "gerrit" << "version";
client->vcsFullySynchronousExec(proc, {}, {p.ssh, arguments}, Core::ShellCommand::NoOutput);
client->vcsFullySynchronousExec(proc, {}, {p.ssh, arguments}, ShellCommand::NoOutput);
QString stdOut = proc.cleanedStdOut().trimmed();
stdOut.remove("gerrit version ");
version = stdOut;
@@ -354,8 +353,7 @@ bool GerritServer::resolveVersion(const GerritParameters &p, bool forceReload)
} else {
const QStringList arguments = curlArguments() << (url(RestUrl) + versionUrlC);
QtcProcess proc;
client->vcsFullySynchronousExec(proc, {}, {curlBinary, arguments},
Core::ShellCommand::NoOutput);
client->vcsFullySynchronousExec(proc, {}, {curlBinary, arguments}, ShellCommand::NoOutput);
// REST endpoint for version is only available from 2.8 and up. Do not consider invalid
// if it fails.
if (proc.result() == ProcessResult::FinishedWithSuccess) {

View File

@@ -924,7 +924,7 @@ bool GitClient::managesFile(const FilePath &workingDirectory, const QString &fil
{
QtcProcess proc;
vcsFullySynchronousExec(proc, workingDirectory, {"ls-files", "--error-unmatch", fileName},
Core::ShellCommand::NoOutput);
ShellCommand::NoOutput);
return proc.result() == ProcessResult::FinishedWithSuccess;
}
@@ -940,7 +940,7 @@ FilePaths GitClient::unmanagedFiles(const FilePaths &filePaths) const
const QDir wd(it.key().toString());
args << transform(it.value(), [&wd](const QString &fp) { return wd.relativeFilePath(fp); });
QtcProcess proc;
vcsFullySynchronousExec(proc, it.key(), args, Core::ShellCommand::NoOutput);
vcsFullySynchronousExec(proc, it.key(), args, ShellCommand::NoOutput);
if (proc.result() != ProcessResult::FinishedWithSuccess)
return filePaths;
const QStringList managedFilePaths

View File

@@ -257,7 +257,7 @@ public:
void vcsDescribe(const FilePath &source, const QString &id) final { m_gitClient.show(source.toString(), id); };
QString vcsTopic(const FilePath &directory) final;
Core::ShellCommand *createInitialCheckoutCommand(const QString &url,
ShellCommand *createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs) final;
@@ -1921,7 +1921,7 @@ QString GitPluginPrivate::vcsTopic(const FilePath &directory)
return topic;
}
Core::ShellCommand *GitPluginPrivate::createInitialCheckoutCommand(const QString &url,
ShellCommand *GitPluginPrivate::createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs)

View File

@@ -29,7 +29,6 @@
#include "resultparser.h"
#include <coreplugin/documentmanager.h>
#include <coreplugin/shellcommand.h>
#include <coreplugin/vcsmanager.h>
#include <git/gitclient.h>
#include <projectexplorer/projectexplorer.h>
@@ -44,6 +43,7 @@
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/shellcommand.h>
#include <QApplication>
#include <QCheckBox>

View File

@@ -35,12 +35,11 @@ class QPlainTextEdit;
class QPushButton;
QT_END_NAMESPACE
namespace Core { class ShellCommand; }
namespace Utils {
class FancyLineEdit;
class InfoLabel;
class PathChooser;
class ShellCommand;
}
namespace GitLab {
@@ -67,7 +66,7 @@ private:
Utils::PathChooser *m_pathChooser = nullptr;
Utils::FancyLineEdit *m_directoryLE = nullptr;
Utils::InfoLabel *m_infoLabel = nullptr;
Core::ShellCommand *m_command = nullptr;
Utils::ShellCommand *m_command = nullptr;
bool m_commandRunning = false;
};

View File

@@ -146,7 +146,7 @@ public:
void vcsAnnotate(const FilePath &filePath, int line) final;
void vcsDescribe(const FilePath &source, const QString &id) final { m_client.view(source.toString(), id); }
Core::ShellCommand *createInitialCheckoutCommand(const QString &url,
ShellCommand *createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs) final;
@@ -826,7 +826,7 @@ void MercurialPluginPrivate::vcsAnnotate(const FilePath &filePath, int line)
m_client.annotate(filePath.parentDir(), filePath.fileName(), QString(), line);
}
Core::ShellCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const QString &url,
ShellCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs)

View File

@@ -223,7 +223,7 @@ public:
void vcsAnnotate(const FilePath &file, int line) final;
void vcsDescribe(const FilePath &source, const QString &changeNr) final;
Core::ShellCommand *createInitialCheckoutCommand(const QString &url,
ShellCommand *createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs) final;
@@ -1280,7 +1280,7 @@ void SubversionPluginPrivate::vcsAnnotate(const FilePath &filePath, int line)
vcsAnnotateHelper(filePath.parentDir(), filePath.fileName(), QString(), line);
}
Core::ShellCommand *SubversionPluginPrivate::createInitialCheckoutCommand(const QString &url,
ShellCommand *SubversionPluginPrivate::createInitialCheckoutCommand(const QString &url,
const Utils::FilePath &baseDirectory,
const QString &localName,
const QStringList &extraArgs)

View File

@@ -29,30 +29,41 @@
#include "vcsplugin.h"
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/vcsmanager.h>
#include <utils/environment.h>
#include <utils/globalfilechangeblocker.h>
#include <utils/qtcprocess.h>
#include <QFutureWatcher>
using namespace Core;
using namespace Utils;
namespace VcsBase {
VcsCommand::VcsCommand(const FilePath &workingDirectory, const Environment &environment) :
Core::ShellCommand(workingDirectory, environment),
ShellCommand(workingDirectory, environment),
m_preventRepositoryChanged(false)
{
connect(ICore::instance(), &ICore::coreAboutToClose, this, [this] {
m_preventRepositoryChanged = true;
abort();
});
VcsOutputWindow::setRepository(workingDirectory.toString());
setDisableUnixTerminal();
m_sshPrompt = VcsBase::sshPrompt();
connect(this, &VcsCommand::started, this, [this] {
if (flags() & ExpectRepoChanges)
Utils::GlobalFileChangeBlocker::instance()->forceBlocked(true);
GlobalFileChangeBlocker::instance()->forceBlocked(true);
});
connect(this, &VcsCommand::finished, this, [this] {
if (flags() & ExpectRepoChanges)
Utils::GlobalFileChangeBlocker::instance()->forceBlocked(false);
GlobalFileChangeBlocker::instance()->forceBlocked(false);
});
VcsOutputWindow *outputWindow = VcsOutputWindow::instance();
@@ -67,7 +78,7 @@ VcsCommand::VcsCommand(const FilePath &workingDirectory, const Environment &envi
const Environment VcsCommand::processEnvironment() const
{
Environment env = Core::ShellCommand::processEnvironment();
Environment env = ShellCommand::processEnvironment();
VcsBase::setProcessEnvironment(&env, flags() & ForceCLocale, m_sshPrompt);
return env;
}
@@ -82,7 +93,25 @@ void VcsCommand::runCommand(QtcProcess &proc,
void VcsCommand::addTask(QFuture<void> &future)
{
Core::ShellCommand::addTask(future);
const QString name = displayName();
const auto id = Id::fromString(name + QLatin1String(".action"));
if (hasProgressParser()) {
m_progress = ProgressManager::addTask(future, name, id);
} else {
// add a timed tasked based on timeout
// we cannot access the future interface directly, so we need to create a new one
// with the same lifetime
auto fi = new QFutureInterface<void>();
auto watcher = new QFutureWatcher<void>();
connect(watcher, &QFutureWatcherBase::finished, [fi, watcher] {
fi->reportFinished();
delete fi;
watcher->deleteLater();
});
watcher->setFuture(future);
m_progress = ProgressManager::addTimedTask(*fi, name, id, qMax(2, timeoutS() / 5)/*itsmagic*/);
}
Internal::VcsPlugin::addFuture(future);
}
@@ -92,13 +121,7 @@ void VcsCommand::emitRepositoryChanged(const FilePath &workingDirectory)
return;
// TODO tell the document manager that the directory now received all expected changes
// Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory);
Core::VcsManager::emitRepositoryChanged(workDirectory(workingDirectory));
}
void VcsCommand::coreAboutToClose()
{
m_preventRepositoryChanged = true;
abort();
VcsManager::emitRepositoryChanged(workDirectory(workingDirectory));
}
} // namespace VcsBase

View File

@@ -27,13 +27,16 @@
#include "vcsbase_global.h"
#include <coreplugin/shellcommand.h>
#include <coreplugin/progressmanager/futureprogress.h>
#include <utils/shellcommand.h>
#include <QPointer>
namespace VcsBase {
class VcsOutputWindow;
class VCSBASE_EXPORT VcsCommand : public Core::ShellCommand
class VCSBASE_EXPORT VcsCommand : public Utils::ShellCommand
{
Q_OBJECT
@@ -57,8 +60,7 @@ protected:
private:
void emitRepositoryChanged(const Utils::FilePath &workingDirectory);
void coreAboutToClose() override;
QPointer<Core::FutureProgress> m_progress;
QString m_sshPrompt;
bool m_preventRepositoryChanged;
};

View File

@@ -26,13 +26,14 @@
#include "vcscommandpage.h"
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/shellcommand.h>
#include <coreplugin/vcsmanager.h>
#include <projectexplorer/jsonwizard/jsonwizard.h>
#include <utils/algorithm.h>
#include <utils/commandline.h>
#include <utils/qtcassert.h>
#include <utils/shellcommand.h>
#include <QDir>
#include <QDebug>
@@ -288,8 +289,7 @@ void VcsCommandPage::delayedInitialize()
extraArgs << tmp;
}
Core::ShellCommand *command
= vc->createInitialCheckoutCommand(repo, FilePath::fromString(base),
ShellCommand *command = vc->createInitialCheckoutCommand(repo, FilePath::fromString(base),
name, extraArgs);
for (const JobData &job : qAsConst(m_additionalJobs)) {