process =
MavenBuild.mavenProcessCache.get( launcher.getChannel(), slistener,
new MavenProcessFactory( project, launcher, envVars,getMavenOpts(listener, envVars),
pom.getParent() ) );
}
ArgumentListBuilder margs = new ArgumentListBuilder().add("-B").add("-f", pom.getRemote());
FilePath localRepo = project.getLocalRepository().locate(MavenModuleSetBuild.this);
if(localRepo!=null)
margs.add("-Dmaven.repo.local="+localRepo.getRemote());
if (project.globalSettingConfigPath != null)
margs.add("-gs" , project.globalSettingConfigPath);
// If incrementalBuild is set
// and the previous build didn't specify that we need a full build
// and we're on Maven 2.1 or later
// and there's at least one module listed in changedModules,
// then do the Maven incremental build commands.
// If there are no changed modules, we're building everything anyway.
boolean maven2_1orLater = new ComparableVersion (mavenVersion).compareTo( new ComparableVersion ("2.1") ) >= 0;
boolean needsFullBuild = getPreviousCompletedBuild() != null &&
getPreviousCompletedBuild().getAction(NeedsFullBuildAction.class) != null;
if (project.isIncrementalBuild() && !needsFullBuild && maven2_1orLater && !changedModules.isEmpty()) {
margs.add("-amd");
margs.add("-pl", Util.join(changedModules, ","));
}
if (project.getAlternateSettings() != null) {
if (IOUtils.isAbsolute(project.getAlternateSettings())) {
margs.add("-s").add(project.getAlternateSettings());
} else {
FilePath mrSettings = getModuleRoot().child(project.getAlternateSettings());
FilePath wsSettings = getWorkspace().child(project.getAlternateSettings());
if (!wsSettings.exists() && mrSettings.exists())
wsSettings = mrSettings;
margs.add("-s").add(wsSettings.getRemote());
}
}
final List<MavenArgumentInterceptorAction> argInterceptors = this.getBuild().getActions(MavenArgumentInterceptorAction.class);
// find the correct maven goals and options, there might by an action overruling the defaults
String goals = project.getGoals(); // default
for (MavenArgumentInterceptorAction mavenArgInterceptor : argInterceptors) {
final String goalsAndOptions = mavenArgInterceptor.getGoalsAndOptions((MavenModuleSetBuild)this.getBuild());
if(StringUtils.isNotBlank(goalsAndOptions)){
goals = goalsAndOptions;
// only one interceptor is allowed to overwrite the whole "goals and options" string
break;
}
}
margs.addTokenized(envVars.expand(goals));
// enable the interceptors to change the whole command argument list
// all available interceptors are allowed to modify the argument list
for (MavenArgumentInterceptorAction mavenArgInterceptor : argInterceptors) {
final ArgumentListBuilder newMargs = mavenArgInterceptor.intercept(margs, (MavenModuleSetBuild)this.getBuild());
if (newMargs != null) {
margs = newMargs;
}
}