提交 f51908fb 编写于 作者: K kohsuke

applied patch from Rob Oxspring. See http://www.nabble.com/Improving-Ant-Support-tf4504289.html


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@4936 71c3de6d-444a-0410-be80-ed276b4c234a
上级 638b3ae5
......@@ -17,7 +17,15 @@ import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;
/**
* @author Kohsuke Kawaguchi
......@@ -39,14 +47,28 @@ public class Ant extends Builder {
*/
private final String antOpts;
private final String buildFile;
private final String properties;
@DataBoundConstructor
public Ant(String targets,String antName, String antOpts) {
public Ant(String targets,String antName, String antOpts, String buildFile, String properties) {
this.targets = targets;
this.antName = antName;
this.antOpts = Util.fixEmpty(antOpts.trim());
this.buildFile = Util.fixEmpty(buildFile);
this.properties = Util.fixEmpty(properties);
}
public String getBuildFile() {
return buildFile;
}
public String getTargets() {
public String getProperties() {
return properties;
}
public String getTargets() {
return targets;
}
......@@ -69,7 +91,7 @@ public class Ant extends Builder {
return antOpts;
}
public boolean perform(Build<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException {
public boolean perform(Build<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
Project proj = build.getProject();
ArgumentListBuilder args = new ArgumentListBuilder();
......@@ -89,7 +111,28 @@ public class Ant extends Builder {
File exec = ai.getExecutable(launcher.isUnix());
args.add(exec.getPath());
}
if(buildFile!=null) {
args.add("-file", buildFile);
}
args.addKeyValuePairs("-D",build.getBuildVariables());
if(properties!=null) {
final Properties p = new Properties();
final Reader reader = new StringReader(properties);
try {
p.load(reader);
}
finally {
reader.close();
}
for (final Entry<Object, Object> entry : p.entrySet()) {
args.add("-D"+entry.getKey()+"="+entry.getValue());
}
}
args.addTokenized(normalizedTarget);
Map<String,String> env = build.getEnvVars();
......
......@@ -7,16 +7,18 @@
</j:forEach>
</select>
</f:entry>
<f:entry title="Targets" description="
Specify Ant target(s) to run. If necessary, you can also specify any ant command line options,
such as '-Dprop=value'. Also, &lt;a href='${rootURL}/env-vars.html' target=_new>some
environment variables are available to the build script&lt;/a>
">
<f:entry title="Targets">
<f:expandableTextbox name="ant.targets" value="${instance.targets}" />
</f:entry>
<f:advanced>
<f:entry title="ANT_OPTS" help="/help/ant/ant-opts.html">
<f:textbox name="ant.antOpts" value="${instance.antOpts}"/>
<f:entry title="Build File" help="/help/ant/ant-buildfile.html">
<f:textbox name="ant.buildFile" value="${instance.buildFile}"/>
</f:entry>
<f:entry title="Properties" help="/help/ant/ant-properties.html">
<f:expandableTextbox name="ant.properties" value="${instance.properties}"/>
</f:entry>
<f:entry title="Java Options" help="/help/ant/ant-opts.html">
<f:expandableTextbox name="ant.antOpts" value="${instance.antOpts}"/>
</f:entry>
</f:advanced>
</j:jelly>
\ No newline at end of file
<div>
If your build requires a custom <a href="http://ant.apache.org/manual/running.html#options">-buildfile</a>,
specify it here. By default Ant will use the <code>build.xml</code> in the root directory,
this option can be used to use build files with a different name or in a subdirectory.
</div>
<div>
If your build requires a custom <a href="http://ant.apache.org/manual/running.html#envvars">ANT_OPTS</a>,
specify them here.
specify it here. Typically this may be used to specify java memory limits to use, for example <code>-Xmx512m</code>.
</div>
\ No newline at end of file
<div>
Properties needed by your ant build can be specified here in the standard properties file format:
<pre># Ant Project Properties
name=value
</pre>
</div>
<div>
For projects that use Ant as the build system. This causes Hudson to
invoke Ant with the given targets and options. Non-0 exit code from
Ant makes Hudson to mark the build as a failure.
invoke Ant with the given targets and options. Any non-zero exit code
causes Hudson to mark the build as a failure.
<p>
If your build script is located in somewhere other than the module top
<tt>build.xml</tt>, then you can use <a href="http://ant.apache.org/manual/running.html#options">
Ant's <tt>-f</tt> option</a> to specify where it is.
Hudson supplies some <a href='../../env-vars.html' target=_new>
environment variables</a> that can be used from within the build script.
</div>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册