Boolean conversion for maven plugin (#1252)

* saving the fixes.
Used commons-configuration2 for
org.apache.commons.configuration2.PropertiesConfiguration.
It makes the configuration easier to read amongst other benefits

* removing tabs

* updating and simplifying based on sugegstion from William. This should
now fix across all generators

* upgraded pom

* added some javadocs for the new method
This commit is contained in:
raghuraman1
2018-10-21 19:54:17 +05:30
committed by William Cheng
parent 33a1ac4397
commit 2b88a1d26f

View File

@@ -35,6 +35,7 @@ import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -571,6 +572,7 @@ public class CodeGenMojo extends AbstractMojo {
}
return;
}
adjustAdditionalProperties(config);
try {
new DefaultGenerator().opts(input).generate();
} catch (Exception e) {
@@ -608,4 +610,30 @@ public class CodeGenMojo extends AbstractMojo {
}
}
}
/**
* This method enables conversion of true/false strings in
* config.additionalProperties (configuration/configOptions) to proper booleans.
* This enables mustache files to handle the properties better.
*
* @param config
*/
private void adjustAdditionalProperties(final CodegenConfig config) {
Map<String, Object> configAdditionalProperties = config.additionalProperties();
Set<String> keySet = configAdditionalProperties.keySet();
for (String key : keySet) {
Object value = configAdditionalProperties.get(key);
if (value != null) {
if (value instanceof String) {
String stringValue = (String) value;
if (stringValue.equalsIgnoreCase("true")) {
configAdditionalProperties.put(key, Boolean.TRUE);
} else if (stringValue.equalsIgnoreCase("false")) {
configAdditionalProperties.put(key, Boolean.FALSE);
}
}
} else {
configAdditionalProperties.put(key, Boolean.FALSE);
}
}
}
}