diff --git a/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ConsoleMojo.java b/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ConsoleMojo.java index d19f6ee1..2a8f1d83 100644 --- a/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ConsoleMojo.java +++ b/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ConsoleMojo.java @@ -19,6 +19,7 @@ import java.util.Map; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.gmaven.adapter.ConsoleWindow; import org.codehaus.gmaven.adapter.ConsoleWindow.WindowHandle; import org.codehaus.gmaven.adapter.ResourceLoader; @@ -39,6 +40,14 @@ public class ConsoleMojo { // TODO: Expose console options + /** + * Skip the execution of this mojo. + * + * @since 2.2.0 + */ + @Parameter(property = "gmaven.console.skip", defaultValue = "false") + private boolean skip; + @Override protected void run() throws Exception { final ResourceLoader resourceLoader = new MojoResourceLoader(getRuntimeRealm(), getScriptpath()); @@ -49,4 +58,9 @@ protected void run() throws Exception { WindowHandle handle = console.open(getRuntimeRealm(), resourceLoader, context, options); handle.await(); } + + @Override + protected boolean isSkipped() { + return skip; + } } diff --git a/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ExecuteMojo.java b/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ExecuteMojo.java index afebf749..e4c30ea8 100644 --- a/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ExecuteMojo.java +++ b/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ExecuteMojo.java @@ -82,6 +82,15 @@ public class ExecuteMojo @Parameter private Map defaults; + + /** + * Skip the execution of this mojo. + * + * @since 2.2.0 + */ + @Parameter(property = "gmaven.execute.skip", defaultValue = "false") + private boolean skip; + @Override protected void run() throws Exception { final ClassSource classSource = classSourceFactory.create(source); @@ -101,4 +110,10 @@ protected void customizeProperties(final PropertiesBuilder builder) { builder.setProperties(properties) .setDefaults(defaults); } + + @Override + protected boolean isSkipped() { + return skip; + } + } diff --git a/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/MojoSupport.java b/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/MojoSupport.java index 291133e5..b72246b5 100644 --- a/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/MojoSupport.java +++ b/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/MojoSupport.java @@ -38,6 +38,10 @@ protected MojoSupport() { } public void execute() throws MojoExecutionException, MojoFailureException { + if (isSkipped()) { + getLog().info("Skipping as requested by the user"); + return; + } try { try { log.trace("Prepare"); @@ -67,4 +71,6 @@ protected void prepare() throws Exception { protected void cleanup() throws Exception { // empty } + + protected abstract boolean isSkipped(); } diff --git a/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ShellMojo.java b/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ShellMojo.java index 879cff51..07ca3bab 100644 --- a/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ShellMojo.java +++ b/groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ShellMojo.java @@ -19,6 +19,7 @@ import java.util.Map; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.gmaven.adapter.ResourceLoader; import org.codehaus.gmaven.adapter.ShellRunner; @@ -38,6 +39,14 @@ public class ShellMojo { // TODO: Expose groovysh options + /** + * Skip the execution of this mojo. + * + * @since 2.2.0 + */ + @Parameter(property = "gmaven.shell.skip", defaultValue = "false") + private boolean skip; + @Override protected void run() throws Exception { final ResourceLoader resourceLoader = new MojoResourceLoader(getRuntimeRealm(), getScriptpath()); @@ -47,4 +56,10 @@ protected void run() throws Exception { shell.run(getRuntimeRealm(), resourceLoader, context, options); } + + @Override + protected boolean isSkipped() { + return skip; + } + } diff --git a/groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/MojoSupportTest.java b/groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/MojoSupportTest.java index 96d43662..714a63e2 100644 --- a/groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/MojoSupportTest.java +++ b/groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/MojoSupportTest.java @@ -58,6 +58,11 @@ protected void run() throws Exception { protected void cleanup() throws Exception { cleanupCount.incrementAndGet(); } + + @Override + protected boolean isSkipped() { + return false; + } } @Before