Skip to content

Commit

Permalink
Merge pull request #96 from sebastian-toepfer/jpms_fixes
Browse files Browse the repository at this point in the history
Jpms fixes
  • Loading branch information
sebastian-toepfer authored Jan 18, 2024
2 parents 5973230 + 848dd5d commit 0a6bc3a
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 92 deletions.
2 changes: 2 additions & 0 deletions api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions api/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
96 changes: 41 additions & 55 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,47 @@
</dependencies>

<build>
<testResources>
<testResource>
<directory>${project.build.directory}/jsonschematests</directory>
<includes>
<!-- no longer part ...
<include>**/tests/draft2019-09/additionalItems.json</include>
-->
<include>**/tests/draft2020-12/additionalProperties.json</include>
<include>**/tests/draft2020-12/boolean_schema.json</include>
<include>**/tests/draft2020-12/enum.json</include>
<include>**/tests/draft2020-12/exclusiveMaximum.json</include>
<include>**/tests/draft2020-12/exclusiveMinimum.json</include>
<include>**/tests/draft2020-12/format.json</include>
<!-- how to validate?
<include>**/tests/draft2020-12/id.json</include>
-->
<!-- more than items keyword needed :(
<include>**/tests/draft2020-12/items.json</include>
-->
<include>**/tests/draft2020-12/maxItems.json</include>
<include>**/tests/draft2020-12/maxLength.json</include>
<include>**/tests/draft2020-12/maximum.json</include>
<include>**/tests/draft2020-12/minItems.json</include>
<include>**/tests/draft2020-12/minLength.json</include>
<include>**/tests/draft2020-12/minimum.json</include>
<include>**/tests/draft2020-12/multipleOf.json</include>
<include>**/tests/draft2020-12/pattern.json</include>
<include>**/tests/draft2020-12/patternProperties.json</include>
<include>**/tests/draft2020-12/prefixItems.json</include>
<include>**/tests/draft2020-12/properties.json</include>
<!--
needs allOf, $anchor and dynamicAnchor and some other stuff :(
<include>**/tests/draft2020-12/ref.json</include>
-->
<include>**/tests/draft2020-12/required.json</include>
<include>**/tests/draft2020-12/type.json</include>
<include>**/tests/draft2020-12/uniqueItems.json</include>
</includes>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -118,61 +159,6 @@
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-jsonschema-tests</id>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.build.directory}/jsonschematests</directory>
<includes>
<!-- no longer part ...
<inculde>**/tests/draft2019-09/additionalItems.json</inculde>
-->
<inculde>**/tests/draft2020-12/additionalProperties.json</inculde>
<inculde>**/tests/draft2020-12/boolean_schema.json</inculde>
<inculde>**/tests/draft2020-12/enum.json</inculde>
<inculde>**/tests/draft2020-12/exclusiveMaximum.json</inculde>
<inculde>**/tests/draft2020-12/exclusiveMinimum.json</inculde>
<inculde>**/tests/draft2020-12/format.json</inculde>
<!-- how to validate?
<inculde>**/tests/draft2020-12/id.json</inculde>
-->
<!-- more than items keyword needed :(
<inculde>**/tests/draft2020-12/items.json</inculde>
-->
<inculde>**/tests/draft2020-12/maxItems.json</inculde>
<inculde>**/tests/draft2020-12/maxLength.json</inculde>
<inculde>**/tests/draft2020-12/maximum.json</inculde>
<inculde>**/tests/draft2020-12/minItems.json</inculde>
<inculde>**/tests/draft2020-12/minLength.json</inculde>
<inculde>**/tests/draft2020-12/minimum.json</inculde>
<inculde>**/tests/draft2020-12/multipleOf.json</inculde>
<inculde>**/tests/draft2020-12/pattern.json</inculde>
<inculde>**/tests/draft2020-12/patternProperties.json</inculde>
<inculde>**/tests/draft2020-12/prefixItems.json</inculde>
<inculde>**/tests/draft2020-12/properties.json</inculde>
<!--
needs allOf, $anchor and dynamicAnchor and some other stuff :(
<inculde>**/tests/draft2020-12/ref.json</inculde>
-->
<inculde>**/tests/draft2020-12/required.json</inculde>
<inculde>**/tests/draft2020-12/type.json</inculde>
<inculde>**/tests/draft2020-12/uniqueItems.json</inculde>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class JsonTestSuiteTestCaseProvider implements ArgumentsProvider {
@Override
@SuppressWarnings("MustBeClosedChecker")
public Stream<? extends Arguments> provideArguments(final ExtensionContext context) throws Exception {
return new Resources()
return new Resources("tests")
.all()
.filter(resource -> resource.hasExtension("json"))
.map(JsonSchemaTestSuites::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@
*/
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;
import java.nio.file.Paths;
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;

final class Resources {

private final String baseDir;

public Resources() {
this(".");
}

public Resources(final String baseDir) {
this.baseDir = baseDir;
}
Expand Down Expand Up @@ -75,40 +70,34 @@ Stream<Resource> 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")
Stream<Resource> toResources() {
final Stream<Resource> 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);
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@
<defaultGoal>install</defaultGoal>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useModulePath>false</useModulePath>
</configuration>
</plugin>

<plugin>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
Expand Down
1 change: 1 addition & 0 deletions vocabulary-spi/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
37 changes: 37 additions & 0 deletions vocabulary-spi/src/test/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 0a6bc3a

Please sign in to comment.