Browse Source

Move addExisting functionality from javac to Path

Fix error in Path constructor


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267905 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 25 years ago
parent
commit
c2007a8479
2 changed files with 29 additions and 35 deletions
  1. +5
    -34
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  2. +24
    -1
      src/main/org/apache/tools/ant/types/Path.java

+ 5
- 34
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -387,32 +387,29 @@ public class Javac extends MatchingTask {
// add our classpath to the mix

if (compileClasspath != null) {
addExistingToClasspath(classpath,compileClasspath);
classpath.addExisting(compileClasspath);
}
addReferencesToPath(classpathReferences, classpath);

// add the system classpath

addExistingToClasspath(classpath, Path.systemClasspath);
classpath.addExisting(Path.systemClasspath);
if (addRuntime) {
if (Project.getJavaVersion() == Project.JAVA_1_1) {
addExistingToClasspath(classpath,
new Path(null,
classpath.addExisting(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(null,
classpath.addExisting(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(null,
classpath.addExisting(new Path(null,
System.getProperty("java.home")
+ File.separator +"jre"
+ File.separator + "lib"
@@ -423,32 +420,6 @@ public class Javac extends MatchingTask {
return classpath;
}


/**
* Takes a Path, and adds each element of
* another Path to a new classpath, if the components exist.
* Components that don't exist, aren't added.
* We do this, because jikes issues warnings for non-existant
* files/dirs in his classpath, and these warnings are pretty
* annoying.
* @param target - target classpath
* @param source - source classpath
* to get file objects.
*/
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);
} else {
log("Dropping from classpath: "+
f.getAbsolutePath(), Project.MSG_VERBOSE);
}
}
}

/**
* Peforms a compile using the classic compiler that shipped with
* JDK 1.1 and 1.2.


+ 24
- 1
src/main/org/apache/tools/ant/types/Path.java View File

@@ -130,7 +130,7 @@ public class Path implements Cloneable {
createPathElement().setPath(path);
}

public Path(Project p) {
public Path(Project project) {
this.project = project;
elements = new Vector();
}
@@ -190,6 +190,29 @@ public class Path implements Cloneable {
}
}

/**
* Adds the components on the given path which exist to this
* Path. Components that don't exist, aren't added.
*
* @param source - source path whose components are examined for existence
*/
public void addExisting(Path source) {
String[] list = source.list();
for (int i=0; i<list.length; i++) {
File f = null;
if (project != null) {
f = project.resolveFile(list[i]);
}
else {
f = new File(list[i]);
}

if (f.exists()) {
setLocation(f);
}
}
}

/**
* Returns all path elements defined by this and netsed path objects.
* @return list of path elements.


Loading…
Cancel
Save