15#include "auto_apms_util/resource.hpp"
17#include "ament_index_cpp/get_resource.hpp"
18#include "ament_index_cpp/get_resources.hpp"
19#include "auto_apms_util/exceptions.hpp"
20#include "auto_apms_util/string.hpp"
21#include "pluginlib/class_loader.hpp"
26const std::string PLUGIN_RESOURCE_TYPE = _AUTO_APMS_UTIL__RESOURCE_TYPE_NAME__PLUGINLIB;
29 const std::string & resource_type,
const std::set<std::string> & exclude_packages)
31 std::set<std::string> packages;
32 for (
const auto & [package, _] : ament_index_cpp::get_resources(resource_type)) {
33 packages.insert(package);
35 if (packages.empty()) {
36 throw exceptions::ResourceError(
37 "Cannot find resources for type '" + resource_type +
"' in any of the installed packages.");
39 if (
const std::set<std::string> common =
getCommonElements(packages, exclude_packages); !common.empty()) {
40 for (
const std::string & package_to_exclude : common) packages.erase(package_to_exclude);
41 if (packages.empty()) {
42 throw exceptions::ResourceError(
43 "Resources for type '" + resource_type +
44 "' are only available in excluded but not in any other of the installed packages (Excluded packages containing "
46 auto_apms_util::join(std::vector<std::string>(common.begin(), common.end()),
", ") +
" ]).");
60 std::string base_path;
61 if (ament_index_cpp::get_resource(PLUGIN_RESOURCE_TYPE, package, content, &base_path)) {
62 std::vector<std::string> paths =
splitString(content,
"\n");
63 if (paths.size() != 1) {
64 throw exceptions::ResourceError(
65 "Invalid '" + PLUGIN_RESOURCE_TYPE +
"' resource marker file installed by package '" + package +
66 "'. Must contain a single line with a relative path to the plugins.xml "
67 "manifest file with respect to the package's install prefix.");
69 return base_path +
'/' + paths[0];
71 throw exceptions::ResourceError(
72 "Cannot find a plugin.xml file in package '" + package +
"' (Plugin resource type is: '" + PLUGIN_RESOURCE_TYPE +
78 std::vector<std::string> xml_paths;
std::vector< std::string > collectPluginXMLPaths(const std::set< std::string > &exclude_packages={})
Collect the paths of plugin.xml manifest files used for initializing pluginlib::ClassLoader objects.
std::string getPluginXMLPath(const std::string &package)
Get the path of a plugin.xml manifest file used for initializing pluginlib::ClassLoader objects.
std::vector< std::string > splitString(const std::string &str, const std::string &delimiter, bool remove_empty=true)
Split a string into multiple tokens using a specific delimiter string (Delimiter may consist of multi...
std::set< KeyT, CompareT, AllocatorT > getCommonElements(std::set< KeyT, CompareT, AllocatorT > c1, std::set< KeyT, CompareT, AllocatorT > c2)
Assemble common elements of two sets.
std::set< std::string > getPackagesWithResourceType(const std::string &resource_type, const std::set< std::string > &exclude_packages={})
Get a list of all package names that register a certain type of ament_index resources.
std::set< std::string > getPackagesWithPluginResources(const std::set< std::string > &exclude_packages={})
Get a list of all package names that register AutoAPMS plugin resources.
Fundamental helper classes and utility functions.