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 (
const std::set<std::string> common =
getCommonElements(packages, exclude_packages); !common.empty()) {
36 for (
const std::string & package_to_exclude : common) packages.erase(package_to_exclude);
49 std::string base_path;
50 if (ament_index_cpp::get_resource(PLUGIN_RESOURCE_TYPE, package, content, &base_path)) {
51 std::vector<std::string> paths =
splitString(content,
"\n");
52 if (paths.size() != 1) {
53 throw exceptions::ResourceError(
54 "Invalid '" + PLUGIN_RESOURCE_TYPE +
"' resource marker file installed by package '" + package +
55 "'. Must contain a single line with a relative path to the plugins.xml "
56 "manifest file with respect to the package's install prefix.");
58 return base_path +
'/' + paths[0];
60 throw exceptions::ResourceError(
61 "Cannot find a plugin.xml file in package '" + package +
"' (Plugin resource type is: '" + PLUGIN_RESOURCE_TYPE +
67 std::vector<std::string> xml_paths;
std::vector< std::string > collectPluginXMLPaths(const std::set< std::string > &exclude_packages={})
Collect the paths of plugins.xml manifest files generated by AutoAPMS.
std::string getPluginXMLPath(const std::string &package)
Get the path of a specific plugins.xml manifest file generated by AutoAPMS.
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.