Fixed NPE in maven-yang-plugin 67/267/1
authorTony Tkacik <ttkacik@cisco.com>
Tue, 30 Apr 2013 13:41:43 +0000 (15:41 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 30 Apr 2013 13:41:43 +0000 (15:41 +0200)
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/YangToSourcesMojo.java

index e124c56c47f8c7ddae2163f2c584af370f2fa8ae..2b7dc33845d12e8a78833e57cc600b85377d4f7e 100644 (file)
@@ -44,7 +44,7 @@ import com.google.common.collect.Maps;
  * </ol>
  * </ol>
  */
-@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES,requiresDependencyResolution=ResolutionScope.COMPILE,requiresProject=true)
+@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
 public final class YangToSourcesMojo extends AbstractMojo {
 
     private static final String LOG_PREFIX = "yang-to-sources:";
@@ -65,11 +65,9 @@ public final class YangToSourcesMojo extends AbstractMojo {
     @Parameter(required = true)
     private String yangFilesRootDir;
 
-
     @Parameter(property = "project", required = true, readonly = true)
     protected MavenProject project;
 
-
     private transient final YangModelParser parser;
 
     @VisibleForTesting
@@ -98,15 +96,16 @@ public final class YangToSourcesMojo extends AbstractMojo {
     private SchemaContext processYang() throws MojoExecutionException {
         try {
             Collection<File> yangFiles = Util.listFiles(yangFilesRootDir);
-            
+
             if (yangFiles.isEmpty()) {
                 getLog().warn(
                         Util.message("No %s file found in %s", LOG_PREFIX,
                                 Util.YANG_SUFFIX, yangFilesRootDir));
                 return null;
-            } 
-            
-            Set<Module> parsedYang = parser.parseYangModels(new ArrayList<File>(yangFiles));
+            }
+
+            Set<Module> parsedYang = parser
+                    .parseYangModels(new ArrayList<File>(yangFiles));
             SchemaContext resolveSchemaContext = parser
                     .resolveSchemaContext(parsedYang);
             getLog().info(
@@ -179,9 +178,10 @@ public final class YangToSourcesMojo extends AbstractMojo {
                         codeGeneratorCfg.getCodeGeneratorClass()));
 
         File outputDir = codeGeneratorCfg.getOutputBaseDir();
-        project.addCompileSourceRoot(outputDir.getPath());
-        Collection<File> generated = g.generateSources(context,
-                outputDir);
+        if (project != null && outputDir != null) {
+            project.addCompileSourceRoot(outputDir.getPath());
+        }
+        Collection<File> generated = g.generateSources(context, outputDir);
         getLog().info(
                 Util.message("Sources generated by %s: %s", LOG_PREFIX,
                         codeGeneratorCfg.getCodeGeneratorClass(), generated));