diff --git a/raml-maven-plugin/pom.xml b/raml-maven-plugin/pom.xml
index 285ba31..c7da727 100644
--- a/raml-maven-plugin/pom.xml
+++ b/raml-maven-plugin/pom.xml
@@ -23,6 +23,7 @@
maven-plugin-plugin
3.4
+ false
raml
diff --git a/raml-maven-plugin/src/main/java/uk/gov/justice/raml/maven/generator/GenerateMojo.java b/raml-maven-plugin/src/main/java/uk/gov/justice/raml/maven/generator/GenerateMojo.java
index c764180..0eb8424 100644
--- a/raml-maven-plugin/src/main/java/uk/gov/justice/raml/maven/generator/GenerateMojo.java
+++ b/raml-maven-plugin/src/main/java/uk/gov/justice/raml/maven/generator/GenerateMojo.java
@@ -34,7 +34,6 @@ public class GenerateMojo extends BasicMojo {
@Parameter(property = "outputDirectory", defaultValue = "${project.build.directory}/generated-sources")
private File outputDirectory;
-
/**
* Base package name used for generated Java classes.
*/
@@ -44,24 +43,32 @@ public class GenerateMojo extends BasicMojo {
@Parameter(property = "generatorProperties", required = false)
private Map generatorProperties;
+ @Parameter(property = "skipGeneration", defaultValue = "false")
+ private boolean skip = false;
+
@Override
public void execute() throws MojoExecutionException {
- configureDefaultFileIncludes();
+ if (!skip) {
+ configureDefaultFileIncludes();
- project.addCompileSourceRoot(outputDirectory.getPath());
- project.addTestCompileSourceRoot(outputDirectory.getPath());
+ project.addCompileSourceRoot(outputDirectory.getPath());
+ project.addTestCompileSourceRoot(outputDirectory.getPath());
- final List sourcePaths = new ArrayList<>();
- project.getCompileSourceRoots().stream().forEach(root -> sourcePaths.add(Paths.get(root)));
+ final List sourcePaths = new ArrayList<>();
+ project.getCompileSourceRoots().stream().forEach(root -> sourcePaths.add(Paths.get(root)));
- try {
- FileUtils.forceMkdir(outputDirectory);
- new GenerateGoalProcessor(new GeneratorFactory(), new FileTreeScannerFactory())
- .generate(configuration(sourcePaths));
- } catch (Exception e) {
- throw new MojoExecutionException("Failed to apply generator to raml", e);
+ try {
+ FileUtils.forceMkdir(outputDirectory);
+ new GenerateGoalProcessor(new GeneratorFactory(), new FileTreeScannerFactory())
+ .generate(configuration(sourcePaths));
+ } catch (Exception e) {
+ throw new MojoExecutionException("Failed to apply generator to raml", e);
+ }
+ } else {
+ getLog().info("Skipping generation plugin execution as generation.skip flag is enabled.");
}
+
}
private GenerateGoalConfig configuration(final List sourcePaths) {
diff --git a/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/generator/GenerateMojoTest.java b/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/generator/GenerateMojoTest.java
index 5f65f32..ecf8f77 100644
--- a/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/generator/GenerateMojoTest.java
+++ b/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/generator/GenerateMojoTest.java
@@ -96,8 +96,6 @@ public void testShouldNotTryToInstatiateGeneratorIfNoRamlFiles() throws Exceptio
GenerateMojo mojo = (GenerateMojo) lookupConfiguredMojo(pom, "generate");
mojo.execute();
-
-
}
public void testShouldGenerateFromOnlyIncludedRaml() throws Exception {
@@ -130,4 +128,13 @@ public void testShouldIncludeRamlFilesFromTheClasspath() throws Exception {
hasProperty("title", equalTo("external-2.raml"))));
}
+ public void testShouldSkipExecution() throws Exception {
+ File pom = getTestFile("src/test/resources/skip-execution/pom.xml");
+ GenerateMojo mojo = (GenerateMojo) lookupConfiguredMojo(pom, "generate");
+
+ mojo.execute();
+
+ List> capturedGeneratorArgs = DummyGeneratorCaptor.getInstance().capturedArgs();
+ assertThat(capturedGeneratorArgs, hasSize(0));
+ }
}
diff --git a/raml-maven-plugin/src/test/resources/skip-execution/pom.xml b/raml-maven-plugin/src/test/resources/skip-execution/pom.xml
new file mode 100644
index 0000000..bbd1584
--- /dev/null
+++ b/raml-maven-plugin/src/test/resources/skip-execution/pom.xml
@@ -0,0 +1,30 @@
+
+ 4.0.0
+
+ uk.gov.justice.raml.test
+ project-to-test
+ 1.0.0-SNAPSHOT
+
+
+
+
+ raml-maven-plugin
+ uk.gov.justice.maven
+
+ uk.gov.justice.raml.maven.generator.DummyGenerator
+
+ uk.gov.justice.api
+ ${basedir}/src/raml
+
+ propertyValueABC
+ propertyValueDDD
+
+ true
+
+
+
+
+
+
diff --git a/raml-maven-plugin/src/test/resources/skip-execution/src/raml/example.raml b/raml-maven-plugin/src/test/resources/skip-execution/src/raml/example.raml
new file mode 100644
index 0000000..184df9c
--- /dev/null
+++ b/raml-maven-plugin/src/test/resources/skip-execution/src/raml/example.raml
@@ -0,0 +1,2 @@
+#%RAML 0.8
+title: example.raml