Skip to content

Commit

Permalink
Merge pull request #1254 from tier4/refactor/openscenario_validator
Browse files Browse the repository at this point in the history
refactor `openscenario validator` package
  • Loading branch information
HansRobo authored May 30, 2024
2 parents 1ceb05c + d6766ea commit 37fecc2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 72 deletions.
25 changes: 9 additions & 16 deletions openscenario/openscenario_validator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,27 @@ 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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
find_package(ament_index_cpp REQUIRED)

add_executable(validate
src/validator_command.cpp)

target_link_libraries(validate ${PROJECT_NAME})
target_link_libraries(validate ${XercesC_LIBRARIES} ament_index_cpp::ament_index_cpp)
target_include_directories(validate PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

ament_export_include_directories(include)
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies(XercesC ament_index_cpp)

install(DIRECTORY include/
DESTINATION include)

install(TARGETS validate
DESTINATION lib/${PROJECT_NAME})

install(TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib/${PROJECT_NAME})
install(DIRECTORY schema
DESTINATION share/${PROJECT_NAME}
)

ament_package()
20 changes: 0 additions & 20 deletions openscenario/openscenario_validator/configure/schema.cpp

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
#ifndef OPENSCENARIO_VALIDATOR__VALIDATOR_HPP_
#define OPENSCENARIO_VALIDATOR__VALIDATOR_HPP_

#include <ament_index_cpp/get_package_share_directory.hpp>
#include <boost/filesystem.hpp>
#include <iostream>
#include <openscenario_validator/schema.hpp>
#include <sstream>
#include <stdexcept>
#include <system_error>
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/validators/common/Grammar.hpp>

namespace openscenario_validator
{
Expand Down Expand Up @@ -79,20 +76,16 @@ class OpenSCENARIOValidator
public:
OpenSCENARIOValidator() : parser(std::make_unique<xercesc::XercesDOMParser>())
{
xercesc::MemBufInputSource schema_input_source(
reinterpret_cast<const XMLByte *>(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);

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
Expand Down
1 change: 1 addition & 0 deletions openscenario/openscenario_validator/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<maintainer email="[email protected]">Kotaro Yoshimoto</maintainer>
<license>Apache License 2.0</license>
<depend>xerces</depend>
<depend>ament_index_cpp</depend>
<export>
<build_type>ament_cmake</build_type>
</export>
Expand Down

0 comments on commit 37fecc2

Please sign in to comment.