| 41 | |
| 42 | // Replaces ${KEY} in command with variables[KEY] |
| 43 | static QString replaceVariables(QString command, const QMap<QString, QString>& variables) |
| 44 | { |
| 45 | while (command.contains(QLatin1String("${"))) { |
| 46 | int pos = command.indexOf(QLatin1String("${")); |
| 47 | int end = command.indexOf(QLatin1Char('}'), pos + 2); |
| 48 | if (end == -1) { |
| 49 | break; |
| 50 | } |
| 51 | QString key = command.mid(pos + 2, end - pos - 2); |
| 52 | |
| 53 | const auto variableIt = variables.constFind(key); |
| 54 | if (variableIt != variables.constEnd()) { |
| 55 | command.replace(pos, 1 + end - pos, *variableIt ); |
| 56 | } else { |
| 57 | qCDebug(CUSTOMSCRIPT) << "found no variable while replacing in shell-command" << command << "key" << key << "available:" << variables; |
| 58 | command.remove(pos, 1 + end - pos); |
| 59 | } |
| 60 | } |
| 61 | return command; |
| 62 | } |
| 63 | |
| 64 | CustomScriptPlugin::CustomScriptPlugin(QObject* parent, const KPluginMetaData& metaData, const QVariantList&) |
| 65 | : IPlugin(QStringLiteral("kdevcustomscript"), parent, metaData) |