Skip to content

Commit

Permalink
feat: support custom module loaded from test classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenWickner committed Oct 25, 2023
1 parent 8201898 commit 9eaf911
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- avoid rounding error when taking over the value from `@Schema(multipleOf)`

### `jsonschema-naven-plugin`
### Added
- support custom configuration `Module` being loaded from test classpath elements

### Changed
- a generated schema is now serialized through the configuration's `ObjectMapper` instance (e.g., granting control over pretty printing or even generating YAML instead of JSON files)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public enum ClasspathType {
/**
* Classes from the project, compile time and runtime dependencies.
*/
WITH_ALL_DEPENDENCIES;
WITH_ALL_DEPENDENCIES,
/**
* Classes from the project (including tests), compile time, runtime and test dependencies.
* Mainly intended for internal use when looking up custom modules.
*/
WITH_ALL_DEPENDENCIES_AND_TESTS;

public Collection<String> getClasspathElements(MavenProject project) {
Collection<String> classpathElements;
Expand All @@ -64,6 +69,13 @@ public Collection<String> getClasspathElements(MavenProject project) {
classpathElements.addAll(project.getRuntimeClasspathElements());
classpathElements.addAll(project.getCompileClasspathElements());
break;
case WITH_ALL_DEPENDENCIES_AND_TESTS:
// to remove duplicates
classpathElements = new HashSet<>();
classpathElements.addAll(project.getRuntimeClasspathElements());
classpathElements.addAll(project.getCompileClasspathElements());
classpathElements.addAll(project.getTestClasspathElements());
break;
default:
throw new IllegalArgumentException("ClasspathType " + this + " not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ private URLClassLoader getClassLoader() {
if (this.classLoader == null) {
// fix the classpath such that the classloader can get classes from any possible dependency
// this does not affect filtering, as the classgraph library uses its own classloader and allows for caching
List<URL> urls = ClasspathType.WITH_ALL_DEPENDENCIES.getUrls(this.project);
List<URL> urls = ClasspathType.WITH_ALL_DEPENDENCIES_AND_TESTS.getUrls(this.project);
this.classLoader = new URLClassLoader(urls.toArray(new URL[0]),
Thread.currentThread().getContextClassLoader());
}
Expand Down

0 comments on commit 9eaf911

Please sign in to comment.