This commit is contained in:
Denisz Mihajlov 2024-10-02 08:33:57 +02:00 committed by GitHub
commit 84173f6686
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 90 additions and 71 deletions

83
pom.xml
View file

@ -21,7 +21,7 @@
<name>KoSIT XML Prüftool Implementierung</name> <name>KoSIT XML Prüftool Implementierung</name>
<groupId>de.kosit</groupId> <groupId>de.kosit</groupId>
<version>1.5.0</version> <version>1.5.1</version>
<artifactId>validationtool</artifactId> <artifactId>validationtool</artifactId>
<description>KoSIT XML Validator against XSD and Schematron based on defined scenarios.</description> <description>KoSIT XML Validator against XSD and Schematron based on defined scenarios.</description>
@ -58,19 +58,19 @@
<version.commons-io>2.11.0</version.commons-io> <version.commons-io>2.11.0</version.commons-io>
<version.commons-lang>3.12.0</version.commons-lang> <version.commons-lang>3.12.0</version.commons-lang>
<version.jacoco>0.8.8</version.jacoco> <version.jacoco>0.8.8</version.jacoco>
<version.jaxb>2.3.7</version.jaxb> <version.jaxb>3.0.1</version.jaxb>
<version.lombok>1.18.24</version.lombok> <version.lombok>1.18.24</version.lombok>
<version.mockito>4.9.0</version.mockito> <version.mockito>4.9.0</version.mockito>
<version.owasp-dependency-check>7.2.0</version.owasp-dependency-check> <version.owasp-dependency-check>7.2.0</version.owasp-dependency-check>
<version.rest-assured>5.2.0</version.rest-assured> <version.rest-assured>5.2.0</version.rest-assured>
<version.saxon-he>11.4</version.saxon-he> <version.saxon-he>12.5</version.saxon-he>
<version.slf4j>1.7.36</version.slf4j> <version.slf4j>1.7.36</version.slf4j>
</properties> </properties>
<repositories> <repositories>
<repository> <repository>
<id>project.local</id> <id>central</id>
<name>project</name> <name>Maven Central</name>
<url>file:${project.basedir}/libs</url> <url>https://repo.maven.apache.org/maven2</url>
</repository> </repository>
</repositories> </repositories>
@ -122,6 +122,11 @@
<version>${version.jaxb}</version> <version>${version.jaxb}</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${version.jaxb}</version>
</dependency>
<dependency> <dependency>
<groupId>org.assertj</groupId> <groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
@ -218,12 +223,19 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version> <version>3.10.1</version>
<configuration> <configuration>
<source>1.8</source> <source>17</source>
<target>1.8</target> <target>17</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
@ -270,8 +282,6 @@
<exclude>org.glassfish.jaxb:jaxb-runtime</exclude> <exclude>org.glassfish.jaxb:jaxb-runtime</exclude>
<exclude>com.sun.istack:istack-commons-runtime</exclude> <exclude>com.sun.istack:istack-commons-runtime</exclude>
<exclude>com.sun.xml.fastinfoset:FastInfoset</exclude> <exclude>com.sun.xml.fastinfoset:FastInfoset</exclude>
<exclude>jakarta.activation:jakarta.activation-api</exclude>
<exclude>jakarta.xml.bind:jakarta.xml.bind-api</exclude>
<exclude>org.jvnet.staxex:stax-ex</exclude> <exclude>org.jvnet.staxex:stax-ex</exclude>
<exclude>org.glassfish.jaxb:txw2</exclude> <exclude>org.glassfish.jaxb:txw2</exclude>
</excludes> </excludes>
@ -323,9 +333,9 @@
<!-- Generate model classes --> <!-- Generate model classes -->
<plugin> <plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId> <groupId>org.jvnet.jaxb</groupId>
<artifactId>maven-jaxb2-plugin</artifactId> <artifactId>jaxb-maven-plugin</artifactId>
<version>0.15.1</version> <version>4.0.8</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
@ -343,18 +353,27 @@
</args> </args>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.jvnet.jaxb2_commons</groupId> <groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb2-basics</artifactId> <artifactId>jaxb-plugins</artifactId>
<version>0.11.1</version> <version>3.0.0</version>
</plugin> </plugin>
</plugins> </plugins>
</configuration> </configuration>
<dependencies> <dependencies>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>4.0.5</version>
</dependency>
<dependency> <dependency>
<groupId>org.glassfish.jaxb</groupId> <groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId> <artifactId>jaxb-runtime</artifactId>
<version>4.0.5</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${version.jaxb}</version> <version>${version.jaxb}</version>
<optional>true</optional>
</dependency> </dependency>
</dependencies> </dependencies>
</plugin> </plugin>
@ -400,11 +419,11 @@
<goal>dump</goal> <goal>dump</goal>
</goals> </goals>
<configuration> <configuration>
<address>localhost</address> <address>localhost</address>
<port>${jacoco.tcp.port}</port> <port>${jacoco.tcp.port}</port>
<append>true</append> <append>true</append>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>generateJacocoReport</id> <id>generateJacocoReport</id>
@ -453,15 +472,15 @@
<artifactId>exec-maven-plugin</artifactId> <artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version> <version>3.1.0</version>
<executions> <executions>
<execution> <execution>
<id>run</id> <id>run</id>
<phase>pre-integration-test</phase> <phase>pre-integration-test</phase>
<goals> <goals>
<goal>exec</goal> <goal>exec</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
<executable>java</executable> <executable>java</executable>
<longClasspath>false</longClasspath> <longClasspath>false</longClasspath>
<async>true</async> <async>true</async>
@ -471,7 +490,7 @@
<argument>${jacocoFailsafe}</argument> <argument>${jacocoFailsafe}</argument>
<argument>-Xmx128m</argument> <argument>-Xmx128m</argument>
<argument>-classpath</argument> <argument>-classpath</argument>
<classpath /> <classpath/>
<argument>de.kosit.validationtool.cmd.CommandLineApplication</argument> <argument>de.kosit.validationtool.cmd.CommandLineApplication</argument>
<argument>-s</argument> <argument>-s</argument>
<argument>${project.build.testOutputDirectory}/examples/simple/scenarios.xml</argument> <argument>${project.build.testOutputDirectory}/examples/simple/scenarios.xml</argument>
@ -492,7 +511,7 @@
<configuration> <configuration>
<target> <target>
<!-- schlafen um den Start des Daemon abzuwarten --> <!-- schlafen um den Start des Daemon abzuwarten -->
<sleep seconds="10" /> <sleep seconds="10"/>
<echo>${jacoco.tcp.port}</echo> <echo>${jacoco.tcp.port}</echo>
</target> </target>
</configuration> </configuration>
@ -518,8 +537,8 @@
<goal>verify</goal> <goal>verify</goal>
</goals> </goals>
<configuration> <configuration>
<!--suppress MavenModelInspection --> <!--suppress MavenModelInspection -->
<argLine>-Dfile.encoding=UTF-8 -Ddaemon.port=${validator.server.port}</argLine> <argLine>-Dfile.encoding=UTF-8 -Ddaemon.port=${validator.server.port}</argLine>
</configuration> </configuration>
</execution> </execution>

