git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271118 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -63,52 +63,41 @@ import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool; | |||||
| import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPoolEntry; | import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPoolEntry; | ||||
| /** | /** | ||||
| * A ClassFile object stores information about a Java class. | |||||
| * | |||||
| * The class may be read from a DataInputStream.and written | |||||
| * to a DataOutputStream. These are usually streams from a Java | |||||
| * class file or a class file component of a Jar file. | |||||
| * A ClassFile object stores information about a Java class. The class may | |||||
| * be read from a DataInputStream.and written to a DataOutputStream. These | |||||
| * are usually streams from a Java class file or a class file component of a | |||||
| * Jar file. | |||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| public class ClassFile { | public class ClassFile { | ||||
| /** | |||||
| * The Magic Value that marks the start of a Java class file | |||||
| */ | |||||
| /** The Magic Value that marks the start of a Java class file */ | |||||
| private final static int CLASS_MAGIC = 0xCAFEBABE; | private final static int CLASS_MAGIC = 0xCAFEBABE; | ||||
| /** | |||||
| * This class' constant pool. | |||||
| */ | |||||
| /** This class' constant pool. */ | |||||
| private ConstantPool constantPool; | private ConstantPool constantPool; | ||||
| /** | |||||
| * The class name for this class. | |||||
| */ | |||||
| /** The class name for this class. */ | |||||
| private String className; | private String className; | ||||
| /** | /** | ||||
| * Read the class from a data stream. | |||||
| * Read the class from a data stream. This method takes an InputStream | |||||
| * as input and parses the class from the stream. <p> | |||||
| * | * | ||||
| * This method takes an InputStream as input and | |||||
| * parses the class from the stream. | |||||
| * <p> | |||||
| * | |||||
| * @param stream an InputStream from which the class will be read | |||||
| * | * | ||||
| * @throws IOException if there is a problem reading from the given stream. | |||||
| * @throws ClassFormatError if the class cannot be parsed correctly | |||||
| * | * | ||||
| * @param stream an InputStream from which the class will be read | |||||
| * @exception IOException if there is a problem reading from the given | |||||
| * stream. | |||||
| * @exception ClassFormatError if the class cannot be parsed correctly | |||||
| */ | */ | ||||
| public void read(InputStream stream) throws IOException, ClassFormatError { | public void read(InputStream stream) throws IOException, ClassFormatError { | ||||
| DataInputStream classStream = new DataInputStream(stream); | DataInputStream classStream = new DataInputStream(stream); | ||||
| if (classStream.readInt() != CLASS_MAGIC) { | if (classStream.readInt() != CLASS_MAGIC) { | ||||
| throw new ClassFormatError("No Magic Code Found - probably not a Java class file."); | |||||
| throw new ClassFormatError("No Magic Code Found " | |||||
| + "- probably not a Java class file."); | |||||
| } | } | ||||
| // right we have a good looking class file. | // right we have a good looking class file. | ||||
| @@ -124,12 +113,16 @@ public class ClassFile { | |||||
| int accessFlags = classStream.readUnsignedShort(); | int accessFlags = classStream.readUnsignedShort(); | ||||
| int thisClassIndex = classStream.readUnsignedShort(); | int thisClassIndex = classStream.readUnsignedShort(); | ||||
| int superClassIndex = classStream.readUnsignedShort(); | int superClassIndex = classStream.readUnsignedShort(); | ||||
| className = ((ClassCPInfo) constantPool.getEntry(thisClassIndex)).getClassName(); | |||||
| ClassCPInfo classInfo | |||||
| = (ClassCPInfo)constantPool.getEntry(thisClassIndex); | |||||
| className = classInfo.getClassName(); | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the classes which this class references. | * Get the classes which this class references. | ||||
| * | |||||
| * @return a vector of class names which this class references | |||||
| */ | */ | ||||
| public Vector getClassRefs() { | public Vector getClassRefs() { | ||||
| @@ -138,8 +131,9 @@ public class ClassFile { | |||||
| for (int i = 0; i < constantPool.size(); ++i) { | for (int i = 0; i < constantPool.size(); ++i) { | ||||
| ConstantPoolEntry entry = constantPool.getEntry(i); | ConstantPoolEntry entry = constantPool.getEntry(i); | ||||
| if (entry != null && entry.getTag() == ConstantPoolEntry.CONSTANT_Class) { | |||||
| ClassCPInfo classEntry = (ClassCPInfo) entry; | |||||
| if (entry != null | |||||
| && entry.getTag() == ConstantPoolEntry.CONSTANT_CLASS) { | |||||
| ClassCPInfo classEntry = (ClassCPInfo)entry; | |||||
| if (!classEntry.getClassName().equals(className)) { | if (!classEntry.getClassName().equals(className)) { | ||||
| classRefs.addElement(ClassFileUtils.convertSlashName(classEntry.getClassName())); | classRefs.addElement(ClassFileUtils.convertSlashName(classEntry.getClassName())); | ||||
| @@ -53,8 +53,18 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.optional.depend; | package org.apache.tools.ant.taskdefs.optional.depend; | ||||
| /** | |||||
| * Iterator interface for iterating over a set of class files | |||||
| * | |||||
| * @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||||
| */ | |||||
| public interface ClassFileIterator { | public interface ClassFileIterator { | ||||
| /** | |||||
| * Get the next class file in the iteration | |||||
| * | |||||
| * @return the next class file in the iterationr | |||||
| */ | |||||
| ClassFile getNextClassFile(); | ClassFile getNextClassFile(); | ||||
| } | } | ||||
| @@ -54,13 +54,12 @@ | |||||
| package org.apache.tools.ant.taskdefs.optional.depend; | package org.apache.tools.ant.taskdefs.optional.depend; | ||||
| /** | /** | ||||
| * Utility class file routines. | |||||
| * | |||||
| * This class porovides a number of static utility methods to convert between the | |||||
| * formats used in the Java class file format and those commonly used in Java | |||||
| * programming. | |||||
| * Utility class file routines. This class provides a number of static | |||||
| * utility methods to convert between the formats used in the Java class | |||||
| * file format and those commonly used in Java programming. | |||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| * | |||||
| */ | */ | ||||
| public class ClassFileUtils { | public class ClassFileUtils { | ||||
| @@ -68,8 +67,7 @@ public class ClassFileUtils { | |||||
| * Convert a class name from class file slash notation to java source | * Convert a class name from class file slash notation to java source | ||||
| * file dot notation. | * file dot notation. | ||||
| * | * | ||||
| * @param slashName the class name in slash notation (eg. java/lang/Object) | |||||
| * | |||||
| * @param name the class name in slash notation org/apache/ant | |||||
| * @return the class name in dot notation (eg. java.lang.Object). | * @return the class name in dot notation (eg. java.lang.Object). | ||||
| */ | */ | ||||
| public static String convertSlashName(String name) { | public static String convertSlashName(String name) { | ||||
| @@ -77,10 +75,10 @@ public class ClassFileUtils { | |||||
| } | } | ||||
| /** | /** | ||||
| * Convert a class name from java source file dot notation to class file slash notation.. | |||||
| * Convert a class name from java source file dot notation to class file | |||||
| * slash notation.. | |||||
| * | * | ||||
| * @param dotName the class name in dot notation (eg. java.lang.Object). | * @param dotName the class name in dot notation (eg. java.lang.Object). | ||||
| * | |||||
| * @return the class name in slash notation (eg. java/lang/Object). | * @return the class name in slash notation (eg. java/lang/Object). | ||||
| */ | */ | ||||
| public static String convertDotName(String dotName) { | public static String convertDotName(String dotName) { | ||||
| @@ -51,7 +51,6 @@ | |||||
| * information on the Apache Software Foundation, please see | * information on the Apache Software Foundation, please see | ||||
| * <http://www.apache.org/>. | * <http://www.apache.org/>. | ||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.optional.depend; | package org.apache.tools.ant.taskdefs.optional.depend; | ||||
| import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
| @@ -74,7 +73,6 @@ import org.apache.tools.ant.taskdefs.MatchingTask; | |||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.types.Reference; | import org.apache.tools.ant.types.Reference; | ||||
| /** | /** | ||||
| * Generate a dependency file for a given set of classes | * Generate a dependency file for a given set of classes | ||||
| * | * | ||||
| @@ -83,79 +81,76 @@ import org.apache.tools.ant.types.Reference; | |||||
| public class Depend extends MatchingTask { | public class Depend extends MatchingTask { | ||||
| /** | /** | ||||
| * A class (struct) user to manage information about a class | * A class (struct) user to manage information about a class | ||||
| * | |||||
| * @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||||
| */ | */ | ||||
| private static class ClassFileInfo { | private static class ClassFileInfo { | ||||
| /** The file where the class file is stored in the file system */ | /** The file where the class file is stored in the file system */ | ||||
| public File absoluteFile; | public File absoluteFile; | ||||
| /** The location of the file relative to its base directory - the root | |||||
| of the package namespace */ | |||||
| /** | |||||
| * The location of the file relative to its base directory - the | |||||
| * root of the package namespace | |||||
| */ | |||||
| public String relativeName; | public String relativeName; | ||||
| /** The Java class name of this class */ | /** The Java class name of this class */ | ||||
| public String className; | public String className; | ||||
| } | } | ||||
| /** | |||||
| * The path where source files exist | |||||
| */ | |||||
| /** The path where source files exist */ | |||||
| private Path srcPath; | private Path srcPath; | ||||
| /** | |||||
| * The path where compiled class files exist. | |||||
| */ | |||||
| /** The path where compiled class files exist. */ | |||||
| private Path destPath; | private Path destPath; | ||||
| /** | |||||
| * The directory which contains the dependency cache. | |||||
| */ | |||||
| /** The directory which contains the dependency cache. */ | |||||
| private File cache; | private File cache; | ||||
| /** | /** | ||||
| * A map which gives for every class a list of te class which it affects. | |||||
| * A map which gives for every class a list of te class which it | |||||
| * affects. | |||||
| */ | */ | ||||
| private Hashtable affectedClassMap; | private Hashtable affectedClassMap; | ||||
| /** | |||||
| * A map which gives information about a class | |||||
| */ | |||||
| /** A map which gives information about a class */ | |||||
| private Hashtable classFileInfoMap; | private Hashtable classFileInfoMap; | ||||
| /** | /** | ||||
| * A map which gives the list of jars and classes from the classpath that | |||||
| * a class depends upon | |||||
| * A map which gives the list of jars and classes from the classpath | |||||
| * that a class depends upon | |||||
| */ | */ | ||||
| private Hashtable classpathDependencies; | private Hashtable classpathDependencies; | ||||
| /** | |||||
| * The list of classes which are out of date. | |||||
| */ | |||||
| /** The list of classes which are out of date. */ | |||||
| private Hashtable outOfDateClasses; | private Hashtable outOfDateClasses; | ||||
| /** | /** | ||||
| * indicates that the dependency relationships should be extended | |||||
| * beyond direct dependencies to include all classes. So if A directly | |||||
| * affects B abd B directly affects C, then A indirectly affects C. | |||||
| * indicates that the dependency relationships should be extended beyond | |||||
| * direct dependencies to include all classes. So if A directly affects | |||||
| * B abd B directly affects C, then A indirectly affects C. | |||||
| */ | */ | ||||
| private boolean closure = false; | private boolean closure = false; | ||||
| /** | /** | ||||
| * Flag which controls whether the reversed dependencies should be dumped | |||||
| * to the log | |||||
| * Flag which controls whether the reversed dependencies should be | |||||
| * dumped to the log | |||||
| */ | */ | ||||
| private boolean dump = false; | private boolean dump = false; | ||||
| /** The classpath to look for additional dependencies */ | /** The classpath to look for additional dependencies */ | ||||
| private Path dependClasspath; | private Path dependClasspath; | ||||
| /** | |||||
| * constants used with the cache file | |||||
| */ | |||||
| /** constants used with the cache file */ | |||||
| private final static String CACHE_FILE_NAME = "dependencies.txt"; | private final static String CACHE_FILE_NAME = "dependencies.txt"; | ||||
| /** String Used to separate classnames in the dependency file */ | |||||
| private final static String CLASSNAME_PREPEND = "||:"; | private final static String CLASSNAME_PREPEND = "||:"; | ||||
| /** | /** | ||||
| * Set the classpath to be used for this dependency check. | * Set the classpath to be used for this dependency check. | ||||
| * | |||||
| * @param classpath the classpath to be used when checking for | |||||
| * dependencies on elements in the classpath | |||||
| */ | */ | ||||
| public void setClasspath(Path classpath) { | public void setClasspath(Path classpath) { | ||||
| if (dependClasspath == null) { | if (dependClasspath == null) { | ||||
| @@ -165,13 +160,19 @@ public class Depend extends MatchingTask { | |||||
| } | } | ||||
| } | } | ||||
| /** Gets the classpath to be used for this dependency check. */ | |||||
| /** | |||||
| * Gets the classpath to be used for this dependency check. | |||||
| * | |||||
| * @return the current dependency classpath | |||||
| */ | |||||
| public Path getClasspath() { | public Path getClasspath() { | ||||
| return dependClasspath; | return dependClasspath; | ||||
| } | } | ||||
| /** | /** | ||||
| * Creates a nested classpath element. | * Creates a nested classpath element. | ||||
| * | |||||
| * @return A path object to be configured by Ant | |||||
| */ | */ | ||||
| public Path createClasspath() { | public Path createClasspath() { | ||||
| if (dependClasspath == null) { | if (dependClasspath == null) { | ||||
| @@ -182,6 +183,9 @@ public class Depend extends MatchingTask { | |||||
| /** | /** | ||||
| * Adds a reference to a CLASSPATH defined elsewhere. | * Adds a reference to a CLASSPATH defined elsewhere. | ||||
| * | |||||
| * @param r a reference to a path object to be used as the depend | |||||
| * classpath | |||||
| */ | */ | ||||
| public void setClasspathRef(Reference r) { | public void setClasspathRef(Reference r) { | ||||
| createClasspath().setRefid(r); | createClasspath().setRefid(r); | ||||
| @@ -189,6 +193,9 @@ public class Depend extends MatchingTask { | |||||
| /** | /** | ||||
| * Read the dependencies from cache file | * Read the dependencies from cache file | ||||
| * | |||||
| * @return a collection of class dependencies | |||||
| * @exception IOException if the dependnecy file cannot be read | |||||
| */ | */ | ||||
| private Hashtable readCachedDependencies() throws IOException { | private Hashtable readCachedDependencies() throws IOException { | ||||
| Hashtable dependencyMap = new Hashtable(); | Hashtable dependencyMap = new Hashtable(); | ||||
| @@ -225,8 +232,12 @@ public class Depend extends MatchingTask { | |||||
| /** | /** | ||||
| * Write the dependencies to cache file | * Write the dependencies to cache file | ||||
| * | |||||
| * @param dependencyMap the map of dependencies to be written out. | |||||
| * @exception IOException if the dependency file cannot be written out. | |||||
| */ | */ | ||||
| private void writeCachedDependencies(Hashtable dependencyMap) throws IOException { | |||||
| private void writeCachedDependencies(Hashtable dependencyMap) | |||||
| throws IOException { | |||||
| if (cache != null) { | if (cache != null) { | ||||
| PrintWriter pw = null; | PrintWriter pw = null; | ||||
| try { | try { | ||||
| @@ -234,12 +245,14 @@ public class Depend extends MatchingTask { | |||||
| File depFile = new File(cache, CACHE_FILE_NAME); | File depFile = new File(cache, CACHE_FILE_NAME); | ||||
| pw = new PrintWriter(new FileWriter(depFile)); | pw = new PrintWriter(new FileWriter(depFile)); | ||||
| for (Enumeration deps = dependencyMap.keys(); deps.hasMoreElements();) { | |||||
| String className = (String) deps.nextElement(); | |||||
| Enumeration e = dependencyMap.keys(); | |||||
| while (e.hasMoreElements()) { | |||||
| String className = (String)e.nextElement(); | |||||
| pw.println(CLASSNAME_PREPEND + className); | pw.println(CLASSNAME_PREPEND + className); | ||||
| Vector dependencyList = (Vector) dependencyMap.get(className); | |||||
| Vector dependencyList | |||||
| = (Vector)dependencyMap.get(className); | |||||
| int size = dependencyList.size(); | int size = dependencyList.size(); | ||||
| for (int x = 0; x < size; x++) { | for (int x = 0; x < size; x++) { | ||||
| pw.println(dependencyList.elementAt(x)); | pw.println(dependencyList.elementAt(x)); | ||||
| @@ -255,10 +268,12 @@ public class Depend extends MatchingTask { | |||||
| /** | /** | ||||
| * Determine the dependencies between classes. | |||||
| * Determine the dependencies between classes. Class dependencies are | |||||
| * determined by examining the class references in a class file to other | |||||
| * classes | |||||
| * | * | ||||
| * Class dependencies are determined by examining the class references in a class file | |||||
| * to other classes | |||||
| * @exception IOException if either the dependnecies cache or the class | |||||
| * files cannot be read or written | |||||
| */ | */ | ||||
| private void determineDependencies() throws IOException { | private void determineDependencies() throws IOException { | ||||
| affectedClassMap = new Hashtable(); | affectedClassMap = new Hashtable(); | ||||
| @@ -277,8 +292,8 @@ public class Depend extends MatchingTask { | |||||
| depCacheFileExists = depCacheFile.exists(); | depCacheFileExists = depCacheFile.exists(); | ||||
| depCacheFileLastModified = depCacheFile.lastModified(); | depCacheFileLastModified = depCacheFile.lastModified(); | ||||
| } | } | ||||
| for (Enumeration e = getClassFiles(destPath).elements(); e.hasMoreElements();) { | |||||
| ClassFileInfo info = (ClassFileInfo) e.nextElement(); | |||||
| for (Enumeration e = getClassFiles(destPath).elements(); e.hasMoreElements(); ) { | |||||
| ClassFileInfo info = (ClassFileInfo)e.nextElement(); | |||||
| log("Adding class info for " + info.className, Project.MSG_DEBUG); | log("Adding class info for " + info.className, Project.MSG_DEBUG); | ||||
| classFileInfoMap.put(info.className, info); | classFileInfoMap.put(info.className, info); | ||||
| @@ -289,7 +304,7 @@ public class Depend extends MatchingTask { | |||||
| if (depCacheFileExists && depCacheFileLastModified > info.absoluteFile.lastModified()) { | if (depCacheFileExists && depCacheFileLastModified > info.absoluteFile.lastModified()) { | ||||
| // depFile exists and is newer than the class file | // depFile exists and is newer than the class file | ||||
| // need to get dependency list from the map. | // need to get dependency list from the map. | ||||
| dependencyList = (Vector) dependencyMap.get(info.className); | |||||
| dependencyList = (Vector)dependencyMap.get(info.className); | |||||
| } | } | ||||
| } | } | ||||
| @@ -306,7 +321,6 @@ public class Depend extends MatchingTask { | |||||
| cacheDirty = true; | cacheDirty = true; | ||||
| dependencyMap.put(info.className, dependencyList); | dependencyMap.put(info.className, dependencyList); | ||||
| } | } | ||||
| } finally { | } finally { | ||||
| if (inFileStream != null) { | if (inFileStream != null) { | ||||
| inFileStream.close(); | inFileStream.close(); | ||||
| @@ -316,10 +330,10 @@ public class Depend extends MatchingTask { | |||||
| // This class depends on each class in the dependency list. For each | // This class depends on each class in the dependency list. For each | ||||
| // one of those, add this class into their affected classes list | // one of those, add this class into their affected classes list | ||||
| for (Enumeration depEnum = dependencyList.elements(); depEnum.hasMoreElements();) { | |||||
| String dependentClass = (String) depEnum.nextElement(); | |||||
| 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) { | if (affectedClasses == null) { | ||||
| affectedClasses = new Hashtable(); | affectedClasses = new Hashtable(); | ||||
| affectedClassMap.put(dependentClass, affectedClasses); | affectedClassMap.put(dependentClass, affectedClasses); | ||||
| @@ -337,13 +351,13 @@ public class Depend extends MatchingTask { | |||||
| Hashtable classpathFileCache = new Hashtable(); | Hashtable classpathFileCache = new Hashtable(); | ||||
| Object nullFileMarker = new Object(); | Object nullFileMarker = new Object(); | ||||
| for (Enumeration e = dependencyMap.keys(); e.hasMoreElements();) { | |||||
| String className = (String) e.nextElement(); | |||||
| Vector dependencyList = (Vector) dependencyMap.get(className); | |||||
| for (Enumeration e = dependencyMap.keys(); e.hasMoreElements(); ) { | |||||
| String className = (String)e.nextElement(); | |||||
| Vector dependencyList = (Vector)dependencyMap.get(className); | |||||
| Hashtable dependencies = new Hashtable(); | Hashtable dependencies = new Hashtable(); | ||||
| classpathDependencies.put(className, dependencies); | classpathDependencies.put(className, dependencies); | ||||
| for (Enumeration e2 = dependencyList.elements(); e2.hasMoreElements();) { | |||||
| String dependency = (String) e2.nextElement(); | |||||
| 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) { | if (classpathFileObject == null) { | ||||
| classpathFileObject = nullFileMarker; | classpathFileObject = nullFileMarker; | ||||
| @@ -363,15 +377,15 @@ public class Depend extends MatchingTask { | |||||
| classpathFileObject = new File(classFilePath); | classpathFileObject = new File(classFilePath); | ||||
| } | } | ||||
| log("Class " + className + | log("Class " + className + | ||||
| " depends on " + classpathFileObject + | |||||
| " due to " + dependency, Project.MSG_DEBUG); | |||||
| " depends on " + classpathFileObject + | |||||
| " due to " + dependency, Project.MSG_DEBUG); | |||||
| } | } | ||||
| } | } | ||||
| classpathFileCache.put(dependency, classpathFileObject); | classpathFileCache.put(dependency, classpathFileObject); | ||||
| } | } | ||||
| if (classpathFileObject != null && classpathFileObject != nullFileMarker) { | if (classpathFileObject != null && classpathFileObject != nullFileMarker) { | ||||
| // we need to add this jar to the list for this class. | // we need to add this jar to the list for this class. | ||||
| File jarFile = (File) classpathFileObject; | |||||
| File jarFile = (File)classpathFileObject; | |||||
| dependencies.put(jarFile, jarFile); | dependencies.put(jarFile, jarFile); | ||||
| } | } | ||||
| } | } | ||||
| @@ -384,12 +398,18 @@ public class Depend extends MatchingTask { | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Delete all the class files which are out of date, by way of their | |||||
| * dependency on a class which is out of date | |||||
| * | |||||
| * @return the number of files deleted. | |||||
| */ | |||||
| private int deleteAllAffectedFiles() { | private int deleteAllAffectedFiles() { | ||||
| int count = 0; | int count = 0; | ||||
| for (Enumeration e = outOfDateClasses.elements(); e.hasMoreElements();) { | |||||
| String className = (String) e.nextElement(); | |||||
| for (Enumeration e = outOfDateClasses.elements(); e.hasMoreElements(); ) { | |||||
| String className = (String)e.nextElement(); | |||||
| count += deleteAffectedFiles(className); | count += deleteAffectedFiles(className); | ||||
| ClassFileInfo classInfo = (ClassFileInfo) classFileInfoMap.get(className); | |||||
| ClassFileInfo classInfo = (ClassFileInfo)classFileInfoMap.get(className); | |||||
| if (classInfo != null && classInfo.absoluteFile.exists()) { | if (classInfo != null && classInfo.absoluteFile.exists()) { | ||||
| classInfo.absoluteFile.delete(); | classInfo.absoluteFile.delete(); | ||||
| count++; | count++; | ||||
| @@ -398,17 +418,24 @@ public class Depend extends MatchingTask { | |||||
| return count; | return count; | ||||
| } | } | ||||
| /** | |||||
| * Delete all the class files of classes which depend on the given class | |||||
| * | |||||
| * @param className the name of the class whose dependent classes willbe | |||||
| * deleted | |||||
| * @return the number of class files removed | |||||
| */ | |||||
| private int deleteAffectedFiles(String className) { | private int deleteAffectedFiles(String className) { | ||||
| int count = 0; | int count = 0; | ||||
| Hashtable affectedClasses = (Hashtable) affectedClassMap.get(className); | |||||
| Hashtable affectedClasses = (Hashtable)affectedClassMap.get(className); | |||||
| if (affectedClasses != null) { | if (affectedClasses != null) { | ||||
| for (Enumeration e = affectedClasses.keys(); e.hasMoreElements();) { | |||||
| String affectedClassName = (String) e.nextElement(); | |||||
| ClassFileInfo affectedClassInfo = (ClassFileInfo) affectedClasses.get(affectedClassName); | |||||
| for (Enumeration e = affectedClasses.keys(); e.hasMoreElements(); ) { | |||||
| String affectedClassName = (String)e.nextElement(); | |||||
| ClassFileInfo affectedClassInfo = (ClassFileInfo)affectedClasses.get(affectedClassName); | |||||
| if (affectedClassInfo.absoluteFile.exists()) { | if (affectedClassInfo.absoluteFile.exists()) { | ||||
| log("Deleting file " + affectedClassInfo.absoluteFile.getPath() + " since " + | log("Deleting file " + affectedClassInfo.absoluteFile.getPath() + " since " + | ||||
| className + " out of date", Project.MSG_VERBOSE); | |||||
| className + " out of date", Project.MSG_VERBOSE); | |||||
| affectedClassInfo.absoluteFile.delete(); | affectedClassInfo.absoluteFile.delete(); | ||||
| count++; | count++; | ||||
| if (closure) { | if (closure) { | ||||
| @@ -420,14 +447,14 @@ public class Depend extends MatchingTask { | |||||
| if (affectedClassName.indexOf("$") != -1) { | if (affectedClassName.indexOf("$") != -1) { | ||||
| // need to delete the main class | // need to delete the main class | ||||
| String topLevelClassName | String topLevelClassName | ||||
| = affectedClassName.substring(0, affectedClassName.indexOf("$")); | |||||
| = affectedClassName.substring(0, affectedClassName.indexOf("$")); | |||||
| log("Top level class = " + topLevelClassName, Project.MSG_VERBOSE); | log("Top level class = " + topLevelClassName, Project.MSG_VERBOSE); | ||||
| ClassFileInfo topLevelClassInfo | ClassFileInfo topLevelClassInfo | ||||
| = (ClassFileInfo) classFileInfoMap.get(topLevelClassName); | |||||
| = (ClassFileInfo)classFileInfoMap.get(topLevelClassName); | |||||
| if (topLevelClassInfo != null && | if (topLevelClassInfo != null && | ||||
| topLevelClassInfo.absoluteFile.exists()) { | |||||
| topLevelClassInfo.absoluteFile.exists()) { | |||||
| log("Deleting file " + topLevelClassInfo.absoluteFile.getPath() + " since " + | log("Deleting file " + topLevelClassInfo.absoluteFile.getPath() + " since " + | ||||
| "one of its inner classes was removed", Project.MSG_VERBOSE); | |||||
| "one of its inner classes was removed", Project.MSG_VERBOSE); | |||||
| topLevelClassInfo.absoluteFile.delete(); | topLevelClassInfo.absoluteFile.delete(); | ||||
| count++; | count++; | ||||
| if (closure) { | if (closure) { | ||||
| @@ -445,7 +472,7 @@ public class Depend extends MatchingTask { | |||||
| /** | /** | ||||
| * Does the work. | * Does the work. | ||||
| * | * | ||||
| * @exception BuildException Thrown in unrecovrable error. | |||||
| * @exception BuildException Thrown in case of an unrecoverable error. | |||||
| */ | */ | ||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| try { | try { | ||||
| @@ -471,38 +498,37 @@ public class Depend extends MatchingTask { | |||||
| if (dump) { | if (dump) { | ||||
| log("Reverse Dependency Dump for " + affectedClassMap.size() + | log("Reverse Dependency Dump for " + affectedClassMap.size() + | ||||
| " classes:", Project.MSG_DEBUG); | |||||
| for (Enumeration e = affectedClassMap.keys(); e.hasMoreElements();) { | |||||
| String className = (String) e.nextElement(); | |||||
| " classes:", Project.MSG_DEBUG); | |||||
| for (Enumeration e = affectedClassMap.keys(); e.hasMoreElements(); ) { | |||||
| String className = (String)e.nextElement(); | |||||
| log(" Class " + className + " affects:", Project.MSG_DEBUG); | log(" Class " + className + " affects:", Project.MSG_DEBUG); | ||||
| Hashtable affectedClasses = (Hashtable) affectedClassMap.get(className); | |||||
| for (Enumeration e2 = affectedClasses.keys(); e2.hasMoreElements();) { | |||||
| String affectedClass = (String) e2.nextElement(); | |||||
| ClassFileInfo info = (ClassFileInfo) affectedClasses.get(affectedClass); | |||||
| Hashtable affectedClasses = (Hashtable)affectedClassMap.get(className); | |||||
| for (Enumeration e2 = affectedClasses.keys(); e2.hasMoreElements(); ) { | |||||
| String affectedClass = (String)e2.nextElement(); | |||||
| ClassFileInfo info = (ClassFileInfo)affectedClasses.get(affectedClass); | |||||
| log(" " + affectedClass + " in " + info.absoluteFile.getPath(), Project.MSG_DEBUG); | log(" " + affectedClass + " in " + info.absoluteFile.getPath(), Project.MSG_DEBUG); | ||||
| } | } | ||||
| } | } | ||||
| if (classpathDependencies != null) { | if (classpathDependencies != null) { | ||||
| log("Classpath file dependencies (Forward):", Project.MSG_DEBUG); | log("Classpath file dependencies (Forward):", Project.MSG_DEBUG); | ||||
| for (Enumeration e = classpathDependencies.keys(); e.hasMoreElements();) { | |||||
| String className = (String) e.nextElement(); | |||||
| for (Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) { | |||||
| String className = (String)e.nextElement(); | |||||
| log(" Class " + className + " depends on:", Project.MSG_DEBUG); | log(" Class " + className + " depends on:", Project.MSG_DEBUG); | ||||
| Hashtable dependencies = (Hashtable) classpathDependencies.get(className); | |||||
| for (Enumeration e2 = dependencies.elements(); e2.hasMoreElements();) { | |||||
| File classpathFile = (File) e2.nextElement(); | |||||
| Hashtable dependencies = (Hashtable)classpathDependencies.get(className); | |||||
| for (Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) { | |||||
| File classpathFile = (File)e2.nextElement(); | |||||
| log(" " + classpathFile.getPath(), Project.MSG_DEBUG); | log(" " + classpathFile.getPath(), Project.MSG_DEBUG); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| // we now need to scan for out of date files. When we have the list | // 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(); | outOfDateClasses = new Hashtable(); | ||||
| for (int i = 0; i < srcPathList.length; i++) { | for (int i = 0; i < srcPathList.length; i++) { | ||||
| File srcDir = (File) project.resolveFile(srcPathList[i]); | |||||
| File srcDir = (File)project.resolveFile(srcPathList[i]); | |||||
| if (srcDir.exists()) { | if (srcDir.exists()) { | ||||
| DirectoryScanner ds = this.getDirectoryScanner(srcDir); | DirectoryScanner ds = this.getDirectoryScanner(srcDir); | ||||
| String[] files = ds.getIncludedFiles(); | String[] files = ds.getIncludedFiles(); | ||||
| @@ -512,20 +538,20 @@ public class Depend extends MatchingTask { | |||||
| // now check classpath file dependencies | // now check classpath file dependencies | ||||
| if (classpathDependencies != null) { | if (classpathDependencies != null) { | ||||
| for (Enumeration e = classpathDependencies.keys(); e.hasMoreElements();) { | |||||
| String className = (String) e.nextElement(); | |||||
| for (Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) { | |||||
| String className = (String)e.nextElement(); | |||||
| if (!outOfDateClasses.containsKey(className)) { | if (!outOfDateClasses.containsKey(className)) { | ||||
| ClassFileInfo info = (ClassFileInfo) classFileInfoMap.get(className); | |||||
| ClassFileInfo info = (ClassFileInfo)classFileInfoMap.get(className); | |||||
| // if we have no info about the class - it may have been deleted already and we | // if we have no info about the class - it may have been deleted already and we | ||||
| // are using cached info. | // are using cached info. | ||||
| if (info != null) { | if (info != null) { | ||||
| Hashtable dependencies = (Hashtable) classpathDependencies.get(className); | |||||
| for (Enumeration e2 = dependencies.elements(); e2.hasMoreElements();) { | |||||
| File classpathFile = (File) e2.nextElement(); | |||||
| Hashtable dependencies = (Hashtable)classpathDependencies.get(className); | |||||
| for (Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) { | |||||
| File classpathFile = (File)e2.nextElement(); | |||||
| if (classpathFile.lastModified() > info.absoluteFile.lastModified()) { | if (classpathFile.lastModified() > info.absoluteFile.lastModified()) { | ||||
| log("Class " + className + | log("Class " + className + | ||||
| " is out of date with respect to " + classpathFile, Project.MSG_DEBUG); | |||||
| " is out of date with respect to " + classpathFile, Project.MSG_DEBUG); | |||||
| outOfDateClasses.put(className, className); | outOfDateClasses.put(className, className); | ||||
| break; | break; | ||||
| } | } | ||||
| @@ -547,8 +573,13 @@ public class Depend extends MatchingTask { | |||||
| } | } | ||||
| /** | /** | ||||
| * Scans the directory looking for source files that are newer than their class files. | |||||
| * The results are returned in the class variable compileList | |||||
| * Scans the directory looking for source files that are newer than | |||||
| * their class files. The results are returned in the class variable | |||||
| * compileList | |||||
| * | |||||
| * @param srcDir the source directory | |||||
| * @param files the names of the files in the source dir which are to be | |||||
| * checked. | |||||
| */ | */ | ||||
| protected void scanDir(File srcDir, String files[]) { | protected void scanDir(File srcDir, String files[]) { | ||||
| @@ -559,9 +590,9 @@ public class Depend extends MatchingTask { | |||||
| if (files[i].endsWith(".java")) { | if (files[i].endsWith(".java")) { | ||||
| String filePath = srcFile.getPath(); | String filePath = srcFile.getPath(); | ||||
| String className = filePath.substring(srcDir.getPath().length() + 1, | String className = filePath.substring(srcDir.getPath().length() + 1, | ||||
| filePath.length() - ".java".length()); | |||||
| filePath.length() - ".java".length()); | |||||
| className = ClassFileUtils.convertSlashName(className); | className = ClassFileUtils.convertSlashName(className); | ||||
| ClassFileInfo info = (ClassFileInfo) classFileInfoMap.get(className); | |||||
| ClassFileInfo info = (ClassFileInfo)classFileInfoMap.get(className); | |||||
| if (info == null) { | if (info == null) { | ||||
| // there was no class file. add this class to the list | // there was no class file. add this class to the list | ||||
| outOfDateClasses.put(className, className); | outOfDateClasses.put(className, className); | ||||
| @@ -579,7 +610,7 @@ public class Depend extends MatchingTask { | |||||
| * Get the list of class files we are going to analyse. | * Get the list of class files we are going to analyse. | ||||
| * | * | ||||
| * @param classLocations a path structure containing all the directories | * @param classLocations a path structure containing all the directories | ||||
| * where classes can be found. | |||||
| * where classes can be found. | |||||
| * @return a vector containing the classes to analyse. | * @return a vector containing the classes to analyse. | ||||
| */ | */ | ||||
| private Vector getClassFiles(Path classLocations) { | private Vector getClassFiles(Path classLocations) { | ||||
| @@ -599,12 +630,16 @@ public class Depend extends MatchingTask { | |||||
| } | } | ||||
| /** | /** | ||||
| * Add the list of class files from the given directory to the | |||||
| * class file vector, including any subdirectories. | |||||
| * Add the list of class files from the given directory to the class | |||||
| * file vector, including any subdirectories. | |||||
| * | * | ||||
| * @param classLocations a path structure containing all the directories | |||||
| * where classes can be found. | |||||
| * @return a vector containing the classes to analyse. | |||||
| * @param classFileList a list of ClassFileInfo objects for all the | |||||
| * files in the diretcort tree | |||||
| * @param dir tyhe directory tree to be searched, recursivley, for class | |||||
| * files | |||||
| * @param root the root of the source tree. This is used to determine | |||||
| * the absoluate class name from the relative position in the | |||||
| * source tree | |||||
| */ | */ | ||||
| private void addClassFiles(Vector classFileList, File dir, File root) { | private void addClassFiles(Vector classFileList, File dir, File root) { | ||||
| String[] filesInDir = dir.list(); | String[] filesInDir = dir.list(); | ||||
| @@ -620,7 +655,7 @@ public class Depend extends MatchingTask { | |||||
| ClassFileInfo info = new ClassFileInfo(); | ClassFileInfo info = new ClassFileInfo(); | ||||
| info.absoluteFile = file; | info.absoluteFile = file; | ||||
| info.relativeName = file.getPath().substring(root.getPath().length() + 1, | info.relativeName = file.getPath().substring(root.getPath().length() + 1, | ||||
| file.getPath().length() - 6); | |||||
| file.getPath().length() - 6); | |||||
| info.className = ClassFileUtils.convertSlashName(info.relativeName); | info.className = ClassFileUtils.convertSlashName(info.relativeName); | ||||
| classFileList.addElement(info); | classFileList.addElement(info); | ||||
| } | } | ||||
| @@ -631,6 +666,8 @@ public class Depend extends MatchingTask { | |||||
| /** | /** | ||||
| * Set the source dirs to find the source Java files. | * Set the source dirs to find the source Java files. | ||||
| * | |||||
| * @param srcPath the source path | |||||
| */ | */ | ||||
| public void setSrcdir(Path srcPath) { | public void setSrcdir(Path srcPath) { | ||||
| this.srcPath = srcPath; | this.srcPath = srcPath; | ||||
| @@ -638,21 +675,39 @@ public class Depend extends MatchingTask { | |||||
| /** | /** | ||||
| * Set the destination directory where the compiled java files exist. | * Set the destination directory where the compiled java files exist. | ||||
| * | |||||
| * @param destPath the destination areas where build files are written | |||||
| */ | */ | ||||
| public void setDestDir(Path destPath) { | public void setDestDir(Path destPath) { | ||||
| this.destPath = destPath; | this.destPath = destPath; | ||||
| } | } | ||||
| /** | |||||
| * Sets the dependency cache file | |||||
| * | |||||
| * @param cache the dependency cache file | |||||
| */ | |||||
| public void setCache(File cache) { | public void setCache(File cache) { | ||||
| this.cache = cache; | this.cache = cache; | ||||
| } | } | ||||
| /** | |||||
| * Set the closure flag. When not set, the depend task will only follow | |||||
| * direct dependencies between classes. When set, transitive | |||||
| * dependenecies are followed until the closure of the dependency set if | |||||
| * reached. | |||||
| * | |||||
| * @param closure indicate if dependency closure is required. | |||||
| */ | |||||
| public void setClosure(boolean closure) { | public void setClosure(boolean closure) { | ||||
| this.closure = closure; | this.closure = closure; | ||||
| } | } | ||||
| /** | /** | ||||
| * Flag to indicate whether the reverse dependency list should be dumped to debug | |||||
| * Flag to indicate whether the reverse dependency list should be dumped | |||||
| * to debug | |||||
| * | |||||
| * @param dump set to true to dump dependency information to the log | |||||
| */ | */ | ||||
| public void setDump(boolean dump) { | public void setDump(boolean dump) { | ||||
| this.dump = dump; | this.dump = dump; | ||||
| @@ -61,10 +61,9 @@ import java.util.Stack; | |||||
| import java.util.Vector; | import java.util.Vector; | ||||
| /** | /** | ||||
| * An iterator which iterates through the contents of a java directory. | |||||
| * | |||||
| * The iterator should be created with the directory at the root of the | |||||
| * Java namespace. | |||||
| * An iterator which iterates through the contents of a java directory. The | |||||
| * iterator should be created with the directory at the root of the Java | |||||
| * namespace. | |||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| @@ -78,32 +77,34 @@ public class DirectoryIterator implements ClassFileIterator { | |||||
| /** | /** | ||||
| * The current directory iterator. As directories encounter lower level | * The current directory iterator. As directories encounter lower level | ||||
| * directories, the current iterator is pushed onto the iterator | |||||
| * stack and a new iterator over the sub directory becomes the current | |||||
| * directory. This implements a depth first traversal of the directory namespace. | |||||
| * directories, the current iterator is pushed onto the iterator stack | |||||
| * and a new iterator over the sub directory becomes the current | |||||
| * directory. This implements a depth first traversal of the directory | |||||
| * namespace. | |||||
| */ | */ | ||||
| private Enumeration currentEnum; | private Enumeration currentEnum; | ||||
| /** | /** | ||||
| * The length of the root directory. This is used to remove the root directory | |||||
| * from full paths. | |||||
| * The length of the root directory. This is used to remove the root | |||||
| * directory from full paths. | |||||
| */ | */ | ||||
| int rootLength; | |||||
| private int rootLength; | |||||
| /** | /** | ||||
| * Creates a directory iterator. | |||||
| * | |||||
| * The directory iterator is created to scan the root directory. If the | |||||
| * changeInto flag is given, then the entries returned will be relative to this | |||||
| * directory and not the current directory. | |||||
| * | |||||
| * @param rootDirectory the root if the directory namespace which is to be iterated over | |||||
| * @param changeInto if true then the returned entries will be relative to the rootDirectory | |||||
| * and not the current directory. | |||||
| * Creates a directory iterator. The directory iterator is created to | |||||
| * scan the root directory. If the changeInto flag is given, then the | |||||
| * entries returned will be relative to this directory and not the | |||||
| * current directory. | |||||
| * | * | ||||
| * @throws IOException if there is a problem reading the directory information. | |||||
| * @param rootDirectory the root if the directory namespace which is to | |||||
| * be iterated over | |||||
| * @param changeInto if true then the returned entries will be relative | |||||
| * to the rootDirectory and not the current directory. | |||||
| * @exception IOException if there is a problem reading the directory | |||||
| * information. | |||||
| */ | */ | ||||
| public DirectoryIterator(File rootDirectory, boolean changeInto) throws IOException { | |||||
| public DirectoryIterator(File rootDirectory, boolean changeInto) | |||||
| throws IOException { | |||||
| super(); | super(); | ||||
| enumStack = new Stack(); | enumStack = new Stack(); | ||||
| @@ -120,11 +121,12 @@ public class DirectoryIterator implements ClassFileIterator { | |||||
| } | } | ||||
| /** | /** | ||||
| * Get a vector covering all the entries (files and subdirectories in a directory). | |||||
| * Get a vector covering all the entries (files and subdirectories in a | |||||
| * directory). | |||||
| * | * | ||||
| * @param directory the directory to be scanned. | * @param directory the directory to be scanned. | ||||
| * | |||||
| * @return a vector containing File objects for each entry in the directory. | |||||
| * @return a vector containing File objects for each entry in the | |||||
| * directory. | |||||
| */ | */ | ||||
| private Vector getDirectoryEntries(File directory) { | private Vector getDirectoryEntries(File directory) { | ||||
| Vector files = new Vector(); | Vector files = new Vector(); | ||||
| @@ -144,15 +146,16 @@ public class DirectoryIterator implements ClassFileIterator { | |||||
| } | } | ||||
| /** | /** | ||||
| * Template method to allow subclasses to supply elements for the iteration. | |||||
| * | |||||
| * The directory iterator maintains a stack of iterators covering each level | |||||
| * in the directory hierarchy. The current iterator covers the current directory | |||||
| * being scanned. If the next entry in that directory is a subdirectory, the current | |||||
| * iterator is pushed onto the stack and a new iterator is created for the | |||||
| * subdirectory. If the entry is a file, it is returned as the next element and the | |||||
| * iterator remains valid. If there are no more entries in the current directory, | |||||
| * the topmost iterator on the statck is popped off to become the current iterator. | |||||
| * Template method to allow subclasses to supply elements for the | |||||
| * iteration. The directory iterator maintains a stack of iterators | |||||
| * covering each level in the directory hierarchy. The current iterator | |||||
| * covers the current directory being scanned. If the next entry in that | |||||
| * directory is a subdirectory, the current iterator is pushed onto the | |||||
| * stack and a new iterator is created for the subdirectory. If the | |||||
| * entry is a file, it is returned as the next element and the iterator | |||||
| * remains valid. If there are no more entries in the current directory, | |||||
| * the topmost iterator on the statck is popped off to become the | |||||
| * current iterator. | |||||
| * | * | ||||
| * @return the next ClassFile in the iteration. | * @return the next ClassFile in the iteration. | ||||
| */ | */ | ||||
| @@ -162,7 +165,7 @@ public class DirectoryIterator implements ClassFileIterator { | |||||
| try { | try { | ||||
| while (nextElement == null) { | while (nextElement == null) { | ||||
| if (currentEnum.hasMoreElements()) { | if (currentEnum.hasMoreElements()) { | ||||
| File element = (File) currentEnum.nextElement(); | |||||
| File element = (File)currentEnum.nextElement(); | |||||
| if (element.isDirectory()) { | if (element.isDirectory()) { | ||||
| @@ -176,11 +179,13 @@ public class DirectoryIterator implements ClassFileIterator { | |||||
| } else { | } else { | ||||
| // we have a file. create a stream for it | // we have a file. create a stream for it | ||||
| FileInputStream inFileStream = new FileInputStream(element); | |||||
| FileInputStream inFileStream | |||||
| = new FileInputStream(element); | |||||
| if (element.getName().endsWith(".class")) { | if (element.getName().endsWith(".class")) { | ||||
| // create a data input stream from the jar input stream | |||||
| // create a data input stream from the jar | |||||
| // input stream | |||||
| ClassFile javaClass = new ClassFile(); | ClassFile javaClass = new ClassFile(); | ||||
| javaClass.read(inFileStream); | javaClass.read(inFileStream); | ||||
| @@ -193,7 +198,7 @@ public class DirectoryIterator implements ClassFileIterator { | |||||
| if (enumStack.empty()) { | if (enumStack.empty()) { | ||||
| break; | break; | ||||
| } else { | } else { | ||||
| currentEnum = (Enumeration) enumStack.pop(); | |||||
| currentEnum = (Enumeration)enumStack.pop(); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -60,19 +60,34 @@ import java.util.zip.ZipEntry; | |||||
| import java.util.zip.ZipInputStream; | import java.util.zip.ZipInputStream; | ||||
| /** | /** | ||||
| * A class file iterator which iterates through the contents of a Java jar file. | |||||
| * A class file iterator which iterates through the contents of a Java jar | |||||
| * file. | |||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| public class JarFileIterator implements ClassFileIterator { | public class JarFileIterator implements ClassFileIterator { | ||||
| /** The jar stream from the jar file being iterated over*/ | |||||
| private ZipInputStream jarStream; | private ZipInputStream jarStream; | ||||
| /** | |||||
| * Construct a iterartor over a jar stream | |||||
| * | |||||
| * @param stream the basic input stream from which the Jar is recived | |||||
| * @exception IOException if the jar stream connot be created | |||||
| */ | |||||
| public JarFileIterator(InputStream stream) throws IOException { | public JarFileIterator(InputStream stream) throws IOException { | ||||
| super(); | super(); | ||||
| jarStream = new ZipInputStream(stream); | jarStream = new ZipInputStream(stream); | ||||
| } | } | ||||
| /** | |||||
| * Read a stream into an array of bytes | |||||
| * | |||||
| * @param stream the stream from which the bytes are read | |||||
| * @return the stream's content as a byte array | |||||
| * @exception IOException if the stream cannot be read | |||||
| */ | |||||
| private byte[] getEntryBytes(InputStream stream) throws IOException { | private byte[] getEntryBytes(InputStream stream) throws IOException { | ||||
| byte[] buffer = new byte[8192]; | byte[] buffer = new byte[8192]; | ||||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); | ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); | ||||
| @@ -85,6 +100,11 @@ public class JarFileIterator implements ClassFileIterator { | |||||
| return baos.toByteArray(); | return baos.toByteArray(); | ||||
| } | } | ||||
| /** | |||||
| * Get the next ClassFile object from the jar | |||||
| * | |||||
| * @return a ClassFile object describing the class from the jar | |||||
| */ | |||||
| public ClassFile getNextClassFile() { | public ClassFile getNextClassFile() { | ||||
| ZipEntry jarEntry; | ZipEntry jarEntry; | ||||
| ClassFile nextElement = null; | ClassFile nextElement = null; | ||||
| @@ -92,7 +112,6 @@ public class JarFileIterator implements ClassFileIterator { | |||||
| try { | try { | ||||
| jarEntry = jarStream.getNextEntry(); | jarEntry = jarStream.getNextEntry(); | ||||
| while (nextElement == null && jarEntry != null) { | while (nextElement == null && jarEntry != null) { | ||||
| String entryName = jarEntry.getName(); | String entryName = jarEntry.getName(); | ||||
| @@ -56,7 +56,6 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||||
| import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| /** | /** | ||||
| * The constant pool entry which stores class information. | * The constant pool entry which stores class information. | ||||
| * | * | ||||
| @@ -65,33 +64,32 @@ import java.io.IOException; | |||||
| public class ClassCPInfo extends ConstantPoolEntry { | public class ClassCPInfo extends ConstantPoolEntry { | ||||
| /** | /** | ||||
| * The class' name. This will be only valid if the entry has been resolved | |||||
| * against the constant pool. | |||||
| * The class' name. This will be only valid if the entry has been | |||||
| * resolved against the constant pool. | |||||
| */ | */ | ||||
| private String className; | private String className; | ||||
| /** | /** | ||||
| * The index into the constant pool where this class' name is stored. If the class | |||||
| * name is changed, this entry is invalid until this entry is connected to a constant | |||||
| * pool. | |||||
| * The index into the constant pool where this class' name is stored. If | |||||
| * the class name is changed, this entry is invalid until this entry is | |||||
| * connected to a constant pool. | |||||
| */ | */ | ||||
| private int index; | private int index; | ||||
| /** | /** | ||||
| * Constructor. | |||||
| * | |||||
| * Sets the tag value for this entry to type Class | |||||
| * Constructor. Sets the tag value for this entry to type Class | |||||
| */ | */ | ||||
| public ClassCPInfo() { | public ClassCPInfo() { | ||||
| super(CONSTANT_Class, 1); | |||||
| super(CONSTANT_CLASS, 1); | |||||
| } | } | ||||
| /** | /** | ||||
| * Read the entry from a stream. | * Read the entry from a stream. | ||||
| * | * | ||||
| * @param cpStream the stream containing the constant pool entry to be read. | |||||
| * | |||||
| * @exception IOException thrown if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the stream containing the constant pool entry to be | |||||
| * read. | |||||
| * @exception IOException thrown if there is a problem reading the entry | |||||
| * from the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| index = cpStream.readUnsignedShort(); | index = cpStream.readUnsignedShort(); | ||||
| @@ -100,6 +98,8 @@ public class ClassCPInfo extends ConstantPoolEntry { | |||||
| /** | /** | ||||
| * Generate a string readable version of this entry | * Generate a string readable version of this entry | ||||
| * | |||||
| * @return string representation of this constant pool entry | |||||
| */ | */ | ||||
| public String toString() { | public String toString() { | ||||
| return "Class Constant Pool Entry for " + className + "[" + index + "]"; | return "Class Constant Pool Entry for " + className + "[" + index + "]"; | ||||
| @@ -108,10 +108,11 @@ public class ClassCPInfo extends ConstantPoolEntry { | |||||
| /** | /** | ||||
| * Resolve this class info against the given constant pool. | * Resolve this class info against the given constant pool. | ||||
| * | * | ||||
| * @param constantPool the constant pool with which to resolve the class. | |||||
| * @param constantPool the constant pool with which to resolve the | |||||
| * class. | |||||
| */ | */ | ||||
| public void resolve(ConstantPool constantPool) { | public void resolve(ConstantPool constantPool) { | ||||
| className = ((Utf8CPInfo) constantPool.getEntry(index)).getValue(); | |||||
| className = ((Utf8CPInfo)constantPool.getEntry(index)).getValue(); | |||||
| super.resolve(constantPool); | super.resolve(constantPool); | ||||
| } | } | ||||
| @@ -53,20 +53,17 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | ||||
| /** | /** | ||||
| * A Constant Pool entry which represents a constant value. | * A Constant Pool entry which represents a constant value. | ||||
| * | * | ||||
| * | |||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| public abstract class ConstantCPInfo extends ConstantPoolEntry { | public abstract class ConstantCPInfo extends ConstantPoolEntry { | ||||
| /** | /** | ||||
| * The entry's untyped value. | |||||
| * | |||||
| * Each subclass interprets the constant value based on the subclass's type. | |||||
| * The value here must be compatible. | |||||
| * The entry's untyped value. Each subclass interprets the constant | |||||
| * value based on the subclass's type. The value here must be | |||||
| * compatible. | |||||
| */ | */ | ||||
| private Object value; | private Object value; | ||||
| @@ -74,7 +71,8 @@ public abstract class ConstantCPInfo extends ConstantPoolEntry { | |||||
| * Initialise the constant entry. | * Initialise the constant entry. | ||||
| * | * | ||||
| * @param tagValue the constant pool entry type to be used. | * @param tagValue the constant pool entry type to be used. | ||||
| * @param entries the number of constant pool entry slots occupied by this entry. | |||||
| * @param entries the number of constant pool entry slots occupied by | |||||
| * this entry. | |||||
| */ | */ | ||||
| protected ConstantCPInfo(int tagValue, int entries) { | protected ConstantCPInfo(int tagValue, int entries) { | ||||
| super(tagValue, entries); | super(tagValue, entries); | ||||
| @@ -60,30 +60,26 @@ import java.util.Hashtable; | |||||
| import java.util.Vector; | import java.util.Vector; | ||||
| /** | /** | ||||
| * The constant pool of a Java class. | |||||
| * | |||||
| * The constant pool is a collection of constants used in a Java class file. It stores | |||||
| * strings, constant values, class names, method names, field names etc. | |||||
| * | |||||
| * @see <a href="http://java.sun.com/docs/books/vmspec/">The Java Virtual Machine Specification</a> | |||||
| * The constant pool of a Java class. The constant pool is a collection of | |||||
| * constants used in a Java class file. It stores strings, constant values, | |||||
| * class names, method names, field names etc. | |||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| * @see <a href="http://java.sun.com/docs/books/vmspec/">The Java Virtual | |||||
| * Machine Specification</a> | |||||
| */ | */ | ||||
| public class ConstantPool { | public class ConstantPool { | ||||
| /** | |||||
| * The entries in the constant pool. | |||||
| */ | |||||
| /** The entries in the constant pool. */ | |||||
| private Vector entries; | private Vector entries; | ||||
| /** | /** | ||||
| * A Hashtable of UTF8 entries - used to get constant pool indexes of the UTF8 values quickly | |||||
| * A Hashtable of UTF8 entries - used to get constant pool indexes of | |||||
| * the UTF8 values quickly | |||||
| */ | */ | ||||
| private Hashtable utf8Indexes; | private Hashtable utf8Indexes; | ||||
| /** | |||||
| * Initialise the constant pool. | |||||
| */ | |||||
| /** Initialise the constant pool. */ | |||||
| public ConstantPool() { | public ConstantPool() { | ||||
| entries = new Vector(); | entries = new Vector(); | ||||
| @@ -98,15 +94,15 @@ public class ConstantPool { | |||||
| * Read the constant pool from a class input stream. | * Read the constant pool from a class input stream. | ||||
| * | * | ||||
| * @param classStream the DataInputStream of a class file. | * @param classStream the DataInputStream of a class file. | ||||
| * | |||||
| * @throws IOException if there is a problem reading the constant pool | |||||
| * from the stream | |||||
| * @exception IOException if there is a problem reading the constant pool | |||||
| * from the stream | |||||
| */ | */ | ||||
| public void read(DataInputStream classStream) throws IOException { | public void read(DataInputStream classStream) throws IOException { | ||||
| int numEntries = classStream.readUnsignedShort(); | int numEntries = classStream.readUnsignedShort(); | ||||
| for (int i = 1; i < numEntries;) { | |||||
| ConstantPoolEntry nextEntry = ConstantPoolEntry.readEntry(classStream); | |||||
| for (int i = 1; i < numEntries; ) { | |||||
| ConstantPoolEntry nextEntry | |||||
| = ConstantPoolEntry.readEntry(classStream); | |||||
| i += nextEntry.getNumEntries(); | i += nextEntry.getNumEntries(); | ||||
| @@ -116,6 +112,8 @@ public class ConstantPool { | |||||
| /** | /** | ||||
| * Get the size of the constant pool. | * Get the size of the constant pool. | ||||
| * | |||||
| * @return the size of the constant pool | |||||
| */ | */ | ||||
| public int size() { | public int size() { | ||||
| return entries.size(); | return entries.size(); | ||||
| @@ -125,8 +123,8 @@ public class ConstantPool { | |||||
| * Add an entry to the constant pool. | * Add an entry to the constant pool. | ||||
| * | * | ||||
| * @param entry the new entry to be added to the constant pool. | * @param entry the new entry to be added to the constant pool. | ||||
| * | |||||
| * @return the index into the constant pool at which the entry is stored. | |||||
| * @return the index into the constant pool at which the entry is | |||||
| * stored. | |||||
| */ | */ | ||||
| public int addEntry(ConstantPoolEntry entry) { | public int addEntry(ConstantPoolEntry entry) { | ||||
| int index = entries.size(); | int index = entries.size(); | ||||
| @@ -141,7 +139,7 @@ public class ConstantPool { | |||||
| } | } | ||||
| if (entry instanceof Utf8CPInfo) { | if (entry instanceof Utf8CPInfo) { | ||||
| Utf8CPInfo utf8Info = (Utf8CPInfo) entry; | |||||
| Utf8CPInfo utf8Info = (Utf8CPInfo)entry; | |||||
| utf8Indexes.put(utf8Info.getValue(), new Integer(index)); | utf8Indexes.put(utf8Info.getValue(), new Integer(index)); | ||||
| } | } | ||||
| @@ -150,14 +148,13 @@ public class ConstantPool { | |||||
| } | } | ||||
| /** | /** | ||||
| * Resolve the entries in the constant pool. | |||||
| * | |||||
| * Resolution of the constant pool involves transforming indexes to | |||||
| * other constant pool entries into the actual data for that entry. | |||||
| * Resolve the entries in the constant pool. Resolution of the constant | |||||
| * pool involves transforming indexes to other constant pool entries | |||||
| * into the actual data for that entry. | |||||
| */ | */ | ||||
| public void resolve() { | public void resolve() { | ||||
| for (Enumeration i = entries.elements(); i.hasMoreElements();) { | |||||
| ConstantPoolEntry poolInfo = (ConstantPoolEntry) i.nextElement(); | |||||
| for (Enumeration i = entries.elements(); i.hasMoreElements(); ) { | |||||
| ConstantPoolEntry poolInfo = (ConstantPoolEntry)i.nextElement(); | |||||
| if (poolInfo != null && !poolInfo.isResolved()) { | if (poolInfo != null && !poolInfo.isResolved()) { | ||||
| poolInfo.resolve(this); | poolInfo.resolve(this); | ||||
| @@ -170,24 +167,22 @@ public class ConstantPool { | |||||
| * Get an constant pool entry at a particular index. | * Get an constant pool entry at a particular index. | ||||
| * | * | ||||
| * @param index the index into the constant pool. | * @param index the index into the constant pool. | ||||
| * | |||||
| * @return the constant pool entry at that index. | * @return the constant pool entry at that index. | ||||
| */ | */ | ||||
| public ConstantPoolEntry getEntry(int index) { | public ConstantPoolEntry getEntry(int index) { | ||||
| return (ConstantPoolEntry) entries.elementAt(index); | |||||
| return (ConstantPoolEntry)entries.elementAt(index); | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the index of a given UTF8 constant pool entry. | * Get the index of a given UTF8 constant pool entry. | ||||
| * | * | ||||
| * @param value the string value of the UTF8 entry. | * @param value the string value of the UTF8 entry. | ||||
| * | |||||
| * @return the index at which the given string occurs in the | |||||
| * constant pool or -1 if the value does not occur. | |||||
| * @return the index at which the given string occurs in the constant | |||||
| * pool or -1 if the value does not occur. | |||||
| */ | */ | ||||
| public int getUTF8Entry(String value) { | public int getUTF8Entry(String value) { | ||||
| int index = -1; | int index = -1; | ||||
| Integer indexInteger = (Integer) utf8Indexes.get(value); | |||||
| Integer indexInteger = (Integer)utf8Indexes.get(value); | |||||
| if (indexInteger != null) { | if (indexInteger != null) { | ||||
| index = indexInteger.intValue(); | index = indexInteger.intValue(); | ||||
| @@ -197,12 +192,12 @@ public class ConstantPool { | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the index of a given CONSTANT_Class entry in the constant pool. | |||||
| * | |||||
| * @param className the name of the class for which the class entry index is required. | |||||
| * Get the index of a given CONSTANT_CLASS entry in the constant pool. | |||||
| * | * | ||||
| * @param className the name of the class for which the class entry | |||||
| * index is required. | |||||
| * @return the index at which the given class entry occurs in the | * @return the index at which the given class entry occurs in the | ||||
| * constant pool or -1 if the value does not occur. | |||||
| * constant pool or -1 if the value does not occur. | |||||
| */ | */ | ||||
| public int getClassEntry(String className) { | public int getClassEntry(String className) { | ||||
| int index = -1; | int index = -1; | ||||
| @@ -211,7 +206,7 @@ public class ConstantPool { | |||||
| Object element = entries.elementAt(i); | Object element = entries.elementAt(i); | ||||
| if (element instanceof ClassCPInfo) { | if (element instanceof ClassCPInfo) { | ||||
| ClassCPInfo classinfo = (ClassCPInfo) element; | |||||
| ClassCPInfo classinfo = (ClassCPInfo)element; | |||||
| if (classinfo.getClassName().equals(className)) { | if (classinfo.getClassName().equals(className)) { | ||||
| index = i; | index = i; | ||||
| @@ -225,10 +220,10 @@ public class ConstantPool { | |||||
| /** | /** | ||||
| * Get the index of a given constant value entry in the constant pool. | * Get the index of a given constant value entry in the constant pool. | ||||
| * | * | ||||
| * @param constantValue the constant value for which the index is required. | |||||
| * | |||||
| * @param constantValue the constant value for which the index is | |||||
| * required. | |||||
| * @return the index at which the given value entry occurs in the | * @return the index at which the given value entry occurs in the | ||||
| * constant pool or -1 if the value does not occur. | |||||
| * constant pool or -1 if the value does not occur. | |||||
| */ | */ | ||||
| public int getConstantEntry(Object constantValue) { | public int getConstantEntry(Object constantValue) { | ||||
| int index = -1; | int index = -1; | ||||
| @@ -237,7 +232,7 @@ public class ConstantPool { | |||||
| Object element = entries.elementAt(i); | Object element = entries.elementAt(i); | ||||
| if (element instanceof ConstantCPInfo) { | if (element instanceof ConstantCPInfo) { | ||||
| ConstantCPInfo constantEntry = (ConstantCPInfo) element; | |||||
| ConstantCPInfo constantEntry = (ConstantCPInfo)element; | |||||
| if (constantEntry.getValue().equals(constantValue)) { | if (constantEntry.getValue().equals(constantValue)) { | ||||
| index = i; | index = i; | ||||
| @@ -249,27 +244,29 @@ public class ConstantPool { | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the index of a given CONSTANT_MethodRef entry in the constant pool. | |||||
| * Get the index of a given CONSTANT_METHODREF entry in the constant | |||||
| * pool. | |||||
| * | * | ||||
| * @param methodClassName the name of the class which contains the method | |||||
| * being referenced. | |||||
| * @param methodClassName the name of the class which contains the | |||||
| * method being referenced. | |||||
| * @param methodName the name of the method being referenced. | * @param methodName the name of the method being referenced. | ||||
| * @param methodType the type descriptor of the metho dbeing referenced. | * @param methodType the type descriptor of the metho dbeing referenced. | ||||
| * | |||||
| * @return the index at which the given method ref entry occurs in the | * @return the index at which the given method ref entry occurs in the | ||||
| * constant pool or -1 if the value does not occur. | |||||
| * constant pool or -1 if the value does not occur. | |||||
| */ | */ | ||||
| public int getMethodRefEntry(String methodClassName, String methodName, String methodType) { | |||||
| public int getMethodRefEntry(String methodClassName, String methodName, | |||||
| String methodType) { | |||||
| int index = -1; | int index = -1; | ||||
| for (int i = 0; i < entries.size() && index == -1; ++i) { | for (int i = 0; i < entries.size() && index == -1; ++i) { | ||||
| Object element = entries.elementAt(i); | Object element = entries.elementAt(i); | ||||
| if (element instanceof MethodRefCPInfo) { | if (element instanceof MethodRefCPInfo) { | ||||
| MethodRefCPInfo methodRefEntry = (MethodRefCPInfo) element; | |||||
| MethodRefCPInfo methodRefEntry = (MethodRefCPInfo)element; | |||||
| if (methodRefEntry.getMethodClassName().equals(methodClassName) | if (methodRefEntry.getMethodClassName().equals(methodClassName) | ||||
| && methodRefEntry.getMethodName().equals(methodName) && methodRefEntry.getMethodType().equals(methodType)) { | |||||
| && methodRefEntry.getMethodName().equals(methodName) | |||||
| && methodRefEntry.getMethodType().equals(methodType)) { | |||||
| index = i; | index = i; | ||||
| } | } | ||||
| } | } | ||||
| @@ -279,28 +276,32 @@ public class ConstantPool { | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the index of a given CONSTANT_InterfaceMethodRef entry in the constant pool. | |||||
| * Get the index of a given CONSTANT_INTERFACEMETHODREF entry in the | |||||
| * constant pool. | |||||
| * | * | ||||
| * @param interfaceMethodClassName the name of the interface which contains the method | |||||
| * being referenced. | |||||
| * @param interfaceMethodClassName the name of the interface which | |||||
| * contains the method being referenced. | |||||
| * @param interfaceMethodName the name of the method being referenced. | * @param interfaceMethodName the name of the method being referenced. | ||||
| * @param interfaceMethodType the type descriptor of the metho dbeing referenced. | |||||
| * | |||||
| * @param interfaceMethodType the type descriptor of the metho dbeing | |||||
| * referenced. | |||||
| * @return the index at which the given method ref entry occurs in the | * @return the index at which the given method ref entry occurs in the | ||||
| * constant pool or -1 if the value does not occur. | |||||
| * constant pool or -1 if the value does not occur. | |||||
| */ | */ | ||||
| public int getInterfaceMethodRefEntry(String interfaceMethodClassName, String interfaceMethodName, String interfaceMethodType) { | |||||
| public int getInterfaceMethodRefEntry(String interfaceMethodClassName, | |||||
| String interfaceMethodName, | |||||
| String interfaceMethodType) { | |||||
| int index = -1; | int index = -1; | ||||
| for (int i = 0; i < entries.size() && index == -1; ++i) { | for (int i = 0; i < entries.size() && index == -1; ++i) { | ||||
| Object element = entries.elementAt(i); | Object element = entries.elementAt(i); | ||||
| if (element instanceof InterfaceMethodRefCPInfo) { | if (element instanceof InterfaceMethodRefCPInfo) { | ||||
| InterfaceMethodRefCPInfo interfaceMethodRefEntry = (InterfaceMethodRefCPInfo) element; | |||||
| InterfaceMethodRefCPInfo interfaceMethodRefEntry | |||||
| = (InterfaceMethodRefCPInfo)element; | |||||
| if (interfaceMethodRefEntry.getInterfaceMethodClassName().equals(interfaceMethodClassName) | if (interfaceMethodRefEntry.getInterfaceMethodClassName().equals(interfaceMethodClassName) | ||||
| && interfaceMethodRefEntry.getInterfaceMethodName().equals(interfaceMethodName) | |||||
| && interfaceMethodRefEntry.getInterfaceMethodType().equals(interfaceMethodType)) { | |||||
| && interfaceMethodRefEntry.getInterfaceMethodName().equals(interfaceMethodName) | |||||
| && interfaceMethodRefEntry.getInterfaceMethodType().equals(interfaceMethodType)) { | |||||
| index = i; | index = i; | ||||
| } | } | ||||
| } | } | ||||
| @@ -310,27 +311,29 @@ public class ConstantPool { | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the index of a given CONSTANT_FieldRef entry in the constant pool. | |||||
| * Get the index of a given CONSTANT_FIELDREF entry in the constant | |||||
| * pool. | |||||
| * | * | ||||
| * @param fieldClassName the name of the class which contains the field | * @param fieldClassName the name of the class which contains the field | ||||
| * being referenced. | |||||
| * being referenced. | |||||
| * @param fieldName the name of the field being referenced. | * @param fieldName the name of the field being referenced. | ||||
| * @param fieldType the type descriptor of the field being referenced. | * @param fieldType the type descriptor of the field being referenced. | ||||
| * | |||||
| * @return the index at which the given field ref entry occurs in the | * @return the index at which the given field ref entry occurs in the | ||||
| * constant pool or -1 if the value does not occur. | |||||
| * constant pool or -1 if the value does not occur. | |||||
| */ | */ | ||||
| public int getFieldRefEntry(String fieldClassName, String fieldName, String fieldType) { | |||||
| public int getFieldRefEntry(String fieldClassName, String fieldName, | |||||
| String fieldType) { | |||||
| int index = -1; | int index = -1; | ||||
| for (int i = 0; i < entries.size() && index == -1; ++i) { | for (int i = 0; i < entries.size() && index == -1; ++i) { | ||||
| Object element = entries.elementAt(i); | Object element = entries.elementAt(i); | ||||
| if (element instanceof FieldRefCPInfo) { | if (element instanceof FieldRefCPInfo) { | ||||
| FieldRefCPInfo fieldRefEntry = (FieldRefCPInfo) element; | |||||
| FieldRefCPInfo fieldRefEntry = (FieldRefCPInfo)element; | |||||
| if (fieldRefEntry.getFieldClassName().equals(fieldClassName) && fieldRefEntry.getFieldName().equals(fieldName) | |||||
| && fieldRefEntry.getFieldType().equals(fieldType)) { | |||||
| if (fieldRefEntry.getFieldClassName().equals(fieldClassName) | |||||
| && fieldRefEntry.getFieldName().equals(fieldName) | |||||
| && fieldRefEntry.getFieldType().equals(fieldType)) { | |||||
| index = i; | index = i; | ||||
| } | } | ||||
| } | } | ||||
| @@ -340,13 +343,13 @@ public class ConstantPool { | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the index of a given CONSTANT_NameAndType entry in the constant pool. | |||||
| * Get the index of a given CONSTANT_NAMEANDTYPE entry in the constant | |||||
| * pool. | |||||
| * | * | ||||
| * @param name the name | * @param name the name | ||||
| * @param type the type | * @param type the type | ||||
| * | |||||
| * @return the index at which the given NameAndType entry occurs in the | * @return the index at which the given NameAndType entry occurs in the | ||||
| * constant pool or -1 if the value does not occur. | |||||
| * constant pool or -1 if the value does not occur. | |||||
| */ | */ | ||||
| public int getNameAndTypeEntry(String name, String type) { | public int getNameAndTypeEntry(String name, String type) { | ||||
| int index = -1; | int index = -1; | ||||
| @@ -355,9 +358,10 @@ public class ConstantPool { | |||||
| Object element = entries.elementAt(i); | Object element = entries.elementAt(i); | ||||
| if (element instanceof NameAndTypeCPInfo) { | if (element instanceof NameAndTypeCPInfo) { | ||||
| NameAndTypeCPInfo nameAndTypeEntry = (NameAndTypeCPInfo) element; | |||||
| NameAndTypeCPInfo nameAndTypeEntry = (NameAndTypeCPInfo)element; | |||||
| if (nameAndTypeEntry.getName().equals(name) && nameAndTypeEntry.getType().equals(type)) { | |||||
| if (nameAndTypeEntry.getName().equals(name) | |||||
| && nameAndTypeEntry.getType().equals(type)) { | |||||
| index = i; | index = i; | ||||
| } | } | ||||
| } | } | ||||
| @@ -56,75 +56,52 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||||
| import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| /** | /** | ||||
| * An entry in the constant pool. | |||||
| * | |||||
| * This class contains a represenation of the constant pool entries. It is | |||||
| * an abstract base class for all the different forms of constant pool entry. | |||||
| * An entry in the constant pool. This class contains a represenation of the | |||||
| * constant pool entries. It is an abstract base class for all the different | |||||
| * forms of constant pool entry. | |||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| * @see ConstantPool | * @see ConstantPool | ||||
| */ | */ | ||||
| public abstract class ConstantPoolEntry { | public abstract class ConstantPoolEntry { | ||||
| /** | |||||
| * Tag value for UTF8 entries. | |||||
| */ | |||||
| public final static int CONSTANT_Utf8 = 1; | |||||
| /** Tag value for UTF8 entries. */ | |||||
| public final static int CONSTANT_UTF8 = 1; | |||||
| /** | |||||
| * Tag value for Integer entries. | |||||
| */ | |||||
| public final static int CONSTANT_Integer = 3; | |||||
| /** Tag value for Integer entries. */ | |||||
| public final static int CONSTANT_INTEGER = 3; | |||||
| /** | |||||
| * Tag value for Float entries. | |||||
| */ | |||||
| public final static int CONSTANT_Float = 4; | |||||
| /** Tag value for Float entries. */ | |||||
| public final static int CONSTANT_FLOAT = 4; | |||||
| /** | |||||
| * Tag value for Long entries. | |||||
| */ | |||||
| public final static int CONSTANT_Long = 5; | |||||
| /** Tag value for Long entries. */ | |||||
| public final static int CONSTANT_LONG = 5; | |||||
| /** | |||||
| * Tag value for Double entries. | |||||
| */ | |||||
| public final static int CONSTANT_Double = 6; | |||||
| /** Tag value for Double entries. */ | |||||
| public final static int CONSTANT_DOUBLE = 6; | |||||
| /** | |||||
| * Tag value for Class entries. | |||||
| */ | |||||
| public final static int CONSTANT_Class = 7; | |||||
| /** Tag value for Class entries. */ | |||||
| public final static int CONSTANT_CLASS = 7; | |||||
| /** | |||||
| * Tag value for String entries. | |||||
| */ | |||||
| public final static int CONSTANT_String = 8; | |||||
| /** Tag value for String entries. */ | |||||
| public final static int CONSTANT_STRING = 8; | |||||
| /** | |||||
| * Tag value for Field Reference entries. | |||||
| */ | |||||
| public final static int CONSTANT_FieldRef = 9; | |||||
| /** Tag value for Field Reference entries. */ | |||||
| public final static int CONSTANT_FIELDREF = 9; | |||||
| /** | |||||
| * Tag value for Method Reference entries. | |||||
| */ | |||||
| public final static int CONSTANT_MethodRef = 10; | |||||
| /** Tag value for Method Reference entries. */ | |||||
| public final static int CONSTANT_METHODREF = 10; | |||||
| /** | |||||
| * Tag value for Interface Method Reference entries. | |||||
| */ | |||||
| public final static int CONSTANT_InterfaceMethodRef = 11; | |||||
| /** Tag value for Interface Method Reference entries. */ | |||||
| public final static int CONSTANT_INTERFACEMETHODREF = 11; | |||||
| /** | |||||
| * Tag value for Name and Type entries. | |||||
| */ | |||||
| public final static int CONSTANT_NameAndType = 12; | |||||
| /** Tag value for Name and Type entries. */ | |||||
| public final static int CONSTANT_NAMEANDTYPE = 12; | |||||
| /** | /** | ||||
| * This entry's tag which identifies the type of this constant pool entry. | |||||
| * This entry's tag which identifies the type of this constant pool | |||||
| * entry. | |||||
| */ | */ | ||||
| private int tag; | private int tag; | ||||
| @@ -141,8 +118,10 @@ public abstract class ConstantPoolEntry { | |||||
| /** | /** | ||||
| * Initialse the constant pool entry. | * Initialse the constant pool entry. | ||||
| * | * | ||||
| * @param tagValue the tag value which identifies which type of constant pool entry this is. | |||||
| * @param entries the number of constant pool entry slots this entry occupies. | |||||
| * @param tagValue the tag value which identifies which type of constant | |||||
| * pool entry this is. | |||||
| * @param entries the number of constant pool entry slots this entry | |||||
| * occupies. | |||||
| */ | */ | ||||
| public ConstantPoolEntry(int tagValue, int entries) { | public ConstantPoolEntry(int tagValue, int entries) { | ||||
| tag = tagValue; | tag = tagValue; | ||||
| @@ -151,82 +130,71 @@ public abstract class ConstantPoolEntry { | |||||
| } | } | ||||
| /** | /** | ||||
| * Read a constant pool entry from a stream. | |||||
| * | |||||
| * This is a factory method which reads a constant pool entry | |||||
| * form a stream and returns the appropriate subclass for the | |||||
| * entry. | |||||
| * | |||||
| * @param cpStream the stream from which the constant pool entry is to be read. | |||||
| * Read a constant pool entry from a stream. This is a factory method | |||||
| * which reads a constant pool entry form a stream and returns the | |||||
| * appropriate subclass for the entry. | |||||
| * | * | ||||
| * @returns the appropriate ConstantPoolEntry subclass representing the | |||||
| * constant pool entry from the stream. | |||||
| * | |||||
| * @throws IOExcception if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the stream from which the constant pool entry is to | |||||
| * be read. | |||||
| * @return the appropriate ConstantPoolEntry subclass representing the | |||||
| * constant pool entry from the stream. | |||||
| * @exception IOException if the constant pool entry cannot be read | |||||
| * from the stream | |||||
| */ | */ | ||||
| public static ConstantPoolEntry readEntry(DataInputStream cpStream) throws IOException { | |||||
| public static ConstantPoolEntry readEntry(DataInputStream cpStream) | |||||
| throws IOException { | |||||
| ConstantPoolEntry cpInfo = null; | ConstantPoolEntry cpInfo = null; | ||||
| int cpTag = cpStream.readUnsignedByte(); | int cpTag = cpStream.readUnsignedByte(); | ||||
| switch (cpTag) { | switch (cpTag) { | ||||
| case CONSTANT_Utf8: | |||||
| case CONSTANT_UTF8: | |||||
| cpInfo = new Utf8CPInfo(); | cpInfo = new Utf8CPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_Integer: | |||||
| case CONSTANT_INTEGER: | |||||
| cpInfo = new IntegerCPInfo(); | cpInfo = new IntegerCPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_Float: | |||||
| case CONSTANT_FLOAT: | |||||
| cpInfo = new FloatCPInfo(); | cpInfo = new FloatCPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_Long: | |||||
| case CONSTANT_LONG: | |||||
| cpInfo = new LongCPInfo(); | cpInfo = new LongCPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_Double: | |||||
| case CONSTANT_DOUBLE: | |||||
| cpInfo = new DoubleCPInfo(); | cpInfo = new DoubleCPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_Class: | |||||
| case CONSTANT_CLASS: | |||||
| cpInfo = new ClassCPInfo(); | cpInfo = new ClassCPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_String: | |||||
| case CONSTANT_STRING: | |||||
| cpInfo = new StringCPInfo(); | cpInfo = new StringCPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_FieldRef: | |||||
| case CONSTANT_FIELDREF: | |||||
| cpInfo = new FieldRefCPInfo(); | cpInfo = new FieldRefCPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_MethodRef: | |||||
| case CONSTANT_METHODREF: | |||||
| cpInfo = new MethodRefCPInfo(); | cpInfo = new MethodRefCPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_InterfaceMethodRef: | |||||
| case CONSTANT_INTERFACEMETHODREF: | |||||
| cpInfo = new InterfaceMethodRefCPInfo(); | cpInfo = new InterfaceMethodRefCPInfo(); | ||||
| break; | break; | ||||
| case CONSTANT_NameAndType: | |||||
| case CONSTANT_NAMEANDTYPE: | |||||
| cpInfo = new NameAndTypeCPInfo(); | cpInfo = new NameAndTypeCPInfo(); | ||||
| break; | break; | ||||
| default: | default: | ||||
| throw new ClassFormatError("Invalid Constant Pool entry Type " + cpTag); | |||||
| throw new ClassFormatError("Invalid Constant Pool entry Type " | |||||
| + cpTag); | |||||
| } | } | ||||
| cpInfo.read(cpStream); | cpInfo.read(cpStream); | ||||
| @@ -235,11 +203,10 @@ public abstract class ConstantPoolEntry { | |||||
| } | } | ||||
| /** | /** | ||||
| * Indicates whether this entry has been resolved. | |||||
| * | |||||
| * In general a constant pool entry can reference another constant | |||||
| * pool entry by its index value. Resolution involves replacing this | |||||
| * index value with the constant pool entry at that index. | |||||
| * Indicates whether this entry has been resolved. In general a constant | |||||
| * pool entry can reference another constant pool entry by its index | |||||
| * value. Resolution involves replacing this index value with the | |||||
| * constant pool entry at that index. | |||||
| * | * | ||||
| * @return true if this entry has been resolved. | * @return true if this entry has been resolved. | ||||
| */ | */ | ||||
| @@ -252,7 +219,7 @@ public abstract class ConstantPoolEntry { | |||||
| * the constant pool. | * the constant pool. | ||||
| * | * | ||||
| * @param constantPool the constant pool of which this entry is a member | * @param constantPool the constant pool of which this entry is a member | ||||
| * and against which this entry is to be resolved. | |||||
| * and against which this entry is to be resolved. | |||||
| */ | */ | ||||
| public void resolve(ConstantPool constantPool) { | public void resolve(ConstantPool constantPool) { | ||||
| resolved = true; | resolved = true; | ||||
| @@ -261,9 +228,10 @@ public abstract class ConstantPoolEntry { | |||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public abstract void read(DataInputStream cpStream) throws IOException; | public abstract void read(DataInputStream cpStream) throws IOException; | ||||
| @@ -277,10 +245,10 @@ public abstract class ConstantPoolEntry { | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the number of Constant Pool Entry slots within the constant pool occupied by this entry. | |||||
| * Get the number of Constant Pool Entry slots within the constant pool | |||||
| * occupied by this entry. | |||||
| * | * | ||||
| * @return the number of slots used. | * @return the number of slots used. | ||||
| * | |||||
| */ | */ | ||||
| public final int getNumEntries() { | public final int getNumEntries() { | ||||
| return numEntries; | return numEntries; | ||||
| @@ -56,23 +56,27 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||||
| import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| /** | /** | ||||
| * The constant pool entry subclass used to represent double constant values. | |||||
| * The constant pool entry subclass used to represent double constant | |||||
| * values. | |||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| public class DoubleCPInfo extends ConstantCPInfo { | public class DoubleCPInfo extends ConstantCPInfo { | ||||
| /** | |||||
| * Constructor | |||||
| */ | |||||
| public DoubleCPInfo() { | public DoubleCPInfo() { | ||||
| super(CONSTANT_Double, 2); | |||||
| super(CONSTANT_DOUBLE, 2); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from the | |||||
| * stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| setValue(new Double(cpStream.readDouble())); | setValue(new Double(cpStream.readDouble())); | ||||
| @@ -56,33 +56,35 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||||
| import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| /** | /** | ||||
| * A FieldRef CP Info | * A FieldRef CP Info | ||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| public class FieldRefCPInfo extends ConstantPoolEntry { | public class FieldRefCPInfo extends ConstantPoolEntry { | ||||
| /** Name of the field's class */ | |||||
| private String fieldClassName; | private String fieldClassName; | ||||
| /** name of the field in that class */ | |||||
| private String fieldName; | private String fieldName; | ||||
| /** The type of the field */ | |||||
| private String fieldType; | private String fieldType; | ||||
| /** Index into the constant pool for the class */ | |||||
| private int classIndex; | private int classIndex; | ||||
| /** Index into the constant pool for the name and type entry */ | |||||
| private int nameAndTypeIndex; | private int nameAndTypeIndex; | ||||
| /** | |||||
| * Constructor. | |||||
| * | |||||
| */ | |||||
| /** Constructor. */ | |||||
| public FieldRefCPInfo() { | public FieldRefCPInfo() { | ||||
| super(CONSTANT_FieldRef, 1); | |||||
| super(CONSTANT_FIELDREF, 1); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| classIndex = cpStream.readUnsignedShort(); | classIndex = cpStream.readUnsignedShort(); | ||||
| @@ -94,16 +96,17 @@ public class FieldRefCPInfo extends ConstantPoolEntry { | |||||
| * the constant pool. | * the constant pool. | ||||
| * | * | ||||
| * @param constantPool the constant pool of which this entry is a member | * @param constantPool the constant pool of which this entry is a member | ||||
| * and against which this entry is to be resolved. | |||||
| * and against which this entry is to be resolved. | |||||
| */ | */ | ||||
| public void resolve(ConstantPool constantPool) { | public void resolve(ConstantPool constantPool) { | ||||
| ClassCPInfo fieldClass = (ClassCPInfo) constantPool.getEntry(classIndex); | |||||
| ClassCPInfo fieldClass = (ClassCPInfo)constantPool.getEntry(classIndex); | |||||
| fieldClass.resolve(constantPool); | fieldClass.resolve(constantPool); | ||||
| fieldClassName = fieldClass.getClassName(); | fieldClassName = fieldClass.getClassName(); | ||||
| NameAndTypeCPInfo nt = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex); | |||||
| NameAndTypeCPInfo nt | |||||
| = (NameAndTypeCPInfo)constantPool.getEntry(nameAndTypeIndex); | |||||
| nt.resolve(constantPool); | nt.resolve(constantPool); | ||||
| @@ -122,22 +125,39 @@ public class FieldRefCPInfo extends ConstantPoolEntry { | |||||
| String value; | String value; | ||||
| if (isResolved()) { | if (isResolved()) { | ||||
| value = "Field : Class = " + fieldClassName + ", name = " + fieldName + ", type = " + fieldType; | |||||
| value = "Field : Class = " + fieldClassName + ", name = " | |||||
| + fieldName + ", type = " + fieldType; | |||||
| } else { | } else { | ||||
| value = "Field : Class index = " + classIndex + ", name and type index = " + nameAndTypeIndex; | |||||
| value = "Field : Class index = " + classIndex | |||||
| + ", name and type index = " + nameAndTypeIndex; | |||||
| } | } | ||||
| return value; | return value; | ||||
| } | } | ||||
| /** | |||||
| * Gets the name of the class definint the field | |||||
| * | |||||
| * @return the name of the class definint the field | |||||
| */ | |||||
| public String getFieldClassName() { | public String getFieldClassName() { | ||||
| return fieldClassName; | return fieldClassName; | ||||
| } | } | ||||
| /** | |||||
| * Get the name of the field | |||||
| * | |||||
| * @return the field's name | |||||
| */ | |||||
| public String getFieldName() { | public String getFieldName() { | ||||
| return fieldName; | return fieldName; | ||||
| } | } | ||||
| /** | |||||
| * Get the type of the field | |||||
| * | |||||
| * @return the field's type in string format | |||||
| */ | |||||
| public String getFieldType() { | public String getFieldType() { | ||||
| return fieldType; | return fieldType; | ||||
| } | } | ||||
| @@ -63,20 +63,18 @@ import java.io.IOException; | |||||
| */ | */ | ||||
| public class FloatCPInfo extends ConstantCPInfo { | public class FloatCPInfo extends ConstantCPInfo { | ||||
| /** | |||||
| * Constructor. | |||||
| * | |||||
| */ | |||||
| /** Constructor. */ | |||||
| public FloatCPInfo() { | public FloatCPInfo() { | ||||
| super(CONSTANT_Float, 1); | |||||
| super(CONSTANT_FLOAT, 1); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| setValue(new Float(cpStream.readFloat())); | setValue(new Float(cpStream.readFloat())); | ||||
| @@ -63,20 +63,18 @@ import java.io.IOException; | |||||
| */ | */ | ||||
| public class IntegerCPInfo extends ConstantCPInfo { | public class IntegerCPInfo extends ConstantCPInfo { | ||||
| /** | |||||
| * Constructor. | |||||
| * | |||||
| */ | |||||
| /** Constructor. */ | |||||
| public IntegerCPInfo() { | public IntegerCPInfo() { | ||||
| super(CONSTANT_Integer, 1); | |||||
| super(CONSTANT_INTEGER, 1); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| setValue(new Integer(cpStream.readInt())); | setValue(new Integer(cpStream.readInt())); | ||||
| @@ -56,34 +56,41 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||||
| import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| /** | /** | ||||
| * A InterfaceMethodRef CP Info | * A InterfaceMethodRef CP Info | ||||
| * | * | ||||
| * | |||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| public class InterfaceMethodRefCPInfo extends ConstantPoolEntry { | public class InterfaceMethodRefCPInfo extends ConstantPoolEntry { | ||||
| /** the class name of the class defining the interafce method */ | |||||
| private String interfaceMethodClassName; | private String interfaceMethodClassName; | ||||
| /** the name of the interface nmethod */ | |||||
| private String interfaceMethodName; | private String interfaceMethodName; | ||||
| /** the method signature of the interface method */ | |||||
| private String interfaceMethodType; | private String interfaceMethodType; | ||||
| /** | |||||
| * the index into the constant pool of the class entry for the interface | |||||
| * class | |||||
| */ | |||||
| private int classIndex; | private int classIndex; | ||||
| private int nameAndTypeIndex; | |||||
| /** | /** | ||||
| * Constructor. | |||||
| * | |||||
| * the index into the constant pool of the name and type entry | |||||
| * describing the method | |||||
| */ | */ | ||||
| private int nameAndTypeIndex; | |||||
| /** Constructor. */ | |||||
| public InterfaceMethodRefCPInfo() { | public InterfaceMethodRefCPInfo() { | ||||
| super(CONSTANT_InterfaceMethodRef, 1); | |||||
| super(CONSTANT_INTERFACEMETHODREF, 1); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| classIndex = cpStream.readUnsignedShort(); | classIndex = cpStream.readUnsignedShort(); | ||||
| @@ -95,16 +102,18 @@ public class InterfaceMethodRefCPInfo extends ConstantPoolEntry { | |||||
| * the constant pool. | * the constant pool. | ||||
| * | * | ||||
| * @param constantPool the constant pool of which this entry is a member | * @param constantPool the constant pool of which this entry is a member | ||||
| * and against which this entry is to be resolved. | |||||
| * and against which this entry is to be resolved. | |||||
| */ | */ | ||||
| public void resolve(ConstantPool constantPool) { | public void resolve(ConstantPool constantPool) { | ||||
| ClassCPInfo interfaceMethodClass = (ClassCPInfo) constantPool.getEntry(classIndex); | |||||
| ClassCPInfo interfaceMethodClass | |||||
| = (ClassCPInfo)constantPool.getEntry(classIndex); | |||||
| interfaceMethodClass.resolve(constantPool); | interfaceMethodClass.resolve(constantPool); | ||||
| interfaceMethodClassName = interfaceMethodClass.getClassName(); | interfaceMethodClassName = interfaceMethodClass.getClassName(); | ||||
| NameAndTypeCPInfo nt = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex); | |||||
| NameAndTypeCPInfo nt | |||||
| = (NameAndTypeCPInfo)constantPool.getEntry(nameAndTypeIndex); | |||||
| nt.resolve(constantPool); | nt.resolve(constantPool); | ||||
| @@ -123,23 +132,40 @@ public class InterfaceMethodRefCPInfo extends ConstantPoolEntry { | |||||
| String value; | String value; | ||||
| if (isResolved()) { | if (isResolved()) { | ||||
| value = "InterfaceMethod : Class = " + interfaceMethodClassName + ", name = " + interfaceMethodName + ", type = " | |||||
| + interfaceMethodType; | |||||
| value = "InterfaceMethod : Class = " + interfaceMethodClassName | |||||
| + ", name = " + interfaceMethodName + ", type = " | |||||
| + interfaceMethodType; | |||||
| } else { | } else { | ||||
| value = "InterfaceMethod : Class index = " + classIndex + ", name and type index = " + nameAndTypeIndex; | |||||
| value = "InterfaceMethod : Class index = " + classIndex | |||||
| + ", name and type index = " + nameAndTypeIndex; | |||||
| } | } | ||||
| return value; | return value; | ||||
| } | } | ||||
| /** | |||||
| * Gets the name of the class defining the interface method | |||||
| * | |||||
| * @return the name of the class defining the interface method | |||||
| */ | |||||
| public String getInterfaceMethodClassName() { | public String getInterfaceMethodClassName() { | ||||
| return interfaceMethodClassName; | return interfaceMethodClassName; | ||||
| } | } | ||||
| /** | |||||
| * Get the name of the interface method | |||||
| * | |||||
| * @return the name of the interface method | |||||
| */ | |||||
| public String getInterfaceMethodName() { | public String getInterfaceMethodName() { | ||||
| return interfaceMethodName; | return interfaceMethodName; | ||||
| } | } | ||||
| /** | |||||
| * Gets the type of the interface method | |||||
| * | |||||
| * @return the interface method's type signature | |||||
| */ | |||||
| public String getInterfaceMethodType() { | public String getInterfaceMethodType() { | ||||
| return interfaceMethodType; | return interfaceMethodType; | ||||
| } | } | ||||
| @@ -63,20 +63,18 @@ import java.io.IOException; | |||||
| */ | */ | ||||
| public class LongCPInfo extends ConstantCPInfo { | public class LongCPInfo extends ConstantCPInfo { | ||||
| /** | |||||
| * Constructor. | |||||
| * | |||||
| */ | |||||
| /** Constructor. */ | |||||
| public LongCPInfo() { | public LongCPInfo() { | ||||
| super(CONSTANT_Long, 2); | |||||
| super(CONSTANT_LONG, 2); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| setValue(new Long(cpStream.readLong())); | setValue(new Long(cpStream.readLong())); | ||||
| @@ -56,33 +56,38 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||||
| import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| /** | /** | ||||
| * A MethodRef CP Info | * A MethodRef CP Info | ||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| public class MethodRefCPInfo extends ConstantPoolEntry { | public class MethodRefCPInfo extends ConstantPoolEntry { | ||||
| /** the name of the class defining this method */ | |||||
| private String methodClassName; | private String methodClassName; | ||||
| /** the name of the method */ | |||||
| private String methodName; | private String methodName; | ||||
| /** the method's type descriptor */ | |||||
| private String methodType; | private String methodType; | ||||
| /** The index into the constant pool which defines the class of this method. */ | |||||
| private int classIndex; | private int classIndex; | ||||
| private int nameAndTypeIndex; | |||||
| /** | /** | ||||
| * Constructor. | |||||
| * | |||||
| * the index into the constant pool which defined the name and type | |||||
| * signature of the method | |||||
| */ | */ | ||||
| private int nameAndTypeIndex; | |||||
| /** Constructor. */ | |||||
| public MethodRefCPInfo() { | public MethodRefCPInfo() { | ||||
| super(CONSTANT_MethodRef, 1); | |||||
| super(CONSTANT_METHODREF, 1); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| classIndex = cpStream.readUnsignedShort(); | classIndex = cpStream.readUnsignedShort(); | ||||
| @@ -98,9 +103,11 @@ public class MethodRefCPInfo extends ConstantPoolEntry { | |||||
| String value; | String value; | ||||
| if (isResolved()) { | if (isResolved()) { | ||||
| value = "Method : Class = " + methodClassName + ", name = " + methodName + ", type = " + methodType; | |||||
| value = "Method : Class = " + methodClassName + ", name = " | |||||
| + methodName + ", type = " + methodType; | |||||
| } else { | } else { | ||||
| value = "Method : Class index = " + classIndex + ", name and type index = " + nameAndTypeIndex; | |||||
| value = "Method : Class index = " + classIndex | |||||
| + ", name and type index = " + nameAndTypeIndex; | |||||
| } | } | ||||
| return value; | return value; | ||||
| @@ -111,16 +118,18 @@ public class MethodRefCPInfo extends ConstantPoolEntry { | |||||
| * the constant pool. | * the constant pool. | ||||
| * | * | ||||
| * @param constantPool the constant pool of which this entry is a member | * @param constantPool the constant pool of which this entry is a member | ||||
| * and against which this entry is to be resolved. | |||||
| * and against which this entry is to be resolved. | |||||
| */ | */ | ||||
| public void resolve(ConstantPool constantPool) { | public void resolve(ConstantPool constantPool) { | ||||
| ClassCPInfo methodClass = (ClassCPInfo) constantPool.getEntry(classIndex); | |||||
| ClassCPInfo methodClass | |||||
| = (ClassCPInfo)constantPool.getEntry(classIndex); | |||||
| methodClass.resolve(constantPool); | methodClass.resolve(constantPool); | ||||
| methodClassName = methodClass.getClassName(); | methodClassName = methodClass.getClassName(); | ||||
| NameAndTypeCPInfo nt = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex); | |||||
| NameAndTypeCPInfo nt | |||||
| = (NameAndTypeCPInfo)constantPool.getEntry(nameAndTypeIndex); | |||||
| nt.resolve(constantPool); | nt.resolve(constantPool); | ||||
| @@ -130,14 +139,29 @@ public class MethodRefCPInfo extends ConstantPoolEntry { | |||||
| super.resolve(constantPool); | super.resolve(constantPool); | ||||
| } | } | ||||
| /** | |||||
| * Get the name of the class defining the method | |||||
| * | |||||
| * @return the name of the class defining this method | |||||
| */ | |||||
| public String getMethodClassName() { | public String getMethodClassName() { | ||||
| return methodClassName; | return methodClassName; | ||||
| } | } | ||||
| /** | |||||
| * Get the name of the method. | |||||
| * | |||||
| * @return the name of the method. | |||||
| */ | |||||
| public String getMethodName() { | public String getMethodName() { | ||||
| return methodName; | return methodName; | ||||
| } | } | ||||
| /** | |||||
| * Get the type signature of the method. | |||||
| * | |||||
| * @return the type signature of the method. | |||||
| */ | |||||
| public String getMethodType() { | public String getMethodType() { | ||||
| return methodType; | return methodType; | ||||
| } | } | ||||
| @@ -56,7 +56,6 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||||
| import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| /** | /** | ||||
| * A NameAndType CP Info | * A NameAndType CP Info | ||||
| * | * | ||||
| @@ -64,20 +63,18 @@ import java.io.IOException; | |||||
| */ | */ | ||||
| public class NameAndTypeCPInfo extends ConstantPoolEntry { | public class NameAndTypeCPInfo extends ConstantPoolEntry { | ||||
| /** | |||||
| * Constructor. | |||||
| * | |||||
| */ | |||||
| /** Constructor. */ | |||||
| public NameAndTypeCPInfo() { | public NameAndTypeCPInfo() { | ||||
| super(CONSTANT_NameAndType, 1); | |||||
| super(CONSTANT_NAMEANDTYPE, 1); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| nameIndex = cpStream.readUnsignedShort(); | nameIndex = cpStream.readUnsignedShort(); | ||||
| @@ -95,7 +92,8 @@ public class NameAndTypeCPInfo extends ConstantPoolEntry { | |||||
| if (isResolved()) { | if (isResolved()) { | ||||
| value = "Name = " + name + ", type = " + type; | value = "Name = " + name + ", type = " + type; | ||||
| } else { | } else { | ||||
| value = "Name index = " + nameIndex + ", descriptor index = " + descriptorIndex; | |||||
| value = "Name index = " + nameIndex | |||||
| + ", descriptor index = " + descriptorIndex; | |||||
| } | } | ||||
| return value; | return value; | ||||
| @@ -106,26 +104,46 @@ public class NameAndTypeCPInfo extends ConstantPoolEntry { | |||||
| * the constant pool. | * the constant pool. | ||||
| * | * | ||||
| * @param constantPool the constant pool of which this entry is a member | * @param constantPool the constant pool of which this entry is a member | ||||
| * and against which this entry is to be resolved. | |||||
| * and against which this entry is to be resolved. | |||||
| */ | */ | ||||
| public void resolve(ConstantPool constantPool) { | public void resolve(ConstantPool constantPool) { | ||||
| name = ((Utf8CPInfo) constantPool.getEntry(nameIndex)).getValue(); | |||||
| type = ((Utf8CPInfo) constantPool.getEntry(descriptorIndex)).getValue(); | |||||
| name = ((Utf8CPInfo)constantPool.getEntry(nameIndex)).getValue(); | |||||
| type = ((Utf8CPInfo)constantPool.getEntry(descriptorIndex)).getValue(); | |||||
| super.resolve(constantPool); | super.resolve(constantPool); | ||||
| } | } | ||||
| /** | |||||
| * Get the name component of this entry | |||||
| * | |||||
| * @return the name of this name and type entry | |||||
| */ | |||||
| public String getName() { | public String getName() { | ||||
| return name; | return name; | ||||
| } | } | ||||
| /** | |||||
| * Get the type signature of this entry | |||||
| * | |||||
| * @return the type signature of this entry | |||||
| */ | |||||
| public String getType() { | public String getType() { | ||||
| return type; | return type; | ||||
| } | } | ||||
| /** the name component of this entry */ | |||||
| private String name; | private String name; | ||||
| /** the type component of this entry */ | |||||
| private String type; | private String type; | ||||
| /** | |||||
| * the index into the constant pool at which the name component's string | |||||
| * value is stored | |||||
| */ | |||||
| private int nameIndex; | private int nameIndex; | ||||
| /** | |||||
| * the index into the constant pool where the type descriptor string is | |||||
| * stored. | |||||
| */ | |||||
| private int descriptorIndex; | private int descriptorIndex; | ||||
| } | } | ||||
| @@ -56,31 +56,26 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||||
| import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| /** | /** | ||||
| * A String Constant Pool Entry. | |||||
| * | |||||
| * The String info contains an index into the constant pool where | |||||
| * a UTF8 string is stored. | |||||
| * A String Constant Pool Entry. The String info contains an index into the | |||||
| * constant pool where a UTF8 string is stored. | |||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| public class StringCPInfo extends ConstantCPInfo { | public class StringCPInfo extends ConstantCPInfo { | ||||
| /** | |||||
| * Constructor. | |||||
| * | |||||
| */ | |||||
| /** Constructor. */ | |||||
| public StringCPInfo() { | public StringCPInfo() { | ||||
| super(CONSTANT_String, 1); | |||||
| super(CONSTANT_STRING, 1); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| index = cpStream.readUnsignedShort(); | index = cpStream.readUnsignedShort(); | ||||
| @@ -94,7 +89,8 @@ public class StringCPInfo extends ConstantCPInfo { | |||||
| * @return the string representation of this constant pool entry. | * @return the string representation of this constant pool entry. | ||||
| */ | */ | ||||
| public String toString() { | public String toString() { | ||||
| return "String Constant Pool Entry for " + getValue() + "[" + index + "]"; | |||||
| return "String Constant Pool Entry for " | |||||
| + getValue() + "[" + index + "]"; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -102,13 +98,14 @@ public class StringCPInfo extends ConstantCPInfo { | |||||
| * the constant pool. | * the constant pool. | ||||
| * | * | ||||
| * @param constantPool the constant pool of which this entry is a member | * @param constantPool the constant pool of which this entry is a member | ||||
| * and against which this entry is to be resolved. | |||||
| * and against which this entry is to be resolved. | |||||
| */ | */ | ||||
| public void resolve(ConstantPool constantPool) { | public void resolve(ConstantPool constantPool) { | ||||
| setValue(((Utf8CPInfo) constantPool.getEntry(index)).getValue()); | |||||
| setValue(((Utf8CPInfo)constantPool.getEntry(index)).getValue()); | |||||
| super.resolve(constantPool); | super.resolve(constantPool); | ||||
| } | } | ||||
| /** the index into the constant pool containing the string's content */ | |||||
| private int index; | private int index; | ||||
| } | } | ||||
| @@ -56,29 +56,27 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||||
| import java.io.DataInputStream; | import java.io.DataInputStream; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| /** | /** | ||||
| * A UTF8 Constant Pool Entry. | * A UTF8 Constant Pool Entry. | ||||
| * | * | ||||
| * @author Conor MacNeill | * @author Conor MacNeill | ||||
| */ | */ | ||||
| public class Utf8CPInfo extends ConstantPoolEntry { | public class Utf8CPInfo extends ConstantPoolEntry { | ||||
| /** The String value of the UTF-8 entry */ | |||||
| private String value; | private String value; | ||||
| /** | |||||
| * Constructor. | |||||
| * | |||||
| */ | |||||
| /** Constructor. */ | |||||
| public Utf8CPInfo() { | public Utf8CPInfo() { | ||||
| super(CONSTANT_Utf8, 1); | |||||
| super(CONSTANT_UTF8, 1); | |||||
| } | } | ||||
| /** | /** | ||||
| * read a constant pool entry from a class stream. | * read a constant pool entry from a class stream. | ||||
| * | * | ||||
| * @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||||
| * | |||||
| * @throws IOException if there is a problem reading the entry from the stream. | |||||
| * @param cpStream the DataInputStream which contains the constant pool | |||||
| * entry to be read. | |||||
| * @exception IOException if there is a problem reading the entry from | |||||
| * the stream. | |||||
| */ | */ | ||||
| public void read(DataInputStream cpStream) throws IOException { | public void read(DataInputStream cpStream) throws IOException { | ||||
| value = cpStream.readUTF(); | value = cpStream.readUTF(); | ||||
| @@ -93,6 +91,11 @@ public class Utf8CPInfo extends ConstantPoolEntry { | |||||
| return "UTF8 Value = " + value; | return "UTF8 Value = " + value; | ||||
| } | } | ||||
| /** | |||||
| * Get the string value of the UTF-8 entry | |||||
| * | |||||
| * @return the UTF-8 value as a Java string | |||||
| */ | |||||
| public String getValue() { | public String getValue() { | ||||
| return value; | return value; | ||||
| } | } | ||||