-
Notifications
You must be signed in to change notification settings - Fork 25
Generate maven plugin stubs for JSON schema plugin #1320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.8.x
Are you sure you want to change the base?
Conversation
beb4ee2 to
ec5fa18
Compare
micronaut-maven-integration-tests/src/it/jsonschema-generate/invoker.properties
Outdated
Show resolved
Hide resolved
| */ | ||
| @Mojo(name = JsonSchemaGeneratorMojo.MOJO_NAME, defaultPhase = LifecyclePhase.GENERATE_SOURCES) | ||
| public class JsonSchemaGeneratorMojo extends AbstractMicronautMojo { | ||
| public class JsonSchemaGeneratorMojo extends AbstractJsonSchemaGeneratorMojo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the generated AbstractJsonSchemaGeneratorMojo won't extend from AbstractMicronautMojo, then we need to check what is in the latter that we are missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does extend from the micronaut mojo. The whole generated file is:
/**
* A configuration class for the JSON schema source generator, encapsulating the configuration
* properties related to the input and output paths, file names, and URL.
*/
public abstract class AbstractJsonSchemaGeneratorMojo extends AbstractMicronautMojo {
/**
* The common prefix for Mojo properties.
*/
protected static final String PROPERTY_PREFIX = "micronaut.jsonschema.generator";
@Parameter(
defaultValue = "${project}",
required = true,
readonly = true
)
protected MavenProject project;
/**
* Determines if this mojo must be executed. The value is true if the mojo is enabled.
*/
@Parameter(
property = "micronaut.jsonschema.generator.enabled",
defaultValue = "false"
)
protected boolean enabled;
/**
* The URL of the JSON schema file to be downloaded and processed.
*/
@Parameter(
property = "micronaut.jsonschema.generator.input.url"
)
protected String inputURL;
/**
* The JSON schema file, typically ending in {@code .schema.json}.
*/
@Parameter(
property = "micronaut.jsonschema.generator.input.file"
)
protected File inputFile;
/**
* The path to the folder where the input files (JSON schemas) are located.
* Each of the files in the directory will be used for generation.
*/
@Parameter(
property = "micronaut.jsonschema.generator.input.directory"
)
protected File inputDirectory;
/**
* The package name to be applied to the generated source files
* This field is optional and can be {@code null} if no package name is needed.
*/
@Parameter(
defaultValue = "io.micronaut.jsonschema",
property = "micronaut.jsonschema.generator.output.package.name"
)
protected String outputPackageName;
/**
* The name of the file where the generated source code will be written
* if there is a single output source..
*/
@Parameter(
property = "micronaut.jsonschema.generator.output.file.name"
)
protected String outputFileName;
/**
* The programming language to generate the output types in..
*/
@Parameter(
defaultValue = "JAVA",
property = "micronaut.jsonschema.generator.language"
)
protected Language language;
/**
* The URL patterns that are allowed.
* Used to filter or validate input resources specified by URL.
* URLs matching at least one pattern will be accepted. The default
* value is {@code "^https://.* /.*.json"}.
*/
@Parameter
protected List<String> acceptedUrlPatterns;
/**
* The path where generated source files will be saved
* The path should be a valid, writable directory path.
*/
@Parameter(
required = true
)
protected File outputDirectory;
/**
* Internal output path for Java sources.
*/
protected abstract File getJavaOutputDirectory();
/**
* Internal output path for Groovy sources.
*/
protected abstract File getGroovyOutputDirectory();
/**
* Internal output path for Kotlin sources.
*/
protected abstract File getKotlinOutputDirectory();
JsonSchemaGeneratorTask.Language convertLanguage(Language value) {
if (value == null) {
return null;
} else {
return JsonSchemaGeneratorTask.Language.valueOf(value.name());
}
}
/**
* Main execution of AbstractJsonSchemaGenerator Mojo.
*/
public void execute() throws MojoExecutionException, MojoFailureException {
if (!this.enabled) {
this.getLog().debug("AbstractJsonSchemaGeneratorMojo is disabled");
} else {
this.project.addCompileSourceRoot(this.getJavaOutputDirectory().getAbsolutePath());
this.project.addCompileSourceRoot(this.getGroovyOutputDirectory().getAbsolutePath());
this.project.addCompileSourceRoot(this.getKotlinOutputDirectory().getAbsolutePath());
try {
JsonSchemaGeneratorTask.Language languageParam = this.convertLanguage(this.language);
JsonSchemaGeneratorTask task = new io.micronaut.jsonschema.generator.plugin.JsonSchemaGeneratorTask(this.inputURL, this.inputFile, this.inputDirectory, this.outputPackageName, this.outputFileName, languageParam, this.acceptedUrlPatterns, this.outputDirectory, this.getJavaOutputDirectory(), this.getGroovyOutputDirectory(), this.getKotlinOutputDirectory());
task.generate();
} catch (IllegalArgumentException e0) {throw new org.apache.maven.plugin.MojoFailureException("Invalid configuration for AbstractJsonSchemaGenerator", e0);
} catch (Exception e1) {throw new org.apache.maven.plugin.MojoExecutionException("Failed to run AbstractJsonSchemaGenerator", e1);
}}
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you specify that? I don't see it in PluginGenerationTrigger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the micronaut parent, PluginGenerationTrigger annotation has useMicronaut with default true.
But the properties here are specified in the json schema repo: https://github.com/micronaut-projects/micronaut-json-schema/pull/165/files#diff-c72e08c7f6ac635067a1a3be17d3b69bb383008b6da3afdfd710e1b97fe5633c
9fc0ba7 to
b2592eb
Compare
|




Switch JSON schema to generate Maven mojo based on micronaut-build-plugin-sourcegen.
The generated plugin will:
This would simplify support, as additional properties would require no manual changes in the plugins. Some properties would already be added in this PR: micronaut-projects/micronaut-json-schema#163.
Current support
Currently a tmp repo is used to verify that build passes and uses this json schema PR: Generate build plugin sources for JSON schema generator micronaut-json-schema#165.
The dependency on micronaut-build-plugin-sourcegen is compile time only.
inputUrllangdefault=JAVA@alvarosanchez would appreciate your feedback