diff --git a/plugins/execute/nativeappjob.cpp b/plugins/execute/nativeappjob.cpp index 07e2bec07a..20f97c62af 100644 --- a/plugins/execute/nativeappjob.cpp +++ b/plugins/execute/nativeappjob.cpp @@ -1,243 +1,146 @@ /* This file is part of KDevelop Copyright 2009 Andreas Pakulat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "nativeappjob.h" #include #include #include #include -#include #include #include -#include #include #include #include -#include -#include #include #include -#include #include #include #include "iexecuteplugin.h" #include "debug.h" using namespace KDevelop; NativeAppJob::NativeAppJob(QObject* parent, KDevelop::ILaunchConfiguration* cfg) - : KDevelop::OutputJob( parent ), proc(0) + : KDevelop::OutputExecuteJob( parent ) , m_cfgname(cfg->name()) { setCapabilities(Killable); IExecutePlugin* iface = KDevelop::ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IExecutePlugin", "kdevexecute")->extension(); Q_ASSERT(iface); KDevelop::EnvironmentGroupList l(KSharedConfig::openConfig()); QString envgrp = iface->environmentGroup(cfg); QString err; QUrl executable = iface->executable( cfg, err ); if( !err.isEmpty() ) { setError( -1 ); setErrorText( err ); return; } if( envgrp.isEmpty() ) { qWarning() << "Launch Configuration:" << cfg->name() << i18n("No environment group specified, looks like a broken " "configuration, please check run configuration '%1'. " "Using default environment group.", cfg->name() ); envgrp = l.defaultGroup(); } + setEnvironmentProfile(envgrp); QStringList arguments = iface->arguments( cfg, err ); if( !err.isEmpty() ) { setError( -2 ); setErrorText( err ); } if( error() != 0 ) { qWarning() << "Launch Configuration:" << cfg->name() << "oops, problem" << errorText(); return; } - proc = new KProcess( this ); - - lineMaker = new KDevelop::ProcessLineMaker( proc, this ); - setStandardToolView(KDevelop::IOutputView::RunView); setBehaviours(KDevelop::IOutputView::AllowUserClose | KDevelop::IOutputView::AutoScroll); - OutputModel* m = new OutputModel; - m->setFilteringStrategy(OutputModel::NativeAppErrorFilter); - setModel(m); - setDelegate( new KDevelop::OutputDelegate ); - - connect( lineMaker, &ProcessLineMaker::receivedStdoutLines, model(), &OutputModel::appendLines ); - connect( proc, static_cast(&KProcess::error), this, &NativeAppJob::processError ); - connect( proc, static_cast(&KProcess::finished), this, &NativeAppJob::processFinished ); + setFilteringStrategy(OutputModel::NativeAppErrorFilter); + setProperties(DisplayStdout | DisplayStderr); // Now setup the process parameters - proc->setEnvironment( l.createEnvironment( envgrp, proc->systemEnvironment()) ); QUrl wc = iface->workingDirectory( cfg ); - if( !wc.isValid() || wc.isEmpty() ) - { + if( !wc.isValid() || wc.isEmpty() ) { wc = QUrl::fromLocalFile( QFileInfo( executable.toLocalFile() ).absolutePath() ); } - proc->setWorkingDirectory( wc.toLocalFile() ); - proc->setProperty( "executable", executable ); + setWorkingDirectory( wc ); qCDebug(PLUGIN_EXECUTE) << "setting app:" << executable << arguments; - proc->setOutputChannelMode(KProcess::MergedChannels); - if (iface->useTerminal(cfg)) { QStringList args = KShell::splitArgs(iface->terminal(cfg)); for (QStringList::iterator it = args.begin(); it != args.end(); ++it) { if (*it == "%exe") { *it = KShell::quoteArg(executable.toLocalFile()); } else if (*it == "%workdir") { *it = KShell::quoteArg(wc.toLocalFile()); } } args.append( arguments ); - proc->setProgram( args ); + *this << args; } else { - proc->setProgram( executable.toLocalFile(), arguments ); + *this << executable.toLocalFile(); + *this << arguments; } - setObjectName(cfg->name()); + setJobName(cfg->name()); } NativeAppJob* findNativeJob(KJob* j) { NativeAppJob* job = qobject_cast(j); if (!job) { const QList jobs = j->findChildren(); if (!jobs.isEmpty()) job = jobs.first(); } return job; } void NativeAppJob::start() { // we kill any execution of the configuration foreach(KJob* j, ICore::self()->runController()->currentJobs()) { NativeAppJob* job = findNativeJob(j); if (job && job != this && job->m_cfgname == m_cfgname) { QMessageBox::StandardButton button = QMessageBox::question(nullptr, i18n("Job already running"), i18n("'%1' is already being executed. Should we kill the previous instance?", m_cfgname)); if (button != QMessageBox::No) j->kill(); } } - qCDebug(PLUGIN_EXECUTE) << "launching?" << proc; - if( proc ) - { - startOutput(); - appendLine( i18n("Starting: %1", proc->program().join(" ") ) ); - proc->start(); - } else - { - qWarning() << "No process, something went wrong when creating the job"; - // No process means we've returned early on from the constructor, some bad error happened - emitResult(); - } -} - -bool NativeAppJob::doKill() -{ - if( proc ) { - proc->kill(); - appendLine( i18n( "*** Killed Application ***" ) ); - } - return true; -} - -void NativeAppJob::processFinished( int exitCode , QProcess::ExitStatus status ) -{ - if (!model()) { - outputDone(); - return; - } - - connect(model(), &OutputModel::allDone, this, &NativeAppJob::outputDone); - lineMaker->flushBuffers(); - - if (exitCode == 0 && status == QProcess::NormalExit) { - appendLine( i18n("*** Exited normally ***") ); - } else if (status == QProcess::NormalExit) { - appendLine( i18n("*** Exited with return code: %1 ***", QString::number(exitCode)) ); - setError(OutputJob::FailedShownError); - } else if (error() == KJob::KilledJobError) { - appendLine( i18n("*** Process aborted ***") ); - setError(KJob::KilledJobError); - } else { - appendLine( i18n("*** Crashed with return code: %1 ***", QString::number(exitCode)) ); - setError(OutputJob::FailedShownError); - } - - model()->ensureAllDone(); -} - -void NativeAppJob::outputDone() -{ - emitResult(); -} - -void NativeAppJob::processError( QProcess::ProcessError error ) -{ - if( error == QProcess::FailedToStart ) - { - setError( FailedShownError ); - QString errmsg = i18n("*** Could not start program '%1'. Make sure that the " - "path is specified correctly ***", proc->program().join(" ") ); - appendLine( errmsg ); - setErrorText( errmsg ); - emitResult(); - } - qCDebug(PLUGIN_EXECUTE) << "Process error"; + OutputExecuteJob::start(); } - -void NativeAppJob::appendLine(const QString& l) -{ - if (KDevelop::OutputModel* m = model()) { - m->appendLine(l); - } -} - -KDevelop::OutputModel* NativeAppJob::model() -{ - return dynamic_cast( OutputJob::model() ); -} - - diff --git a/plugins/execute/nativeappjob.h b/plugins/execute/nativeappjob.h index cd88cc58ed..45a287aa51 100644 --- a/plugins/execute/nativeappjob.h +++ b/plugins/execute/nativeappjob.h @@ -1,56 +1,47 @@ /* This file is part of KDevelop Copyright 2009 Andreas Pakulat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_PLUGIN_NATIVEAPPJOB_H #define KDEVPLATFORM_PLUGIN_NATIVEAPPJOB_H +#include + #include -#include namespace KDevelop { class ILaunchConfiguration; -class ProcessLineMaker; -class OutputModel; } class KProcess; -class NativeAppJob : public KDevelop::OutputJob +class NativeAppJob : public KDevelop::OutputExecuteJob { -Q_OBJECT + Q_OBJECT + public: NativeAppJob( QObject* parent, KDevelop::ILaunchConfiguration* cfg ); + void start() override; - bool doKill() override; - KDevelop::OutputModel* model(); -private slots: - void processError(QProcess::ProcessError); - void processFinished(int,QProcess::ExitStatus); - void outputDone(); private: - void appendLine(const QString &l); - - KProcess* proc; - KDevelop::ProcessLineMaker* lineMaker; QString m_cfgname; }; #endif