1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
/*
* This file is part of KDevelop
*
* Copyright 2007 Hamish Rodda <rodda@kde.org>
* Copyright 2009 Niko Sams <niko.sams@gmail.com>
*
* This program 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 program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "executescriptplugin.h"
#include <QApplication>
#include <klocale.h>
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <kdebug.h>
#include <kjob.h>
#include <kparts/mainwindow.h>
#include <kmessagebox.h>
#include <kaboutdata.h>
#include <interfaces/icore.h>
#include <interfaces/iruncontroller.h>
#include <interfaces/ilaunchconfiguration.h>
#include <interfaces/iprojectcontroller.h>
#include <interfaces/iuicontroller.h>
#include <util/environmentgrouplist.h>
#include "scriptappconfig.h"
#include <project/projectmodel.h>
#include <project/builderjob.h>
#include <kshell.h>
#include <util/kdevstringhandler.h>
QString ExecuteScriptPlugin::_scriptAppConfigTypeId = "Script Application";
QString ExecuteScriptPlugin::interpreterEntry = "Interpreter";
QString ExecuteScriptPlugin::workingDirEntry = "Working Directory";
QString ExecuteScriptPlugin::executableEntry = "Executable";
QString ExecuteScriptPlugin::executeOnRemoteHostEntry = "Execute on Remote Host";
QString ExecuteScriptPlugin::remoteHostEntry = "Remote Host";
QString ExecuteScriptPlugin::argumentsEntry = "Arguments";
QString ExecuteScriptPlugin::isExecutableEntry = "isExecutable";
QString ExecuteScriptPlugin::environmentGroupEntry = "EnvironmentGroup";
//QString ExecuteScriptPlugin::useTerminalEntry = "Use External Terminal";
QString ExecuteScriptPlugin::userIdToRunEntry = "User Id to Run";
QString ExecuteScriptPlugin::projectTargetEntry = "Project Target";
using namespace KDevelop;
K_PLUGIN_FACTORY(KDevExecuteFactory, registerPlugin<ExecuteScriptPlugin>(); )
K_EXPORT_PLUGIN(KDevExecuteFactory(KAboutData("kdevexecutescript", "kdevexecutescript", ki18n("Execute script support"), "1.0 Beta 1", ki18n("Allows running of scripts"), KAboutData::License_GPL)
.addAuthor(ki18n("Niko Sams"), ki18n("Author"), "niko.sams@gmail.com", "http://nikosams.blogspot.com")
))
ExecuteScriptPlugin::ExecuteScriptPlugin(QObject *parent, const QVariantList&)
: KDevelop::IPlugin(KDevExecuteFactory::componentData(), parent)
{
KDEV_USE_EXTENSION_INTERFACE( IExecuteScriptPlugin )
m_configType = new ScriptAppConfigType();
m_configType->addLauncher( new ScriptAppLauncher() );
kDebug() << "adding script launch config";
core()->runController()->addConfigurationType( m_configType );
}
ExecuteScriptPlugin::~ExecuteScriptPlugin()
{
}
void ExecuteScriptPlugin::unload()
{
core()->runController()->removeConfigurationType( m_configType );
delete m_configType;
m_configType = 0;
}
KUrl ExecuteScriptPlugin::script( KDevelop::ILaunchConfiguration* cfg, QString& err_ ) const
{
KUrl script;
if( !cfg )
{
return script;
}
KConfigGroup grp = cfg->config();
if( grp.readEntry(ExecuteScriptPlugin::isExecutableEntry, false ) )
{
script = grp.readEntry( ExecuteScriptPlugin::executableEntry, KUrl("") );
} else
{
QStringList prjitem = grp.readEntry( ExecuteScriptPlugin::projectTargetEntry, QStringList() );
KDevelop::ProjectModel* model = KDevelop::ICore::self()->projectController()->projectModel();
KDevelop::ProjectBaseItem* item = dynamic_cast<KDevelop::ProjectBaseItem*>( model->itemFromIndex(
model->pathToIndex(prjitem) ) );
if( item && item->file() )
{
script = item->file()->url();
}
}
if( !script.isLocalFile() || script.isEmpty() )
{
err_ = i18n("No valid executable specified");
kWarning() << "Launch Configuration:" << cfg->name() << "no valid script set";
} else
{
KShell::Errors err;
if( KShell::splitArgs( script.toLocalFile(), KShell::TildeExpand | KShell::AbortOnMeta, &err ).isEmpty() || err != KShell::NoError )
{
script = KUrl();
if( err == KShell::BadQuoting )
{
err_ = i18n("There is a quoting error in the script "
"for the launch configuration '%1'. "
"Aborting start.", cfg->name() );
} else
{
err_ = i18n("A shell meta character was included in the "
"script for the launch configuration '%1', "
"this is not supported currently. Aborting start.", cfg->name() );
}
kWarning() << "Launch Configuration:" << cfg->name() << "script has meta characters";
}
}
return script;
}
QString ExecuteScriptPlugin::remoteHost(ILaunchConfiguration* cfg, QString& err) const
{
if (!cfg) return QString();
KConfigGroup grp = cfg->config();
if(grp.readEntry(ExecuteScriptPlugin::executeOnRemoteHostEntry, false)) {
QString host = grp.readEntry(ExecuteScriptPlugin::remoteHostEntry, "");
if (host.isEmpty()) {
err = i18n("No remote host set for launch configuration '%1'. "
"Aborting start.", cfg->name() );
kWarning() << "Launch Configuration:" << cfg->name() << "no remote host set";
}
return host;
}
return QString();
}
QStringList ExecuteScriptPlugin::arguments( KDevelop::ILaunchConfiguration* cfg, QString& err_ ) const
{
if( !cfg )
{
return QStringList();
}
KShell::Errors err;
QStringList args = KShell::splitArgs( cfg->config().readEntry( ExecuteScriptPlugin::argumentsEntry, "" ), KShell::TildeExpand | KShell::AbortOnMeta, &err );
if( err != KShell::NoError )
{
if( err == KShell::BadQuoting )
{
err_ = i18n("There is a quoting error in the arguments for "
"the launch configuration '%1'. Aborting start.", cfg->name() );
} else
{
err_ = i18n("A shell meta character was included in the "
"arguments for the launch configuration '%1', "
"this is not supported currently. Aborting start.", cfg->name() );
}
args = QStringList();
kWarning() << "Launch Configuration:" << cfg->name() << "arguments have meta characters";
}
return args;
}
QString ExecuteScriptPlugin::environmentGroup( KDevelop::ILaunchConfiguration* cfg ) const
{
if( !cfg )
{
return "";
}
return cfg->config().readEntry( ExecuteScriptPlugin::environmentGroupEntry, "" );
}
QString ExecuteScriptPlugin::interpreter( KDevelop::ILaunchConfiguration* cfg, QString& err ) const
{
QString interpreter;
if( !cfg )
{
return interpreter;
}
KConfigGroup grp = cfg->config();
interpreter = grp.readEntry( ExecuteScriptPlugin::interpreterEntry, QString("") );
if( interpreter.isEmpty() )
{
err = i18n("No valid interpreter specified");
kWarning() << "Launch Configuration:" << cfg->name() << "no valid interpreter set";
} else
{
KShell::Errors err_;
if( KShell::splitArgs( interpreter, KShell::TildeExpand | KShell::AbortOnMeta, &err_ ).isEmpty() || err_ != KShell::NoError )
{
interpreter.clear();
if( err_ == KShell::BadQuoting )
{
err = i18n("There is a quoting error in the interpreter "
"for the launch configuration '%1'. "
"Aborting start.", cfg->name() );
} else
{
err = i18n("A shell meta character was included in the "
"interpreter for the launch configuration '%1', "
"this is not supported currently. Aborting start.", cfg->name() );
}
kWarning() << "Launch Configuration:" << cfg->name() << "interpreter has meta characters";
}
}
return interpreter;
}
/*
bool ExecuteScriptPlugin::useTerminal( KDevelop::ILaunchConfiguration* cfg ) const
{
if( !cfg )
{
return false;
}
return cfg->config().readEntry( ExecuteScriptPlugin::useTerminalEntry, false );
}
*/
KUrl ExecuteScriptPlugin::workingDirectory( KDevelop::ILaunchConfiguration* cfg ) const
{
if( !cfg )
{
return KUrl();
}
return cfg->config().readEntry( ExecuteScriptPlugin::workingDirEntry, KUrl() );
}
QString ExecuteScriptPlugin::scriptAppConfigTypeId() const
{
return _scriptAppConfigTypeId;
}
#include "executescriptplugin.moc"
|