FileDocCategorySizeDatePackage
AbstractAnalyzer.javaAPI DocApache Ant 1.7010033Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.util.depend

AbstractAnalyzer

public abstract class AbstractAnalyzer extends Object implements DependencyAnalyzer
An abstract implementation of the analyzer interface providing support for the bulk of interface methods.

Fields Summary
public static final int
MAX_LOOPS
Maximum number of loops for looking for indirect dependencies.
private org.apache.tools.ant.types.Path
sourcePath
The source path for the source files
private org.apache.tools.ant.types.Path
classPath
The classpath containg dirs and jars of class files
private Vector
rootClasses
The list of root classes
private boolean
determined
true if dependencies have been determined
private Vector
fileDependencies
the list of File objects that the root classes depend upon
private Vector
classDependencies
the list of java classes the root classes depend upon
private boolean
closure
true if indirect dependencies should be gathered
Constructors Summary
protected AbstractAnalyzer()
Setup the analyzer


        
      
        reset();
    
Methods Summary
public voidaddClassPath(org.apache.tools.ant.types.Path classPath)
Add a classpath to the classpath being used by the analyzer. The classpath contains the binary classfiles for the classes being analyzed The elements may either be the directories or jar files.Not all analyzers will use this information.

param
classPath the Path instance specifying the classpath elements

        if (classPath == null) {
            return;
        }

        this.classPath.append(classPath);
        this.classPath.setProject(classPath.getProject());
    
public voidaddRootClass(java.lang.String className)
Add a root class. The root classes are used to drive the determination of dependency information. The analyzer will start at the root classes and add dependencies from there.

param
className the name of the class in Java dot notation.

        if (className == null) {
            return;
        }
        if (!rootClasses.contains(className)) {
            rootClasses.addElement(className);
        }
    
public voidaddSourcePath(org.apache.tools.ant.types.Path sourcePath)
Add a source path to the source path used by this analyzer. The elements in the given path contain the source files for the classes being analyzed. Not all analyzers will use this information.

param
sourcePath The Path instance specifying the source path elements.

        if (sourcePath == null) {
            return;
        }
        this.sourcePath.append(sourcePath);
        this.sourcePath.setProject(sourcePath.getProject());
    
public voidconfig(java.lang.String name, java.lang.Object info)
Configure an aspect of the analyzer. The set of aspects that are supported is specific to each analyzer instance.

param
name the name of the aspect being configured
param
info the configuration info.

        // do nothing by default
    
protected abstract voiddetermineDependencies(java.util.Vector files, java.util.Vector classes)
Determine the dependencies of the current set of root classes

param
files a vector into which Files upon which the root classes depend should be placed.
param
classes a vector of Strings into which the names of classes upon which the root classes depend should be placed.

public java.io.FilegetClassContainer(java.lang.String classname)
Get the file that contains the class definition

param
classname the name of the required class
return
the file instance, zip or class, containing the class or null if the class could not be found.
exception
IOException if the files in the classpath cannot be read.

        String classLocation = classname.replace('.", '/") + ".class";
        // we look through the classpath elements. If the element is a dir
        // we look for the file. IF it is a zip, we look for the zip entry
        return getResourceContainer(classLocation, classPath.list());
    
public java.util.EnumerationgetClassDependencies()
Get the list of classes upon which root classes depend. This is a list of Java classnames in dot notation.

return
an enumeration of Strings, each being the name of a Java class in dot notation.

        if (!determined) {
            determineDependencies(fileDependencies, classDependencies);
        }
        return classDependencies.elements();
    
public java.util.EnumerationgetFileDependencies()
Get the list of files in the file system upon which the root classes depend. The files will be either the classfiles or jar files upon which the root classes depend.

return
an enumeration of File instances.

        if (!supportsFileDependencies()) {
            throw new RuntimeException("File dependencies are not supported "
                + "by this analyzer");
        }
        if (!determined) {
            determineDependencies(fileDependencies, classDependencies);
        }
        return fileDependencies.elements();
    
private java.io.FilegetResourceContainer(java.lang.String resourceLocation, java.lang.String[] paths)
Get the file that contains the resource

param
resourceLocation the name of the required resource.
param
paths the paths which will be searched for the resource.
return
the file instance, zip or class, containing the class or null if the class could not be found.
exception
IOException if the files in the given paths cannot be read.

        for (int i = 0; i < paths.length; ++i) {
            File element = new File(paths[i]);
            if (!element.exists()) {
                continue;
            }
            if (element.isDirectory()) {
                File resource = new File(element, resourceLocation);
                if (resource.exists()) {
                    return resource;
                }
            } else {
                // must be a zip of some sort
                ZipFile zipFile = null;
                try {
                    zipFile = new ZipFile(element);
                    if (zipFile.getEntry(resourceLocation) != null) {
                        return element;
                    }
                } finally {
                    if (zipFile != null) {
                        zipFile.close();
                    }
                }
            }
        }
        return null;
    
protected java.util.EnumerationgetRootClasses()
Get an enumeration of the root classes

return
an enumeration of Strings, each of which is a class name for a root class.

        return rootClasses.elements();
    
public java.io.FilegetSourceContainer(java.lang.String classname)
Get the file that contains the class source.

param
classname the name of the required class
return
the file instance, zip or java, containing the source or null if the source for the class could not be found.
exception
IOException if the files in the sourcepath cannot be read.

        String sourceLocation = classname.replace('.", '/") + ".java";

        // we look through the source path elements. If the element is a dir
        // we look for the file. If it is a zip, we look for the zip entry.
        // This isn't normal for source paths but we get it for free
        return getResourceContainer(sourceLocation, sourcePath.list());
    
protected booleanisClosureRequired()
Indicate if the analyzer is required to follow indirect class relationships.

return
true if indirect relationships should be followed.

        return closure;
    
public voidreset()
Reset the dependency list. This will reset the determined dependencies and the also list of root classes.

        rootClasses.removeAllElements();
        determined = false;
        fileDependencies = new Vector();
        classDependencies = new Vector();
    
public voidsetClosure(boolean closure)
Set the closure flag. If this flag is true the analyzer will traverse all class relationships until it has collected the entire set of direct and indirect dependencies

param
closure true if dependencies should be traversed to determine indirect dependencies.

        this.closure = closure;
    
protected abstract booleansupportsFileDependencies()
Indicate if the particular subclass supports file dependency information.

return
true if file dependencies are supported.