dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
optionsparser.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "optionsparser.h"
29 
30 #include <QtCore/QCoreApplication>
31 
32 using namespace ExtensionSystem;
33 using namespace ExtensionSystem::Internal;
34 
35 OptionsParser::OptionsParser(PluginManagerPrivate *pmPrivate):m_pmPrivate(pmPrivate)
36 {
37  m_pmPrivate->arguments.clear();
38 }
39 
40 QStringList OptionsParser::parse(QStringList pluginOptions, QStringList pluginTests, QStringList pluginNoLoad)
41 {
42  checkForNoLoadOption(pluginNoLoad);
43  checkForTestOption(pluginTests);
44  checkForPluginOption(pluginOptions);
45  return m_errorStrings;
46 }
47 
48 void OptionsParser::checkForTestOption(QStringList pluginTests)
49 {
50  if (pluginTests.length() == 1 && pluginTests.at(0).toLower() == QStringLiteral("all")) {
51  for (auto spec : m_pmPrivate->pluginSpecs)
52  m_pmPrivate->testSpecs.append(spec);
53  return;
54  }
55 
56  foreach (QString plugin, pluginTests) {
57  PluginSpec *spec = m_pmPrivate->pluginByName(plugin);
58  if (!spec) {
59  m_errorStrings.append(QCoreApplication::translate("PluginManager",
60  "Invalid test option, the plugin '%0' does not exist.").arg(plugin));
61  } else {
62  m_pmPrivate->testSpecs.append(spec);
63  }
64  }
65  return;
66 }
67 
68 void OptionsParser::checkForNoLoadOption(QStringList pluginNoLoad)
69 {
70  foreach (QString plugin, pluginNoLoad) {
71  PluginSpec *spec = m_pmPrivate->pluginByName(plugin);
72  if (!spec) {
73  m_errorStrings.append(QCoreApplication::translate("PluginManager",
74  "Invalid no-load option, the plugin '%0' does not exist.").arg(plugin));
75  } else {
76  m_pmPrivate->pluginSpecs.removeAll(spec);
77  delete spec;
78  m_pmPrivate->resolveDependencies();
79  }
80  }
81  return;
82 }
83 
84 void OptionsParser::checkForPluginOption(QStringList pluginOptions)
85 {
86  foreach (QString option, pluginOptions) {
87  QString simplified = option.simplified().replace(" ", "");
88  QString argument;
89  QString value;
90  if(option.contains("=")) {
91  if(simplified.split("=").length() != 2) {
92  m_errorStrings.append(QCoreApplication::translate(("PluginManager"),
93  "Wrong plugin options syntax: %0").arg(option));
94  continue;
95  }
96  argument = simplified.split("=").at(0);
97  value = simplified.split("=").at(1);
98  }
99  else {
100  argument = option;
101  }
102  bool requiresParameter;
103  PluginSpec *spec = m_pmPrivate->pluginForOption(argument, &requiresParameter);
104  if (!spec) {
105  m_errorStrings.append(QCoreApplication::translate("PluginManager",
106  "No Plugin was found for given argument: %0").arg(argument));
107  continue;
108  }
109  spec->addArgument(argument);
110  if(!value.isEmpty())
111  spec->addArgument(value);
112  }
113  return;
114 }
OptionsParser(PluginManagerPrivate *pmPrivate)
PluginSpec * pluginForOption(const QString &option, bool *requiresArgument) const
QStringList parse(QStringList pluginOptions, QStringList pluginTests, QStringList pluginNoLoad)
void addArgument(const QString &argument)
Definition: pluginspec.cpp:290
Contains the information of the plugins xml description file and information about the plugin's curre...
Definition: pluginspec.h:63
PluginSpec * pluginByName(const QString &name) const