289 if (search_identity.empty()) {
290 throw auto_apms_util::exceptions::ResourceIdentityFormatError(
291 "Cannot create behavior resource with empty identity.");
294 std::set<std::string> search_packages;
295 if (!search_identity.package_name.empty()) {
296 search_packages.insert(search_identity.package_name);
302 size_t matching_count = 0;
303 for (
const auto & p : search_packages) {
305 std::string base_path;
306 if (ament_index_cpp::get_resource(
307 _AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_TYPE_NAME__BEHAVIOR, p, content, &base_path)) {
308 for (
const auto & line :
311 line, _AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_MARKER_FILE_FIELD_PER_LINE_SEP,
false);
312 if (parts.size() != 6) {
313 throw auto_apms_util::exceptions::ResourceError(
314 "Invalid behavior tree resource file (Package: '" + p +
"'). Invalid line: " + line +
".");
318 std::string found_category = parts[0];
319 std::string found_alias = parts[1];
320 if (search_identity.category_name.empty()) {
322 if (found_alias != search_identity.behavior_alias) {
325 }
else if (found_category != search_identity.category_name || found_alias != search_identity.behavior_alias) {
336 unique_identity_.category_name = found_category;
339 unique_identity_.behavior_alias = found_alias;
342 unique_identity_.package_name = p;
345 default_build_handler_ = parts[2];
348 build_request_file_path_ = base_path +
"/" + parts[3];
349 if (std::filesystem::is_regular_file(build_request_file_path_)) {
350 std::ifstream file(build_request_file_path_);
352 throw auto_apms_util::exceptions::ResourceError(
353 "Failed to open behavior resource file '" + build_request_file_path_ +
"'");
355 build_request_ = std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
357 build_request_file_path_ =
"";
358 build_request_ = parts[3];
362 entrypoint_ = parts[4];
365 std::vector<std::string> node_manifest_paths;
367 node_manifest_paths.push_back(std::filesystem::path(path).is_absolute() ? path : (base_path +
"/" + path));
374 if (matching_count == 0) {
375 throw auto_apms_util::exceptions::ResourceError(
376 "No behavior resource with identity '" + search_identity.str() +
"' was registered.");
378 if (matching_count > 1) {
379 throw auto_apms_util::exceptions::ResourceError(
380 "Behavior resource identity '" + search_identity.str() +
"' is ambiguous. You must be more precise.");