Added default output directory to CodeGeneratorImpl in maven-sal-api-gen-plugin. 78/578/1
authorMartin Vitez <mvitez@cisco.com>
Tue, 9 Jul 2013 11:23:28 +0000 (13:23 +0200)
committerMartin Vitez <mvitez@cisco.com>
Tue, 9 Jul 2013 11:23:28 +0000 (13:23 +0200)
Removed default output directory from yang-maven-plugin.

Signed-off-by: Martin Vitez <mvitez@cisco.com>
opendaylight/sal/yang-prototype/code-generator/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/controller/maven/sal/api/gen/plugin/CodeGeneratorImpl.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/ConfigArg.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/YangToSourcesProcessor.java

index 29a78ab..4dadc5d 100644 (file)
@@ -19,8 +19,8 @@ import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
 import org.opendaylight.controller.sal.binding.generator.impl.BindingGeneratorImpl;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
 import org.opendaylight.controller.sal.binding.model.api.Enumeration;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
 import org.opendaylight.controller.sal.binding.model.api.Type;
 import org.opendaylight.controller.sal.java.api.generator.GeneratorJavaFile;
@@ -30,28 +30,30 @@ import org.opendaylight.controller.yang2sources.spi.CodeGenerator;
 
 public final class CodeGeneratorImpl implements CodeGenerator {
 
-       @Override
-       public Collection<File> generateSources(SchemaContext context,
-            File outputBaseDir, Set<Module> yangModules) throws IOException {
+    @Override
+    public Collection<File> generateSources(SchemaContext context, File outputBaseDir, Set<Module> yangModules)
+            throws IOException {
+        if (outputBaseDir == null) {
+            outputBaseDir = new File("target" + File.separator + "generated-sources" + File.separator + "maven-sal-api-gen");
+        }
 
-               final BindingGenerator bindingGenerator = new BindingGeneratorImpl();
-               final List<Type> types = bindingGenerator.generateTypes(context,yangModules);
-               final Set<GeneratedType> typesToGenerate = new HashSet<>();
-               final Set<GeneratedTransferObject> tosToGenerate = new HashSet<>();
-               final Set<Enumeration> enumsToGenerate = new HashSet<>();
+        final BindingGenerator bindingGenerator = new BindingGeneratorImpl();
+        final List<Type> types = bindingGenerator.generateTypes(context, yangModules);
+        final Set<GeneratedType> typesToGenerate = new HashSet<>();
+        final Set<GeneratedTransferObject> tosToGenerate = new HashSet<>();
+        final Set<Enumeration> enumsToGenerate = new HashSet<>();
 
-               for (Type type : types) {
-                       if (type instanceof GeneratedTransferObject) {
-                               tosToGenerate.add((GeneratedTransferObject) type);
-                       } else if (type instanceof GeneratedType) {
-                               typesToGenerate.add((GeneratedType) type);
-                       } else if (type instanceof Enumeration) {
-                               enumsToGenerate.add((Enumeration) type);
-                       }
+        for (Type type : types) {
+            if (type instanceof GeneratedTransferObject) {
+                tosToGenerate.add((GeneratedTransferObject) type);
+            } else if (type instanceof GeneratedType) {
+                typesToGenerate.add((GeneratedType) type);
+            } else if (type instanceof Enumeration) {
+                enumsToGenerate.add((Enumeration) type);
+            }
         }
 
-        final GeneratorJavaFile generator = new GeneratorJavaFile(
-                               typesToGenerate, tosToGenerate, enumsToGenerate);
+        final GeneratorJavaFile generator = new GeneratorJavaFile(typesToGenerate, tosToGenerate, enumsToGenerate);
 
         return generator.generateToFile(outputBaseDir);
     }
@@ -75,6 +77,6 @@ public final class CodeGeneratorImpl implements CodeGenerator {
     @Override
     public void setMavenProject(MavenProject project) {
         // no additional information needed
-       }
+    }
 
 }
index 0df9a63..88f4dde 100644 (file)
@@ -23,10 +23,13 @@ public abstract class ConfigArg {
     private final File outputBaseDir;
 
     public ConfigArg(String outputBaseDir) {
-        this.outputBaseDir = new File(outputBaseDir);
+        this.outputBaseDir = outputBaseDir == null ? null : new File(outputBaseDir);
     }
 
     public File getOutputBaseDir(MavenProject project) {
+        if (outputBaseDir == null) {
+            return null;
+        }
         if (outputBaseDir.isAbsolute()) {
             return outputBaseDir;
         } else {
@@ -40,21 +43,19 @@ public abstract class ConfigArg {
      * Configuration argument for code generator class and output directory.
      */
     public static final class CodeGeneratorArg extends ConfigArg {
-        private static final String CODE_GEN_DEFAULT_DIR = "target"
-                + File.separator + "generated-sources";
-        private static final String CODE_GEN_DEFAULT_RESOURCE_DIR = "target"
-                + File.separator + "generated-resources";
+        private static final String CODE_GEN_DEFAULT_RESOURCE_DIR = "target" + File.separator + "generated-resources";
+
         private String codeGeneratorClass;
         private File resourceBaseDir = new File(CODE_GEN_DEFAULT_RESOURCE_DIR);
 
         private Map<String, String> additionalConfiguration = Maps.newHashMap();
 
         public CodeGeneratorArg() {
-            super(CODE_GEN_DEFAULT_DIR);
+            super(null);
         }
 
         public CodeGeneratorArg(String codeGeneratorClass) {
-            this(codeGeneratorClass, CODE_GEN_DEFAULT_DIR);
+            this(codeGeneratorClass, null);
         }
 
         public CodeGeneratorArg(String codeGeneratorClass, String outputBaseDir) {
@@ -62,8 +63,7 @@ public abstract class ConfigArg {
             this.codeGeneratorClass = codeGeneratorClass;
         }
 
-        public CodeGeneratorArg(String codeGeneratorClass,
-                String outputBaseDir, String resourceBaseDir) {
+        public CodeGeneratorArg(String codeGeneratorClass, String outputBaseDir, String resourceBaseDir) {
             super(outputBaseDir);
             this.codeGeneratorClass = codeGeneratorClass;
             this.resourceBaseDir = new File(resourceBaseDir);
@@ -71,8 +71,7 @@ public abstract class ConfigArg {
 
         @Override
         public void check() {
-            Preconditions.checkNotNull(codeGeneratorClass,
-                    "codeGeneratorClass for CodeGenerator cannot be null");
+            Preconditions.checkNotNull(codeGeneratorClass, "codeGeneratorClass for CodeGenerator cannot be null");
         }
 
         public String getCodeGeneratorClass() {
index cc7c536..b781d72 100644 (file)
@@ -220,7 +220,9 @@ class YangToSourcesProcessor {
                 codeGeneratorCfg.getCodeGeneratorClass(),
                 codeGeneratorCfg.getAdditionalConfiguration()));
 
-        project.addCompileSourceRoot(outputDir.getAbsolutePath());
+        if(outputDir != null) {
+            project.addCompileSourceRoot(outputDir.getAbsolutePath());
+        }
         g.setLog(log);
         g.setMavenProject(project);
         g.setAdditionalConfig(codeGeneratorCfg.getAdditionalConfiguration());