From bfd5d8ea051e2426e5be7ba2d26a654e51b71bc6 Mon Sep 17 00:00:00 2001 From: Kotaro Yoshimoto Date: Mon, 20 May 2024 15:22:54 +0900 Subject: [PATCH 1/3] refactor: delete in-memory xml schema from openscenario_validator --- .../openscenario_validator/CMakeLists.txt | 21 ++++--------------- .../configure/schema.cpp | 20 ------------------ .../include/openscenario_validator/schema.hpp | 18 ---------------- .../openscenario_validator/validator.hpp | 20 +++++------------- 4 files changed, 9 insertions(+), 70 deletions(-) delete mode 100644 openscenario/openscenario_validator/configure/schema.cpp delete mode 100644 openscenario/openscenario_validator/include/openscenario_validator/schema.hpp diff --git a/openscenario/openscenario_validator/CMakeLists.txt b/openscenario/openscenario_validator/CMakeLists.txt index 1bf9cbf94e4..1e8c5397b8a 100644 --- a/openscenario/openscenario_validator/CMakeLists.txt +++ b/openscenario/openscenario_validator/CMakeLists.txt @@ -5,24 +5,15 @@ project(openscenario_validator) find_package(ament_cmake REQUIRED) find_package(XercesC REQUIRED) -file(READ ${CMAKE_CURRENT_SOURCE_DIR}/configure/OpenSCENARIO-1.3.xsd ${PROJECT_NAME}_OPENSCENARIO_1_3_XSD) - -configure_file(configure/schema.cpp src/schema.cpp) - -add_library(${PROJECT_NAME} STATIC src/schema.cpp) - -target_link_libraries(${PROJECT_NAME} ${XercesC_LIBRARIES}) -target_include_directories(${PROJECT_NAME} PUBLIC - $ - $) - add_executable(validate src/validator_command.cpp) -target_link_libraries(validate ${PROJECT_NAME}) +target_link_libraries(validate ${XercesC_LIBRARIES}) +target_include_directories(validate PUBLIC + $ + $) ament_export_include_directories(include) -ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) install(DIRECTORY include/ DESTINATION include) @@ -30,8 +21,4 @@ install(DIRECTORY include/ install(TARGETS validate DESTINATION lib/${PROJECT_NAME}) -install(TARGETS ${PROJECT_NAME} - EXPORT export_${PROJECT_NAME} - ARCHIVE DESTINATION lib/${PROJECT_NAME}) - ament_package() diff --git a/openscenario/openscenario_validator/configure/schema.cpp b/openscenario/openscenario_validator/configure/schema.cpp deleted file mode 100644 index 99acc296fc2..00000000000 --- a/openscenario/openscenario_validator/configure/schema.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2015 TIER IV, Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -namespace openscenario_validator -{ -const char schema[] = R"###(${${PROJECT_NAME}_OPENSCENARIO_1_3_XSD})###"; -} // namespace openscenario_validator diff --git a/openscenario/openscenario_validator/include/openscenario_validator/schema.hpp b/openscenario/openscenario_validator/include/openscenario_validator/schema.hpp deleted file mode 100644 index e3a68520d19..00000000000 --- a/openscenario/openscenario_validator/include/openscenario_validator/schema.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 TIER IV, Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace openscenario_validator -{ -extern const char schema[]; -} // namespace openscenario_validator diff --git a/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp b/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp index 53216c07fab..6b74bf001d7 100644 --- a/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp +++ b/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -79,20 +78,11 @@ class OpenSCENARIOValidator public: OpenSCENARIOValidator() : parser(std::make_unique()) { - xercesc::MemBufInputSource schema_input_source( - reinterpret_cast(schema), strlen(schema), "xsd"); - - if (not parser->loadGrammar(schema_input_source, xercesc::Grammar::SchemaGrammarType)) { - throw std::runtime_error( - "Failed to load XSD schema. This is an unexpected error and an implementation issue. " - "Please contact the developer."); - } else { - parser->setDoNamespaces(true); - parser->setDoSchema(true); - parser->setErrorHandler(&error_handler); - parser->setValidationSchemaFullChecking(true); - parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always); - } + parser->setDoNamespaces(true); + parser->setDoSchema(true); + parser->setErrorHandler(&error_handler); + parser->setValidationSchemaFullChecking(true); + parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always); } auto validate(const boost::filesystem::path & xml_file) -> void From e49557f2dcce5757e44d3e6c3a415a0598cdda78 Mon Sep 17 00:00:00 2001 From: Kotaro Yoshimoto Date: Mon, 20 May 2024 15:38:29 +0900 Subject: [PATCH 2/3] refactor: use noNamespaceSchemaLocation for validation in openscenario_validator --- openscenario/openscenario_validator/CMakeLists.txt | 8 +++++++- .../include/openscenario_validator/validator.hpp | 9 ++++++--- openscenario/openscenario_validator/package.xml | 1 + .../{configure => schema}/OpenSCENARIO-1.2.xsd | 0 .../{configure => schema}/OpenSCENARIO-1.3.xsd | 0 5 files changed, 14 insertions(+), 4 deletions(-) rename openscenario/openscenario_validator/{configure => schema}/OpenSCENARIO-1.2.xsd (100%) rename openscenario/openscenario_validator/{configure => schema}/OpenSCENARIO-1.3.xsd (100%) diff --git a/openscenario/openscenario_validator/CMakeLists.txt b/openscenario/openscenario_validator/CMakeLists.txt index 1e8c5397b8a..75e8f4eab1d 100644 --- a/openscenario/openscenario_validator/CMakeLists.txt +++ b/openscenario/openscenario_validator/CMakeLists.txt @@ -4,16 +4,18 @@ project(openscenario_validator) find_package(ament_cmake REQUIRED) find_package(XercesC REQUIRED) +find_package(ament_index_cpp REQUIRED) add_executable(validate src/validator_command.cpp) -target_link_libraries(validate ${XercesC_LIBRARIES}) +target_link_libraries(validate ${XercesC_LIBRARIES} ament_index_cpp::ament_index_cpp) target_include_directories(validate PUBLIC $ $) ament_export_include_directories(include) +ament_export_dependencies(XercesC ament_index_cpp) install(DIRECTORY include/ DESTINATION include) @@ -21,4 +23,8 @@ install(DIRECTORY include/ install(TARGETS validate DESTINATION lib/${PROJECT_NAME}) +install(DIRECTORY schema + DESTINATION share/${PROJECT_NAME} +) + ament_package() diff --git a/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp b/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp index 6b74bf001d7..c39c9fdb129 100644 --- a/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp +++ b/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp @@ -15,16 +15,14 @@ #ifndef OPENSCENARIO_VALIDATOR__VALIDATOR_HPP_ #define OPENSCENARIO_VALIDATOR__VALIDATOR_HPP_ +#include #include #include #include #include #include -#include #include #include -#include -#include namespace openscenario_validator { @@ -83,6 +81,11 @@ class OpenSCENARIOValidator parser->setErrorHandler(&error_handler); parser->setValidationSchemaFullChecking(true); parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always); + + std::string schema_path = + ament_index_cpp::get_package_share_directory("openscenario_validator") + + "/schema/OpenSCENARIO-1.3.xsd"; + parser->setExternalNoNamespaceSchemaLocation(schema_path.c_str()); } auto validate(const boost::filesystem::path & xml_file) -> void diff --git a/openscenario/openscenario_validator/package.xml b/openscenario/openscenario_validator/package.xml index 5177c3ce728..1c3f7c2a2af 100644 --- a/openscenario/openscenario_validator/package.xml +++ b/openscenario/openscenario_validator/package.xml @@ -7,6 +7,7 @@ Kotaro Yoshimoto Apache License 2.0 xerces + ament_index_cpp ament_cmake diff --git a/openscenario/openscenario_validator/configure/OpenSCENARIO-1.2.xsd b/openscenario/openscenario_validator/schema/OpenSCENARIO-1.2.xsd similarity index 100% rename from openscenario/openscenario_validator/configure/OpenSCENARIO-1.2.xsd rename to openscenario/openscenario_validator/schema/OpenSCENARIO-1.2.xsd diff --git a/openscenario/openscenario_validator/configure/OpenSCENARIO-1.3.xsd b/openscenario/openscenario_validator/schema/OpenSCENARIO-1.3.xsd similarity index 100% rename from openscenario/openscenario_validator/configure/OpenSCENARIO-1.3.xsd rename to openscenario/openscenario_validator/schema/OpenSCENARIO-1.3.xsd From d6766ea8c66e1cb8a5db42d4c893e70e553359f0 Mon Sep 17 00:00:00 2001 From: Kotaro Yoshimoto Date: Tue, 28 May 2024 18:31:26 +0900 Subject: [PATCH 3/3] refactor: validator.hpp --- .../include/openscenario_validator/validator.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp b/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp index c39c9fdb129..d4b4fef2e9d 100644 --- a/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp +++ b/openscenario/openscenario_validator/include/openscenario_validator/validator.hpp @@ -82,10 +82,10 @@ class OpenSCENARIOValidator parser->setValidationSchemaFullChecking(true); parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always); - std::string schema_path = - ament_index_cpp::get_package_share_directory("openscenario_validator") + - "/schema/OpenSCENARIO-1.3.xsd"; - parser->setExternalNoNamespaceSchemaLocation(schema_path.c_str()); + parser->setExternalNoNamespaceSchemaLocation( + (ament_index_cpp::get_package_share_directory("openscenario_validator") + + "/schema/OpenSCENARIO-1.3.xsd") + .c_str()); } auto validate(const boost::filesystem::path & xml_file) -> void