I’m using ant tasks in my project to do a lot of things like creating directories, deleting files and so on. In this case I get a list of branches from my SVN-server, which works perfectly. This all happens during the runtime of my program, firing the tasks from out the java-code.
My question is: Is it possible to manipulate the ant-file (tasks.xml)? The user should enter username/password combination and when firing the task, these credentials should be used in my ant-task instead of the properties.
Ant-file:
<target name="getBranchList">
<exec executable="c:/svnclient/svn.exe"
output="c:/test/output/versionsonsvn.log">
<arg value="ls" />
<arg value="--username" />
<arg value="${svn.user}" />
<arg value="--password" />
<arg value="${svn.password}" />
<arg value="--non-interactive" />
<arg value="--trust-server-cert" />
<arg value="${svn.server}" />
</exec>
</target>
How I use it in Java:
import org.apache.tools.ant.*;
public static void main(final String[] args) {
Vector<String> v = new Vector<String>();
v.add("getBranchList");
v.add("someOtherTask");
fireAntTasks("c:/test/tasks.xml", v); }
private void fireAntTasks(String fileName, Vector<String> v) {
File taskFile = new File(fileName);
if (buildFile.exists()) {
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTargets(v);
} else {
System.out.println("File not found!");
}
}
The only solution I could imagine is to manipulate the file directly (setting the properties in “tasks.xml” during runtime). But maybe there is a better way to get this working…
Greetings
Christian
I’m not sure I completely understand you but I’m guessing your trying to get user input to replace some properties.
You can either use the Input Task which will prompt the user of which you can store into a variable.
Or you can load a properties file that the user edit before executing ant through the property task.