From 29b7c42cb3c5b6fa17d24852bfea309e0fa21716 Mon Sep 17 00:00:00 2001 From: Sebastian Toepfer <61313468+sebastian-toepfer@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:33:24 +0100 Subject: [PATCH 1/3] prepare testsuite to run with jpms enabled --- core/pom.xml | 96 ++++++++----------- .../JsonTestSuiteTestCaseProvider.java | 2 +- .../jsonschema/core/testsuite/Resources.java | 45 ++++----- 3 files changed, 59 insertions(+), 84 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index b78780b0..ffcc7598 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -96,6 +96,47 @@ + + + ${project.build.directory}/jsonschematests + + + **/tests/draft2020-12/additionalProperties.json + **/tests/draft2020-12/boolean_schema.json + **/tests/draft2020-12/enum.json + **/tests/draft2020-12/exclusiveMaximum.json + **/tests/draft2020-12/exclusiveMinimum.json + **/tests/draft2020-12/format.json + + + **/tests/draft2020-12/maxItems.json + **/tests/draft2020-12/maxLength.json + **/tests/draft2020-12/maximum.json + **/tests/draft2020-12/minItems.json + **/tests/draft2020-12/minLength.json + **/tests/draft2020-12/minimum.json + **/tests/draft2020-12/multipleOf.json + **/tests/draft2020-12/pattern.json + **/tests/draft2020-12/patternProperties.json + **/tests/draft2020-12/prefixItems.json + **/tests/draft2020-12/properties.json + + **/tests/draft2020-12/required.json + **/tests/draft2020-12/type.json + **/tests/draft2020-12/uniqueItems.json + + + + org.apache.maven.plugins @@ -118,61 +159,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - - - add-jsonschema-tests - - add-test-resource - - - - - ${project.build.directory}/jsonschematests - - - **/tests/draft2020-12/additionalProperties.json - **/tests/draft2020-12/boolean_schema.json - **/tests/draft2020-12/enum.json - **/tests/draft2020-12/exclusiveMaximum.json - **/tests/draft2020-12/exclusiveMinimum.json - **/tests/draft2020-12/format.json - - - **/tests/draft2020-12/maxItems.json - **/tests/draft2020-12/maxLength.json - **/tests/draft2020-12/maximum.json - **/tests/draft2020-12/minItems.json - **/tests/draft2020-12/minLength.json - **/tests/draft2020-12/minimum.json - **/tests/draft2020-12/multipleOf.json - **/tests/draft2020-12/pattern.json - **/tests/draft2020-12/patternProperties.json - **/tests/draft2020-12/prefixItems.json - **/tests/draft2020-12/properties.json - - **/tests/draft2020-12/required.json - **/tests/draft2020-12/type.json - **/tests/draft2020-12/uniqueItems.json - - - - - - - - org.apache.maven.plugins maven-surefire-plugin diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/JsonTestSuiteTestCaseProvider.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/JsonTestSuiteTestCaseProvider.java index a12a7709..4c1116bb 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/JsonTestSuiteTestCaseProvider.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/JsonTestSuiteTestCaseProvider.java @@ -39,7 +39,7 @@ class JsonTestSuiteTestCaseProvider implements ArgumentsProvider { @Override @SuppressWarnings("MustBeClosedChecker") public Stream provideArguments(final ExtensionContext context) throws Exception { - return new Resources() + return new Resources("tests") .all() .filter(resource -> resource.hasExtension("json")) .map(JsonSchemaTestSuites::new) diff --git a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/Resources.java b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/Resources.java index 9c7c2c3c..9a6b021f 100644 --- a/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/Resources.java +++ b/core/src/test/java/io/github/sebastiantoepfer/jsonschema/core/testsuite/Resources.java @@ -23,8 +23,8 @@ */ package io.github.sebastiantoepfer.jsonschema.core.testsuite; -import java.io.File; import java.io.IOException; +import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; @@ -32,7 +32,6 @@ import java.util.Objects; import java.util.Spliterator; import java.util.Spliterators; -import java.util.regex.Pattern; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -40,10 +39,6 @@ final class Resources { private final String baseDir; - public Resources() { - this("."); - } - public Resources(final String baseDir) { this.baseDir = baseDir; } @@ -75,13 +70,22 @@ Stream all() { } } - private static class PathResources { + private URI baseUri() { + try { + return Resource.class.getClassLoader().getResource(baseDir).toURI(); + } catch (URISyntaxException e) { + throw new IllegalStateException(e); + } + } + + private class PathResources { - private static final Pattern PATH_SEPARATOR = Pattern.compile(File.pathSeparator); + private final Path basePath; private final Path path; public PathResources(final Path path) { this.path = Objects.requireNonNull(path); + this.basePath = Paths.get(baseUri()).getParent(); } @SuppressWarnings("StreamResourceLeak") @@ -89,26 +93,11 @@ Stream toResources() { final Stream result; try { if (path.toFile().isFile()) { - result = - Stream.of( - new Resource( - path - .toFile() - .getAbsolutePath() - .substring( - PATH_SEPARATOR - .splitAsStream(System.getProperty("java.class.path")) - .map(Path::of) - .filter(path::startsWith) - .map(Path::toFile) - .map(File::getAbsolutePath) - .map(String::length) - .map(i -> i + 1) - .findAny() - .orElse(0) - ) - ) - ); + if (path.startsWith(basePath)) { + result = Stream.of(new Resource(basePath.relativize(path).toString())); + } else { + result = Stream.of(new Resource(path.toString())); + } } else { result = Files.list(path).map(PathResources::new).flatMap(PathResources::toResources); } From c4e7ea526a0f74c3c9b4676d709441f1848bed27 Mon Sep 17 00:00:00 2001 From: Sebastian Toepfer <61313468+sebastian-toepfer@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:36:54 +0100 Subject: [PATCH 2/3] fix jpms definitions --- api/src/main/java/module-info.java | 2 + api/src/test/java/module-info.java | 5 +++ core/src/test/java/module-info.java | 8 ++++ vocabulary-spi/src/main/java/module-info.java | 1 + vocabulary-spi/src/test/java/module-info.java | 37 +++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 vocabulary-spi/src/test/java/module-info.java diff --git a/api/src/main/java/module-info.java b/api/src/main/java/module-info.java index d66a3570..6a06bc6c 100644 --- a/api/src/main/java/module-info.java +++ b/api/src/main/java/module-info.java @@ -27,6 +27,8 @@ exports io.github.sebastiantoepfer.jsonschema.keyword; exports io.github.sebastiantoepfer.jsonschema.spi; + uses io.github.sebastiantoepfer.jsonschema.spi.JsonSchemaFactory; + requires io.github.sebastiantoepfer.ddd.common; requires io.github.sebastiantoepfer.ddd.media.json; requires jakarta.json; diff --git a/api/src/test/java/module-info.java b/api/src/test/java/module-info.java index 3d799ba8..46d5f263 100644 --- a/api/src/test/java/module-info.java +++ b/api/src/test/java/module-info.java @@ -28,6 +28,11 @@ requires io.github.sebastiantoepfer.ddd.media.json; requires jakarta.json; + uses io.github.sebastiantoepfer.jsonschema.spi.JsonSchemaFactory; + + provides io.github.sebastiantoepfer.jsonschema.spi.JsonSchemaFactory + with io.github.sebastiantoepfer.jsonschema.FakeJsonSchemaFactory; + requires org.junit.jupiter.api; requires org.junit.jupiter.params; requires org.hamcrest; diff --git a/core/src/test/java/module-info.java b/core/src/test/java/module-info.java index a4d9ec46..ad6a3a0e 100644 --- a/core/src/test/java/module-info.java +++ b/core/src/test/java/module-info.java @@ -29,6 +29,14 @@ requires io.github.sebastiantoepfer.ddd.media.core; requires jakarta.json; + uses io.github.sebastiantoepfer.jsonschema.vocabulary.spi.LazyVocabularies; + + provides io.github.sebastiantoepfer.jsonschema.spi.JsonSchemaFactory + with io.github.sebastiantoepfer.jsonschema.core.DefaultJsonSchemaFactory; + + provides io.github.sebastiantoepfer.jsonschema.vocabulary.spi.LazyVocabularies + with io.github.sebastiantoepfer.jsonschema.core.vocab.OfficialVocabularies; + requires com.google.errorprone.annotations; requires org.junit.jupiter.api; requires org.junit.jupiter.params; diff --git a/vocabulary-spi/src/main/java/module-info.java b/vocabulary-spi/src/main/java/module-info.java index 68e99b3f..cb6cab9c 100644 --- a/vocabulary-spi/src/main/java/module-info.java +++ b/vocabulary-spi/src/main/java/module-info.java @@ -25,5 +25,6 @@ module io.github.sebastiantoepfer.jsonschema.vocabulary.spi { exports io.github.sebastiantoepfer.jsonschema.vocabulary.spi; + uses io.github.sebastiantoepfer.jsonschema.vocabulary.spi.LazyVocabularies; requires io.github.sebastiantoepfer.jsonschema; } diff --git a/vocabulary-spi/src/test/java/module-info.java b/vocabulary-spi/src/test/java/module-info.java new file mode 100644 index 00000000..58d59acb --- /dev/null +++ b/vocabulary-spi/src/test/java/module-info.java @@ -0,0 +1,37 @@ +/* + * The MIT License + * + * Copyright 2024 sebastian. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +open module io.github.sebastiantoepfer.jsonschema.vocabulary.spi { + exports io.github.sebastiantoepfer.jsonschema.vocabulary.spi; + + uses io.github.sebastiantoepfer.jsonschema.vocabulary.spi.LazyVocabularies; + + provides io.github.sebastiantoepfer.jsonschema.vocabulary.spi.LazyVocabularies + with io.github.sebastiantoepfer.jsonschema.vocabulary.spi.TestLazyVocabularies; + + requires io.github.sebastiantoepfer.jsonschema; + + requires org.junit.jupiter.api; + requires hamcrest.optional; + requires org.hamcrest; +} From 848dd5d2dd8e974af59665b4427b370e1876eece Mon Sep 17 00:00:00 2001 From: Sebastian Toepfer <61313468+sebastian-toepfer@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:37:15 +0100 Subject: [PATCH 3/3] enable jpms also for tests --- pom.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pom.xml b/pom.xml index f61368ea..81ca08b2 100644 --- a/pom.xml +++ b/pom.xml @@ -94,14 +94,6 @@ install - - org.apache.maven.plugins - maven-surefire-plugin - - false - - - org.cyclonedx cyclonedx-maven-plugin