forked from loafle/openapi-generator-original
[maven] mark Mojo threadSafe=true + fix concurrency issue in Co… (#5898)
This commit is contained in:
parent
c5472be422
commit
84099eefdc
@ -70,7 +70,7 @@ import com.google.common.io.Files;
|
||||
* Goal which generates client/server code from a OpenAPI json/yaml definition.
|
||||
*/
|
||||
@SuppressWarnings({"unused", "MismatchedQueryAndUpdateOfCollection"})
|
||||
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
|
||||
public class CodeGenMojo extends AbstractMojo {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CodeGenMojo.class);
|
||||
|
@ -79,22 +79,8 @@ public class CodegenConfigurator {
|
||||
public static CodegenConfigurator fromFile(String configFile, Module... modules) {
|
||||
|
||||
if (isNotEmpty(configFile)) {
|
||||
ObjectMapper mapper;
|
||||
DynamicSettings settings = readDynamicSettings(configFile, modules);
|
||||
|
||||
if (FilenameUtils.isExtension(configFile, new String[]{"yml", "yaml"})) {
|
||||
mapper = Yaml.mapper();
|
||||
} else {
|
||||
mapper = Json.mapper();
|
||||
}
|
||||
|
||||
if (modules != null && modules.length > 0) {
|
||||
mapper.registerModules(modules);
|
||||
}
|
||||
|
||||
mapper.registerModule(new GuavaModule());
|
||||
|
||||
try {
|
||||
DynamicSettings settings = mapper.readValue(new File(configFile), DynamicSettings.class);
|
||||
CodegenConfigurator configurator = new CodegenConfigurator();
|
||||
|
||||
GeneratorSettings generatorSettings = settings.getGeneratorSettings();
|
||||
@ -134,13 +120,32 @@ public class CodegenConfigurator {
|
||||
configurator.workflowSettingsBuilder = WorkflowSettings.newBuilder(workflowSettings);
|
||||
|
||||
return configurator;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static DynamicSettings readDynamicSettings(String configFile, Module... modules) {
|
||||
ObjectMapper mapper;
|
||||
|
||||
if (FilenameUtils.isExtension(configFile.toLowerCase(Locale.ROOT), new String[]{"yml", "yaml"})) {
|
||||
mapper = Yaml.mapper().copy();
|
||||
} else {
|
||||
mapper = Json.mapper().copy();
|
||||
}
|
||||
|
||||
if (modules != null && modules.length > 0) {
|
||||
mapper.registerModules(modules);
|
||||
}
|
||||
|
||||
mapper.registerModule(new GuavaModule());
|
||||
|
||||
try {
|
||||
return mapper.readValue(new File(configFile), DynamicSettings.class);
|
||||
} catch (IOException ex) {
|
||||
LOGGER.error(ex.getMessage());
|
||||
throw new RuntimeException("Unable to deserialize config file: " + configFile);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CodegenConfigurator addServerVariable(String key, String value) {
|
||||
this.serverVariables.put(key, value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user