forked from qt-creator/qt-creator
ProjectExplorer: Use StandardRunnable in LocalApplicationRunControl
Also un-export LocalApplicationRunControl. Change-Id: Ide5dbb61035d9f648f517a9d89763803ac0c4d26 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -40,6 +40,103 @@
|
|||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
class LocalApplicationRunControl : public RunControl
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
LocalApplicationRunControl(RunConfiguration *runConfiguration, Core::Id mode);
|
||||||
|
|
||||||
|
void start() override;
|
||||||
|
StopResult stop() override;
|
||||||
|
bool isRunning() const override;
|
||||||
|
|
||||||
|
void setRunnable(const StandardRunnable &runnable) { m_runnable = runnable; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void processStarted();
|
||||||
|
void processExited(int exitCode, QProcess::ExitStatus status);
|
||||||
|
|
||||||
|
ApplicationLauncher m_applicationLauncher;
|
||||||
|
StandardRunnable m_runnable;
|
||||||
|
bool m_running = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalApplicationRunControl::LocalApplicationRunControl(RunConfiguration *rc, Core::Id mode)
|
||||||
|
: RunControl(rc, mode)
|
||||||
|
{
|
||||||
|
setIcon(Icons::RUN_SMALL);
|
||||||
|
EnvironmentAspect *environment = rc->extraAspect<EnvironmentAspect>();
|
||||||
|
Utils::Environment env;
|
||||||
|
if (environment)
|
||||||
|
env = environment->environment();
|
||||||
|
m_applicationLauncher.setEnvironment(env);
|
||||||
|
|
||||||
|
connect(&m_applicationLauncher, &ApplicationLauncher::appendMessage,
|
||||||
|
this, static_cast<void(RunControl::*)(const QString &, Utils::OutputFormat)>(&RunControl::appendMessage));
|
||||||
|
connect(&m_applicationLauncher, &ApplicationLauncher::processStarted,
|
||||||
|
this, &LocalApplicationRunControl::processStarted);
|
||||||
|
connect(&m_applicationLauncher, &ApplicationLauncher::processExited,
|
||||||
|
this, &LocalApplicationRunControl::processExited);
|
||||||
|
connect(&m_applicationLauncher, &ApplicationLauncher::bringToForegroundRequested,
|
||||||
|
this, &RunControl::bringApplicationToForeground);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalApplicationRunControl::start()
|
||||||
|
{
|
||||||
|
emit started();
|
||||||
|
if (m_runnable.executable.isEmpty()) {
|
||||||
|
appendMessage(tr("No executable specified.") + QLatin1Char('\n'), Utils::ErrorMessageFormat);
|
||||||
|
emit finished();
|
||||||
|
} else if (!QFileInfo::exists(m_runnable.executable)) {
|
||||||
|
appendMessage(tr("Executable %1 does not exist.")
|
||||||
|
.arg(QDir::toNativeSeparators(m_runnable.executable)) + QLatin1Char('\n'),
|
||||||
|
Utils::ErrorMessageFormat);
|
||||||
|
emit finished();
|
||||||
|
} else {
|
||||||
|
m_running = true;
|
||||||
|
QString msg = tr("Starting %1...").arg(QDir::toNativeSeparators(m_runnable.executable)) + QLatin1Char('\n');
|
||||||
|
appendMessage(msg, Utils::NormalMessageFormat);
|
||||||
|
m_applicationLauncher.start(m_runnable.runMode, m_runnable.executable, m_runnable.commandLineArguments);
|
||||||
|
setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalApplicationRunControl::StopResult LocalApplicationRunControl::stop()
|
||||||
|
{
|
||||||
|
m_applicationLauncher.stop();
|
||||||
|
return StoppedSynchronously;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalApplicationRunControl::isRunning() const
|
||||||
|
{
|
||||||
|
return m_running;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalApplicationRunControl::processStarted()
|
||||||
|
{
|
||||||
|
// Console processes only know their pid after being started
|
||||||
|
setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalApplicationRunControl::processExited(int exitCode, QProcess::ExitStatus status)
|
||||||
|
{
|
||||||
|
m_running = false;
|
||||||
|
setApplicationProcessHandle(ProcessHandle());
|
||||||
|
QString msg;
|
||||||
|
if (status == QProcess::CrashExit) {
|
||||||
|
msg = tr("%1 crashed")
|
||||||
|
.arg(QDir::toNativeSeparators(m_runnable.executable));
|
||||||
|
} else {
|
||||||
|
msg = tr("%1 exited with code %2")
|
||||||
|
.arg(QDir::toNativeSeparators(m_runnable.executable)).arg(exitCode);
|
||||||
|
}
|
||||||
|
appendMessage(msg + QLatin1Char('\n'), Utils::NormalMessageFormat);
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocalApplicationRunControlFactory
|
||||||
|
|
||||||
static bool isLocal(RunConfiguration *runConfiguration)
|
static bool isLocal(RunConfiguration *runConfiguration)
|
||||||
{
|
{
|
||||||
Target *target = runConfiguration ? runConfiguration->target() : 0;
|
Target *target = runConfiguration ? runConfiguration->target() : 0;
|
||||||
@@ -56,115 +153,12 @@ RunControl *LocalApplicationRunControlFactory::create(RunConfiguration *runConfi
|
|||||||
{
|
{
|
||||||
Q_UNUSED(errorMessage)
|
Q_UNUSED(errorMessage)
|
||||||
QTC_ASSERT(runConfiguration->runnable().is<StandardRunnable>(), return 0);
|
QTC_ASSERT(runConfiguration->runnable().is<StandardRunnable>(), return 0);
|
||||||
auto runnable = runConfiguration->runnable().as<StandardRunnable>();
|
|
||||||
auto runControl = new LocalApplicationRunControl(runConfiguration, mode);
|
auto runControl = new LocalApplicationRunControl(runConfiguration, mode);
|
||||||
runControl->setCommand(runnable.executable, runnable.commandLineArguments);
|
runControl->setRunnable(runConfiguration->runnable().as<StandardRunnable>());
|
||||||
runControl->setApplicationLauncherMode(runnable.runMode);
|
|
||||||
runControl->setWorkingDirectory(runnable.workingDirectory);
|
|
||||||
|
|
||||||
return runControl;
|
return runControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
// ApplicationRunControl
|
|
||||||
|
|
||||||
LocalApplicationRunControl::LocalApplicationRunControl(RunConfiguration *rc, Core::Id mode)
|
|
||||||
: RunControl(rc, mode), m_runMode(ApplicationLauncher::Console), m_running(false)
|
|
||||||
{
|
|
||||||
setIcon(Icons::RUN_SMALL);
|
|
||||||
EnvironmentAspect *environment = rc->extraAspect<EnvironmentAspect>();
|
|
||||||
Utils::Environment env;
|
|
||||||
if (environment)
|
|
||||||
env = environment->environment();
|
|
||||||
m_applicationLauncher.setEnvironment(env);
|
|
||||||
|
|
||||||
connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,Utils::OutputFormat)),
|
|
||||||
this, SLOT(slotAppendMessage(QString,Utils::OutputFormat)));
|
|
||||||
connect(&m_applicationLauncher, SIGNAL(processStarted()),
|
|
||||||
this, SLOT(processStarted()));
|
|
||||||
connect(&m_applicationLauncher, SIGNAL(processExited(int,QProcess::ExitStatus)),
|
|
||||||
this, SLOT(processExited(int,QProcess::ExitStatus)));
|
|
||||||
connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
|
|
||||||
this, SLOT(bringApplicationToForeground(qint64)));
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalApplicationRunControl::~LocalApplicationRunControl()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalApplicationRunControl::start()
|
|
||||||
{
|
|
||||||
emit started();
|
|
||||||
if (m_executable.isEmpty()) {
|
|
||||||
appendMessage(tr("No executable specified.") + QLatin1Char('\n'), Utils::ErrorMessageFormat);
|
|
||||||
emit finished();
|
|
||||||
} else if (!QFileInfo::exists(m_executable)) {
|
|
||||||
appendMessage(tr("Executable %1 does not exist.").arg(QDir::toNativeSeparators(m_executable)) + QLatin1Char('\n'),
|
|
||||||
Utils::ErrorMessageFormat);
|
|
||||||
emit finished();
|
|
||||||
} else {
|
|
||||||
m_running = true;
|
|
||||||
QString msg = tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable)) + QLatin1Char('\n');
|
|
||||||
appendMessage(msg, Utils::NormalMessageFormat);
|
|
||||||
m_applicationLauncher.start(m_runMode, m_executable, m_commandLineArguments);
|
|
||||||
setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalApplicationRunControl::StopResult LocalApplicationRunControl::stop()
|
|
||||||
{
|
|
||||||
m_applicationLauncher.stop();
|
|
||||||
return StoppedSynchronously;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LocalApplicationRunControl::isRunning() const
|
|
||||||
{
|
|
||||||
return m_running;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalApplicationRunControl::setCommand(const QString &executable, const QString &commandLineArguments)
|
|
||||||
{
|
|
||||||
m_executable = executable;
|
|
||||||
m_commandLineArguments = commandLineArguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalApplicationRunControl::setApplicationLauncherMode(const ApplicationLauncher::Mode mode)
|
|
||||||
{
|
|
||||||
m_runMode = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalApplicationRunControl::setWorkingDirectory(const QString &workingDirectory)
|
|
||||||
{
|
|
||||||
m_applicationLauncher.setWorkingDirectory(workingDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalApplicationRunControl::slotAppendMessage(const QString &err,
|
|
||||||
Utils::OutputFormat format)
|
|
||||||
{
|
|
||||||
appendMessage(err, format);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalApplicationRunControl::processStarted()
|
|
||||||
{
|
|
||||||
// Console processes only know their pid after being started
|
|
||||||
setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalApplicationRunControl::processExited(int exitCode, QProcess::ExitStatus status)
|
|
||||||
{
|
|
||||||
m_running = false;
|
|
||||||
setApplicationProcessHandle(ProcessHandle());
|
|
||||||
QString msg;
|
|
||||||
if (status == QProcess::CrashExit) {
|
|
||||||
msg = tr("%1 crashed")
|
|
||||||
.arg(QDir::toNativeSeparators(m_executable));
|
|
||||||
} else {
|
|
||||||
msg = tr("%1 exited with code %2")
|
|
||||||
.arg(QDir::toNativeSeparators(m_executable)).arg(exitCode);
|
|
||||||
}
|
|
||||||
appendMessage(msg + QLatin1Char('\n'), Utils::NormalMessageFormat);
|
|
||||||
emit finished();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
|
#include "localapplicationruncontrol.moc"
|
||||||
|
@@ -27,7 +27,6 @@
|
|||||||
#define LOCALAPPLICATIONRUNCONTROL_H
|
#define LOCALAPPLICATIONRUNCONTROL_H
|
||||||
|
|
||||||
#include "runconfiguration.h"
|
#include "runconfiguration.h"
|
||||||
#include "applicationlauncher.h"
|
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -41,33 +40,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT LocalApplicationRunControl : public RunControl
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
LocalApplicationRunControl(RunConfiguration *runConfiguration, Core::Id mode);
|
|
||||||
~LocalApplicationRunControl();
|
|
||||||
void start();
|
|
||||||
StopResult stop();
|
|
||||||
bool isRunning() const;
|
|
||||||
|
|
||||||
void setCommand(const QString &executable, const QString &commandLineArguments);
|
|
||||||
void setApplicationLauncherMode(const ApplicationLauncher::Mode mode);
|
|
||||||
void setWorkingDirectory(const QString &workingDirectory);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void processStarted();
|
|
||||||
void processExited(int exitCode, QProcess::ExitStatus status);
|
|
||||||
void slotAppendMessage(const QString &err, Utils::OutputFormat isError);
|
|
||||||
private:
|
|
||||||
ApplicationLauncher m_applicationLauncher;
|
|
||||||
QString m_executable;
|
|
||||||
QString m_commandLineArguments;
|
|
||||||
ApplicationLauncher::Mode m_runMode;
|
|
||||||
bool m_running;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
#endif // LOCALAPPLICATIONRUNCONTROL_H
|
#endif // LOCALAPPLICATIONRUNCONTROL_H
|
||||||
|
Reference in New Issue
Block a user