Skip to content

Commit

Permalink
Add skip parameter (groovy#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Oct 9, 2021
1 parent 2e1c240 commit f1165c7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public class ExecuteMojo
@Parameter
private Map<String, String> 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);
Expand All @@ -101,4 +110,10 @@ protected void customizeProperties(final PropertiesBuilder builder) {
builder.setProperties(properties)
.setDefaults(defaults);
}

@Override
protected boolean isSkipped() {
return skip;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -67,4 +71,6 @@ protected void prepare() throws Exception {
protected void cleanup() throws Exception {
// empty
}

protected abstract boolean isSkipped();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand All @@ -47,4 +56,10 @@ protected void run() throws Exception {

shell.run(getRuntimeRealm(), resourceLoader, context, options);
}

@Override
protected boolean isSkipped() {
return skip;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ protected void run() throws Exception {
protected void cleanup() throws Exception {
cleanupCount.incrementAndGet();
}

@Override
protected boolean isSkipped() {
return false;
}
}

@Before
Expand Down

3 comments on commit f1165c7

@jdillon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx. I'm curious what the use-case is to skip for console and shell goals as those are meant to be interactive?

@ppalaga
Copy link
Owner Author

@ppalaga ppalaga commented on f1165c7 Oct 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, you've got me! I added the params there without having any clear idea what the mojos do :D
Should I remove the params from console and shell?

@jdillon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ppalaga curious did you have a use-case for skip on exec then or is the change purely theoretical that goals should have a skip flag?

I think there could be a use-case for skip for exec goal, though use of this goal often produces side-effects which are needed for other goal executions and skipping could cause other failures; but this is highly dependent on what the build designer had intended. I don't object to adding a skip flag to exec though.

For shell and console, these goals are only really useful for an interactive user to run so having a skip flag is pointless, and if for some reason was defaulted to skip=true would mean additional configuration to actually use the goals which I think would be unfortunate.

Personally and maybe more of a style issue is that if a gmaven:execute goal was meant to be skippable it probably should have been defined in a profile. But I can not really say what various users do with this goal, but personally I use it to augment the Maven build in a way that produces side-effects needed for subsequent phases; so skipping would break things.

All that said I don't object to a skip flag on execute, if you have a solid use-case for skipping please do remove the skips from the other goals and I think we can merge the PR with the exec skip feature.

Please sign in to comment.