Browse Source

Did some cleanup.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267882 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
6d7c130971
9 changed files with 96 additions and 60 deletions
  1. +1
    -1
      build.xml
  2. +11
    -11
      src/main/org/apache/tools/ant/taskdefs/Cvs.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
  4. +9
    -9
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  5. +8
    -8
      src/main/org/apache/tools/ant/taskdefs/Patch.java
  6. +8
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
  7. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  8. +52
    -20
      src/main/org/apache/tools/ant/types/Commandline.java
  9. +4
    -0
      src/main/org/apache/tools/ant/types/Environment.java

+ 1
- 1
build.xml View File

@@ -250,7 +250,7 @@


<target name="get.snapshot"> <target name="get.snapshot">
<get src="http://jakarta.apache.org/build/tmp/ant/ant.src.zip" dest="ant-src.zip" /> <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>


<target name="make.snapshot"> <target name="make.snapshot">


+ 11
- 11
src/main/org/apache/tools/ant/taskdefs/Cvs.java View File

@@ -88,20 +88,20 @@ public class Cvs extends Task {


toExecute.setExecutable("cvs"); toExecute.setExecutable("cvs");
if (cvsRoot != null) { if (cvsRoot != null) {
toExecute.addValue("-d");
toExecute.addValue(cvsRoot);
toExecute.createArgument().setValue("-d");
toExecute.createArgument().setValue(cvsRoot);
} }
if (noexec) { if (noexec) {
toExecute.addValue("-n");
toExecute.createArgument().setValue("-n");
} }
if (quiet) { 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) { if (pack != null) {
toExecute.addValue(pack);
toExecute.createArgument().setValue(pack);
} }


Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
@@ -141,16 +141,16 @@ public class Cvs extends Task {
public void setTag(String p) { public void setTag(String p) {
// Check if not real tag => set it to null // Check if not real tag => set it to null
if (p != null && p.trim().length() > 0) { 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) { public void setDate(String p) {
if(p != null && p.trim().length() > 0) { if(p != null && p.trim().length() > 0) {
cmd.addValue("-D");
cmd.addValue(p);
cmd.createArgument().setValue("-D");
cmd.createArgument().setValue(p);
} }
} }




+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java View File

@@ -135,7 +135,7 @@ public class ExecuteOn extends ExecTask {
String myos = System.getProperty("os.name"); String myos = System.getProperty("os.name");


if (parallel) { if (parallel) {
cmdl.addLine(s);
cmdl.addArguments(s);
exe.setCommandline(cmdl.getCommandline()); exe.setCommandline(cmdl.getCommandline());
err = exe.execute(); err = exe.execute();
if (err != 0) { if (err != 0) {


+ 9
- 9
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -223,7 +223,7 @@ public class Javadoc extends Task {
} }
public void setDestdir(File dir) { public void setDestdir(File dir) {
cmd.createArgument().setValue("-d"); cmd.createArgument().setValue("-d");
cmd.createArgument().setValue(dir.getAbsolutePath());
cmd.createArgument().setFile(dir);
destDir = dir; destDir = dir;
} }
public void setSourcefiles(String src) { public void setSourcefiles(String src) {
@@ -235,7 +235,7 @@ public class Javadoc extends Task {
public void setOverview(File f) { public void setOverview(File f) {
if (!javadoc1) { if (!javadoc1) {
cmd.createArgument().setValue("-overview"); cmd.createArgument().setValue("-overview");
cmd.createArgument().setValue(f.getAbsolutePath());
cmd.createArgument().setFile(f);
} }
} }
public void setPublic(boolean b) { public void setPublic(boolean b) {
@@ -400,13 +400,13 @@ public class Javadoc extends Task {
public void setStylesheetfile(File f) { public void setStylesheetfile(File f) {
if (!javadoc1) { if (!javadoc1) {
cmd.createArgument().setValue("-stylesheetfile"); cmd.createArgument().setValue("-stylesheetfile");
cmd.createArgument().setValue(f.getAbsolutePath());
cmd.createArgument().setFile(f);
} }
} }
public void setHelpfile(File f) { public void setHelpfile(File f) {
if (!javadoc1) { if (!javadoc1) {
cmd.createArgument().setValue("-helpfile"); cmd.createArgument().setValue("-helpfile");
cmd.createArgument().setValue(f.getAbsolutePath());
cmd.createArgument().setFile(f);
} }
} }
public void setDocencoding(String enc) { public void setDocencoding(String enc) {
@@ -517,10 +517,10 @@ public class Javadoc extends Task {


if ( (!javadoc1) || (sourcePath == null) ) { if ( (!javadoc1) || (sourcePath == null) ) {
cmd.createArgument().setValue("-classpath"); cmd.createArgument().setValue("-classpath");
cmd.createArgument().setValue(classpath.toString());
cmd.createArgument().setPath(classpath);
if (sourcePath != null) { if (sourcePath != null) {
cmd.createArgument().setValue("-sourcepath"); cmd.createArgument().setValue("-sourcepath");
cmd.createArgument().setValue(sourcePath.toString());
cmd.createArgument().setPath(sourcePath);
} }
} else { } else {
cmd.createArgument().setValue("-classpath"); cmd.createArgument().setValue("-classpath");
@@ -547,7 +547,7 @@ public class Javadoc extends Task {
cmd.createArgument().setValue(doclet.getName()); cmd.createArgument().setValue(doclet.getName());
if (doclet.getPath() != null) { if (doclet.getPath() != null) {
cmd.createArgument().setValue("-docletpath"); cmd.createArgument().setValue("-docletpath");
cmd.createArgument().setValue(doclet.getPath().toString());
cmd.createArgument().setPath(doclet.getPath());
} }
for (Enumeration e = doclet.getParams(); e.hasMoreElements();) { for (Enumeration e = doclet.getParams(); e.hasMoreElements();) {
DocletParam param = (DocletParam)e.nextElement(); DocletParam param = (DocletParam)e.nextElement();
@@ -564,7 +564,7 @@ public class Javadoc extends Task {
} }
if (bootclasspath != null) { if (bootclasspath != null) {
cmd.createArgument().setValue("-bootclasspath"); cmd.createArgument().setValue("-bootclasspath");
cmd.createArgument().setValue(bootclasspath.toString());
cmd.createArgument().setPath(bootclasspath);
} }
// add the links arguments // add the links arguments
@@ -573,7 +573,7 @@ public class Javadoc extends Task {
LinkArgument la = (LinkArgument)e.nextElement(); LinkArgument la = (LinkArgument)e.nextElement();
if (la.getHref() == null) { 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()) { if (la.isLinkOffline()) {


+ 8
- 8
src/main/org/apache/tools/ant/taskdefs/Patch.java View File

@@ -85,8 +85,8 @@ public class Patch extends Task {
throw new BuildException("patchfile "+file+" doesn\'t exist", throw new BuildException("patchfile "+file+" doesn\'t exist",
location); location);
} }
cmd.addValue("-i");
cmd.addValue(file.getAbsolutePath());
cmd.createArgument().setValue("-i");
cmd.createArgument().setFile(file);
havePatchfile = true; havePatchfile = true;
} }


@@ -95,7 +95,7 @@ public class Patch extends Task {
*/ */
public void setBackups(boolean backups) { public void setBackups(boolean backups) {
if (backups) { if (backups) {
cmd.addValue("-b");
cmd.createArgument().setValue("-b");
} }
} }


@@ -104,7 +104,7 @@ public class Patch extends Task {
*/ */
public void setIgnorewhitespace(boolean ignore) { public void setIgnorewhitespace(boolean ignore) {
if (ignore) { if (ignore) {
cmd.addValue("-l");
cmd.createArgument().setValue("-l");
} }
} }


@@ -118,7 +118,7 @@ public class Patch extends Task {
if (num < 0) { if (num < 0) {
throw new BuildException("strip has to be >= 0", location); 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) { public void setQuiet(boolean q) {
if (q) { if (q) {
cmd.addValue("-s");
cmd.createArgument().setValue("-s");
} }
} }


@@ -135,7 +135,7 @@ public class Patch extends Task {
*/ */
public void setReverse(boolean r) { public void setReverse(boolean r) {
if (r) { if (r) {
cmd.addValue("-R");
cmd.createArgument().setValue("-R");
} }
} }


@@ -148,7 +148,7 @@ public class Patch extends Task {
cmd.setExecutable("patch"); cmd.setExecutable("patch");


if (originalFile != null) { if (originalFile != null) {
cmd.addValue(originalFile.getAbsolutePath());
cmd.createArgument().setFile(originalFile);
} }


Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,


+ 8
- 8
src/main/org/apache/tools/ant/taskdefs/optional/Cab.java View File

@@ -194,23 +194,23 @@ public class Cab extends MatchingTask {
{ {
Commandline command = new Commandline(); Commandline command = new Commandline();
command.setExecutable("cabarc"); command.setExecutable("cabarc");
command.addValue("-r");
command.addValue("-p");
command.createArgument().setValue("-r");
command.createArgument().setValue("-p");


if (!doCompress) if (!doCompress)
{ {
command.addValue("-m");
command.addValue("none");
command.createArgument().setValue("-m");
command.createArgument().setValue("none");
} }


if (cmdOptions != null) 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; return command;
} }


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -224,8 +224,8 @@ public class JUnitTask extends Task {
// Create a watchdog based on the timeout attribute // Create a watchdog based on the timeout attribute
final Execute execute = new Execute(new PumpStreamHandler(), createWatchdog()); final Execute execute = new Execute(new PumpStreamHandler(), createWatchdog());
final Commandline cmdl = new Commandline(); 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()); execute.setCommandline(cmdl.getCommandline());
log("Execute JUnit: " + cmdl, Project.MSG_VERBOSE); log("Execute JUnit: " + cmdl, Project.MSG_VERBOSE);
exitValue = execute.execute(); exitValue = execute.execute();


+ 52
- 20
src/main/org/apache/tools/ant/types/Commandline.java View File

@@ -55,6 +55,7 @@
package org.apache.tools.ant.types; package org.apache.tools.ant.types;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import java.io.File;
import java.util.Vector; import java.util.Vector;
import java.util.StringTokenizer; import java.util.StringTokenizer;


@@ -93,7 +94,7 @@ public class Commandline {
if (tmp != null && tmp.length > 0) { if (tmp != null && tmp.length > 0) {
setExecutable(tmp[0]); setExecutable(tmp[0]);
for (int i=1; i<tmp.length; i++) { 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 { public class Argument {


private String[] parts;
private Reference pathRef;

/** /**
* Sets a single commandline argument. * Sets a single commandline argument.
* *
* @param value a single commandline argument. * @param value a single commandline argument.
*/ */
public void setValue(String value) { 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 * @param line line to split into several commandline arguments
*/ */
public void setLine(String line) { 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. * @return the argument object.
*/ */
public Argument createArgument() { public Argument createArgument() {
if (argument == null) {
argument = new Argument();
}
Argument argument = new Argument();
definition.addElement(argument);
return 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++) { for (int i=0; i < line.length; i++) {
createArgument().setValue(line[i]); createArgument().setValue(line[i]);
} }
} }



/** /**
* Returns the executable and all defined arguments. * Returns the executable and all defined arguments.
*/ */
public String[] getCommandline() { public String[] getCommandline() {
if (executable == null) return getArguments();
final String[] args = getArguments(); final String[] args = getArguments();
if (executable == null) return args;
final String[] result = new String[args.length+1]; final String[] result = new String[args.length+1];
result[0] = executable; result[0] = executable;
System.arraycopy(args, 0, result, 1, args.length); System.arraycopy(args, 0, result, 1, args.length);
@@ -185,10 +209,18 @@ public class Commandline {
* <code>addValue</code> or the argument object. * <code>addValue</code> or the argument object.
*/ */
public String[] getArguments() { 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() { public int size() {
return definition.size() + (executable == null ? 0 : 1);
return getCommandline().length;
} }


} }

+ 4
- 0
src/main/org/apache/tools/ant/types/Environment.java View File

@@ -85,6 +85,10 @@ public class Environment {
this.value = path.toString(); this.value = path.toString();
} }


public void setFile(java.io.File file) {
this.value = file.getAbsolutePath();
}

public String getContent() throws BuildException { public String getContent() throws BuildException {
if (key == null || value == null) { if (key == null || value == null) {
throw new BuildException("key and value must be specified for environment variables."); throw new BuildException("key and value must be specified for environment variables.");


Loading…
Cancel
Save