330 if (search_identity.empty()) {
331 throw auto_apms_util::exceptions::ResourceIdentityFormatError(
332 "Cannot create behavior resource with empty identity.");
335 std::set<std::string> search_packages;
336 if (!search_identity.package_name.empty()) {
337 search_packages.insert(search_identity.package_name);
343 size_t matching_count = 0;
344 for (
const auto & p : search_packages) {
345 const ament_index_cpp::PathWithResource resource =
346 ament_index_cpp::get_resource(_AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_TYPE_NAME__BEHAVIOR, p);
347 if (resource.resourcePath) {
348 const std::string & content = resource.contents;
349 const std::string base_path = resource.resourcePath->string();
350 for (
const auto & line :
353 line, _AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_MARKER_FILE_FIELD_PER_LINE_SEP,
false);
354 if (parts.size() != 6) {
355 throw auto_apms_util::exceptions::ResourceError(
356 "Invalid behavior tree resource file (Package: '" + p +
"'). Invalid line: " + line +
".");
360 std::string found_category = parts[0];
361 std::string found_alias = parts[1];
362 if (search_identity.category_name.empty()) {
364 if (found_alias != search_identity.behavior_alias) {
367 }
else if (found_category != search_identity.category_name || found_alias != search_identity.behavior_alias) {
378 unique_identity_.category_name = found_category;
381 unique_identity_.behavior_alias = found_alias;
384 unique_identity_.package_name = p;
387 default_build_handler_ = parts[2];
390 build_request_file_path_ = base_path +
"/" + parts[3];
391 if (std::filesystem::is_regular_file(build_request_file_path_)) {
392 std::ifstream file(build_request_file_path_);
394 throw auto_apms_util::exceptions::ResourceError(
395 "Failed to open behavior resource file '" + build_request_file_path_ +
"'");
397 build_request_ = std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
399 build_request_file_path_ =
"";
400 build_request_ = parts[3];
404 entry_point_ = parts[4];
407 std::vector<std::string> node_manifest_paths;
409 node_manifest_paths.push_back(std::filesystem::path(path).is_absolute() ? path : (base_path +
"/" + path));
416 if (matching_count == 0) {
417 throw auto_apms_util::exceptions::ResourceError(
418 "No behavior resource with identity '" + search_identity.str() +
"' was registered.");
420 if (matching_count > 1) {
421 throw auto_apms_util::exceptions::ResourceError(
422 "Behavior resource identity '" + search_identity.str() +
"' is ambiguous. You must be more precise.");