PackageBuilder.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 ArmarXCore::core
19  * @author Cedric Seehausen (usdnr at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #include "PackageBuilder.h"
34 
35 #include <filesystem>
36 #include <algorithm>
37 #include <fstream>
38 
39 using namespace ScenarioManager;
40 using namespace Parser;
41 using namespace Data_Structure;
42 
43 std::map<std::string, DependencyTree> PackageBuilder::cachedTrees;
44 
46 {
47  armarx::CMakePackageFinder pFinder(name);
49 
50  StringList scenarios = parser.getScenariosFromFolder(pFinder.getScenariosDir());
51 
52  //format them into the right parsing
53  int i = 0;
54  for (auto scenario : scenarios)
55  {
56  scenario.append("::Package::" + name);
57  scenarios[i] = scenario;
58  ARMARX_INFO_S << scenario << " " << scenarios[i];
59  i++;
60  }
61 
62  return parsePackage(name, scenarios);
63 }
64 
65 PackagePtr PackageBuilder::parsePackage(std::string name, StringList openedScenarios)
66 {
68 
69  if (pFinder.packageFound())
70  {
71  PackagePtr result;
72 
73  result = PackagePtr(new Package(name, pFinder.getConfigDir(), pFinder.getScenariosDir()));
74 
75  DependenciesGenerator generator;
76  generator.generateDependenciesCfg(result);
77 
78  const std::vector<std::string> executables = pFinder.getComponentExecutableNames();
79  for (auto executable : executables)
80  {
81  auto application = std::make_shared<Data_Structure::Application>(executable, pFinder.getBinaryDir(), result->getName());
82  result->addApplication(application);
83  }
84 
85  std::string scenarioDir = pFinder.getScenariosDir();
87  std::vector<std::string> packageScenarios = parser.getScenariosFromFolder(scenarioDir);
88 
89  for (auto scenarioName : packageScenarios)
90  {
91  for (unsigned int i = 0; i < openedScenarios.size(); i++)
92  {
93  StringList stringSplit;
94 
95  auto pos = openedScenarios[i].find("::Package::");
96  stringSplit.push_back(openedScenarios[i].substr(0, pos));
97  stringSplit.push_back(openedScenarios[i].substr(pos + 11));
98 
99  if (scenarioName.compare(stringSplit.at(0)) == 0 && result->getName().compare(stringSplit.at(1)) == 0)
100  {
101  ScenarioPtr scenario;
102 
103  auto subfolderPos = scenarioName.find("/");
104  if (subfolderPos != std::string::npos)
105  {
106  scenario = parser.parseScenario(result, scenarioName.substr(subfolderPos + 1), scenarioName.substr(0, subfolderPos));
107  }
108  else
109  {
110  scenario = parser.parseScenario(result, scenarioName);
111  }
112 
113  if (scenario.get() != nullptr)
114  {
115  scenario->reloadAppInstances();
116  result->addScenario(scenario);
117  }
118  else
119  {
120  ARMARX_INFO_S << "Could not find / parse Scenario at " + scenarioDir + " despite CMake knows it.";
121  }
122  continue;
123  }
124  }
125  }
126  return result;
127  }
128 
129  ARMARX_INFO << "Package '" << name << "' not found!";
130  return PackagePtr();
131 }
132 
134 {
135  StringList result;
136 
137  StringList packages = GetDefaultPackages();
138  for (auto package : packages)
139  {
142 
143  StringList scenarios = parser.getScenariosFromFolder(finder.getScenariosDir());
144 
145  if (std::find(scenarios.begin(), scenarios.end(), scenario) != scenarios.end())
146  {
147  result.push_back(package);
148  }
149  }
150 
151  return result;
152 }
153 
155 {
156  StringList packages;
158  {
159  return armarx::Application::getInstance()->getArmarXPackageNames();
160  }
161  return packages;
162 }
StringUtil.hpp
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:36
ScenarioManager::Parser::DependenciesGenerator::generateDependenciesCfg
void generateDependenciesCfg(ScenarioManager::Data_Structure::PackagePtr package)
Definition: DependenciesGenerator.cpp:88
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:485
armarx::CMakePackageFinder::getScenariosDir
std::string getScenariosDir() const
Definition: CMakePackageFinder.h:180
armarx::CMakePackageFinderCache::findPackage
const CMakePackageFinder & findPackage(const std::string &packageName, const std::filesystem::path &packagePath="", bool suppressStdErr=false, bool usePackagePathOnlyAsHint=false)
Definition: CMakePackageFinderCache.cpp:20
ScenarioManager::Parser::PackageBuilder::parsePackage
ScenarioManager::Data_Structure::PackagePtr parsePackage(std::string name)
Parses the package of the given name and creates a Package out of the parsed data.
Definition: PackageBuilder.cpp:45
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
ScenarioManager::Parser::XMLScenarioParser
This class provides different methods to parse and save scenario data in XML-Files....
Definition: XMLScenarioParser.h:56
ScenarioManager::Parser::PackageBuilder::GetDefaultPackages
static StringList GetDefaultPackages()
Definition: PackageBuilder.cpp:154
PackageBuilder.h
ScenarioManager::Data_Structure::PackagePtr
std::shared_ptr< Package > PackagePtr
Definition: Package.h:121
armarx::CMakePackageFinder::getComponentExecutableNames
std::vector< std::string > getComponentExecutableNames() const
Definition: CMakePackageFinder.cpp:666
ScenarioManager::Parser::DependenciesGenerator
Definition: DependenciesGenerator.h:38
armarx::CMakePackageFinder::getBinaryDir
std::string getBinaryDir() const
Definition: CMakePackageFinder.h:159
DependenciesGenerator.h
XMLScenarioParser.h
armarx::Application::getInstance
static ApplicationPtr getInstance()
Retrieve shared pointer to the application object.
Definition: Application.cpp:289
CMakePackageFinder.h
IceStorm::parser
Parser * parser
Definition: Parser.cpp:33
armarx::CMakePackageFinder::getConfigDir
std::string getConfigDir() const
Returns the path needed to find this package with cmake, i.e.
Definition: CMakePackageFinder.h:102
ScenarioManager
Definition: Application.cpp:166
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::CMakePackageFinderCache::GlobalCache
static CMakePackageFinderCache GlobalCache
Definition: CMakePackageFinderCache.h:19
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
Logging.h
ArmarXDataPath.h
Application.h
ScenarioManager::Parser::PackageBuilder::FilterPackagesForScenario
static StringList FilterPackagesForScenario(std::string scenario)
Definition: PackageBuilder.cpp:133
ScenarioManager::Parser::StringList
std::vector< std::string > StringList
Definition: PackageBuilder.h:34