summaryrefslogtreecommitdiffstats
path: root/configgen
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahoo-inc.com>2017-06-19 12:47:49 +0200
committerBjørn Christian Seime <bjorncs@yahoo-inc.com>2017-06-19 14:42:31 +0200
commitac1d2c4f7512f5372b7e4ce91a34e46f63a71a97 (patch)
treea4a70c6d751478c1b364d66859a86d0585aea598 /configgen
parent5b6faca5f132a290b875c266daf7b19082708b44 (diff)
Add constructor to create config instance from constructor parameters
Diffstat (limited to 'configgen')
-rw-r--r--configgen/src/main/java/com/yahoo/config/codegen/MakeConfigProperties.java51
1 files changed, 28 insertions, 23 deletions
diff --git a/configgen/src/main/java/com/yahoo/config/codegen/MakeConfigProperties.java b/configgen/src/main/java/com/yahoo/config/codegen/MakeConfigProperties.java
index 01163945732..6542eb2ab35 100644
--- a/configgen/src/main/java/com/yahoo/config/codegen/MakeConfigProperties.java
+++ b/configgen/src/main/java/com/yahoo/config/codegen/MakeConfigProperties.java
@@ -13,7 +13,7 @@ import java.util.StringTokenizer;
*/
public class MakeConfigProperties {
- private final List<String> legalLanguages = Arrays.asList("java", "cpp", "cppng" );
+ private static final List<String> legalLanguages = Arrays.asList("java", "cpp", "cppng" );
final File destDir;
final File[] specFiles;
@@ -23,18 +23,29 @@ public class MakeConfigProperties {
final boolean generateFrameworkCode;
MakeConfigProperties() throws PropertyException {
- destDir = checkDestinationDir();
- specFiles = checkSpecificationFiles();
- language = checkLanguage();
- dirInRoot = checkDirInRoot();
- dumpTree = System.getProperty("config.dumpTree") != null &&
- System.getProperty("config.dumpTree").equalsIgnoreCase("true");
- generateFrameworkCode = System.getProperty("config.useFramework") == null ||
- System.getProperty("config.useFramework").equalsIgnoreCase("true");
+ this(System.getProperty("config.dest"),
+ System.getProperty("config.spec"),
+ System.getProperty("config.lang"),
+ System.getProperty("config.subdir"),
+ System.getProperty("config.dumpTree"),
+ System.getProperty("config.useFramework"));
}
- private File checkDestinationDir() throws PropertyException {
- String destination = System.getProperty("config.dest");
+ public MakeConfigProperties(String destDir,
+ String specFiles,
+ String language,
+ String dirInRoot,
+ String dumpTree,
+ String generateFrameworkCode) throws PropertyException {
+ this.destDir = checkDestinationDir(destDir);
+ this.specFiles = checkSpecificationFiles(specFiles);
+ this.language = checkLanguage(language);
+ this.dirInRoot = checkDirInRoot(this.destDir, dirInRoot);
+ this.dumpTree = Boolean.parseBoolean(dumpTree);
+ this.generateFrameworkCode = Boolean.parseBoolean(generateFrameworkCode);
+ }
+
+ private static File checkDestinationDir(String destination) throws PropertyException {
if (destination == null)
throw new PropertyException("Missing property: config.dest.");
@@ -45,8 +56,7 @@ public class MakeConfigProperties {
return dir;
}
- private String checkDirInRoot() throws PropertyException {
- String dirInRoot = System.getProperty("config.subdir");
+ private static String checkDirInRoot(File destDir, String dirInRoot) throws PropertyException {
// Optional parameter
if (dirInRoot == null) { return null; }
File f = new File(destDir, dirInRoot);
@@ -56,12 +66,8 @@ public class MakeConfigProperties {
return dirInRoot;
}
- /**
- * @return Desired programming language of generated code, default is "java".
- * @throws PropertyException if supplied language is not a legal language.
- */
- private String checkLanguage() throws PropertyException {
- String inputLang = System.getProperty("config.lang", "java").toLowerCase();
+ private static String checkLanguage(String lang) throws PropertyException {
+ String inputLang = lang != null ? lang.toLowerCase() : "java";
if (! legalLanguages.contains(inputLang)) {
throw new PropertyException
("Unsupported code language: '" + inputLang + "'. Supported languages are: " + legalLanguages);
@@ -69,12 +75,11 @@ public class MakeConfigProperties {
return inputLang;
}
- private static File[] checkSpecificationFiles() throws PropertyException {
- String string = System.getProperty("config.spec");
- if (string == null)
+ private static File[] checkSpecificationFiles(String spec) throws PropertyException {
+ if (spec == null)
throw new PropertyException("Missing property: config.spec.");
- StringTokenizer st = new StringTokenizer(string, ",");
+ StringTokenizer st = new StringTokenizer(spec, ",");
if (st.countTokens() == 0)
throw new PropertyException("Missing property: config.spec.");