View file

@ -68,7 +68,7 @@ public interface ResolvingConfigurationStrategy {
* function. * function.
* *
* @param scenarioRepository an optional repository, your implementation might not need this * @param scenarioRepository an optional repository, your implementation might not need this
* @return a preconfigured {@link net.sf.saxon.lib.UnparsedTextURIResolver} or null for using saxons default * @return a preconfigured {@link UnparsedTextURIResolver} or null for using saxons default
*/ */
UnparsedTextURIResolver createUnparsedTextURIResolver(URI scenarioRepository); UnparsedTextURIResolver createUnparsedTextURIResolver(URI scenarioRepository);

View file

@ -132,7 +132,7 @@ public class Validator {
final Processor processor = ProcessorProvider.getProcessor(); final Processor processor = ProcessorProvider.getProcessor();
final List<Configuration> config = getConfiguration(cmd); final List<Configuration> config = getConfiguration(cmd);
final InternalCheck check = new InternalCheck(processor, config.toArray(new Configuration[0])); final InternalCheck check = new InternalCheck(processor, config.toArray(new Configuration[0]));
final CommandLineOptions.CliOptions cliOptions = defaultIfNull(cmd.getCliOptions(), new CliOptions()); final CliOptions cliOptions = defaultIfNull(cmd.getCliOptions(), new CliOptions());
final Path outputDirectory = determineOutputDirectory(cliOptions); final Path outputDirectory = determineOutputDirectory(cliOptions);
if (cliOptions.isExtractHtml()) { if (cliOptions.isExtractHtml()) {
check.getCheckSteps().add(new ExtractHtmlContentAction(processor, outputDirectory)); check.getCheckSteps().add(new ExtractHtmlContentAction(processor, outputDirectory));
@ -235,7 +235,7 @@ public class Validator {
} }
private static NamingStrategy determineNamingStrategy(final CommandLineOptions.CliOptions cmd) { private static NamingStrategy determineNamingStrategy(final CliOptions cmd) {
final DefaultNamingStrategy namingStrategy = new DefaultNamingStrategy(); final DefaultNamingStrategy namingStrategy = new DefaultNamingStrategy();
if (isNotEmpty(cmd.getReportPrefix())) { if (isNotEmpty(cmd.getReportPrefix())) {
namingStrategy.setPrefix(cmd.getReportPrefix()); namingStrategy.setPrefix(cmd.getReportPrefix());
@ -256,7 +256,7 @@ public class Validator {
return a; return a;
} }
private static Path determineOutputDirectory(final CommandLineOptions.CliOptions cmd) { private static Path determineOutputDirectory(final CliOptions cmd) {
final Path dir; final Path dir;
if (cmd.getOutputPath() != null) { if (cmd.getOutputPath() != null) {
dir = cmd.getOutputPath(); dir = cmd.getOutputPath();
@ -269,7 +269,7 @@ public class Validator {
return dir; return dir;
} }
private static Collection<Input> determineTestTargets(final CommandLineOptions.CliOptions cmd) throws IOException { private static Collection<Input> determineTestTargets(final CliOptions cmd) throws IOException {
final Collection<Input> targets = new ArrayList<>(); final Collection<Input> targets = new ArrayList<>();
if (cmd.getFiles() != null && !cmd.getFiles().isEmpty()) { if (cmd.getFiles() != null && !cmd.getFiles().isEmpty()) {
cmd.getFiles().forEach(e -> targets.addAll(determineTestTarget(e))); cmd.getFiles().forEach(e -> targets.addAll(determineTestTarget(e)));

View file

@ -114,7 +114,7 @@ class XPathBuilder implements Builder<XPathExecutable> {
final Iterable<String> iterable = () -> iterator; final Iterable<String> iterable = () -> iterator;
StreamSupport.stream(iterable.spliterator(), false).filter(e -> !ArrayUtils.contains(IGNORED_PREFIXES, e)) StreamSupport.stream(iterable.spliterator(), false).filter(e -> !ArrayUtils.contains(IGNORED_PREFIXES, e))
.filter(StringUtils::isNotBlank).forEach(e -> ns.put(e, this.executable.getUnderlyingExpression().getInternalExpression() .filter(StringUtils::isNotBlank).forEach(e -> ns.put(e, this.executable.getUnderlyingExpression().getInternalExpression()
.getRetainedStaticContext().getURIForPrefix(e, false))); .getRetainedStaticContext().getURIForPrefix(e, false).toString()));
getNamespaces().putAll(ns); getNamespaces().putAll(ns);
} }

View file

@ -20,8 +20,9 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.StringJoiner; import java.util.StringJoiner;
import javax.xml.bind.ValidationEvent; import jakarta.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler; import jakarta.xml.bind.ValidationEventHandler;
import javax.xml.transform.ErrorListener; import javax.xml.transform.ErrorListener;
import javax.xml.transform.SourceLocator; import javax.xml.transform.SourceLocator;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;

View file

@ -33,7 +33,11 @@ import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema; import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory; import javax.xml.validation.SchemaFactory;
import net.sf.saxon.lib.UnparsedTextURIResolver;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -50,13 +54,8 @@ import de.kosit.validationtool.model.scenarios.ResourceType;
import de.kosit.validationtool.model.scenarios.ScenarioType; import de.kosit.validationtool.model.scenarios.ScenarioType;
import de.kosit.validationtool.model.scenarios.ValidateWithSchematron; import de.kosit.validationtool.model.scenarios.ValidateWithSchematron;
import net.sf.saxon.lib.UnparsedTextURIResolver;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XPathCompiler; import net.sf.saxon.s9api.XPathCompiler;
import net.sf.saxon.s9api.XPathExecutable; import net.sf.saxon.s9api.XPathExecutable;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
/** /**
* Repository für verschiedene XML Artefakte zur Vearbeitung der Prüfszenarien. * Repository für verschiedene XML Artefakte zur Vearbeitung der Prüfszenarien.

View file

@ -24,14 +24,14 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.StringJoiner; import java.util.StringJoiner;
import javax.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement; import jakarta.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import javax.xml.bind.JAXBIntrospector; import jakarta.xml.bind.JAXBIntrospector;
import javax.xml.bind.Marshaller; import jakarta.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller; import jakarta.xml.bind.Unmarshaller;
import javax.xml.bind.ValidationEventHandler; import jakarta.xml.bind.ValidationEventHandler;
import javax.xml.bind.annotation.XmlRegistry; import jakarta.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLOutputFactory;

View file

@ -112,11 +112,11 @@ public class DefaultCheck implements Check {
@Override @Override
public Result checkInput(final Input input) { public Result checkInput(final Input input) {
final CheckAction.Bag t = new CheckAction.Bag(input, createReport()); final Bag t = new Bag(input, createReport());
return runCheckInternal(t); return runCheckInternal(t);
} }
protected Result runCheckInternal(final CheckAction.Bag t) { protected Result runCheckInternal(final Bag t) {
final long started = System.currentTimeMillis(); final long started = System.currentTimeMillis();
log.info("Checking content of {}", t.getInput().getName()); log.info("Checking content of {}", t.getInput().getName());
for (final CheckAction action : this.checkSteps) { for (final CheckAction action : this.checkSteps) {

View file

@ -21,7 +21,7 @@ import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import javax.xml.bind.util.JAXBSource; import jakarta.xml.bind.util.JAXBSource;
import javax.xml.transform.Source; import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
@ -42,7 +42,7 @@ import net.sf.saxon.om.TreeInfo;
* This class is known to work with: * This class is known to work with:
* <ul> * <ul>
* <li>{@link StreamSource} - both {@link java.io.InputStream} based and {@link java.io.Reader} based</li> * <li>{@link StreamSource} - both {@link java.io.InputStream} based and {@link java.io.Reader} based</li>
* <li>{@link javax.xml.transform.dom.DOMSource}</li> * <li>{@link DOMSource}</li>
* <li>{@link javax.xml.bind.util.JAXBSource}</li> * <li>{@link javax.xml.bind.util.JAXBSource}</li>
* <li>{@link TreeInfo}</li> * <li>{@link TreeInfo}</li>
* </ul> * </ul>

View file

@ -97,7 +97,7 @@ public class StreamHelper {
private final LazyReadInput reference; private final LazyReadInput reference;
public CountInputStream(final LazyReadInput input, final InputStream stream) { public CountInputStream(final LazyReadInput input, final InputStream stream) {
super(new org.apache.commons.io.input.CountingInputStream(stream)); super(new CountingInputStream(stream));
this.reference = input; this.reference = input;
} }

View file

@ -20,9 +20,9 @@ import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import javax.xml.bind.Marshaller; import jakarta.xml.bind.Marshaller;
import javax.xml.bind.util.JAXBSource; import jakarta.xml.bind.util.JAXBSource;
import org.xml.sax.ContentHandler; import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler; import org.xml.sax.DTDHandler;

View file

@ -64,7 +64,7 @@ public class SchematronValidationAction implements CheckAction {
// resolving nur relative zum Repository // resolving nur relative zum Repository
transformer.setURIResolver(scenario.getUriResolver()); transformer.setURIResolver(scenario.getUriResolver());
final CollectingErrorEventHandler e = new CollectingErrorEventHandler(); final CollectingErrorEventHandler e = new CollectingErrorEventHandler();
transformer.setMessageListener(e); transformer.setErrorListener(e);
final XdmDestination result = new XdmDestination(); final XdmDestination result = new XdmDestination();
transformer.setDestination(result); transformer.setDestination(result);

View file

@ -16,7 +16,7 @@
package de.kosit.validationtool.impl.xml; package de.kosit.validationtool.impl.xml;
import javax.xml.bind.annotation.adapters.XmlAdapter; import jakarta.xml.bind.annotation.adapters.XmlAdapter;
public class StringTrimAdapter extends XmlAdapter<String, String> { public class StringTrimAdapter extends XmlAdapter<String, String> {

View file

@ -16,7 +16,5 @@
project_version=${project.version} project_version=${project.version}
framework_version=1.0.2 framework_version=1.0.2
engine_name=KoSIT Validator engine_name=KoSIT Validator
build_timestamp=${build.timestamp}
build_number=${build.number} build_number=${build.number}
build_revision=${build.revision}
build_branch=${build.branch}

View file

@ -65,6 +65,8 @@ public class CreateReportActionTest {
bag.setReport(null); bag.setReport(null);
this.action.check(bag); this.action.check(bag);
assertThat(bag.getReport()).isNotNull(); assertThat(bag.getReport()).isNotNull();
final String reportString = serialize(bag.getReport());
System.out.println(reportString);
} }
@Test @Test
@ -77,7 +79,7 @@ public class CreateReportActionTest {
this.action.check(bag); this.action.check(bag);
assertThat(bag.getReport()).isNotNull(); assertThat(bag.getReport()).isNotNull();
final String reportString = serialize(bag.getReport()); final String reportString = serialize(bag.getReport());
assertThat(reportString).contains("SAXParseException"); assertThat(reportString).contains("IOException");
} }
@Test @Test

View file

@ -67,7 +67,7 @@ public class SchemaValidatorActionTest {
@Test @Test
public void testSimple() throws MalformedURLException { public void testSimple() throws MalformedURLException {
final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL())); final Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()));
this.service.check(bag); this.service.check(bag);
assertThat(bag.getSchemaValidationResult().isValid()).isTrue(); assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
assertThat(bag.getSchemaValidationResult()).isNotNull(); assertThat(bag.getSchemaValidationResult()).isNotNull();
@ -77,7 +77,7 @@ public class SchemaValidatorActionTest {
@Test @Test
public void testValidationFailure() throws MalformedURLException { public void testValidationFailure() throws MalformedURLException {
final Input input = InputFactory.read(Simple.SCHEMA_INVALID.toURL()); final Input input = InputFactory.read(Simple.SCHEMA_INVALID.toURL());
final CheckAction.Bag bag = createBag(input); final Bag bag = createBag(input);
this.service.check(bag); this.service.check(bag);
assertThat(bag.getSchemaValidationResult().isValid()).isFalse(); assertThat(bag.getSchemaValidationResult().isValid()).isFalse();
bag.getSchemaValidationResult().getErrors().forEach(e -> { bag.getSchemaValidationResult().getErrors().forEach(e -> {
@ -153,7 +153,7 @@ public class SchemaValidatorActionTest {
@Test @Test
public void testProcessingError() throws IOException, SAXException { public void testProcessingError() throws IOException, SAXException {
final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL())); final Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()));
final Scenario scenario = bag.getScenarioSelectionResult().getObject(); final Scenario scenario = bag.getScenarioSelectionResult().getObject();
final Schema schema = mock(Schema.class); final Schema schema = mock(Schema.class);
final Validator validator = mock(Validator.class); final Validator validator = mock(Validator.class);