Skip to content

Commit

Permalink
fix: Enable usage of maven plugin with jdk11 (#223)
Browse files Browse the repository at this point in the history
* fix: Enable usage of maven plugin with jdk11
* chore(docs): Add draft 2020-12 to documentation where missing
  • Loading branch information
CarstenWickner committed Jan 10, 2022
1 parent b8e55ac commit 4cda027
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### Dependency Update
- Replace `log4j` test dependency with `logback` (still only test dependency)

### `jsonschema-maven-plugin`
#### Fixed
- Enable usage under JDK11 (by adjusting usage of `reflections`, in order to allow finding classes in dependencies/jar)

#### Dependency Update
- Update `reflections` runtime dependency from 0.9.12 to 0.10.2

## [4.21.0] - 2021-12-03
### `jsonschema-generator`
#### Fixed
Expand Down
1 change: 1 addition & 0 deletions jsonschema-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ The version of JSON Schema that is to be used can be configured with the `<schem
</configuration>
```
Allowed values are (as per `com.github.victools.jsonschema.generator.SchemaVersion`):
- `DRAFT_2020_12`
- `DRAFT_2019_09`
- `DRAFT_7`
- `DRAFT_6`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.Scanner;
import org.reflections.scanners.Scanners;
import org.reflections.util.ConfigurationBuilder;

/**
* Maven plugin for the victools/jsonschema-generator.
Expand Down Expand Up @@ -108,7 +110,7 @@ public class SchemaGeneratorMojo extends AbstractMojo {
private String schemaFileName;

/**
* The schema version to be used: DRAFT_6, DRAFT_7 or DRAFT_2019_09.
* The schema version to be used: DRAFT_6, DRAFT_7, DRAFT_2019_09 or DRAFT_2020_12.
*/
@Parameter(property = "schemaVersion", defaultValue = "DRAFT_7")
private SchemaVersion schemaVersion;
Expand Down Expand Up @@ -139,7 +141,7 @@ public class SchemaGeneratorMojo extends AbstractMojo {
/**
* The classloader used for loading generator modules and classes.
*/
private ClassLoader classLoader = null;
private URLClassLoader classLoader = null;

/**
* The list of all the classes on the classpath.
Expand Down Expand Up @@ -225,8 +227,17 @@ private void generateSchema(Class<?> schemaClass) throws MojoExecutionException
*/
private List<PotentialSchemaClass> getAllClassNames() {
if (this.allTypes == null) {
Reflections reflections = new Reflections("", new SubTypesScanner(false), this.getClassLoader());
Stream<PotentialSchemaClass> allTypesStream = reflections.getAllTypes().stream()
Scanner subTypeScanner = Scanners.SubTypes.filterResultsBy(c -> true);
URLClassLoader urlClassLoader = this.getClassLoader();
ConfigurationBuilder configBuilder = new ConfigurationBuilder()
.forPackage("", urlClassLoader)
.addScanners(subTypeScanner);
if (urlClassLoader != null) {
configBuilder.addUrls(urlClassLoader.getURLs());
}
Reflections reflections = new Reflections(configBuilder);
Stream<PotentialSchemaClass> allTypesStream = reflections.getAll(subTypeScanner)
.stream()
.map(PotentialSchemaClass::new);
if (this.excludeClassNames != null && this.excludeClassNames.length > 0) {
Set<Pattern> exclusions = Stream.of(this.excludeClassNames)
Expand Down Expand Up @@ -411,7 +422,7 @@ private void setModules(SchemaGeneratorConfigBuilder configBuilder) throws MojoE
*
* @return The classloader
*/
private ClassLoader getClassLoader() {
private URLClassLoader getClassLoader() {
if (this.classLoader == null) {
List<String> runtimeClasspathElements = null;
try {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<version.junitparams>1.1.1</version.junitparams>
<version.logback>1.2.7</version.logback>
<version.mockito>2.27.0</version.mockito>
<version.reflections>0.9.12</version.reflections>
<version.reflections>0.10.2</version.reflections>
<version.slf4j>1.7.32</version.slf4j>
<version.swagger-1.5>1.5.22</version.swagger-1.5>
<version.swagger-2>2.1.2</version.swagger-2>
Expand Down
2 changes: 1 addition & 1 deletion slate-docs/source/includes/_main-generator.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The [victools:jsonschema-generator](https://github.com/victools/jsonschema-generator/tree/master/jsonschema-generator) aims at allowing the generation of JSON Schema (Draft 6, Draft 7 or Draft 2019-09) to document Java code.
The [victools:jsonschema-generator](https://github.com/victools/jsonschema-generator/tree/master/jsonschema-generator) aims at allowing the generation of JSON Schema (Draft 6, Draft 7, Draft 2019-09 or Draft 2020-12) to document Java code.
This is expressly not limited to _JSON_ but also allows for a Java API to be documented (i.e. including methods and the associated return values).

# Generator – Options
Expand Down
2 changes: 1 addition & 1 deletion slate-docs/source/includes/_maven-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ There are some additional parameters available in the plugin `<configuration>`:
| --- | --- | --- | --- |
| 1 | `<schemaFilePath>` | `src/main/resources` | Directory to generate all schemas in |
| 2 | `<schemaFileName>` | `{0}-schema.json` | Relative path from the `<schemaFilePath>` including the file name pattern. Two placeholders are supported: `{0}` will be replaced with the respective simple class name (e.g. `TypeA`) `{1}` will be replaced with the respective package path (e.g. `com/myOrg/myApp`) in case you want to preserve the original package structure |
| 3 | `<schemaVersion>` | `DRAFT_7` | JSON Schema version to apply (`DRAFT_6`, `DRAFT_7` or `DRAFT_2019_09`) |
| 3 | `<schemaVersion>` | `DRAFT_7` | JSON Schema version to apply (`DRAFT_6`, `DRAFT_7`, `DRAFT_2019_09` or `DRAFT_2020_12`) |

```xml
<options>
Expand Down

0 comments on commit 4cda027

Please sign in to comment.