提交 ac99bea6 编写于 作者: K kohsuke

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
上级 ed2566ce
......@@ -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) {
......
package hudson.tasks;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.FreeStyleProject;
import org.jvnet.hudson.test.HudsonTestCase;
/**
* @author Kohsuke Kawaguchi
*/
public class MavenTest extends HudsonTestCase {
/**
* Tests the round-tripping of the configuration.
*/
public void testConfigRoundtrip() throws Exception {
FreeStyleProject p = createFreeStyleProject();
p.getBuildersList().add(new Maven("a",null,"b.pom","c=d","-e"));
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage(p,"configure");
HtmlForm form = page.getFormByName("config");
form.submit((HtmlButton)last(form.getHtmlElementsByTagName("button")));
Maven m = (Maven)p.getBuildersList().get(Maven.DESCRIPTOR);
assertNotNull(m);
assertEquals("a",m.targets);
assertNull(m.mavenName);
assertEquals("b.pom",m.pom);
assertEquals("c=d",m.properties);
assertEquals("-e",m.jvmOptions);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册