ArmarXPackageToolInterface.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX::
19 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
26 
27 #include <cstdlib>
28 #include <filesystem>
29 
30 #include <SimoxUtility/algorithm/string/string_tools.h>
31 
33 
34 #define ARMARX_PACKAGE_TOOL "armarx-package"
35 
36 namespace armarx
37 {
38 
40  {
41  packageToolPath = finder.getBinaryDir() + "/" + ARMARX_PACKAGE_TOOL;
42 
43  if (!std::filesystem::exists(packageToolPath))
44  {
45  if (system((std::string(ARMARX_PACKAGE_TOOL) + " -h").c_str()) == 0)
46  {
47  packageToolPath = ARMARX_PACKAGE_TOOL;
48  }
49  else
50  {
51  ARMARX_ERROR_S << "unable to find armarx package tool!";
52  }
53  }
54  }
55 
56  bool
57  ArmarXPackageToolInterface::checkPackagePath(const std::string& pathToPackageRoot,
58  std::string& output) const
59  {
60  int result;
61  if (!std::filesystem::exists(pathToPackageRoot))
62  {
63  return false;
64  }
65 
66  std::string cmd = packageToolPath + " status --dir \"" + pathToPackageRoot + "\"";
67  output = CMakePackageFinder::ExecCommand(cmd, result);
68 
69  if (result == 0)
70  {
71  return true;
72  }
73  else
74  {
75  return false;
76  }
77  }
78 
79  bool
80  ArmarXPackageToolInterface::checkPackagePath(const std::string& pathToPackageRoot) const
81  {
82  std::string output;
83  return checkPackagePath(pathToPackageRoot, output);
84  }
85 
86  bool
87  ArmarXPackageToolInterface::addStatechart(const std::string& statechartGroupName,
88  const std::string& statePath,
89  const std::string& packagePath) const
90  {
91  int result = 0;
92  std::string escapedStatePath = simox::alg::replace_all(statePath, " ", "\\ ");
93  std::string escapedStatechartGroupName =
94  simox::alg::replace_all(statechartGroupName, " ", "\\ ");
95  std::string cmd = packageToolPath + " add statechart " + escapedStatechartGroupName + "/" +
96  escapedStatePath + " -l " + escapedStatechartGroupName;
97 
98  if (!packagePath.empty())
99  {
100  if (!std::filesystem::exists(packagePath))
101  {
102  return false;
103  }
104  cmd += " --dir " + packagePath;
105  }
106 
108  return result == 0;
109  }
110 
111  bool
112  ArmarXPackageToolInterface::addFullXmlStatechart(const std::string& statechartGroupName,
113  const std::string& statePath,
114  const std::string& packagePath) const
115  {
116  return addXmlStatechart("xmlstate", "default", statechartGroupName, statePath, packagePath);
117  }
118 
119  bool
120  ArmarXPackageToolInterface::addXmlOnlyXmlStatechart(const std::string& statechartGroupName,
121  const std::string& statePath,
122  const std::string& packagePath) const
123  {
124  return addXmlStatechart(
125  "xmlstate-xmlonly", "xmlonly", statechartGroupName, statePath, packagePath);
126  }
127 
128  bool
129  ArmarXPackageToolInterface::addCppOnlyXmlStatechart(const std::string& statechartGroupName,
130  const std::string& statePath,
131  const std::string& packagePath) const
132  {
133  return addXmlStatechart("xmlstate", "cpponly", statechartGroupName, statePath, packagePath);
134  }
135 
136  std::string
138  {
139  return lastOutput;
140  }
141 
142  bool
143  ArmarXPackageToolInterface::addXmlStatechart(const std::string& componentType,
144  const std::string& replacementStrategyType,
145  const std::string& statechartGroupName,
146  const std::string& statePath,
147  const std::string& packagePath) const
148  {
149  int result = 0;
150  std::string escapedStatePath = simox::alg::replace_all(statePath, " ", "\\ ");
151  std::string escapedStatechartGroupName =
152  simox::alg::replace_all(statechartGroupName, " ", "\\ ");
153  std::string cmd = packageToolPath + " add " + componentType + " " +
154  escapedStatechartGroupName + "/" + escapedStatePath + " -l " +
155  escapedStatechartGroupName + " -s " + replacementStrategyType;
156 
157  if (!packagePath.empty())
158  {
159  cmd += " --dir " + packagePath;
160  }
161 
162  lastOutput = CMakePackageFinder::ExecCommand(cmd, result);
163  ARMARX_INFO << "Executed:\n" << cmd << "\nreturned = " << result;
164  return result == 0;
165  }
166 } // namespace armarx
armarx::ArmarXPackageToolInterface::getLastOutput
std::string getLastOutput() const
Definition: ArmarXPackageToolInterface.cpp:137
armarx::ArmarXPackageToolInterface::addStatechart
bool addStatechart(const std::string &statechartGroupName, const std::string &statePath, const std::string &packagePath="") const
Definition: ArmarXPackageToolInterface.cpp:87
ARMARX_PACKAGE_TOOL
#define ARMARX_PACKAGE_TOOL
Definition: ArmarXPackageToolInterface.cpp:34
ArmarXPackageToolInterface.h
armarx::CMakePackageFinder::ExecCommand
static std::string ExecCommand(std::string command, int &result, bool suppressStdErr=false)
Definition: CMakePackageFinder.cpp:434
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:216
armarx::CMakePackageFinder::getBinaryDir
std::string getBinaryDir() const
Definition: CMakePackageFinder.h:174
armarx::ArmarXPackageToolInterface::addCppOnlyXmlStatechart
bool addCppOnlyXmlStatechart(const std::string &statechartGroupName, const std::string &statePath, const std::string &packagePath) const
Definition: ArmarXPackageToolInterface.cpp:129
armarx::ArmarXPackageToolInterface::checkPackagePath
bool checkPackagePath(const std::string &pathToPackageRoot, std::string &output) const
Definition: ArmarXPackageToolInterface.cpp:57
armarx::ArmarXPackageToolInterface::ArmarXPackageToolInterface
ArmarXPackageToolInterface()
Definition: ArmarXPackageToolInterface.cpp:39
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:202
Logging.h
armarx::ArmarXPackageToolInterface::addXmlOnlyXmlStatechart
bool addXmlOnlyXmlStatechart(const std::string &statechartGroupName, const std::string &statePath, const std::string &packagePath) const
Definition: ArmarXPackageToolInterface.cpp:120
armarx::ArmarXPackageToolInterface::addFullXmlStatechart
bool addFullXmlStatechart(const std::string &statechartGroupName, const std::string &statePath, const std::string &packagePath) const
Definition: ArmarXPackageToolInterface.cpp:112
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27