Browse Source

Made Path resolve relative paths through Project. Moved it to the

types package on the same instance, so I had to touch a lot of ather
files as well.
Reported by:	Frederic Lavigne <fred@L2FProd.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267827 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
abd5987913
17 changed files with 109 additions and 212 deletions
  1. +1
    -1
      bootstrap.sh
  2. +0
    -1
      build.xml
  3. +3
    -2
      src/main/org/apache/tools/ant/AntClassLoader.java
  4. +12
    -0
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  5. +7
    -165
      src/main/org/apache/tools/ant/Path.java
  6. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
  7. +6
    -2
      src/main/org/apache/tools/ant/taskdefs/Java.java
  8. +16
    -10
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  9. +12
    -5
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  10. +8
    -4
      src/main/org/apache/tools/ant/taskdefs/Rmic.java
  11. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/DDCreator.java
  12. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java
  13. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLRun.java
  14. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLStop.java
  15. +10
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java
  16. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  17. +9
    -6
      src/main/org/apache/tools/ant/types/CommandlineJava.java

+ 1
- 1
bootstrap.sh View File

@@ -38,8 +38,8 @@ mkdir -p ${CLASSDIR}
echo ... Compiling Ant Classes

javac -d ${CLASSDIR} ${TOOLS}/tar/*.java
javac -d ${CLASSDIR} ${TOOLS}/ant/*.java
javac -d ${CLASSDIR} ${TOOLS}/ant/types/*.java
javac -d ${CLASSDIR} ${TOOLS}/ant/*.java
javac -d ${CLASSDIR} ${TOOLS}/ant/taskdefs/*.java

echo ... Copying Required Files


+ 0
- 1
build.xml View File

@@ -69,7 +69,6 @@
debug="on"
deprecation="off"
optimize="on" >
<exclude name="**/version.txt" />
<exclude name="**/Script.java" unless="bsf.present" />
<exclude name="**/NetRexxC.java" unless="netrexx.present" />
<exclude name="**/XslpLiaison.java" unless="xslp.present" />


