提交 9519de18 编写于 作者: I imod

additionaly pass reference to current build to intercepting methods

上级 fda6daa0
...@@ -45,16 +45,19 @@ public interface MavenArgumentInterceptorAction extends Action { ...@@ -45,16 +45,19 @@ public interface MavenArgumentInterceptorAction extends Action {
* This method will be called on one and only one action during a build. If * This method will be called on one and only one action during a build. If
* there are two actions present in the build, the second will be ignored. * there are two actions present in the build, the second will be ignored.
* *
* @param build
* reference to the current build, might be used for some
* calculations for the correct arguments
* @return the maven goals and options to start maven with. Result is * @return the maven goals and options to start maven with. Result is
* ignored if <code>null</code> or empty. Variables will be expanded * ignored if <code>null</code> or empty. Variables will be expanded
* by the caller. * by the caller.
*/ */
public String getGoalsAndOptions(); public String getGoalsAndOptions(MavenModuleSetBuild build);
/** /**
* Change/add arguments to any needs, but special care has to be taken, as * Change/add arguments to any needs, but special care has to be taken, as
* the list contains every argument needed for the default execution (e.g. * the list contains every argument needed for the default execution (e.g.
* -f /path/to/pom.xml or -B). <br /> * <code>-f /path/to/pom.xml</code> or <code>-B</code>). <br />
* An easy example would be to add "<code>-DskipTests</code>" to skip the * An easy example would be to add "<code>-DskipTests</code>" to skip the
* test execution on request. * test execution on request.
* *
...@@ -66,8 +69,11 @@ public interface MavenArgumentInterceptorAction extends Action { ...@@ -66,8 +69,11 @@ public interface MavenArgumentInterceptorAction extends Action {
* @param mavenargs * @param mavenargs
* the calculated default maven arguments (never * the calculated default maven arguments (never
* <code>null</code>). * <code>null</code>).
* @param build
* reference to the current build, might be used for some
* calculations for the correct arguments
* @return the new arguments to be used. * @return the new arguments to be used.
*/ */
public ArgumentListBuilder intercept(ArgumentListBuilder mavenargs); public ArgumentListBuilder intercept(ArgumentListBuilder mavenargs, MavenModuleSetBuild build);
} }
...@@ -760,7 +760,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -760,7 +760,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
// find the correct maven goals and options, there might by an action overruling the defaults // find the correct maven goals and options, there might by an action overruling the defaults
String goals = project.getGoals(); // default String goals = project.getGoals(); // default
for (MavenArgumentInterceptorAction mavenArgInterceptor : argInterceptors) { for (MavenArgumentInterceptorAction mavenArgInterceptor : argInterceptors) {
final String goalsAndOptions = mavenArgInterceptor.getGoalsAndOptions(); final String goalsAndOptions = mavenArgInterceptor.getGoalsAndOptions(this.getBuild());
if(StringUtils.isNotBlank(goalsAndOptions)){ if(StringUtils.isNotBlank(goalsAndOptions)){
goals = goalsAndOptions; goals = goalsAndOptions;
// only one interceptor is allowed to overwrite the whole "goals and options" string // only one interceptor is allowed to overwrite the whole "goals and options" string
...@@ -772,7 +772,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -772,7 +772,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
// enable the interceptors to change the whole command argument list // enable the interceptors to change the whole command argument list
// all available interceptors are allowed to modify the argument list // all available interceptors are allowed to modify the argument list
for (MavenArgumentInterceptorAction mavenArgInterceptor : argInterceptors) { for (MavenArgumentInterceptorAction mavenArgInterceptor : argInterceptors) {
final ArgumentListBuilder newMargs = mavenArgInterceptor.intercept(margs); final ArgumentListBuilder newMargs = mavenArgInterceptor.intercept(margs, this.getBuild());
if (newMargs != null) { if (newMargs != null) {
margs = newMargs; margs = newMargs;
} }
......
...@@ -105,11 +105,11 @@ public class MavenArgumentInterceptorTest extends HudsonTestCase { ...@@ -105,11 +105,11 @@ public class MavenArgumentInterceptorTest extends HudsonTestCase {
return null; return null;
} }
public String getGoalsAndOptions() { public String getGoalsAndOptions(MavenModuleSetBuild build) {
return goalsAndOptions; return goalsAndOptions;
} }
public ArgumentListBuilder intercept(ArgumentListBuilder mavenargs) { public ArgumentListBuilder intercept(ArgumentListBuilder mavenargs, MavenModuleSetBuild build) {
if (args != null) { if (args != null) {
for (String arg : this.args) { for (String arg : this.args) {
mavenargs.add(arg); mavenargs.add(arg);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册