Add property "yang.skip" 83/40183/4
authorDavid <david.lopez.munoz@ericsson.com>
Fri, 10 Jun 2016 21:05:59 +0000 (23:05 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 23 Jun 2016 11:27:26 +0000 (11:27 +0000)
This property allows the plugin to be configured so
to skip the generation of java sources out of yang files.
The purpose is to save the time spent genereting java code
that is already in place, and the user knows that haven't
changed since the last compilation.

Usage:
   mvn  install -Dyang.skip=true

Change-Id: I39d3da20864f7655cae68dfa9f4b67ec96137d9f
Signed-off-by: David <david.lopez.munoz@ericsson.com>
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java
yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojoTest.java

index 0d3f970e1ea3f82be48dfdf7ef88988d71eb145c..a6752b167b85423304bc4eac8176e27daaa27b09 100644 (file)
@@ -86,6 +86,9 @@ public final class YangToSourcesMojo extends AbstractMojo {
     @Parameter( readonly = true, defaultValue = "${project.remoteArtifactRepositories}" )
     private List<ArtifactRepository> remoteRepos;
 
+    // When set to "true", then the execution of the plugin is disabled
+    @Parameter( property = "yang.skip" )
+    private String yang_skip;
 
     public YangToSourcesMojo() {
     }
@@ -113,7 +116,7 @@ public final class YangToSourcesMojo extends AbstractMojo {
             yangToSourcesProcessor = new YangToSourcesProcessor(buildContext, yangFilesRootFile,
                     excludedFiles, codeGeneratorArgs, project, inspectDependencies);
         }
-        yangToSourcesProcessor.execute();
+        yangToSourcesProcessor.conditionalExecute("true".equals(yang_skip));
     }
 
     private static List<CodeGeneratorArg> processCodeGenerators(final CodeGeneratorArg[] codeGenerators) {
index 4140e01173499df86fe8b6d74df828a236c33113..c1a1cbea9860cf446c35cf95c932f94080d119fb 100644 (file)
@@ -97,6 +97,14 @@ class YangToSourcesProcessor {
         }
     }
 
+    void conditionalExecute(boolean skip) throws MojoExecutionException, MojoFailureException {
+        if (skip) {
+            LOG.info("Skipping YANG code generation because property yang.skip is true");
+        } else {
+            execute();
+        }
+    }
+
     private ContextHolder processYang() throws MojoExecutionException {
         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
         SchemaContext resolveSchemaContext;
index 9e31f25a29ecff50bf0d9400ea624cb714f3462a..c3571e058e03fef5efb24d91feae8dff9b4b0b9a 100644 (file)
@@ -49,7 +49,7 @@ public class YangToSourcesMojoTest {
         this.mojo = new YangToSourcesMojo(processor);
         this.mojo.setProject(this.project);
         this.mojo.execute();
-        Mockito.verify(processor).execute();
+        Mockito.verify(processor).conditionalExecute(false);
     }
 
     @Test