various PATH like structures. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267782 13f79535-47bb-0310-9956-ffa450edef68master
@@ -246,10 +246,13 @@ | |||
<javac srcdir="${src.tests.dir}" | |||
destdir="${build.tests}" | |||
classpath="${lib.dir}/${name}.jar:${classpath}" | |||
debug="on" | |||
deprecation="off" | |||
optimize="on" > | |||
<classpath> | |||
<pathelement location="${lib.dir}/${name}.jar" /> | |||
<pathelement path="${classpath}" /> | |||
</classpath> | |||
<include name="**/*.java"/> | |||
<exclude name="**/AllJUnitTests.java" unless="junit.present" /> | |||
<exclude name="**/EnumeratedAttributeTest.java" unless="junit.present" /> | |||
@@ -91,6 +91,9 @@ public class Path { | |||
private Vector definition; | |||
public static Path systemClasspath = | |||
new Path(System.getProperty("java.class.path")); | |||
public Path(String path) { | |||
this(); | |||
setPath(path); | |||
@@ -109,14 +109,14 @@ public class Javac extends MatchingTask { | |||
private Vector srcPathElements = new Vector(); | |||
private Vector srcDirs= new Vector(); | |||
private File destDir; | |||
private String compileClasspath; | |||
private Path compileClasspath; | |||
private boolean debug = false; | |||
private boolean optimize = false; | |||
private boolean deprecation = false; | |||
private boolean filtering = false; | |||
private String target; | |||
private String bootclasspath; | |||
private String extdirs; | |||
private Path bootclasspath; | |||
private Path extdirs; | |||
protected Vector compileList = new Vector(); | |||
protected Hashtable filecopyList = new Hashtable(); | |||
@@ -187,24 +187,66 @@ public class Javac extends MatchingTask { | |||
/** | |||
* Set the classpath to be used for this compilation. | |||
*/ | |||
public void setClasspath(String classpath) { | |||
compileClasspath = project.translatePath(classpath); | |||
public void setClasspath(Path classpath) { | |||
if (compileClasspath == null) { | |||
compileClasspath = classpath; | |||
} else { | |||
compileClasspath.append(classpath); | |||
} | |||
} | |||
/** | |||
* Maybe creates a nested classpath element. | |||
*/ | |||
public Path createClasspath() { | |||
if (compileClasspath == null) { | |||
compileClasspath = new Path(); | |||
} | |||
return compileClasspath; | |||
} | |||
/** | |||
* Sets the bootclasspath that will be used to compile the classes | |||
* against. | |||
*/ | |||
public void setBootclasspath(String bootclasspath) { | |||
this.bootclasspath = project.translatePath(bootclasspath); | |||
public void setBootclasspath(Path bootclasspath) { | |||
if (this.bootclasspath == null) { | |||
this.bootclasspath = bootclasspath; | |||
} else { | |||
this.bootclasspath.append(bootclasspath); | |||
} | |||
} | |||
/** | |||
* Maybe creates a nested classpath element. | |||
*/ | |||
public Path createBootclasspath() { | |||
if (bootclasspath == null) { | |||
bootclasspath = new Path(); | |||
} | |||
return bootclasspath; | |||
} | |||
/** | |||
* Sets the extension directories that will be used during the | |||
* compilation. | |||
*/ | |||
public void setExtdirs(String extdirs) { | |||
this.extdirs = project.translatePath(extdirs); | |||
public void setExtdirs(Path extdirs) { | |||
if (this.extdirs == null) { | |||
this.extdirs = extdirs; | |||
} else { | |||
this.extdirs.append(extdirs); | |||
} | |||
} | |||
/** | |||
* Maybe creates a nested classpath element. | |||
*/ | |||
public Path createExtdirs() { | |||
if (extdirs == null) { | |||
extdirs = new Path(); | |||
} | |||
return extdirs; | |||
} | |||
/** | |||
@@ -387,14 +429,14 @@ public class Javac extends MatchingTask { | |||
* <code>classes.zip</code> be added to the classpath. | |||
*/ | |||
private String getCompileClasspath(boolean addRuntime) { | |||
StringBuffer classpath = new StringBuffer(); | |||
Path classpath = new Path(); | |||
// add dest dir to classpath so that previously compiled and | |||
// untouched classes are on classpath | |||
//classpath.append(sourceDir.getAbsolutePath()); | |||
//classpath.append(File.pathSeparator); | |||
classpath.append(destDir.getAbsolutePath()); | |||
classpath.setLocation(destDir.getAbsolutePath()); | |||
// add our classpath to the mix | |||
@@ -404,26 +446,27 @@ public class Javac extends MatchingTask { | |||
// add the system classpath | |||
addExistingToClasspath(classpath,System.getProperty("java.class.path")); | |||
addExistingToClasspath(classpath, Path.systemClasspath); | |||
if (addRuntime) { | |||
if (Project.getJavaVersion() == Project.JAVA_1_1) { | |||
addExistingToClasspath(classpath, | |||
System.getProperty("java.home") | |||
+ File.separator + "lib" | |||
+ File.separator + "classes.zip"); | |||
new Path(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, | |||
System.getProperty("java.home") | |||
+ File.separator + "lib" | |||
+ File.separator + "rt.jar"); | |||
new Path(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, | |||
System.getProperty("java.home") | |||
+ File.separator +"jre" | |||
+ File.separator + "lib" | |||
+ File.separator + "rt.jar"); | |||
new Path(System.getProperty("java.home") | |||
+ File.separator +"jre" | |||
+ File.separator + "lib" | |||
+ File.separator + "rt.jar")); | |||
} | |||
} | |||
@@ -442,21 +485,18 @@ public class Javac extends MatchingTask { | |||
* @param source - source classpath | |||
* to get file objects. | |||
*/ | |||
private void addExistingToClasspath(StringBuffer target,String source) { | |||
StringTokenizer tok = new StringTokenizer(source, | |||
System.getProperty("path.separator"), false); | |||
while (tok.hasMoreTokens()) { | |||
File f = project.resolveFile(tok.nextToken()); | |||
if (f.exists()) { | |||
target.append(File.pathSeparator); | |||
target.append(f.getAbsolutePath()); | |||
private void addExistingToClasspath(Path target, Path source) { | |||
String[] list = source.list(); | |||
for (int i=0; i<list.length; i++) { | |||
File f = project.resolveFile(list[i]); | |||
if (f.exists()) { | |||
target.setLocation(f.getAbsolutePath()); | |||
} else { | |||
log("Dropping from classpath: "+ | |||
f.getAbsolutePath(), Project.MSG_VERBOSE); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
@@ -496,10 +536,10 @@ public class Javac extends MatchingTask { | |||
argList.addElement("-classpath"); | |||
// Just add "sourcepath" to classpath ( for JDK1.1 ) | |||
if (Project.getJavaVersion().startsWith("1.1")) { | |||
argList.addElement(classpath + File.pathSeparator + | |||
argList.addElement(classpath.toString() + File.pathSeparator + | |||
getSourcePath()); | |||
} else { | |||
argList.addElement(classpath); | |||
argList.addElement(classpath.toString()); | |||
argList.addElement("-sourcepath"); | |||
argList.addElement(getSourcePath()); | |||
if (target != null) { | |||
@@ -515,11 +555,11 @@ public class Javac extends MatchingTask { | |||
} | |||
if (bootclasspath != null) { | |||
argList.addElement("-bootclasspath"); | |||
argList.addElement(bootclasspath); | |||
argList.addElement(bootclasspath.toString()); | |||
} | |||
if (extdirs != null) { | |||
argList.addElement("-extdirs"); | |||
argList.addElement(extdirs); | |||
argList.addElement(extdirs.toString()); | |||
} | |||
log("Compilation args: " + argList.toString(), | |||
@@ -582,7 +622,7 @@ public class Javac extends MatchingTask { | |||
argList.addElement("-d"); | |||
argList.addElement(destDir.getAbsolutePath()); | |||
argList.addElement("-classpath"); | |||
argList.addElement(classpath); | |||
argList.addElement(classpath.toString()); | |||
argList.addElement("-sourcepath"); | |||
argList.addElement(getSourcePath()); | |||
if (target != null) { | |||
@@ -597,11 +637,11 @@ public class Javac extends MatchingTask { | |||
} | |||
if (bootclasspath != null) { | |||
argList.addElement("-bootclasspath"); | |||
argList.addElement(bootclasspath); | |||
argList.addElement(bootclasspath.toString()); | |||
} | |||
if (extdirs != null) { | |||
argList.addElement("-extdirs"); | |||
argList.addElement(extdirs); | |||
argList.addElement(extdirs.toString()); | |||
} | |||
log("Compilation args: " + argList.toString(), | |||
@@ -669,8 +709,7 @@ public class Javac extends MatchingTask { | |||
private void doJikesCompile() throws BuildException { | |||
log("Using jikes compiler", Project.MSG_VERBOSE); | |||
StringBuffer classpath = new StringBuffer(); | |||
classpath.append(getCompileClasspath(true)); | |||
Path classpath = new Path(getCompileClasspath(true)); | |||
// Jikes doesn't support an extension dir (-extdir) | |||
// so we'll emulate it for compatibility and convenience. | |||
@@ -678,8 +717,7 @@ public class Javac extends MatchingTask { | |||
// Jikes has no option for source-path so we | |||
// will add it to classpath. | |||
classpath.append(File.pathSeparator); | |||
classpath.append(getSourcePath()); | |||
classpath.setPath(getSourcePath()); | |||
Vector argList = new Vector(); | |||
@@ -797,23 +835,20 @@ public class Javac extends MatchingTask { | |||
* so that you don't have to specify them all one by one. | |||
* @param classpath - stringbuffer to append jar files to | |||
*/ | |||
private void addExtdirsToClasspath(StringBuffer classpath) { | |||
private void addExtdirsToClasspath(Path classpath) { | |||
// FIXME | |||
// Should we scan files recursively? How does | |||
// javac handle this? | |||
if (extdirs != null) { | |||
StringTokenizer tok = new StringTokenizer(extdirs, | |||
File.pathSeparator, | |||
false); | |||
while (tok.hasMoreTokens()) { | |||
File dir = project.resolveFile(tok.nextToken()); | |||
String[] list = extdirs.list(); | |||
for (int j=0; j<list.length; j++) { | |||
File dir = project.resolveFile(list[j]); | |||
String[] files = dir.list(new JarFilenameFilter()); | |||
for (int i=0 ; i < files.length ; i++) { | |||
File f = new File(dir,files[i]); | |||
if (f.exists() && f.isFile()) { | |||
classpath.append(File.pathSeparator); | |||
classpath.append(f.getAbsolutePath()); | |||
classpath.setLocation(f.getAbsolutePath()); | |||
} | |||
} | |||
} | |||
@@ -111,7 +111,7 @@ public class Javadoc extends Exec { | |||
public class DocletInfo { | |||
private String name; | |||
private String path; | |||
private Path path; | |||
private Vector params = new Vector(); | |||
@@ -123,15 +123,26 @@ public class Javadoc extends Exec { | |||
return name; | |||
} | |||
public void setPath(String path) { | |||
this.path = Project.translatePath(path); | |||
public void setPath(Path path) { | |||
if (this.path == null) { | |||
this.path = path; | |||
} else { | |||
this.path.append(path); | |||
} | |||
} | |||
public String getPath() { | |||
public Path getPath() { | |||
return path; | |||
} | |||
public Object createParam() { | |||
public Path createPath() { | |||
if (path == null) { | |||
path = new Path(); | |||
} | |||
return path; | |||
} | |||
public DocletParam createParam() { | |||
DocletParam param = new DocletParam(); | |||
params.addElement(param); | |||
@@ -144,7 +155,7 @@ public class Javadoc extends Exec { | |||
} | |||
private String maxmemory = null; | |||
private String sourcePath = null; | |||
private Path sourcePath = null; | |||
private String additionalParam = null; | |||
private File destDir = null; | |||
private File overviewFile = null; | |||
@@ -158,8 +169,8 @@ public class Javadoc extends Exec { | |||
private boolean version = true; | |||
private DocletInfo doclet = null; | |||
private boolean old = false; | |||
private String classpath = null; | |||
private String bootclasspath = null; | |||
private Path classpath = null; | |||
private Path bootclasspath = null; | |||
private String extdirs = null; | |||
private boolean verbose = false; | |||
private String locale = null; | |||
@@ -199,8 +210,18 @@ public class Javadoc extends Exec { | |||
additionalParam = src; | |||
} | |||
public void setSourcepath(String src) { | |||
sourcePath = project.translatePath(src); | |||
public void setSourcepath(Path src) { | |||
if (sourcePath == null) { | |||
sourcePath = src; | |||
} else { | |||
sourcePath.append(src); | |||
} | |||
} | |||
public Path createSourcepath() { | |||
if (sourcePath == null) { | |||
sourcePath = new Path(); | |||
} | |||
return sourcePath; | |||
} | |||
public void setDestdir(String src) { | |||
destDir = project.resolveFile(src); | |||
@@ -233,7 +254,7 @@ public class Javadoc extends Exec { | |||
doclet.setName(src); | |||
} | |||
public void setDocletPath(String src) { | |||
public void setDocletPath(Path src) { | |||
if (doclet == null) { | |||
doclet = new DocletInfo(); | |||
} | |||
@@ -248,11 +269,31 @@ public class Javadoc extends Exec { | |||
public void setOld(String src) { | |||
old = Project.toBoolean(src); | |||
} | |||
public void setClasspath(String src) { | |||
classpath = project.translatePath(src); | |||
public void setClasspath(Path src) { | |||
if (classpath == null) { | |||
classpath = src; | |||
} else { | |||
classpath.append(src); | |||
} | |||
} | |||
public Path createClasspath() { | |||
if (classpath == null) { | |||
classpath = new Path(); | |||
} | |||
return classpath; | |||
} | |||
public void setBootclasspath(String src) { | |||
bootclasspath = project.translatePath(src); | |||
public void setBootclasspath(Path src) { | |||
if (bootclasspath == null) { | |||
bootclasspath = src; | |||
} else { | |||
bootclasspath.append(src); | |||
} | |||
} | |||
public Path createBootclasspath() { | |||
if (bootclasspath == null) { | |||
bootclasspath = new Path(); | |||
} | |||
return bootclasspath; | |||
} | |||
public void setExtdirs(String src) { | |||
extdirs = src; | |||
@@ -420,7 +461,7 @@ public class Javadoc extends Exec { | |||
// ------------------------------------------------ general javadoc arguments | |||
if (classpath == null) | |||
classpath = System.getProperty("java.class.path"); | |||
classpath = Path.systemClasspath; | |||
if(maxmemory != null){ | |||
@@ -434,15 +475,15 @@ public class Javadoc extends Exec { | |||
if ( (!javadoc1) || (sourcePath == null) ) { | |||
argList.addElement("-classpath"); | |||
argList.addElement(classpath); | |||
argList.addElement(classpath.toString()); | |||
if (sourcePath != null) { | |||
argList.addElement("-sourcepath"); | |||
argList.addElement(sourcePath); | |||
argList.addElement(sourcePath.toString()); | |||
} | |||
} else { | |||
argList.addElement("-classpath"); | |||
argList.addElement(sourcePath + | |||
System.getProperty("path.separator") + classpath); | |||
argList.addElement(sourcePath.toString() + | |||
System.getProperty("path.separator") + classpath.toString()); | |||
} | |||
if (destDir != null) { | |||
@@ -510,7 +551,7 @@ public class Javadoc extends Exec { | |||
argList.addElement(doclet.getName()); | |||
if (doclet.getPath() != null) { | |||
argList.addElement("-docletpath"); | |||
argList.addElement(doclet.getPath()); | |||
argList.addElement(doclet.getPath().toString()); | |||
} | |||
for (Enumeration e = doclet.getParams(); e.hasMoreElements();) { | |||
DocletParam param = (DocletParam)e.nextElement(); | |||
@@ -527,7 +568,7 @@ public class Javadoc extends Exec { | |||
} | |||
if (bootclasspath != null) { | |||
argList.addElement("-bootclasspath"); | |||
argList.addElement(bootclasspath); | |||
argList.addElement(bootclasspath.toString()); | |||
} | |||
if (extdirs != null) { | |||
argList.addElement("-extdirs"); | |||
@@ -712,15 +753,15 @@ public class Javadoc extends Exec { | |||
* with the packages found in that path subdirs matching one of the given | |||
* patterns. | |||
*/ | |||
private void evaluatePackages(String sourcePath, Vector packages, Vector argList) { | |||
private void evaluatePackages(Path sourcePath, Vector packages, Vector argList) { | |||
log("Parsing source files for packages", Project.MSG_INFO); | |||
log("Source path = " + sourcePath, Project.MSG_VERBOSE); | |||
log("Source path = " + sourcePath.toString(), Project.MSG_VERBOSE); | |||
log("Packages = " + packages, Project.MSG_VERBOSE); | |||
Vector addedPackages = new Vector(); | |||
PathTokenizer tokenizer = new PathTokenizer(sourcePath); | |||
while (tokenizer.hasMoreTokens()) { | |||
File source = new File(project.translatePath(tokenizer.nextToken())); | |||
String[] list = sourcePath.list(); | |||
for (int j=0; j<list.length; j++) { | |||
File source = project.resolveFile(list[j]); | |||
Hashtable map = mapClasses(source); | |||
@@ -87,7 +87,7 @@ public class Rmic extends MatchingTask { | |||
private String classname; | |||
private String sourceBase; | |||
private String stubVersion; | |||
private String compileClasspath; | |||
private Path compileClasspath; | |||
private boolean verify = false; | |||
private boolean filtering = false; | |||
@@ -123,8 +123,22 @@ public class Rmic extends MatchingTask { | |||
/** | |||
* Set the classpath to be used for this compilation. | |||
*/ | |||
public void setClasspath(String classpath) { | |||
compileClasspath = project.translatePath(classpath); | |||
public void setClasspath(Path classpath) { | |||
if (compileClasspath == null) { | |||
compileClasspath = classpath; | |||
} else { | |||
compileClasspath.append(classpath); | |||
} | |||
} | |||
/** | |||
* Maybe creates a nesetd classpath element. | |||
*/ | |||
public Path createClasspath() { | |||
if (compileClasspath == null) { | |||
compileClasspath = new Path(); | |||
} | |||
return compileClasspath; | |||
} | |||
/** | |||
@@ -352,11 +366,9 @@ public class Rmic extends MatchingTask { | |||
// we need a way to not use the current classpath. | |||
private String getCompileClasspath(File baseFile) { | |||
StringBuffer classpath = new StringBuffer(); | |||
// add dest dir to classpath so that previously compiled and | |||
// untouched classes are on classpath | |||
classpath.append(baseFile.getAbsolutePath()); | |||
Path classpath = new Path(baseFile.getAbsolutePath()); | |||
// add our classpath to the mix | |||
@@ -365,14 +377,13 @@ public class Rmic extends MatchingTask { | |||
} | |||
// add the system classpath | |||
addExistingToClasspath(classpath, Path.systemClasspath); | |||
addExistingToClasspath(classpath,System.getProperty("java.class.path")); | |||
// in jdk 1.2, the system classes are not on the visible classpath. | |||
if (Project.getJavaVersion().startsWith("1.2")) { | |||
String bootcp = System.getProperty("sun.boot.class.path"); | |||
if (bootcp != null) { | |||
addExistingToClasspath(classpath, bootcp); | |||
addExistingToClasspath(classpath, new Path(bootcp)); | |||
} | |||
} | |||
return classpath.toString(); | |||
@@ -389,21 +400,18 @@ public class Rmic extends MatchingTask { | |||
* @param source - source classpath | |||
* to get file objects. | |||
*/ | |||
private void addExistingToClasspath(StringBuffer target,String source) { | |||
StringTokenizer tok = new StringTokenizer(source, | |||
System.getProperty("path.separator"), false); | |||
while (tok.hasMoreTokens()) { | |||
File f = project.resolveFile(tok.nextToken()); | |||
if (f.exists()) { | |||
target.append(File.pathSeparator); | |||
target.append(f.getAbsolutePath()); | |||
private void addExistingToClasspath(Path target, Path source) { | |||
String[] list = source.list(); | |||
for (int i=0; i<list.length; i++) { | |||
File f = project.resolveFile(list[i]); | |||
if (f.exists()) { | |||
target.setLocation(f.getAbsolutePath()); | |||
} else { | |||
log("Dropping from classpath: "+ | |||
f.getAbsolutePath(), Project.MSG_VERBOSE); | |||
} | |||
} | |||
} | |||
} | |||
} | |||