+ 3
- 2
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -75,7 +75,7 @@ public class AntClassLoader extends ClassLoader {
/**
* The classpath that is to be used when loading classes using this class loader.
*/
private Path classpath;
private org.apache.tools.ant.types.Path classpath;
/**
* The project to which this class loader belongs.
@@ -93,7 +93,8 @@ public class AntClassLoader extends ClassLoader {
* @param project the project to ehich this classloader is to belong.
* @param classpath the classpath to use to load the classes.
*/
public AntClassLoader(Project project, Path classpath) {
public AntClassLoader(Project project,
org.apache.tools.ant.types.Path classpath) {
this.project = project;
this.classpath = classpath;
}


+ 12
- 0
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -54,6 +54,8 @@

package org.apache.tools.ant;

import org.apache.tools.ant.types.Path;

import java.lang.reflect.*;
import java.io.File;
import java.util.*;
@@ -447,6 +449,16 @@ public class IntrospectionHelper {

};

// resolve relative paths through Project
} else if (org.apache.tools.ant.types.Path.class.equals(arg)) {
return new AttributeSetter() {
public void set(Project p, Object parent, String value)
throws InvocationTargetException, IllegalAccessException {
m.invoke(parent, new Path[] {new Path(p, value)});
}

};

// EnumeratedAttributes have their own helper class
} else if (org.apache.tools.ant.EnumeratedAttribute.class.isAssignableFrom(arg)) {
return new AttributeSetter() {


+ 7
- 165
src/main/org/apache/tools/ant/Path.java View File

@@ -54,176 +54,18 @@

package org.apache.tools.ant;

import java.io.File;
import java.util.Vector;
import java.util.StringTokenizer;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;

/**
* This object represents a path as used by CLASSPATH or PATH
* environment variable.
*
* <code>
* &lt;sometask&gt;<br>
* &nbsp;&nbsp;&lt;somepath&gt;
* &nbsp;&nbsp;&nbsp;&nbsp;&lt;pathelement location="/path/to/file.jar" /&gt;
* &nbsp;&nbsp;&nbsp;&nbsp;&lt;pathelement path="/path/to/file2.jar:/path/to/class2;/path/to/class3" /&gt;
* &nbsp;&nbsp;&nbsp;&nbsp;&lt;pathelement location="/path/to/file3.jar" /&gt;
* &nbsp;&nbsp;&nbsp;&nbsp;&lt;pathelement location="/path/to/file4.jar" /&gt;
* &nbsp;&nbsp;&lt;/somepath&gt;
* &lt;/sometask&gt;<br>
* </code>
*
* The object implemention <code>sometask</code> must provide a method called
* <code>createSomepath</code> which returns an instance of <code>Path</code>.
* Nested path definitions are handled by the Path object and must be labeled
* <code>pathelement</code>.<p>
* This class has been moved to org.apache.tools.ant.types.
*
* The path element takes a parameter <code>path</code> which will be parsed
* and split into single elements. It will usually be used
* to define a path from an environment variable.
*
* @author Thomas.Haas@softwired-inc.com
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
* @deprecated This class has been moved to org.apache.tools.ant.types.
*/

public class Path {

private Vector definition;

public static Path systemClasspath =
new Path(System.getProperty("java.class.path"));

public Path(String path) {
this();
setPath(path);
}

public Path() {
definition = new Vector();
}

/**
* Adds a element definition to the path.
* @param location the location of the element to add (must not be
* <code>null</code> nor empty.
*/
public void setLocation(String location) {
if (location != null && location.length() > 0) {
String element = translateFile(location);
if (definition.indexOf(element) == -1) {
definition.addElement(element);
}
}
}


/**
* Append the contents of the other Path instance to this.
*/
public void append(Path other) {
String[] l = other.list();
for (int i=0; i<l.length; i++) {
if (definition.indexOf(l[i]) == -1) {
definition.addElement(l[i]);
}
}
}

/**
* Parses a path definition and creates single PathElements.
* @param path the path definition.
*/
public void setPath(String path) {
final Vector elements = translatePath(path);
for (int i=0; i < elements.size(); i++) {
String element = (String) elements.elementAt(i);
if (definition.indexOf(element) == -1) {
definition.addElement(element);
}
}
}


public Path createPathElement() {
return this;
}


/**
* Returns all path elements defined by this and netsed path objects.
* @return list of path elements.
*/
public String[] list() {
final String[] result = new String[definition.size()];
definition.copyInto(result);
return result;
}


/**
* Returns a textual representation of the path, which can be used as
* CLASSPATH or PATH environment variable definition.
* @return a textual representation of the path.
*/
public String toString() {
final String[] list = list();

// empty path return empty string
if (list.length == 0) return "";

// path containing one or more elements
final StringBuffer result = new StringBuffer(list[0].toString());
for (int i=1; i < list.length; i++) {
result.append(File.pathSeparatorChar);
result.append(list[i]);
}

return result.toString();
}



public static Vector translatePath(String source) {
final Vector result = new Vector();
if (source == null) return result;

PathTokenizer tok = new PathTokenizer(source);
StringBuffer element = new StringBuffer();
while (tok.hasMoreTokens()) {
element.setLength(0);
element.append(tok.nextToken());
for (int i=0; i<element.length(); i++) {
translateFileSep(element, i);
}
result.addElement(element.toString());
}
return result;
}


public static String translateFile(String source) {
if (source == null) return "";

final StringBuffer result = new StringBuffer(source);
for (int i=0; i < result.length(); i++) {
translateFileSep(result, i);
}

return result.toString();
}


protected static boolean translateFileSep(StringBuffer buffer, int pos) {
if (buffer.charAt(pos) == '/' || buffer.charAt(pos) == '\\') {
buffer.setCharAt(pos, File.separatorChar);
return true;
}
return false;
public class Path extends org.apache.tools.ant.types.Path {
public Path(Project p, String path) {
super(p, path);
}

public int size() {
return definition.size();
public Path(Project p) {
super(p);
}
}

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

@@ -56,7 +56,7 @@
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Path;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Commandline;

import java.lang.reflect.InvocationTargetException;


+ 6
- 2
src/main/org/apache/tools/ant/taskdefs/Java.java View File

@@ -54,7 +54,11 @@

package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.*;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;

import java.lang.reflect.*;
import java.util.*;

@@ -139,7 +143,7 @@ public class Java extends Exec {
*/
public Path createClasspath() {
if (classpath == null) {
classpath = new Path();
classpath = new Path(project);
}
return classpath;
}


+ 16
- 10
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -54,7 +54,10 @@

package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;

import java.lang.reflect.Method;
import java.io.*;
@@ -115,7 +118,7 @@ public class Javac extends MatchingTask {
*/
public Path createSrc() {
if (src != null) {
src = new Path();
src = new Path(project);
}
return src;
}
@@ -155,7 +158,7 @@ public class Javac extends MatchingTask {
*/
public Path createClasspath() {
if (compileClasspath == null) {
compileClasspath = new Path();
compileClasspath = new Path(project);
}
return compileClasspath;
}
@@ -177,7 +180,7 @@ public class Javac extends MatchingTask {
*/
public Path createBootclasspath() {
if (bootclasspath == null) {
bootclasspath = new Path();
bootclasspath = new Path(project);
}
return bootclasspath;
}
@@ -199,7 +202,7 @@ public class Javac extends MatchingTask {
*/
public Path createExtdirs() {
if (extdirs == null) {
extdirs = new Path();
extdirs = new Path(project);
}
return extdirs;
}
@@ -349,7 +352,7 @@ public class Javac extends MatchingTask {
* <code>classes.zip</code> be added to the classpath.
*/
private Path getCompileClasspath(boolean addRuntime) {
Path classpath = new Path();
Path classpath = new Path(project);

// add dest dir to classpath so that previously compiled and
// untouched classes are on classpath
@@ -368,20 +371,23 @@ public class Javac extends MatchingTask {
if (addRuntime) {
if (Project.getJavaVersion() == Project.JAVA_1_1) {
addExistingToClasspath(classpath,
new Path(System.getProperty("java.home")
new Path(null,
System.getProperty("java.home")
+ File.separator + "lib"
+ File.separator
+ "classes.zip"));
} else {
// JDK > 1.1 seems to set java.home to the JRE directory.
addExistingToClasspath(classpath,
new Path(System.getProperty("java.home")
new Path(null,
System.getProperty("java.home")
+ File.separator + "lib"
+ File.separator + "rt.jar"));
// Just keep the old version as well and let addExistingToPath
// sort it out.
addExistingToClasspath(classpath,
new Path(System.getProperty("java.home")
new Path(null,
System.getProperty("java.home")
+ File.separator +"jre"
+ File.separator + "lib"
+ File.separator + "rt.jar"));
@@ -608,7 +614,7 @@ public class Javac extends MatchingTask {
private void doJikesCompile() throws BuildException {
log("Using jikes compiler", Project.MSG_VERBOSE);

Path classpath = new Path();
Path classpath = new Path(project);

// Jikes doesn't support bootclasspath dir (-bootclasspath)
// so we'll emulate it for compatibility and convenience.


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

@@ -54,7 +54,10 @@

package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;

import java.io.*;
import java.util.*;
@@ -137,7 +140,7 @@ public class Javadoc extends Exec {
public Path createPath() {
if (path == null) {
path = new Path();
path = new Path(getProject());
}
return path;
}
@@ -219,7 +222,7 @@ public class Javadoc extends Exec {
}
public Path createSourcepath() {
if (sourcePath == null) {
sourcePath = new Path();
sourcePath = new Path(project);
}
return sourcePath;
}
@@ -278,7 +281,7 @@ public class Javadoc extends Exec {
}
public Path createClasspath() {
if (classpath == null) {
classpath = new Path();
classpath = new Path(project);
}
return classpath;
}
@@ -291,7 +294,7 @@ public class Javadoc extends Exec {
}
public Path createBootclasspath() {
if (bootclasspath == null) {
bootclasspath = new Path();
bootclasspath = new Path(project);
}
return bootclasspath;
}
@@ -448,6 +451,10 @@ public class Javadoc extends Exec {
}

public void execute() throws BuildException {
if ("javadoc2".equals(taskType)) {
log("!! javadoc2 is deprecated. Use javadoc instead. !!");
}

if (sourcePath == null || destDir == null ) {
String msg = "sourcePath and destDir attributes must be set!";
throw new BuildException(msg);


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

@@ -54,7 +54,11 @@

package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;

import java.io.*;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -136,7 +140,7 @@ public class Rmic extends MatchingTask {
*/
public Path createClasspath() {
if (compileClasspath == null) {
compileClasspath = new Path();
compileClasspath = new Path(project);
}
return compileClasspath;
}
@@ -368,7 +372,7 @@ public class Rmic extends MatchingTask {
private String getCompileClasspath(File baseFile) {
// add dest dir to classpath so that previously compiled and
// untouched classes are on classpath
Path classpath = new Path(baseFile.getAbsolutePath());
Path classpath = new Path(project, baseFile.getAbsolutePath());

// add our classpath to the mix

@@ -383,7 +387,7 @@ public class Rmic extends MatchingTask {
if (Project.getJavaVersion().startsWith("1.2")) {
String bootcp = System.getProperty("sun.boot.class.path");
if (bootcp != null) {
addExistingToClasspath(classpath, new Path(bootcp));
addExistingToClasspath(classpath, new Path(project, bootcp));
}
}
return classpath.toString();


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/optional/ejb/DDCreator.java View File

@@ -53,8 +53,11 @@
*/
package org.apache.tools.ant.taskdefs.optional.ejb;

import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.Path;

import java.io.File;

@@ -126,7 +129,7 @@ public class DDCreator extends MatchingTask {
ddCreatorTask.setFork("yes");
ddCreatorTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.DDCreatorHelper");
ddCreatorTask.setArgs(args);
ddCreatorTask.setClasspath(new Path(execClassPath));
ddCreatorTask.setClasspath(new Path(project, execClassPath));
if (ddCreatorTask.executeJava() != 0) {
throw new BuildException("Execution of ddcreator helper failed");
}


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java View File

@@ -54,8 +54,11 @@
package org.apache.tools.ant.taskdefs.optional.ejb;


import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.Path;

import java.io.File;

@@ -146,7 +149,7 @@ public class Ejbc extends MatchingTask {
}
helperTask.setArgs(args);
helperTask.setClasspath(new Path(execClassPath));
helperTask.setClasspath(new Path(project, execClassPath));
if (helperTask.executeJava() != 0) {
throw new BuildException("Execution of ejbc helper failed");
}


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLRun.java View File

@@ -54,8 +54,11 @@
package org.apache.tools.ant.taskdefs.optional.ejb;


import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.Path;

import java.io.File;

@@ -156,7 +159,7 @@ public class WLRun extends Task {
jvmArgs += " -Dweblogic.system.propertiesFile=" + weblogicPropertiesFile;

weblogicServer.setJvmargs(jvmArgs);
weblogicServer.setClasspath(new Path(execClassPath));
weblogicServer.setClasspath(new Path(project, execClassPath));
if (weblogicServer.executeJava() != 0) {
throw new BuildException("Execution of weblogic server failed");
}


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLStop.java View File

@@ -54,8 +54,11 @@
package org.apache.tools.ant.taskdefs.optional.ejb;


import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.Path;

import java.io.File;

@@ -116,7 +119,7 @@ public class WLStop extends Task {
String args = serverURL + " SHUTDOWN " + username + " " + password + " " + delay;

weblogicAdmin.setArgs(args);
weblogicAdmin.setClasspath(new Path(execClassPath));
weblogicAdmin.setClasspath(new Path(project, execClassPath));
weblogicAdmin.execute();
}


+ 10
- 3
src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java View File

@@ -54,10 +54,13 @@

package org.apache.tools.ant.taskdefs.optional.javacc;

import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Path;

import java.io.File;
import java.io.IOException;
@@ -68,7 +71,7 @@ import java.io.IOException;
*/
public class JavaCC extends Task {

private Path userclasspath = new Path();
private Path userclasspath = null;
private File metahome = null;
private File metaworkingdir = null;
private File target = null;
@@ -89,6 +92,10 @@ public class JavaCC extends Task {
}

public Path createUserclasspath() {
if (userclasspath == null) {
userclasspath = new Path(project);
}
return userclasspath;
}

@@ -126,7 +133,7 @@ public class JavaCC extends Task {
throw new BuildException("Userclasspath not set.");
}

final Path classpath = cmdl.createClasspath();
final Path classpath = cmdl.createClasspath(project);
classpath.createPathElement().setLocation(metahome.getAbsolutePath() + "/lib/metamatadebug.jar");
classpath.createPathElement().setLocation(metahome.getAbsolutePath() + "/lib/metamata.jar");
classpath.createPathElement().setLocation(metahome.getAbsolutePath() + "/lib/JavaCC.zip");


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

@@ -55,12 +55,12 @@
package org.apache.tools.ant.taskdefs.optional.junit;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Path;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Path;

import java.io.File;
import java.io.IOException;
@@ -104,7 +104,7 @@ public class JUnitTask extends Task {
* @param junit path to junit classes.
*/
public void setJunit(String junit) {
commandline.createClasspath().createPathElement().setLocation(junit);
commandline.createClasspath(project).createPathElement().setLocation(junit);
}

public void setDefaulthaltonerror(boolean value) {
@@ -155,7 +155,7 @@ public class JUnitTask extends Task {


public Path createClasspath() {
return commandline.createClasspath();
return commandline.createClasspath(project);
}

public JUnitTest createTest() {
@@ -189,7 +189,7 @@ public class JUnitTask extends Task {

final String oldclasspath = System.getProperty("java.class.path");

commandline.createClasspath().createPathElement().setPath(oldclasspath);
commandline.createClasspath(project).createPathElement().setPath(oldclasspath);
/*
* This doesn't work on JDK 1.1, should use a Classloader of our own
* anyway --SB


+ 9
- 6
src/main/org/apache/tools/ant/types/CommandlineJava.java View File

@@ -54,7 +54,7 @@

package org.apache.tools.ant.types;

import org.apache.tools.ant.Path;
import org.apache.tools.ant.Project;

/*
*
@@ -64,7 +64,7 @@ public class CommandlineJava {

private Commandline vmCommand = new Commandline();
private Commandline javaCommand = new Commandline();
private Path classpath = new Path();
private Path classpath = null;
private String vmVersion;


@@ -93,7 +93,10 @@ public class CommandlineJava {
javaCommand.setExecutable(classname);
}

public Path createClasspath() {
public Path createClasspath(Project p) {
if (classpath == null) {
classpath = new Path(p);
}
return classpath;
}

@@ -103,14 +106,14 @@ public class CommandlineJava {

public String[] getCommandline() {
int size = vmCommand.size() + javaCommand.size();
if (classpath.size() > 0) {
if (classpath != null && classpath.size() > 0) {
size += 2;
}
String[] result = new String[size];
System.arraycopy(vmCommand.getCommandline(), 0,
result, 0, vmCommand.size());
if (classpath.size() > 0) {
if (classpath != null && classpath.size() > 0) {
result[vmCommand.size()] = "-classpath";
result[vmCommand.size()+1] = classpath.toString();
}
@@ -127,7 +130,7 @@ public class CommandlineJava {

public int size() {
int size = vmCommand.size() + javaCommand.size();
if (classpath.size() > 0) {
if (classpath != null && classpath.size() > 0) {
size += 2;
}
return size;


Loading…
Cancel
Save