conor 02/04/08 06:57:06 Modified: src/main/org/apache/tools/ant/taskdefs/optional/depend Depend.java src/main/org/apache/tools/ant/types/optional/depend ClassfileSet.java DependScanner.java docs/manual/OptionalTypes classfileset.html Log: Add capability to classfileset to specify the root classes using a fileset Revision Changes Path 1.19 +33 -23 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java Index: Depend.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -w -u -r1.18 -r1.19 --- Depend.java 18 Mar 2002 02:44:29 -0000 1.18 +++ Depend.java 8 Apr 2002 13:57:05 -0000 1.19 @@ -86,16 +86,16 @@ */ private static class ClassFileInfo { /** The file where the class file is stored in the file system */ - public File absoluteFile; + private File absoluteFile; /** * The location of the file relative to its base directory - the * root of the package namespace */ - public String relativeName; + private String relativeName; /** The Java class name of this class */ - public String className; + private String className; } /** The path where source files exist */ @@ -142,9 +142,9 @@ private Path dependClasspath; /** constants used with the cache file */ - private final static String CACHE_FILE_NAME = "dependencies.txt"; + private static final String CACHE_FILE_NAME = "dependencies.txt"; /** String Used to separate classnames in the dependency file */ - private final static String CLASSNAME_PREPEND = "||:"; + private static final String CLASSNAME_PREPEND = "||:"; /** * Set the classpath to be used for this dependency check. @@ -300,8 +300,10 @@ Vector dependencyList = null; if (cache != null) { - // try to read the dependency info from the map if it is not out of date - if (depCacheFileExists && depCacheFileLastModified > info.absoluteFile.lastModified()) { + // try to read the dependency info from the map if it is + // not out of date + if (depCacheFileExists + && depCacheFileLastModified > info.absoluteFile.lastModified()) { // depFile exists and is newer than the class file // need to get dependency list from the map. dependencyList = (Vector)dependencyMap.get(info.className); @@ -333,7 +335,8 @@ for (Enumeration depEnum = dependencyList.elements(); depEnum.hasMoreElements(); ) { String dependentClass = (String)depEnum.nextElement(); - Hashtable affectedClasses = (Hashtable)affectedClassMap.get(dependentClass); + Hashtable affectedClasses + = (Hashtable)affectedClassMap.get(dependentClass); if (affectedClasses == null) { affectedClasses = new Hashtable(); affectedClassMap.put(dependentClass, affectedClasses); @@ -347,7 +350,8 @@ if (dependClasspath != null) { // now determine which jars each class depends upon classpathDependencies = new Hashtable(); - AntClassLoader loader = new AntClassLoader(getProject(), dependClasspath); + AntClassLoader loader + = new AntClassLoader(getProject(), dependClasspath); Hashtable classpathFileCache = new Hashtable(); Object nullFileMarker = new Object(); @@ -358,11 +362,13 @@ classpathDependencies.put(className, dependencies); for (Enumeration e2 = dependencyList.elements(); e2.hasMoreElements(); ) { String dependency = (String)e2.nextElement(); - Object classpathFileObject = classpathFileCache.get(dependency); + Object classpathFileObject + = classpathFileCache.get(dependency); if (classpathFileObject == null) { classpathFileObject = nullFileMarker; - if (!dependency.startsWith("java.") && !dependency.startsWith("javax.")) { + if (!dependency.startsWith("java.") + && !dependency.startsWith("javax.")) { URL classURL = loader.getResource(dependency.replace('.', '/') + ".class"); if (classURL != null) { if (classURL.getProtocol().equals("jar")) { @@ -409,7 +415,8 @@ for (Enumeration e = outOfDateClasses.elements(); e.hasMoreElements(); ) { String className = (String)e.nextElement(); count += deleteAffectedFiles(className); - ClassFileInfo classInfo = (ClassFileInfo)classFileInfoMap.get(className); + ClassFileInfo classInfo + = (ClassFileInfo)classFileInfoMap.get(className); if (classInfo != null && classInfo.absoluteFile.exists()) { classInfo.absoluteFile.delete(); count++; @@ -479,7 +486,8 @@ long start = System.currentTimeMillis(); String[] srcPathList = srcPath.list(); if (srcPathList.length == 0) { - throw new BuildException("srcdir attribute must be set!", location); + throw new BuildException("srcdir attribute must be set!", + location); } if (destPath == null) { @@ -487,7 +495,8 @@ } if (cache != null && cache.exists() && !cache.isDirectory()) { - throw new BuildException("The cache, if specified, must point to a directory"); + throw new BuildException("The cache, if specified, must " + + "point to a directory"); } if (cache != null && !cache.exists()) { @@ -525,7 +534,8 @@ } // we now need to scan for out of date files. When we have the list - // we go through and delete all class files which are affected by these files. + // we go through and delete all class files which are affected by + // these files. outOfDateClasses = new Hashtable(); for (int i = 0; i < srcPathList.length; i++) { File srcDir = (File)project.resolveFile(srcPathList[i]); 1.9 +37 -5 jakarta-ant/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java Index: ClassfileSet.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -u -r1.8 -r1.9 --- ClassfileSet.java 4 Apr 2002 15:40:45 -0000 1.8 +++ ClassfileSet.java 8 Apr 2002 13:57:05 -0000 1.9 @@ -53,14 +53,12 @@ */ package org.apache.tools.ant.types.optional.depend; - - import java.util.Vector; +import java.util.Enumeration; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.FileSet; - /** * A ClassfileSet is a FileSet, that enlists all classes that depend on a * certain set of root classes. @@ -80,6 +78,11 @@ private Vector rootClasses = new Vector(); /** + * The list of filesets which contain root classes + */ + private Vector rootFileSets = new Vector(); + + /** * Inner class used to contain info about root classes */ public static class ClassRoot { @@ -112,6 +115,17 @@ } /** + * Add a fileset to which contains a collection of root classes used to + * drive the search from classes + * + * @param rootFileSet a root file set to be used to search for dependent + * classes + */ + public void addRootFileset(FileSet rootFileSet) { + rootFileSets.addElement(rootFileSet); + } + + /** * Create a ClassfileSet from another ClassfileSet * * @param s the other classfileset @@ -142,10 +156,28 @@ return getRef(p).getDirectoryScanner(p); } + Vector allRootClasses = (Vector)rootClasses.clone(); + for (Enumeration e = rootFileSets.elements(); e.hasMoreElements();) { + FileSet additionalRootSet = (FileSet)e.nextElement(); + DirectoryScanner additionalScanner + = additionalRootSet.getDirectoryScanner(p); + String[] files = additionalScanner.getIncludedFiles(); + for (int i = 0; i < files.length; ++i) { + if (files[i].endsWith(".class")) { + String classFilePath + = files[i].substring(0, files[i].length() - 6); + String className + = classFilePath.replace('/', '.').replace('\\', '.'); + allRootClasses.addElement(className); + } + } + } + + DirectoryScanner parentScanner = super.getDirectoryScanner(p); DependScanner scanner = new DependScanner(parentScanner); scanner.setBasedir(getDir(p)); - scanner.setRootClasses(rootClasses); + scanner.setRootClasses(allRootClasses); scanner.scan(); return scanner; } 1.10 +8 -1 jakarta-ant/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java Index: DependScanner.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -w -u -r1.9 -r1.10 --- DependScanner.java 4 Apr 2002 13:59:19 -0000 1.9 +++ DependScanner.java 8 Apr 2002 13:57:05 -0000 1.10 @@ -99,6 +99,13 @@ */ private DirectoryScanner parentScanner; + /** + * Create a DependScanner, using the given scanner to provide the basic + * set of files from which class files come. + * + * @param parentScanner the DirectoryScanner which returns the files from + * which class files must come. + */ public DependScanner(DirectoryScanner parentScanner) { this.parentScanner = parentScanner; } 1.3 +17 -0 jakarta-ant/docs/manual/OptionalTypes/classfileset.html Index: classfileset.html =================================================================== RCS file: /home/cvs/jakarta-ant/docs/manual/OptionalTypes/classfileset.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -u -r1.2 -r1.3 --- classfileset.html 4 Apr 2002 13:32:02 -0000 1.2 +++ classfileset.html 8 Apr 2002 13:57:06 -0000 1.3 @@ -60,6 +60,14 @@ </tr> </table> +<h4>RootFileSet</h4> +<p> +A root fileset is used to add a set of root classes from a fileset. In this case the entries in +the fileset are expected to be Java class files. The name of the Java class is determined by the +relative location of the classfile in the fileset. So, the file +<code>org/apache/tools/ant/Project.class</code> corresponds to the Java class +<code>org.apache.tools.ant.Project</code>.</p> + <h4>Examples</h4> <blockquote><pre> <classfileset id="reqdClasses" dir="${classes.dir}"> @@ -77,6 +85,15 @@ <fileset refid="reqdClasses"/> </jar> </pre></blockquote> + +<blockquote><pre> +<classfileset id="reqdClasses" dir="${classes.dir}"> + <rootfileset dir="${classes.dir}" includes="org/apache/tools/ant/Project*.class" /> +</classfileset> +</pre></blockquote> + +<p>This example constructs the classfileset using all the class with names starting with Project +in the org.apache.tools.ant package</p> <hr> <p align="center">Copyright © 2002 Apache Software Foundation. All rights
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>