forked from loafle/openapi-generator-original
run "mvn formatter:format" on maven plug-in
This commit is contained in:
parent
1e53557570
commit
eb498e23b8
@ -3,17 +3,15 @@ package io.swagger.codegen.plugin;
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2005 The Apache Software Foundation.
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvp;
|
import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvp;
|
||||||
@ -61,8 +59,7 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
/**
|
/**
|
||||||
* Location of the output directory.
|
* Location of the output directory.
|
||||||
*/
|
*/
|
||||||
@Parameter(name = "output",
|
@Parameter(name = "output", property = "swagger.codegen.maven.plugin.output",
|
||||||
property = "swagger.codegen.maven.plugin.output",
|
|
||||||
defaultValue = "${project.build.directory}/generated-sources/swagger")
|
defaultValue = "${project.build.directory}/generated-sources/swagger")
|
||||||
private File output;
|
private File output;
|
||||||
|
|
||||||
@ -91,8 +88,8 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
private File templateDirectory;
|
private File templateDirectory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds authorization headers when fetching the swagger definitions remotely.
|
* Adds authorization headers when fetching the swagger definitions remotely. " Pass in a
|
||||||
" Pass in a URL-encoded string of name:header with a comma separating multiple values
|
* URL-encoded string of name:header with a comma separating multiple values
|
||||||
*/
|
*/
|
||||||
@Parameter(name = "auth")
|
@Parameter(name = "auth")
|
||||||
private String auth;
|
private String auth;
|
||||||
@ -251,8 +248,8 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
private Boolean skip;
|
private Boolean skip;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the output directory to the project as a source root, so that the
|
* Add the output directory to the project as a source root, so that the generated java types
|
||||||
* generated java types are compiled and included in the project artifact.
|
* are compiled and included in the project artifact.
|
||||||
*/
|
*/
|
||||||
@Parameter(defaultValue = "true")
|
@Parameter(defaultValue = "true")
|
||||||
private boolean addCompileSourceRoot = true;
|
private boolean addCompileSourceRoot = true;
|
||||||
@ -395,11 +392,13 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
if (configOptions != null) {
|
if (configOptions != null) {
|
||||||
|
|
||||||
if (configOptions.containsKey("instantiation-types")) {
|
if (configOptions.containsKey("instantiation-types")) {
|
||||||
applyInstantiationTypesKvp(configOptions.get("instantiation-types").toString(), configurator);
|
applyInstantiationTypesKvp(configOptions.get("instantiation-types").toString(),
|
||||||
|
configurator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (importMappings == null && configOptions.containsKey("import-mappings")) {
|
if (importMappings == null && configOptions.containsKey("import-mappings")) {
|
||||||
applyImportMappingsKvp(configOptions.get("import-mappings").toString(), configurator);
|
applyImportMappingsKvp(configOptions.get("import-mappings").toString(),
|
||||||
|
configurator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configOptions.containsKey("type-mappings")) {
|
if (configOptions.containsKey("type-mappings")) {
|
||||||
@ -407,21 +406,26 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (configOptions.containsKey("language-specific-primitives")) {
|
if (configOptions.containsKey("language-specific-primitives")) {
|
||||||
applyLanguageSpecificPrimitivesCsv(configOptions.get("language-specific-primitives").toString(), configurator);
|
applyLanguageSpecificPrimitivesCsv(configOptions
|
||||||
|
.get("language-specific-primitives").toString(), configurator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configOptions.containsKey("additional-properties")) {
|
if (configOptions.containsKey("additional-properties")) {
|
||||||
applyAdditionalPropertiesKvp(configOptions.get("additional-properties").toString(), configurator);
|
applyAdditionalPropertiesKvp(configOptions.get("additional-properties").toString(),
|
||||||
|
configurator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configOptions.containsKey("reserved-words-mappings")) {
|
if (configOptions.containsKey("reserved-words-mappings")) {
|
||||||
applyReservedWordsMappingsKvp(configOptions.get("reserved-words-mappings").toString(), configurator);
|
applyReservedWordsMappingsKvp(configOptions.get("reserved-words-mappings")
|
||||||
|
.toString(), configurator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (importMappings != null && !configOptions.containsKey("import-mappings")) {
|
if (importMappings != null && !configOptions.containsKey("import-mappings")) {
|
||||||
String importMappingsAsString = importMappings.toString();
|
String importMappingsAsString = importMappings.toString();
|
||||||
applyImportMappingsKvp(importMappingsAsString.substring(0, importMappingsAsString.length() - 1), configurator);
|
applyImportMappingsKvp(
|
||||||
|
importMappingsAsString.substring(0, importMappingsAsString.length() - 1),
|
||||||
|
configurator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (environmentVariables != null) {
|
if (environmentVariables != null) {
|
||||||
@ -444,8 +448,8 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
if (configOptions != null) {
|
if (configOptions != null) {
|
||||||
for (CliOption langCliOption : config.cliOptions()) {
|
for (CliOption langCliOption : config.cliOptions()) {
|
||||||
if (configOptions.containsKey(langCliOption.getOpt())) {
|
if (configOptions.containsKey(langCliOption.getOpt())) {
|
||||||
input.getConfig().additionalProperties().put(langCliOption.getOpt(),
|
input.getConfig().additionalProperties()
|
||||||
configOptions.get(langCliOption.getOpt()));
|
.put(langCliOption.getOpt(), configOptions.get(langCliOption.getOpt()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -453,7 +457,8 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
if (configHelp) {
|
if (configHelp) {
|
||||||
for (CliOption langCliOption : config.cliOptions()) {
|
for (CliOption langCliOption : config.cliOptions()) {
|
||||||
System.out.println("\t" + langCliOption.getOpt());
|
System.out.println("\t" + langCliOption.getOpt());
|
||||||
System.out.println("\t " + langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
|
System.out.println("\t "
|
||||||
|
+ langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -465,7 +470,8 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
// 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:
|
||||||
getLog().error(e);
|
getLog().error(e);
|
||||||
throw new MojoExecutionException("Code generation failed. See above for the full exception.");
|
throw new MojoExecutionException(
|
||||||
|
"Code generation failed. See above for the full exception.");
|
||||||
}
|
}
|
||||||
|
|
||||||
addCompileSourceRootIfConfigured();
|
addCompileSourceRootIfConfigured();
|
||||||
@ -473,14 +479,18 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
|
|
||||||
private void addCompileSourceRootIfConfigured() {
|
private void addCompileSourceRootIfConfigured() {
|
||||||
if (addCompileSourceRoot) {
|
if (addCompileSourceRoot) {
|
||||||
final Object sourceFolderObject = configOptions == null ? null : configOptions.get(CodegenConstants.SOURCE_FOLDER);
|
final Object sourceFolderObject =
|
||||||
final String sourceFolder = sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();
|
configOptions == null ? null : configOptions
|
||||||
|
.get(CodegenConstants.SOURCE_FOLDER);
|
||||||
|
final String sourceFolder =
|
||||||
|
sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();
|
||||||
|
|
||||||
String sourceJavaFolder = output.toString() + "/" + sourceFolder;
|
String sourceJavaFolder = output.toString() + "/" + sourceFolder;
|
||||||
project.addCompileSourceRoot(sourceJavaFolder);
|
project.addCompileSourceRoot(sourceJavaFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset all environment variables to their original value. This prevents unexpected behaviour
|
// Reset all environment variables to their original value. This prevents unexpected
|
||||||
|
// behaviour
|
||||||
// when running the plugin multiple consecutive times with different configurations.
|
// when running the plugin multiple consecutive times with different configurations.
|
||||||
for (Map.Entry<String, String> entry : originalEnvironmentVariables.entrySet()) {
|
for (Map.Entry<String, String> entry : originalEnvironmentVariables.entrySet()) {
|
||||||
if (entry.getValue() == null) {
|
if (entry.getValue() == null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user