Improved Maven builder to define separate fields for additional parameters

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@13211 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2008-11-12 20:11:59 +00:00
1 parent ed2566ce0e
commit ac99bea602
2 files changed
+71 -8

No files matched your search

+37 -8
View File
@@ -33,6 +33,7 @@ import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Properties;
import net.sf.json.JSONObject;
@@ -46,20 +47,43 @@ public class Maven extends Builder {
* The targets and other maven options.
* Can be separated by SP or NL.
*/
private final String targets;
public final String targets;
/**
* Identifies {@link MavenInstallation} to be used.
*/
private final String mavenName;
public final String mavenName;
/**
* MAVEN_OPTS if not null.
*/
public final String jvmOptions;
/**
* Optional POM file path relative to the workspace.
* Used for the Maven '-f' option.
*/
public final String pom;
/**
* Optional properties to be passed to Maven. Follows {@link Properties} syntax.
*/
public final String properties;
private final static String MAVEN_1_INSTALLATION_COMMON_FILE = "bin/maven";
private final static String MAVEN_2_INSTALLATION_COMMON_FILE = "bin/mvn";
@DataBoundConstructor
public Maven(String targets,String name) {
this(targets,name,null,null,null);
}
@DataBoundConstructor
public Maven(String targets,String name, String pom, String properties, String jvmOptions) {
this.targets = targets;
this.mavenName = name;
this.pom = Util.fixEmptyAndTrim(pom);
this.properties = Util.fixEmptyAndTrim(properties);
this.jvmOptions = Util.fixEmptyAndTrim(jvmOptions);
}
public String getTargets() {
@@ -129,11 +153,12 @@ public class Maven extends Builder {
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
AbstractProject proj = build.getProject();
String targets = this.targets;
VariableResolver<String> vr = build.getBuildVariableResolver();
ParametersAction parameters = build.getAction(ParametersAction.class);
if (parameters != null)
targets = parameters.substitute(build,targets);
targets = Util.replaceMacro(targets,build.getBuildVariableResolver());
if(parameters!=null)
vr = parameters.createVariableResolver(build);
String targets = Util.replaceMacro(this.targets,vr);
int startIndex = 0;
int endIndex;
@@ -165,6 +190,7 @@ public class Maven extends Builder {
args.add(exec);
}
args.addKeyValuePairs("-D",build.getBuildVariables());
args.addKeyValuePairsFromPropertyString("-D",properties,vr);
args.addTokenized(normalizedTarget);
if(ai!=null) {
@@ -182,6 +208,9 @@ public class Maven extends Builder {
// see http://maven.apache.org/continuum/faqs.html#how-does-continuum-detect-a-successful-build
env.put("MAVEN_TERMINATE_CMD","on");
if(jvmOptions!=null)
env.put("MAVEN_OPTS",jvmOptions);
try {
int r = launcher.launch(args.toCommandArray(),env,listener.getLogger(),proj.getModuleRoot()).join();
if (0 != r) {