diff options
Diffstat (limited to 'configgen')
4 files changed, 35 insertions, 29 deletions
diff --git a/configgen/src/main/java/com/yahoo/config/codegen/MakeConfig.java b/configgen/src/main/java/com/yahoo/config/codegen/MakeConfig.java index b2c19f26b5f..91d401c91b7 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/MakeConfig.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/MakeConfig.java @@ -14,27 +14,26 @@ public class MakeConfig { private final ClassBuilder classBuilder; - public MakeConfig(InnerCNode root, NormalizedDefinition nd, String path, MakeConfigProperties properties) { - classBuilder = createClassBuilder(root, nd, path, properties); + public MakeConfig(InnerCNode root, NormalizedDefinition nd, MakeConfigProperties properties) { + classBuilder = createClassBuilder(root, nd, properties); } - public static ClassBuilder createClassBuilder(InnerCNode root, NormalizedDefinition nd, String path, MakeConfigProperties prop) { + public static ClassBuilder createClassBuilder(InnerCNode root, NormalizedDefinition nd, MakeConfigProperties prop) { if (prop.language.equals("cppng") || prop.language.equals("cpp")) return new CppClassBuilder(root, nd, prop.destDir, prop.dirInRoot); else - return new JavaClassBuilder(root, nd, prop.destDir); + return new JavaClassBuilder(root, nd, prop.destDir, prop.javaPackagePrefix); } public static boolean makeConfig(MakeConfigProperties properties) throws FileNotFoundException { for (File specFile : properties.specFiles) { - String path = specFile.toURI().toString(); String name = specFile.getName(); if (name.endsWith(".def")) name = name.substring(0, name.length() - 4); DefParser parser = new DefParser(name, new FileReader(specFile)); InnerCNode configRoot = parser.getTree(); checkNamespace(name, configRoot); if (configRoot != null) { - MakeConfig mc = new MakeConfig(configRoot, parser.getNormalizedDefinition(), path, properties); + MakeConfig mc = new MakeConfig(configRoot, parser.getNormalizedDefinition(), properties); mc.buildClasses(); if (properties.dumpTree) { System.out.println("\nTree dump:"); 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 6542eb2ab35..ca10e973ba2 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/MakeConfigProperties.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/MakeConfigProperties.java @@ -19,6 +19,7 @@ public class MakeConfigProperties { final File[] specFiles; final String language; final String dirInRoot; // Where within fileroot to store generated class files + final String javaPackagePrefix; final boolean dumpTree; final boolean generateFrameworkCode; @@ -28,7 +29,8 @@ public class MakeConfigProperties { System.getProperty("config.lang"), System.getProperty("config.subdir"), System.getProperty("config.dumpTree"), - System.getProperty("config.useFramework")); + System.getProperty("config.useFramework"), + System.getProperty("config.packagePrefix")); } public MakeConfigProperties(String destDir, @@ -36,13 +38,15 @@ public class MakeConfigProperties { String language, String dirInRoot, String dumpTree, - String generateFrameworkCode) throws PropertyException { + String generateFrameworkCode, + String javaPackagePrefix) 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); + this.javaPackagePrefix = javaPackagePrefix; } private static File checkDestinationDir(String destination) throws PropertyException { diff --git a/configgen/src/main/scala/com/yahoo/config/codegen/JavaClassBuilder.scala b/configgen/src/main/scala/com/yahoo/config/codegen/JavaClassBuilder.scala index 5a47d2f7cea..c8c0b659b2f 100644 --- a/configgen/src/main/scala/com/yahoo/config/codegen/JavaClassBuilder.scala +++ b/configgen/src/main/scala/com/yahoo/config/codegen/JavaClassBuilder.scala @@ -15,12 +15,14 @@ import scala.collection.JavaConversions._ class JavaClassBuilder( root: InnerCNode, nd: NormalizedDefinition, - destDir: File) + destDir: File, + rawPackagePrefix: String) extends ClassBuilder { import JavaClassBuilder._ - val javaPackage = PackagePrefix + root.getNamespace + val packagePrefix = if (rawPackagePrefix != null) rawPackagePrefix else "com.yahoo." + val javaPackage = packagePrefix + root.getNamespace val className = createClassName(root.getName) override def createConfigClasses() { @@ -72,7 +74,7 @@ class JavaClassBuilder( private def getImportFrameworkClasses(namespace: String): String = { if (namespace != CNode.DEFAULT_NAMESPACE) - "import " + PackagePrefix + CNode.DEFAULT_NAMESPACE + ".*;\n" + "import " + packagePrefix + CNode.DEFAULT_NAMESPACE + ".*;\n" else "" } @@ -120,11 +122,28 @@ class JavaClassBuilder( |} """.stripMargin.trim } + + /** + * @param rootDir The root directory for the destination path. + * @param namespace The namespace from the def file + * @return the destination path for the generated config file, including the given rootDir. + */ + private def getDestPath(rootDir: File, namespace: String): File = { + var dir: File = rootDir + val subDirs: Array[String] = (packagePrefix + namespace).split("""\.""") + for (subDir <- subDirs) { + dir = new File(dir, subDir) + this.synchronized { + if (!dir.isDirectory && !dir.mkdir) throw new CodegenRuntimeException("Could not create " + dir.getPath) + } + } + dir + } + } object JavaClassBuilder { - private val PackagePrefix: String = System.getProperty("config.packagePrefix", "com.yahoo.") val Indentation = " " @@ -161,20 +180,4 @@ object JavaClassBuilder { candidate } - /** - * @param rootDir The root directory for the destination path. - * @param namespace The namespace from the def file - * @return the destination path for the generated config file, including the given rootDir. - */ - private def getDestPath(rootDir: File, namespace: String): File = { - var dir: File = rootDir - val subDirs: Array[String] = (PackagePrefix + namespace).split("""\.""") - for (subDir <- subDirs) { - dir = new File(dir, subDir) - this.synchronized { - if (!dir.isDirectory && !dir.mkdir) throw new CodegenRuntimeException("Could not create " + dir.getPath) - } - } - dir - } } diff --git a/configgen/src/test/scala/com/yahoo/config/codegen/JavaClassBuilderTest.scala b/configgen/src/test/scala/com/yahoo/config/codegen/JavaClassBuilderTest.scala index e2bcd6328c8..4b35f3fb713 100644 --- a/configgen/src/test/scala/com/yahoo/config/codegen/JavaClassBuilderTest.scala +++ b/configgen/src/test/scala/com/yahoo/config/codegen/JavaClassBuilderTest.scala @@ -55,7 +55,7 @@ class JavaClassBuilderTest { val parser = new DefParser("test", new StringReader(testDefinition)) val root = parser.getTree - val builder = new JavaClassBuilder(root, parser.getNormalizedDefinition, null) + val builder = new JavaClassBuilder(root, parser.getNormalizedDefinition, null, null) val configClass = builder.getConfigClass("TestConfig") print(configClass) } |