FileDocCategorySizeDatePackage
DependScanner.javaAPI DocApache Ant 1.706404Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types.optional.depend

DependScanner

public class DependScanner extends org.apache.tools.ant.DirectoryScanner
DirectoryScanner for finding class dependencies.

Fields Summary
public static final String
DEFAULT_ANALYZER_CLASS
The name of the analyzer to use by default.
private Vector
rootClasses
The root classes to drive the search for dependent classes.
private Vector
included
The names of the classes to include in the fileset.
private org.apache.tools.ant.DirectoryScanner
parentScanner
The parent scanner which gives the basic set of files. Only files which are in this set and which can be reached from a root class will end up being included in the result set.
Constructors Summary
public DependScanner(org.apache.tools.ant.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.


                                                 
       
        this.parentScanner = parentScanner;
    
Methods Summary
public voidaddDefaultExcludes()

see
DirectoryScanner#addDefaultExcludes

    
public java.lang.String[]getExcludedDirectories()
{@inheritDoc}.

        return null;
    
public java.lang.String[]getExcludedFiles()
{@inheritDoc}.

        return null;
    
public java.lang.String[]getIncludedDirectories()
{@inheritDoc}.

        return new String[0];
    
public intgetIncludedDirsCount()
{@inheritDoc}.

        return 0;
    
public java.lang.String[]getIncludedFiles()
Get the names of the class files on which baseClass depends.

return
the names of the files.

        String[] files = new String[getIncludedFilesCount()];
        for (int i = 0; i < files.length; i++) {
            files[i] = (String) included.elementAt(i);
        }
        return files;
    
public synchronized intgetIncludedFilesCount()
{@inheritDoc}.

        if (included == null) {
            throw new IllegalStateException();
        }
        return included.size();
    
public java.lang.String[]getNotIncludedDirectories()
{@inheritDoc}.

        return null;
    
public java.lang.String[]getNotIncludedFiles()
{@inheritDoc}.

        return null;
    
public synchronized voidscan()
Scans the base directory for files on which baseClass depends.

exception
IllegalStateException when basedir was set incorrectly.

        included = new Vector();
        String analyzerClassName = DEFAULT_ANALYZER_CLASS;
        DependencyAnalyzer analyzer = null;
        try {
            Class analyzerClass = Class.forName(analyzerClassName);
            analyzer = (DependencyAnalyzer) analyzerClass.newInstance();
        } catch (Exception e) {
            throw new BuildException("Unable to load dependency analyzer: "
                + analyzerClassName, e);
        }
        analyzer.addClassPath(new Path(null, basedir.getPath()));

        for (Enumeration e = rootClasses.elements(); e.hasMoreElements();) {
            String rootClass = (String) e.nextElement();
            analyzer.addRootClass(rootClass);
        }
        Enumeration e = analyzer.getClassDependencies();

        String[] parentFiles = parentScanner.getIncludedFiles();
        Hashtable parentSet = new Hashtable();
        for (int i = 0; i < parentFiles.length; ++i) {
            parentSet.put(parentFiles[i], parentFiles[i]);
        }
        while (e.hasMoreElements()) {
            String classname = (String) e.nextElement();
            String filename = classname.replace('.", File.separatorChar);
            filename = filename + ".class";
            File depFile = new File(basedir, filename);
            if (depFile.exists() && parentSet.containsKey(filename)) {
                // This is included
                included.addElement(filename);
            }
        }
    
public voidsetCaseSensitive(boolean isCaseSensitive)
{@inheritDoc}.

    
public voidsetExcludes(java.lang.String[] excludes)
{@inheritDoc}.

    
public voidsetIncludes(java.lang.String[] includes)
{@inheritDoc}.

    
public synchronized voidsetRootClasses(java.util.Vector rootClasses)
Sets the root classes to be used to drive the scan.

param
rootClasses the rootClasses to be used for this scan.

        this.rootClasses = rootClasses;