git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267882 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -250,7 +250,7 @@ | |||
| <target name="get.snapshot"> | |||
| <get src="http://jakarta.apache.org/build/tmp/ant/ant.src.zip" dest="ant-src.zip" /> | |||
| <expand src="ant-src.zip" dest="." /> | |||
| <unzip src="ant-src.zip" dest="." /> | |||
| </target> | |||
| <target name="make.snapshot"> | |||
| @@ -88,20 +88,20 @@ public class Cvs extends Task { | |||
| toExecute.setExecutable("cvs"); | |||
| if (cvsRoot != null) { | |||
| toExecute.addValue("-d"); | |||
| toExecute.addValue(cvsRoot); | |||
| toExecute.createArgument().setValue("-d"); | |||
| toExecute.createArgument().setValue(cvsRoot); | |||
| } | |||
| if (noexec) { | |||
| toExecute.addValue("-n"); | |||
| toExecute.createArgument().setValue("-n"); | |||
| } | |||
| if (quiet) { | |||
| toExecute.addValue("-q"); | |||
| toExecute.createArgument().setValue("-q"); | |||
| } | |||
| toExecute.addValue(command); | |||
| toExecute.addLine(cmd.getCommandline()); | |||
| toExecute.createArgument().setValue(command); | |||
| toExecute.addArguments(cmd.getCommandline()); | |||
| if (pack != null) { | |||
| toExecute.addValue(pack); | |||
| toExecute.createArgument().setValue(pack); | |||
| } | |||
| Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO, | |||
| @@ -141,16 +141,16 @@ public class Cvs extends Task { | |||
| public void setTag(String p) { | |||
| // Check if not real tag => set it to null | |||
| if (p != null && p.trim().length() > 0) { | |||
| cmd.addValue("-r"); | |||
| cmd.addValue(p); | |||
| cmd.createArgument().setValue("-r"); | |||
| cmd.createArgument().setValue(p); | |||
| } | |||
| } | |||
| public void setDate(String p) { | |||
| if(p != null && p.trim().length() > 0) { | |||
| cmd.addValue("-D"); | |||
| cmd.addValue(p); | |||
| cmd.createArgument().setValue("-D"); | |||
| cmd.createArgument().setValue(p); | |||
| } | |||
| } | |||
| @@ -135,7 +135,7 @@ public class ExecuteOn extends ExecTask { | |||
| String myos = System.getProperty("os.name"); | |||
| if (parallel) { | |||
| cmdl.addLine(s); | |||
| cmdl.addArguments(s); | |||
| exe.setCommandline(cmdl.getCommandline()); | |||
| err = exe.execute(); | |||
| if (err != 0) { | |||
| @@ -223,7 +223,7 @@ public class Javadoc extends Task { | |||
| } | |||
| public void setDestdir(File dir) { | |||
| cmd.createArgument().setValue("-d"); | |||
| cmd.createArgument().setValue(dir.getAbsolutePath()); | |||
| cmd.createArgument().setFile(dir); | |||
| destDir = dir; | |||
| } | |||
| public void setSourcefiles(String src) { | |||
| @@ -235,7 +235,7 @@ public class Javadoc extends Task { | |||
| public void setOverview(File f) { | |||
| if (!javadoc1) { | |||
| cmd.createArgument().setValue("-overview"); | |||
| cmd.createArgument().setValue(f.getAbsolutePath()); | |||
| cmd.createArgument().setFile(f); | |||
| } | |||
| } | |||
| public void setPublic(boolean b) { | |||
| @@ -400,13 +400,13 @@ public class Javadoc extends Task { | |||
| public void setStylesheetfile(File f) { | |||
| if (!javadoc1) { | |||
| cmd.createArgument().setValue("-stylesheetfile"); | |||
| cmd.createArgument().setValue(f.getAbsolutePath()); | |||
| cmd.createArgument().setFile(f); | |||
| } | |||
| } | |||
| public void setHelpfile(File f) { | |||
| if (!javadoc1) { | |||
| cmd.createArgument().setValue("-helpfile"); | |||
| cmd.createArgument().setValue(f.getAbsolutePath()); | |||
| cmd.createArgument().setFile(f); | |||
| } | |||
| } | |||
| public void setDocencoding(String enc) { | |||
| @@ -517,10 +517,10 @@ public class Javadoc extends Task { | |||
| if ( (!javadoc1) || (sourcePath == null) ) { | |||
| cmd.createArgument().setValue("-classpath"); | |||
| cmd.createArgument().setValue(classpath.toString()); | |||
| cmd.createArgument().setPath(classpath); | |||
| if (sourcePath != null) { | |||
| cmd.createArgument().setValue("-sourcepath"); | |||
| cmd.createArgument().setValue(sourcePath.toString()); | |||
| cmd.createArgument().setPath(sourcePath); | |||
| } | |||
| } else { | |||
| cmd.createArgument().setValue("-classpath"); | |||
| @@ -547,7 +547,7 @@ public class Javadoc extends Task { | |||
| cmd.createArgument().setValue(doclet.getName()); | |||
| if (doclet.getPath() != null) { | |||
| cmd.createArgument().setValue("-docletpath"); | |||
| cmd.createArgument().setValue(doclet.getPath().toString()); | |||
| cmd.createArgument().setPath(doclet.getPath()); | |||
| } | |||
| for (Enumeration e = doclet.getParams(); e.hasMoreElements();) { | |||
| DocletParam param = (DocletParam)e.nextElement(); | |||
| @@ -564,7 +564,7 @@ public class Javadoc extends Task { | |||
| } | |||
| if (bootclasspath != null) { | |||
| cmd.createArgument().setValue("-bootclasspath"); | |||
| cmd.createArgument().setValue(bootclasspath.toString()); | |||
| cmd.createArgument().setPath(bootclasspath); | |||
| } | |||
| // add the links arguments | |||
| @@ -573,7 +573,7 @@ public class Javadoc extends Task { | |||
| LinkArgument la = (LinkArgument)e.nextElement(); | |||
| if (la.getHref() == null) { | |||
| throw new BuildException("Links must provide the RUL to the external class documentation."); | |||
| throw new BuildException("Links must provide the URL to the external class documentation."); | |||
| } | |||
| if (la.isLinkOffline()) { | |||
| @@ -85,8 +85,8 @@ public class Patch extends Task { | |||
| throw new BuildException("patchfile "+file+" doesn\'t exist", | |||
| location); | |||
| } | |||
| cmd.addValue("-i"); | |||
| cmd.addValue(file.getAbsolutePath()); | |||
| cmd.createArgument().setValue("-i"); | |||
| cmd.createArgument().setFile(file); | |||
| havePatchfile = true; | |||
| } | |||
| @@ -95,7 +95,7 @@ public class Patch extends Task { | |||
| */ | |||
| public void setBackups(boolean backups) { | |||
| if (backups) { | |||
| cmd.addValue("-b"); | |||
| cmd.createArgument().setValue("-b"); | |||
| } | |||
| } | |||
| @@ -104,7 +104,7 @@ public class Patch extends Task { | |||
| */ | |||
| public void setIgnorewhitespace(boolean ignore) { | |||
| if (ignore) { | |||
| cmd.addValue("-l"); | |||
| cmd.createArgument().setValue("-l"); | |||
| } | |||
| } | |||
| @@ -118,7 +118,7 @@ public class Patch extends Task { | |||
| if (num < 0) { | |||
| throw new BuildException("strip has to be >= 0", location); | |||
| } | |||
| cmd.addValue("-p"+num); | |||
| cmd.createArgument().setValue("-p"+num); | |||
| } | |||
| /** | |||
| @@ -126,7 +126,7 @@ public class Patch extends Task { | |||
| */ | |||
| public void setQuiet(boolean q) { | |||
| if (q) { | |||
| cmd.addValue("-s"); | |||
| cmd.createArgument().setValue("-s"); | |||
| } | |||
| } | |||
| @@ -135,7 +135,7 @@ public class Patch extends Task { | |||
| */ | |||
| public void setReverse(boolean r) { | |||
| if (r) { | |||
| cmd.addValue("-R"); | |||
| cmd.createArgument().setValue("-R"); | |||
| } | |||
| } | |||
| @@ -148,7 +148,7 @@ public class Patch extends Task { | |||
| cmd.setExecutable("patch"); | |||
| if (originalFile != null) { | |||
| cmd.addValue(originalFile.getAbsolutePath()); | |||
| cmd.createArgument().setFile(originalFile); | |||
| } | |||
| Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO, | |||
| @@ -194,23 +194,23 @@ public class Cab extends MatchingTask { | |||
| { | |||
| Commandline command = new Commandline(); | |||
| command.setExecutable("cabarc"); | |||
| command.addValue("-r"); | |||
| command.addValue("-p"); | |||
| command.createArgument().setValue("-r"); | |||
| command.createArgument().setValue("-p"); | |||
| if (!doCompress) | |||
| { | |||
| command.addValue("-m"); | |||
| command.addValue("none"); | |||
| command.createArgument().setValue("-m"); | |||
| command.createArgument().setValue("none"); | |||
| } | |||
| if (cmdOptions != null) | |||
| { | |||
| command.addValue(cmdOptions); | |||
| command.createArgument().setValue(cmdOptions); | |||
| } | |||
| command.addValue("n"); | |||
| command.addValue(cabFile.getAbsolutePath()); | |||
| command.addValue("@" + listFile.getAbsolutePath()); | |||
| command.createArgument().setValue("n"); | |||
| command.createArgument().setFile(cabFile); | |||
| command.createArgument().setValue("@" + listFile.getAbsolutePath()); | |||
| return command; | |||
| } | |||
| @@ -224,8 +224,8 @@ public class JUnitTask extends Task { | |||
| // Create a watchdog based on the timeout attribute | |||
| final Execute execute = new Execute(new PumpStreamHandler(), createWatchdog()); | |||
| final Commandline cmdl = new Commandline(); | |||
| cmdl.addLine(commandline.getCommandline()); | |||
| cmdl.addLine(test.getCommandline()); | |||
| cmdl.addArguments(commandline.getCommandline()); | |||
| cmdl.addArguments(test.getCommandline()); | |||
| execute.setCommandline(cmdl.getCommandline()); | |||
| log("Execute JUnit: " + cmdl, Project.MSG_VERBOSE); | |||
| exitValue = execute.execute(); | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.types; | |||
| import org.apache.tools.ant.BuildException; | |||
| import java.io.File; | |||
| import java.util.Vector; | |||
| import java.util.StringTokenizer; | |||
| @@ -93,7 +94,7 @@ public class Commandline { | |||
| if (tmp != null && tmp.length > 0) { | |||
| setExecutable(tmp[0]); | |||
| for (int i=1; i<tmp.length; i++) { | |||
| addValue(tmp[i]); | |||
| createArgument().setValue(tmp[i]); | |||
| } | |||
| } | |||
| } | |||
| @@ -107,13 +108,16 @@ public class Commandline { | |||
| */ | |||
| public class Argument { | |||
| private String[] parts; | |||
| private Reference pathRef; | |||
| /** | |||
| * Sets a single commandline argument. | |||
| * | |||
| * @param value a single commandline argument. | |||
| */ | |||
| public void setValue(String value) { | |||
| Commandline.this.addValue(value); | |||
| parts = new String[] {value}; | |||
| } | |||
| /** | |||
| @@ -122,7 +126,35 @@ public class Commandline { | |||
| * @param line line to split into several commandline arguments | |||
| */ | |||
| public void setLine(String line) { | |||
| Commandline.this.addLine(translateCommandline(line)); | |||
| parts = translateCommandline(line); | |||
| } | |||
| /** | |||
| * Sets a single commandline argument and treats it like a | |||
| * PATH - ensures the right separator for the local platform | |||
| * is used. | |||
| * | |||
| * @param value a single commandline argument. | |||
| */ | |||
| public void setPath(Path value) { | |||
| parts = new String[] {value.toString()}; | |||
| } | |||
| /** | |||
| * Sets a single commandline argument to the absolute filename | |||
| * of the given file. | |||
| * | |||
| * @param value a single commandline argument. | |||
| */ | |||
| public void setFile(File value) { | |||
| parts = new String[] {value.getAbsolutePath()}; | |||
| } | |||
| /** | |||
| * Returns the parts this Argument consists of. | |||
| */ | |||
| public String[] getParts() { | |||
| return parts; | |||
| } | |||
| } | |||
| @@ -133,9 +165,8 @@ public class Commandline { | |||
| * @return the argument object. | |||
| */ | |||
| public Argument createArgument() { | |||
| if (argument == null) { | |||
| argument = new Argument(); | |||
| } | |||
| Argument argument = new Argument(); | |||
| definition.addElement(argument); | |||
| return argument; | |||
| } | |||
| @@ -154,25 +185,18 @@ public class Commandline { | |||
| } | |||
| public void addValue(String value) { | |||
| if (value == null || value.length() == 0) return; | |||
| definition.addElement(value); | |||
| } | |||
| public void addLine(String[] line) { | |||
| public void addArguments(String[] line) { | |||
| for (int i=0; i < line.length; i++) { | |||
| createArgument().setValue(line[i]); | |||
| } | |||
| } | |||
| /** | |||
| * Returns the executable and all defined arguments. | |||
| */ | |||
| public String[] getCommandline() { | |||
| if (executable == null) return getArguments(); | |||
| final String[] args = getArguments(); | |||
| if (executable == null) return args; | |||
| final String[] result = new String[args.length+1]; | |||
| result[0] = executable; | |||
| System.arraycopy(args, 0, result, 1, args.length); | |||
| @@ -185,10 +209,18 @@ public class Commandline { | |||
| * <code>addValue</code> or the argument object. | |||
| */ | |||
| public String[] getArguments() { | |||
| final String [] result; | |||
| result = new String[definition.size()]; | |||
| definition.copyInto(result); | |||
| return result; | |||
| Vector result = new Vector(definition.size()*2); | |||
| for (int i=0; i<definition.size(); i++) { | |||
| Argument arg = (Argument) definition.elementAt(i); | |||
| String[] s = arg.getParts(); | |||
| for (int j=0; j<s.length; j++) { | |||
| result.addElement(s[j]); | |||
| } | |||
| } | |||
| String [] res = new String[result.size()]; | |||
| result.copyInto(res); | |||
| return res; | |||
| } | |||
| @@ -294,7 +326,7 @@ public class Commandline { | |||
| } | |||
| public int size() { | |||
| return definition.size() + (executable == null ? 0 : 1); | |||
| return getCommandline().length; | |||
| } | |||
| } | |||
| @@ -85,6 +85,10 @@ public class Environment { | |||
| this.value = path.toString(); | |||
| } | |||
| public void setFile(java.io.File file) { | |||
| this.value = file.getAbsolutePath(); | |||
| } | |||
| public String getContent() throws BuildException { | |||
| if (key == null || value == null) { | |||
| throw new BuildException("key and value must be specified for environment variables."); | |||