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 
28 
29 #include <SimoxUtility/algorithm/string/string_tools.h>
30 
31 #include <filesystem>
32 #include <cstdlib>
33 
34 #define ARMARX_PACKAGE_TOOL "armarx-package"
35 
36 namespace armarx
37 {
38 
40  finder("ArmarXCore")
41  {
42  packageToolPath = finder.getBinaryDir() + "/" + ARMARX_PACKAGE_TOOL;
43 
44  if (!std::filesystem::exists(packageToolPath))
45  {
46  if (system((std::string(ARMARX_PACKAGE_TOOL) + " -h").c_str()) == 0)
47  {
48  packageToolPath = ARMARX_PACKAGE_TOOL;
49  }
50  else
51  {
52  ARMARX_ERROR_S << "unable to find armarx package tool!";
53  }
54  }
55  }
56 
57  bool ArmarXPackageToolInterface::checkPackagePath(const std::string& pathToPackageRoot, std::string& output) const
58  {
59  int result;
60  if (!std::filesystem::exists(pathToPackageRoot))
61  {
62  return false;
63  }
64 
65  std::string cmd = packageToolPath + " status --dir \"" + pathToPackageRoot + "\"";
66  output = CMakePackageFinder::ExecCommand(cmd, result);
67 
68  if (result == 0)
69  {
70  return true;
71  }
72  else
73  {
74  return false;
75  }
76  }
77 
78  bool ArmarXPackageToolInterface::checkPackagePath(const std::string& pathToPackageRoot) const
79  {
80  std::string output;
81  return checkPackagePath(pathToPackageRoot, output);
82  }
83 
84  bool ArmarXPackageToolInterface::addStatechart(const std::string& statechartGroupName, const std::string& statePath, const std::string& packagePath) const
85  {
86  int result = 0;
87  std::string escapedStatePath = simox::alg::replace_all(statePath, " ", "\\ ");
88  std::string escapedStatechartGroupName = simox::alg::replace_all(statechartGroupName, " ", "\\ ");
89  std::string cmd = packageToolPath + " add statechart " + escapedStatechartGroupName + "/" + escapedStatePath + " -l " + escapedStatechartGroupName;
90 
91  if (!packagePath.empty())
92  {
93  if (!std::filesystem::exists(packagePath))
94  {
95  return false;
96  }
97  cmd += " --dir " + packagePath;
98  }
99 
101  return result == 0;
102 
103  }
104 
105  bool ArmarXPackageToolInterface::addFullXmlStatechart(const std::string& statechartGroupName, const std::string& statePath, const std::string& packagePath) const
106  {
107  return addXmlStatechart("xmlstate", "default", statechartGroupName, statePath, packagePath);
108  }
109 
110  bool ArmarXPackageToolInterface::addXmlOnlyXmlStatechart(const std::string& statechartGroupName, const std::string& statePath, const std::string& packagePath) const
111  {
112  return addXmlStatechart("xmlstate-xmlonly", "xmlonly", statechartGroupName, statePath, packagePath);
113  }
114 
115  bool ArmarXPackageToolInterface::addCppOnlyXmlStatechart(const std::string& statechartGroupName, const std::string& statePath, const std::string& packagePath) const
116  {
117  return addXmlStatechart("xmlstate", "cpponly", statechartGroupName, statePath, packagePath);
118  }
119 
121  {
122  return lastOutput;
123  }
124 
125  bool ArmarXPackageToolInterface::addXmlStatechart(const std::string& componentType, const std::string& replacementStrategyType, const std::string& statechartGroupName, const std::string& statePath, const std::string& packagePath) const
126  {
127  int result = 0;
128  std::string escapedStatePath = simox::alg::replace_all(statePath, " ", "\\ ");
129  std::string escapedStatechartGroupName = simox::alg::replace_all(statechartGroupName, " ", "\\ ");
130  std::string cmd = packageToolPath + " add " + componentType + " " + escapedStatechartGroupName + "/" + escapedStatePath + " -l " + escapedStatechartGroupName + " -s " + replacementStrategyType;
131 
132  if (!packagePath.empty())
133  {
134  cmd += " --dir " + packagePath;
135  }
136 
137  lastOutput = CMakePackageFinder::ExecCommand(cmd, result);
138  ARMARX_INFO << "Executed:\n" << cmd << "\nreturned = " << result;
139  return result == 0;
140  }
141 }
armarx::ArmarXPackageToolInterface::getLastOutput
std::string getLastOutput() const
Definition: ArmarXPackageToolInterface.cpp:120
armarx::ArmarXPackageToolInterface::addStatechart
bool addStatechart(const std::string &statechartGroupName, const std::string &statePath, const std::string &packagePath="") const
Definition: ArmarXPackageToolInterface.cpp:84
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:412
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
armarx::CMakePackageFinder::getBinaryDir
std::string getBinaryDir() const
Definition: CMakePackageFinder.h:159
armarx::ArmarXPackageToolInterface::addCppOnlyXmlStatechart
bool addCppOnlyXmlStatechart(const std::string &statechartGroupName, const std::string &statePath, const std::string &packagePath) const
Definition: ArmarXPackageToolInterface.cpp:115
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:174
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
Logging.h
armarx::ArmarXPackageToolInterface::addXmlOnlyXmlStatechart
bool addXmlOnlyXmlStatechart(const std::string &statechartGroupName, const std::string &statePath, const std::string &packagePath) const
Definition: ArmarXPackageToolInterface.cpp:110
armarx::ArmarXPackageToolInterface::addFullXmlStatechart
bool addFullXmlStatechart(const std::string &statechartGroupName, const std::string &statePath, const std::string &packagePath) const
Definition: ArmarXPackageToolInterface.cpp:105
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28