forked from loafle/openapi-generator-original
* feat: OpenApi-generation from within eclipse (#509) * Added life-cycle-mapping for recognition by M2E * Make BuildContext injectable by M2E in oder to detect if json-source has been modified and a regeneration is required. * core: fix indentation problems, remove commented code
This commit is contained in:
parent
293d29ab3b
commit
eb5a8cc752
@ -15,6 +15,11 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.sonatype.plexus</groupId>
|
||||||
|
<artifactId>plexus-build-api</artifactId>
|
||||||
|
<version>0.0.7</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-core</artifactId>
|
<artifactId>maven-core</artifactId>
|
||||||
|
@ -42,6 +42,7 @@ import org.apache.maven.plugin.MojoExecutionException;
|
|||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
|
import org.apache.maven.plugins.annotations.Component;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
import org.openapitools.codegen.CliOption;
|
import org.openapitools.codegen.CliOption;
|
||||||
@ -50,6 +51,8 @@ import org.openapitools.codegen.CodegenConfig;
|
|||||||
import org.openapitools.codegen.CodegenConstants;
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
import org.openapitools.codegen.DefaultGenerator;
|
import org.openapitools.codegen.DefaultGenerator;
|
||||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||||
|
import org.sonatype.plexus.build.incremental.BuildContext;
|
||||||
|
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -61,6 +64,13 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(CodeGenMojo.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(CodeGenMojo.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The build context is only avail when running from within eclipse.
|
||||||
|
* It is used to update the eclipse-m2e-layer when the plugin is executed inside the IDE.
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
private BuildContext buildContext = new DefaultBuildContext();
|
||||||
|
|
||||||
@Parameter(name="validateSpec", required = false, defaultValue = "true")
|
@Parameter(name="validateSpec", required = false, defaultValue = "true")
|
||||||
private Boolean validateSpec;
|
private Boolean validateSpec;
|
||||||
|
|
||||||
@ -329,274 +339,300 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
@Parameter(readonly = true, required = true, defaultValue = "${project}")
|
@Parameter(readonly = true, required = true, defaultValue = "${project}")
|
||||||
private MavenProject project;
|
private MavenProject project;
|
||||||
|
|
||||||
|
public void setBuildContext(BuildContext buildContext) {
|
||||||
|
this.buildContext = buildContext;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws MojoExecutionException {
|
public void execute() throws MojoExecutionException {
|
||||||
|
File inputSpecFile = new File(inputSpec);
|
||||||
|
addCompileSourceRootIfConfigured();
|
||||||
|
|
||||||
if (skip) {
|
|
||||||
getLog().info("Code generation is skipped.");
|
|
||||||
// Even when no new sources are generated, the existing ones should
|
|
||||||
// still be compiled if needed.
|
|
||||||
addCompileSourceRootIfConfigured();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// attempt to read from config file
|
|
||||||
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configurationFile);
|
|
||||||
|
|
||||||
// if a config file wasn't specified or we were unable to read it
|
|
||||||
if (configurator == null) {
|
|
||||||
configurator = new CodegenConfigurator();
|
|
||||||
}
|
|
||||||
|
|
||||||
configurator.setVerbose(verbose);
|
|
||||||
|
|
||||||
// now override with any specified parameters
|
|
||||||
if (validateSpec != null) {
|
|
||||||
configurator.setValidateSpec(validateSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skipOverwrite != null) {
|
|
||||||
configurator.setSkipOverwrite(skipOverwrite);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeOperationIdPrefix != null) {
|
|
||||||
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(inputSpec)) {
|
|
||||||
configurator.setInputSpec(inputSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(gitUserId)) {
|
|
||||||
configurator.setGitUserId(gitUserId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(gitRepoId)) {
|
|
||||||
configurator.setGitRepoId(gitRepoId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(ignoreFileOverride)) {
|
|
||||||
configurator.setIgnoreFileOverride(ignoreFileOverride);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: After 3.0.0 release (maybe for 3.1.0): Fully deprecate lang.
|
|
||||||
if (isNotEmpty(generatorName)) {
|
|
||||||
configurator.setGeneratorName(generatorName);
|
|
||||||
|
|
||||||
// check if generatorName & language are set together, inform user this needs to be updated to prevent future issues.
|
|
||||||
if (isNotEmpty(language)) {
|
|
||||||
LOGGER.warn("The 'language' option is deprecated and was replaced by 'generatorName'. Both can not be set together");
|
|
||||||
throw new MojoExecutionException("Illegal configuration: 'language' and 'generatorName' can not be set both, remove 'language' from your configuration");
|
|
||||||
}
|
|
||||||
} else if (isNotEmpty(language)) {
|
|
||||||
LOGGER.warn("The 'language' option is deprecated and may reference language names only in the next major release (4.0). Please use 'generatorName' instead.");
|
|
||||||
configurator.setGeneratorName(language);
|
|
||||||
} else {
|
|
||||||
LOGGER.error("A generator name (generatorName) is required.");
|
|
||||||
throw new MojoExecutionException("The generator requires 'generatorName'. Refer to documentation for a list of options.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
configurator.setOutputDir(output.getAbsolutePath());
|
|
||||||
|
|
||||||
if (isNotEmpty(auth)) {
|
|
||||||
configurator.setAuth(auth);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(apiPackage)) {
|
|
||||||
configurator.setApiPackage(apiPackage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(modelPackage)) {
|
|
||||||
configurator.setModelPackage(modelPackage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(invokerPackage)) {
|
|
||||||
configurator.setInvokerPackage(invokerPackage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(groupId)) {
|
|
||||||
configurator.setGroupId(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(artifactId)) {
|
|
||||||
configurator.setArtifactId(artifactId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(artifactVersion)) {
|
|
||||||
configurator.setArtifactVersion(artifactVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(library)) {
|
|
||||||
configurator.setLibrary(library);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(modelNamePrefix)) {
|
|
||||||
configurator.setModelNamePrefix(modelNamePrefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(modelNameSuffix)) {
|
|
||||||
configurator.setModelNameSuffix(modelNameSuffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null != templateDirectory) {
|
|
||||||
configurator.setTemplateDir(templateDirectory.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set generation options
|
|
||||||
if (null != generateApis && generateApis) {
|
|
||||||
System.setProperty(CodegenConstants.APIS, "");
|
|
||||||
} else {
|
|
||||||
System.clearProperty(CodegenConstants.APIS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null != generateModels && generateModels) {
|
|
||||||
System.setProperty(CodegenConstants.MODELS, modelsToGenerate);
|
|
||||||
} else {
|
|
||||||
System.clearProperty(CodegenConstants.MODELS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null != generateSupportingFiles && generateSupportingFiles) {
|
|
||||||
System.setProperty(CodegenConstants.SUPPORTING_FILES, supportingFilesToGenerate);
|
|
||||||
} else {
|
|
||||||
System.clearProperty(CodegenConstants.SUPPORTING_FILES);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.toString());
|
|
||||||
System.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.toString());
|
|
||||||
System.setProperty(CodegenConstants.API_TESTS, generateApiTests.toString());
|
|
||||||
System.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.toString());
|
|
||||||
System.setProperty(CodegenConstants.WITH_XML, withXml.toString());
|
|
||||||
|
|
||||||
if (configOptions != null) {
|
|
||||||
// Retained for backwards-compataibility with configOptions -> instantiation-types
|
|
||||||
if (instantiationTypes == null && configOptions.containsKey("instantiation-types")) {
|
|
||||||
applyInstantiationTypesKvp(configOptions.get("instantiation-types").toString(),
|
|
||||||
configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retained for backwards-compataibility with configOptions -> import-mappings
|
|
||||||
if (importMappings == null && configOptions.containsKey("import-mappings")) {
|
|
||||||
applyImportMappingsKvp(configOptions.get("import-mappings").toString(),
|
|
||||||
configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retained for backwards-compataibility with configOptions -> type-mappings
|
|
||||||
if (typeMappings == null && configOptions.containsKey("type-mappings")) {
|
|
||||||
applyTypeMappingsKvp(configOptions.get("type-mappings").toString(), configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retained for backwards-compataibility with configOptions -> language-specific-primitives
|
|
||||||
if (languageSpecificPrimitives == null && configOptions.containsKey("language-specific-primitives")) {
|
|
||||||
applyLanguageSpecificPrimitivesCsv(configOptions
|
|
||||||
.get("language-specific-primitives").toString(), configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retained for backwards-compataibility with configOptions -> additional-properties
|
|
||||||
if (additionalProperties == null && configOptions.containsKey("additional-properties")) {
|
|
||||||
applyAdditionalPropertiesKvp(configOptions.get("additional-properties").toString(),
|
|
||||||
configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retained for backwards-compataibility with configOptions -> reserved-words-mappings
|
|
||||||
if (reservedWordsMappings == null && configOptions.containsKey("reserved-words-mappings")) {
|
|
||||||
applyReservedWordsMappingsKvp(configOptions.get("reserved-words-mappings")
|
|
||||||
.toString(), configurator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Apply Instantiation Types
|
|
||||||
if (instantiationTypes != null && (configOptions == null || !configOptions.containsKey("instantiation-types"))) {
|
|
||||||
applyInstantiationTypesKvpList(instantiationTypes, configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Apply Import Mappings
|
|
||||||
if (importMappings != null && (configOptions == null || !configOptions.containsKey("import-mappings"))) {
|
|
||||||
applyImportMappingsKvpList(importMappings, configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Apply Type Mappings
|
|
||||||
if (typeMappings != null && (configOptions == null || !configOptions.containsKey("type-mappings"))) {
|
|
||||||
applyTypeMappingsKvpList(typeMappings, configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Apply Language Specific Primitives
|
|
||||||
if (languageSpecificPrimitives != null && (configOptions == null || !configOptions.containsKey("language-specific-primitives"))) {
|
|
||||||
applyLanguageSpecificPrimitivesCsvList(languageSpecificPrimitives, configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Apply Additional Properties
|
|
||||||
if (additionalProperties != null && (configOptions == null || !configOptions.containsKey("additional-properties"))) {
|
|
||||||
applyAdditionalPropertiesKvpList(additionalProperties, configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Apply Reserved Words Mappings
|
|
||||||
if (reservedWordsMappings != null && (configOptions == null || !configOptions.containsKey("reserved-words-mappings"))) {
|
|
||||||
applyReservedWordsMappingsKvpList(reservedWordsMappings, configurator);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (environmentVariables != null) {
|
|
||||||
|
|
||||||
for (String key : environmentVariables.keySet()) {
|
|
||||||
originalEnvironmentVariables.put(key, System.getProperty(key));
|
|
||||||
String value = environmentVariables.get(key);
|
|
||||||
if (value == null) {
|
|
||||||
// don't put null values
|
|
||||||
value = "";
|
|
||||||
}
|
|
||||||
System.setProperty(key, value);
|
|
||||||
configurator.addSystemProperty(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final ClientOptInput input = configurator.toClientOptInput();
|
|
||||||
final CodegenConfig config = input.getConfig();
|
|
||||||
|
|
||||||
if (configOptions != null) {
|
|
||||||
for (CliOption langCliOption : config.cliOptions()) {
|
|
||||||
if (configOptions.containsKey(langCliOption.getOpt())) {
|
|
||||||
input.getConfig().additionalProperties()
|
|
||||||
.put(langCliOption.getOpt(), configOptions.get(langCliOption.getOpt()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (configHelp) {
|
|
||||||
for (CliOption langCliOption : config.cliOptions()) {
|
|
||||||
System.out.println("\t" + langCliOption.getOpt());
|
|
||||||
System.out.println("\t "
|
|
||||||
+ langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
adjustAdditionalProperties(config);
|
|
||||||
try {
|
try {
|
||||||
|
if (skip) {
|
||||||
|
getLog().info("Code generation is skipped.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buildContext != null) {
|
||||||
|
if (buildContext.isIncremental()) {
|
||||||
|
if (inputSpec != null) {
|
||||||
|
if (inputSpecFile.exists()) {
|
||||||
|
if (!buildContext.hasDelta(inputSpecFile)) {
|
||||||
|
getLog().info(
|
||||||
|
"Code generation is skipped in delta-build because source-json was not modified.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// attempt to read from config file
|
||||||
|
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configurationFile);
|
||||||
|
|
||||||
|
// if a config file wasn't specified or we were unable to read it
|
||||||
|
if (configurator == null) {
|
||||||
|
configurator = new CodegenConfigurator();
|
||||||
|
}
|
||||||
|
|
||||||
|
configurator.setVerbose(verbose);
|
||||||
|
|
||||||
|
// now override with any specified parameters
|
||||||
|
if (validateSpec != null) {
|
||||||
|
configurator.setValidateSpec(validateSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skipOverwrite != null) {
|
||||||
|
configurator.setSkipOverwrite(skipOverwrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removeOperationIdPrefix != null) {
|
||||||
|
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(inputSpec)) {
|
||||||
|
configurator.setInputSpec(inputSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(gitUserId)) {
|
||||||
|
configurator.setGitUserId(gitUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(gitRepoId)) {
|
||||||
|
configurator.setGitRepoId(gitRepoId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(ignoreFileOverride)) {
|
||||||
|
configurator.setIgnoreFileOverride(ignoreFileOverride);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: After 3.0.0 release (maybe for 3.1.0): Fully deprecate lang.
|
||||||
|
if (isNotEmpty(generatorName)) {
|
||||||
|
configurator.setGeneratorName(generatorName);
|
||||||
|
|
||||||
|
// check if generatorName & language are set together, inform user this needs to be updated to prevent future issues.
|
||||||
|
if (isNotEmpty(language)) {
|
||||||
|
LOGGER.warn("The 'language' option is deprecated and was replaced by 'generatorName'. Both can not be set together");
|
||||||
|
throw new MojoExecutionException(
|
||||||
|
"Illegal configuration: 'language' and 'generatorName' can not be set both, remove 'language' from your configuration");
|
||||||
|
}
|
||||||
|
} else if (isNotEmpty(language)) {
|
||||||
|
LOGGER.warn(
|
||||||
|
"The 'language' option is deprecated and may reference language names only in the next major release (4.0). Please use 'generatorName' instead.");
|
||||||
|
configurator.setGeneratorName(language);
|
||||||
|
} else {
|
||||||
|
LOGGER.error("A generator name (generatorName) is required.");
|
||||||
|
throw new MojoExecutionException("The generator requires 'generatorName'. Refer to documentation for a list of options.");
|
||||||
|
}
|
||||||
|
|
||||||
|
configurator.setOutputDir(output.getAbsolutePath());
|
||||||
|
|
||||||
|
if (isNotEmpty(auth)) {
|
||||||
|
configurator.setAuth(auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(apiPackage)) {
|
||||||
|
configurator.setApiPackage(apiPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(modelPackage)) {
|
||||||
|
configurator.setModelPackage(modelPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(invokerPackage)) {
|
||||||
|
configurator.setInvokerPackage(invokerPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(groupId)) {
|
||||||
|
configurator.setGroupId(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(artifactId)) {
|
||||||
|
configurator.setArtifactId(artifactId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(artifactVersion)) {
|
||||||
|
configurator.setArtifactVersion(artifactVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(library)) {
|
||||||
|
configurator.setLibrary(library);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(modelNamePrefix)) {
|
||||||
|
configurator.setModelNamePrefix(modelNamePrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmpty(modelNameSuffix)) {
|
||||||
|
configurator.setModelNameSuffix(modelNameSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != templateDirectory) {
|
||||||
|
configurator.setTemplateDir(templateDirectory.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set generation options
|
||||||
|
if (null != generateApis && generateApis) {
|
||||||
|
System.setProperty(CodegenConstants.APIS, "");
|
||||||
|
} else {
|
||||||
|
System.clearProperty(CodegenConstants.APIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != generateModels && generateModels) {
|
||||||
|
System.setProperty(CodegenConstants.MODELS, modelsToGenerate);
|
||||||
|
} else {
|
||||||
|
System.clearProperty(CodegenConstants.MODELS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != generateSupportingFiles && generateSupportingFiles) {
|
||||||
|
System.setProperty(CodegenConstants.SUPPORTING_FILES, supportingFilesToGenerate);
|
||||||
|
} else {
|
||||||
|
System.clearProperty(CodegenConstants.SUPPORTING_FILES);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.toString());
|
||||||
|
System.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.toString());
|
||||||
|
System.setProperty(CodegenConstants.API_TESTS, generateApiTests.toString());
|
||||||
|
System.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.toString());
|
||||||
|
System.setProperty(CodegenConstants.WITH_XML, withXml.toString());
|
||||||
|
|
||||||
|
if (configOptions != null) {
|
||||||
|
// Retained for backwards-compataibility with configOptions -> instantiation-types
|
||||||
|
if (instantiationTypes == null && configOptions.containsKey("instantiation-types")) {
|
||||||
|
applyInstantiationTypesKvp(configOptions.get("instantiation-types").toString(),
|
||||||
|
configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retained for backwards-compataibility with configOptions -> import-mappings
|
||||||
|
if (importMappings == null && configOptions.containsKey("import-mappings")) {
|
||||||
|
applyImportMappingsKvp(configOptions.get("import-mappings").toString(),
|
||||||
|
configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retained for backwards-compataibility with configOptions -> type-mappings
|
||||||
|
if (typeMappings == null && configOptions.containsKey("type-mappings")) {
|
||||||
|
applyTypeMappingsKvp(configOptions.get("type-mappings").toString(), configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retained for backwards-compataibility with configOptions -> language-specific-primitives
|
||||||
|
if (languageSpecificPrimitives == null && configOptions.containsKey("language-specific-primitives")) {
|
||||||
|
applyLanguageSpecificPrimitivesCsv(configOptions
|
||||||
|
.get("language-specific-primitives").toString(), configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retained for backwards-compataibility with configOptions -> additional-properties
|
||||||
|
if (additionalProperties == null && configOptions.containsKey("additional-properties")) {
|
||||||
|
applyAdditionalPropertiesKvp(configOptions.get("additional-properties").toString(),
|
||||||
|
configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retained for backwards-compataibility with configOptions -> reserved-words-mappings
|
||||||
|
if (reservedWordsMappings == null && configOptions.containsKey("reserved-words-mappings")) {
|
||||||
|
applyReservedWordsMappingsKvp(configOptions.get("reserved-words-mappings")
|
||||||
|
.toString(), configurator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Instantiation Types
|
||||||
|
if (instantiationTypes != null && (configOptions == null || !configOptions.containsKey("instantiation-types"))) {
|
||||||
|
applyInstantiationTypesKvpList(instantiationTypes, configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Import Mappings
|
||||||
|
if (importMappings != null && (configOptions == null || !configOptions.containsKey("import-mappings"))) {
|
||||||
|
applyImportMappingsKvpList(importMappings, configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Type Mappings
|
||||||
|
if (typeMappings != null && (configOptions == null || !configOptions.containsKey("type-mappings"))) {
|
||||||
|
applyTypeMappingsKvpList(typeMappings, configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Language Specific Primitives
|
||||||
|
if (languageSpecificPrimitives != null
|
||||||
|
&& (configOptions == null || !configOptions.containsKey("language-specific-primitives"))) {
|
||||||
|
applyLanguageSpecificPrimitivesCsvList(languageSpecificPrimitives, configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Additional Properties
|
||||||
|
if (additionalProperties != null && (configOptions == null || !configOptions.containsKey("additional-properties"))) {
|
||||||
|
applyAdditionalPropertiesKvpList(additionalProperties, configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Reserved Words Mappings
|
||||||
|
if (reservedWordsMappings != null && (configOptions == null || !configOptions.containsKey("reserved-words-mappings"))) {
|
||||||
|
applyReservedWordsMappingsKvpList(reservedWordsMappings, configurator);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (environmentVariables != null) {
|
||||||
|
|
||||||
|
for (String key : environmentVariables.keySet()) {
|
||||||
|
originalEnvironmentVariables.put(key, System.getProperty(key));
|
||||||
|
String value = environmentVariables.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
// don't put null values
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
System.setProperty(key, value);
|
||||||
|
configurator.addSystemProperty(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final ClientOptInput input = configurator.toClientOptInput();
|
||||||
|
final CodegenConfig config = input.getConfig();
|
||||||
|
|
||||||
|
if (configOptions != null) {
|
||||||
|
for (CliOption langCliOption : config.cliOptions()) {
|
||||||
|
if (configOptions.containsKey(langCliOption.getOpt())) {
|
||||||
|
input.getConfig().additionalProperties()
|
||||||
|
.put(langCliOption.getOpt(), configOptions.get(langCliOption.getOpt()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configHelp) {
|
||||||
|
for (CliOption langCliOption : config.cliOptions()) {
|
||||||
|
System.out.println("\t" + langCliOption.getOpt());
|
||||||
|
System.out.println("\t "
|
||||||
|
+ langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
adjustAdditionalProperties(config);
|
||||||
new DefaultGenerator().opts(input).generate();
|
new DefaultGenerator().opts(input).generate();
|
||||||
|
|
||||||
|
if (buildContext != null) {
|
||||||
|
buildContext.refresh(new File(getCompileSourceRoot()));
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Maven logs exceptions thrown by plugins only if invoked with -e
|
// Maven logs exceptions thrown by plugins only if invoked with -e
|
||||||
// I find it annoying to jump through hoops to get basic diagnostic information,
|
// I find it annoying to jump through hoops to get basic diagnostic information,
|
||||||
// so let's log it in any case:
|
// so let's log it in any case:
|
||||||
|
if (buildContext != null) {
|
||||||
|
buildContext.addError(inputSpecFile, 0, 0, "unexpected error in Open-API generation", e);
|
||||||
|
}
|
||||||
getLog().error(e);
|
getLog().error(e);
|
||||||
throw new MojoExecutionException(
|
throw new MojoExecutionException(
|
||||||
"Code generation failed. See above for the full exception.");
|
"Code generation failed. See above for the full exception.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCompileSourceRoot() {
|
||||||
|
final Object sourceFolderObject =
|
||||||
|
configOptions == null ? null : configOptions
|
||||||
|
.get(CodegenConstants.SOURCE_FOLDER);
|
||||||
|
final String sourceFolder =
|
||||||
|
sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();
|
||||||
|
|
||||||
addCompileSourceRootIfConfigured();
|
String sourceJavaFolder = output.toString() + "/" + sourceFolder;
|
||||||
|
return sourceJavaFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCompileSourceRootIfConfigured() {
|
private void addCompileSourceRootIfConfigured() {
|
||||||
if (addCompileSourceRoot) {
|
if (addCompileSourceRoot) {
|
||||||
final Object sourceFolderObject =
|
project.addCompileSourceRoot(getCompileSourceRoot());
|
||||||
configOptions == null ? null : configOptions
|
|
||||||
.get(CodegenConstants.SOURCE_FOLDER);
|
|
||||||
final String sourceFolder =
|
|
||||||
sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();
|
|
||||||
|
|
||||||
String sourceJavaFolder = output.toString() + "/" + sourceFolder;
|
|
||||||
project.addCompileSourceRoot(sourceJavaFolder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset all environment variables to their original value. This prevents unexpected
|
// Reset all environment variables to their original value. This prevents unexpected
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
<lifecycleMappingMetadata>
|
||||||
|
<pluginExecutions>
|
||||||
|
<pluginExecution>
|
||||||
|
<pluginExecutionFilter>
|
||||||
|
<goals>
|
||||||
|
<goal>generate</goal>
|
||||||
|
</goals>
|
||||||
|
</pluginExecutionFilter>
|
||||||
|
<action>
|
||||||
|
<execute>
|
||||||
|
<runOnIncremental>true</runOnIncremental>
|
||||||
|
<runOnConfiguration>true</runOnConfiguration>
|
||||||
|
</execute>
|
||||||
|
</action>
|
||||||
|
</pluginExecution>
|
||||||
|
</pluginExecutions>
|
||||||
|
</lifecycleMappingMetadata>
|
Loading…
x
Reference in New Issue
Block a user