@@ -111,9 +111,10 @@ public class Depend extends MatchingTask {
private Hashtable classFileInfoMap;
/**
* A map which gives the list of jars a class depends upon
* A map which gives the list of jars and classes from the classpath that
* a class depends upon
*/
private Hashtable classJar Dependencies;
private Hashtable classpath Dependencies;
/**
* The list of classes which are out of date.
@@ -133,32 +134,33 @@ public class Depend extends MatchingTask {
*/
private boolean dump = false;
private Path compileClasspath;
/** The classpath to look for additional dependencies */
private Path dependClasspath;
/**
* Set the classpath to be used for this compilation .
* Set the classpath to be used for this dependency check .
*/
public void setClasspath(Path classpath) {
if (compile Classpath == null) {
compile Classpath = classpath;
if (depend Classpath == null) {
depend Classpath = classpath;
} else {
compile Classpath.append(classpath);
depend Classpath.append(classpath);
}
}
/** Gets the classpath to be used for this compilation . */
/** Gets the classpath to be used for this dependency check . */
public Path getClasspath() {
return compile Classpath;
return depend Classpath;
}
/**
* Maybe c reates a nested classpath element.
* C reates a nested classpath element.
*/
public Path createClasspath() {
if (compile Classpath == null) {
compile Classpath = new Path(project);
if (depend Classpath == null) {
depend Classpath = new Path(project);
}
return compile Classpath.createPath();
return depend Classpath.createPath();
}
/**
@@ -167,9 +169,6 @@ public class Depend extends MatchingTask {
public void setClasspathRef(Reference r) {
createClasspath().setRefid(r);
}
private void writeDependencyList(File depFile, Vector dependencyList) throws IOException {
// new dependencies so need to write them out to the cache
@@ -279,44 +278,50 @@ public class Depend extends MatchingTask {
}
}
classJar Dependencies = null;
if (compile Classpath != null) {
classpath Dependencies = null;
if (depend Classpath != null) {
// now determine which jars each class depends upon
classJar Dependencies = new Hashtable();
AntClassLoader loader = new AntClassLoader(getProject(), compile Classpath);
Hashtable jar FileCache = new Hashtable();
Object nullJar File = new Object();
classpath Dependencies = new Hashtable();
AntClassLoader loader = new AntClassLoader(getProject(), depend Classpath);
Hashtable classpath FileCache = new Hashtable();
Object nullFileMarker = new Object();
for (Enumeration e = dependencyMap.keys(); e.hasMoreElements();) {
String className = (String)e.nextElement();
Vector dependencyList = (Vector)dependencyMap.get(className);
Hashtable jarD ependencies = new Hashtable();
classJarDependencies.put(className, jarD ependencies);
Hashtable d ependencies = new Hashtable();
classpathDependencies.put(className, d ependencies);
for (Enumeration e2 = dependencyList.elements(); e2.hasMoreElements();) {
String dependency =(String)e2.nextElement();
Object jarFileObject = jar FileCache.get(dependency);
if (jar FileObject == null) {
jarFileObject = nullJarFile ;
Object classpathFileObject = classpath FileCache.get(dependency);
if (classpath FileObject == null) {
classpathFileObject = nullFileMarker ;
if (!dependency.startsWith("java.") && !dependency.startsWith("javax.")) {
URL classURL = loader.getResource(dependency.replace('.', '/') + ".class");
if (classURL != null) {
String jarFilePath = classURL.getFile();
if (jarFilePath.startsWith("file:")) {
int classMarker = jarFilePath.indexOf('!');
jarFilePath = jarFilePath.substring(5, classMarker);
if (classURL.getProtocol().equals("jar")) {
String jarFilePath = classURL.getFile();
if (jarFilePath.startsWith("file:")) {
int classMarker = jarFilePath.indexOf('!');
jarFilePath = jarFilePath.substring(5, classMarker);
}
classpathFileObject = new File(jarFilePath);
}
else if (classURL.getProtocol().equals("file")) {
String classFilePath = classURL.getFile();
classpathFileObject = new File(classFilePath);
}
jarFileObject = new File(jarFilePath);
log("Class " + className +
" depends on " + jarFileObject +
" depends on " + classpath FileObject +
" due to " + dependency, Project.MSG_DEBUG);
}
}
jarFileCache.put(dependency, jar FileObject);
classpathFileCache.put(dependency, classpath FileObject);
}
if (jarFileObject != null && jarFileObject != nullJarFile ) {
if (classpathFileObject != null && classpathFileObject != nullFileMarker ) {
// we need to add this jar to the list for this class.
File jarFile = (File)jar FileObject;
jarD ependencies.put(jarFile, jarFile);
File jarFile = (File)classpath FileObject;
d ependencies.put(jarFile, jarFile);
}
}
}
@@ -423,15 +428,15 @@ public class Depend extends MatchingTask {
}
}
if (classJar Dependencies != null) {
log("Jar dependencies (Forward):", Project.MSG_DEBUG);
for (Enumeration e = classJar Dependencies.keys(); e.hasMoreElements();) {
if (classpath Dependencies != null) {
log("Classpath file dependencies (Forward):", Project.MSG_DEBUG);
for (Enumeration e = classpath Dependencies.keys(); e.hasMoreElements();) {
String className = (String)e.nextElement();
log(" Class " + className + " depends on:", Project.MSG_DEBUG);
Hashtable jarDependencies = (Hashtable)classJar Dependencies.get(className);
for (Enumeration e2 = jarD ependencies.elements(); e2.hasMoreElements();) {
File jar File = (File)e2.nextElement();
log(" " + jar File.getPath(), Project.MSG_DEBUG);
Hashtable dependencies = (Hashtable)classpath Dependencies.get(className);
for (Enumeration e2 = d ependencies.elements(); e2.hasMoreElements();) {
File classpath File = (File)e2.nextElement();
log(" " + classpath File.getPath(), Project.MSG_DEBUG);
}
}
}
@@ -450,18 +455,18 @@ public class Depend extends MatchingTask {
}
}
// now check jar dependencies
if (classJar Dependencies != null) {
for (Enumeration e = classJar Dependencies.keys(); e.hasMoreElements();) {
// now check classpath file dependencies
if (classpath Dependencies != null) {
for (Enumeration e = classpath Dependencies.keys(); e.hasMoreElements();) {
String className = (String)e.nextElement();
if (!outOfDateClasses.containsKey(className)) {
ClassFileInfo info = (ClassFileInfo)classFileInfoMap.get(className);
Hashtable jarDependencies = (Hashtable)classJar Dependencies.get(className);
for (Enumeration e2 = jarD ependencies.elements(); e2.hasMoreElements();) {
File jar File = (File)e2.nextElement();
if (jar File.lastModified() > info.absoluteFile.lastModified()) {
Hashtable dependencies = (Hashtable)classpath Dependencies.get(className);
for (Enumeration e2 = d ependencies.elements(); e2.hasMoreElements();) {
File classpath File = (File)e2.nextElement();
if (classpath File.lastModified() > info.absoluteFile.lastModified()) {
log("Class " + className +
" is out of date with respect to " + jar File, Project.MSG_DEBUG);
" is out of date with respect to " + classpath File, Project.MSG_DEBUG);
outOfDateClasses.put(className, className);
break;
}