forked from loafle/openapi-generator-original
Fix environment variable support in successive Maven plugin executions (#5351)
* Fix environment variable support in successive Maven plugin executions System properties were retained across multiple successive executions, resulting in unpredictable behavior. Property values are now properly reset to their original value after plugin execution. Fixes #5350 * Add explanation to environment variable reset mechanism in Maven plugin
This commit is contained in:
parent
2e46bb9b9f
commit
fea8699d8b
@ -381,9 +381,12 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, String> originalEnvironmentVariables = new HashMap<>();
|
||||||
|
|
||||||
if (environmentVariables != null) {
|
if (environmentVariables != null) {
|
||||||
|
|
||||||
for(String key : environmentVariables.keySet()) {
|
for(String key : environmentVariables.keySet()) {
|
||||||
|
originalEnvironmentVariables.put(key, System.getProperty(key));
|
||||||
String value = environmentVariables.get(key);
|
String value = environmentVariables.get(key);
|
||||||
if(value == null) {
|
if(value == null) {
|
||||||
// don't put null values
|
// don't put null values
|
||||||
@ -431,5 +434,15 @@ public class CodeGenMojo extends AbstractMojo {
|
|||||||
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
|
||||||
|
// when running the plugin multiple consecutive times with different configurations.
|
||||||
|
for(Map.Entry<String, String> entry : originalEnvironmentVariables.entrySet()) {
|
||||||
|
if(entry.getValue() == null) {
|
||||||
|
System.clearProperty(entry.getKey());
|
||||||
|
} else {
|
||||||
|
System.setProperty(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user