From 9caeed5081071d6a2de28844d0a724918f8c6d86 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Wed, 22 Aug 2012 12:32:43 +0000 Subject: [PATCH] Java 1.5, continued git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1376015 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/PropertyHelper.java | 1 + .../tools/ant/taskdefs/ManifestTask.java | 8 +- .../tools/ant/taskdefs/MatchingTask.java | 2 +- .../apache/tools/ant/taskdefs/Redirector.java | 96 ++++++------- .../taskdefs/optional/depend/AntAnalyzer.java | 41 +++--- .../taskdefs/optional/depend/ClassFile.java | 6 +- .../depend/constantpool/ConstantPool.java | 43 +++--- .../tools/ant/types/AbstractFileSet.java | 46 +++---- .../tools/ant/types/ArchiveFileSet.java | 5 +- .../tools/ant/types/ArchiveScanner.java | 31 ++--- .../apache/tools/ant/types/Assertions.java | 21 +-- .../apache/tools/ant/types/Commandline.java | 54 ++++---- .../tools/ant/types/CommandlineJava.java | 36 +++-- .../apache/tools/ant/types/Description.java | 34 ++--- .../tools/ant/types/EnumeratedAttribute.java | 4 +- .../org/apache/tools/ant/types/FileList.java | 17 ++- .../tools/ant/types/FilterSetCollection.java | 24 +--- .../org/apache/tools/ant/types/Mapper.java | 9 +- .../apache/tools/ant/types/PatternSet.java | 51 +++---- .../apache/tools/ant/types/Permissions.java | 36 +++-- .../apache/tools/ant/types/PropertySet.java | 129 +++++++++--------- .../tools/ant/types/RedirectorElement.java | 26 ++-- .../apache/tools/ant/types/TarScanner.java | 5 +- .../apache/tools/ant/types/XMLCatalog.java | 34 ++--- .../apache/tools/ant/types/ZipScanner.java | 8 +- .../tools/ant/types/mappers/FilterMapper.java | 2 +- .../ant/types/optional/ScriptMapper.java | 8 +- .../types/optional/depend/ClassfileSet.java | 26 ++-- .../types/optional/depend/DependScanner.java | 27 ++-- .../types/optional/image/ImageOperation.java | 2 +- .../ant/types/optional/image/Rotate.java | 3 - .../resources/AbstractClasspathResource.java | 2 +- .../AbstractResourceCollectionWrapper.java | 15 +- .../ant/types/resources/ArchiveResource.java | 4 +- .../tools/ant/types/resources/Archives.java | 6 +- .../BaseResourceCollectionContainer.java | 34 +++-- .../tools/ant/types/resources/FailFast.java | 14 +- .../tools/ant/types/resources/Files.java | 13 +- .../resources/ImmutableResourceException.java | 1 + .../types/resources/JavaConstantResource.java | 2 +- .../resources/MappedResourceCollection.java | 2 +- .../types/resources/ResourceDecorator.java | 2 +- .../ant/types/resources/ResourceList.java | 23 ++-- .../tools/ant/types/resources/Restrict.java | 6 +- .../tools/ant/types/resources/Sort.java | 4 +- .../tools/ant/types/resources/Tokens.java | 34 +++-- .../tools/ant/types/resources/Union.java | 70 ++++++---- .../DelegatedResourceComparator.java | 30 ++-- .../types/resources/comparators/Reverse.java | 2 +- .../ant/types/resources/selectors/And.java | 4 +- .../types/resources/selectors/Compare.java | 3 +- .../types/resources/selectors/InstanceOf.java | 8 +- .../types/resources/selectors/Majority.java | 4 +- .../ant/types/resources/selectors/None.java | 9 +- .../ant/types/resources/selectors/Or.java | 4 +- .../selectors/ResourceSelectorContainer.java | 24 ++-- .../selectors/AbstractSelectorContainer.java | 22 ++- .../ant/types/selectors/AndSelector.java | 9 +- .../selectors/BaseSelectorContainer.java | 31 ++--- .../selectors/ContainsRegexpSelector.java | 2 +- .../ant/types/selectors/ContainsSelector.java | 2 +- .../ant/types/selectors/DateSelector.java | 2 +- .../ant/types/selectors/DependSelector.java | 2 +- .../ant/types/selectors/DepthSelector.java | 2 +- .../ant/types/selectors/ExtendSelector.java | 6 +- .../ant/types/selectors/FilenameSelector.java | 2 +- .../ant/types/selectors/MajoritySelector.java | 14 +- .../ant/types/selectors/NoneSelector.java | 9 +- .../ant/types/selectors/NotSelector.java | 2 +- .../tools/ant/types/selectors/OrSelector.java | 9 +- .../ant/types/selectors/PresentSelector.java | 4 +- .../ant/types/selectors/SelectSelector.java | 8 +- .../types/selectors/SelectorContainer.java | 2 +- .../ant/types/selectors/SelectorUtils.java | 16 +-- .../ant/types/selectors/SizeSelector.java | 2 +- .../ant/types/selectors/TokenizedPattern.java | 12 +- .../ant/types/selectors/TypeSelector.java | 2 +- .../ant/types/selectors/WritableSelector.java | 5 +- .../selectors/modifiedselector/Cache.java | 2 +- .../modifiedselector/ChecksumAlgorithm.java | 2 +- .../modifiedselector/DigestAlgorithm.java | 2 +- .../modifiedselector/EqualComparator.java | 2 +- .../modifiedselector/ModifiedSelector.java | 40 +++--- .../modifiedselector/PropertiesfileCache.java | 8 +- .../ant/util/depend/AbstractAnalyzer.java | 18 +-- .../ant/util/depend/DependencyAnalyzer.java | 4 +- .../util/depend/bcel/AncestorAnalyzer.java | 28 ++-- .../util/depend/bcel/DependencyVisitor.java | 6 +- .../ant/util/depend/bcel/FullAnalyzer.java | 27 ++-- 89 files changed, 687 insertions(+), 772 deletions(-) diff --git a/src/main/org/apache/tools/ant/PropertyHelper.java b/src/main/org/apache/tools/ant/PropertyHelper.java index 62022c175..a6f60b610 100644 --- a/src/main/org/apache/tools/ant/PropertyHelper.java +++ b/src/main/org/apache/tools/ant/PropertyHelper.java @@ -163,6 +163,7 @@ public class PropertyHelper implements GetProperty { String property, Object value, PropertyHelper propertyHelper); } + //TODO PropertyEnumerator Delegate type, would improve PropertySet // -------------------------------------------------------- // diff --git a/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java b/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java index b30c5c5ff..2d5958091 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java @@ -113,10 +113,10 @@ public class ManifestTask extends Task { */ public void addConfiguredSection(Manifest.Section section) throws ManifestException { - Enumeration attributeKeys = section.getAttributeKeys(); + Enumeration attributeKeys = section.getAttributeKeys(); while (attributeKeys.hasMoreElements()) { Attribute attribute = section.getAttribute( - (String) attributeKeys.nextElement()); + attributeKeys.nextElement()); checkAttribute(attribute); } nestedManifest.addConfiguredSection(section); @@ -249,9 +249,9 @@ public class ManifestTask extends Task { } //look for and print warnings - for (Enumeration e = nestedManifest.getWarnings(); + for (Enumeration e = nestedManifest.getWarnings(); e.hasMoreElements();) { - log("Manifest warning: " + (String) e.nextElement(), + log("Manifest warning: " + e.nextElement(), Project.MSG_WARN); } try { diff --git a/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java b/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java index 51d9d2601..3466d3b22 100644 --- a/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java @@ -263,7 +263,7 @@ public abstract class MatchingTask extends Task implements SelectorContainer { * * @return an enumerator that goes through each of the selectors */ - public Enumeration selectorElements() { + public Enumeration selectorElements() { return fileset.selectorElements(); } diff --git a/src/main/org/apache/tools/ant/taskdefs/Redirector.java b/src/main/org/apache/tools/ant/taskdefs/Redirector.java index 5d2b1ad94..ed6b64a99 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Redirector.java +++ b/src/main/org/apache/tools/ant/taskdefs/Redirector.java @@ -37,7 +37,7 @@ import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.Task; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.filters.util.ChainReaderHelper; -import org.apache.tools.ant.util.LineOrientedOutputStream; +import org.apache.tools.ant.types.FilterChain; import org.apache.tools.ant.util.LineOrientedOutputStreamRedirector; import org.apache.tools.ant.util.StringUtils; import org.apache.tools.ant.util.TeeOutputStream; @@ -51,7 +51,7 @@ import org.apache.tools.ant.util.KeepAliveOutputStream; /** * The Redirector class manages the setup and connection of input and output * redirection for an Ant project component. - * + * * @since Ant 1.6 */ public class Redirector { @@ -157,13 +157,13 @@ public class Redirector { private PrintStream errorPrintStream = null; /** The output filter chains */ - private Vector outputFilterChains; + private Vector outputFilterChains; /** The error filter chains */ - private Vector errorFilterChains; + private Vector errorFilterChains; /** The input filter chains */ - private Vector inputFilterChains; + private Vector inputFilterChains; /** The output encoding */ private String outputEncoding = DEFAULT_ENCODING; @@ -194,7 +194,7 @@ public class Redirector { /** * Create a redirector instance for the given task - * + * * @param managingTask * the task for which the redirector is to work */ @@ -204,7 +204,7 @@ public class Redirector { /** * Create a redirector instance for the given task - * + * * @param managingTask * the project component for which the redirector is to work * @since Ant 1.6.3 @@ -215,7 +215,7 @@ public class Redirector { /** * Set the input to use for the task - * + * * @param input * the file from which input is read. */ @@ -225,7 +225,7 @@ public class Redirector { /** * Set the input to use for the task - * + * * @param input * the files from which input is read. */ @@ -241,7 +241,7 @@ public class Redirector { /** * Set the string to use as input - * + * * @param inputString * the string which is used as the input source */ @@ -254,7 +254,7 @@ public class Redirector { /** * Set whether to include the value of the input string in log messages. * Defaults to true. - * + * * @param logInputString * true or false. * @since Ant 1.7 @@ -265,7 +265,7 @@ public class Redirector { /** * Set a stream to use as input. - * + * * @param inputStream * the stream from which input will be read * @since Ant 1.6.3 @@ -279,7 +279,7 @@ public class Redirector { /** * File the output of the process is redirected to. If error is not * redirected, it too will appear in the output - * + * * @param out * the file to which output stream is written */ @@ -290,7 +290,7 @@ public class Redirector { /** * Files the output of the process is redirected to. If error is not * redirected, it too will appear in the output - * + * * @param out * the files to which output stream is written */ @@ -306,7 +306,7 @@ public class Redirector { /** * Set the output encoding. - * + * * @param outputEncoding * String. */ @@ -322,7 +322,7 @@ public class Redirector { /** * Set the error encoding. - * + * * @param errorEncoding * String. */ @@ -337,7 +337,7 @@ public class Redirector { /** * Set the input encoding. - * + * * @param inputEncoding * String. */ @@ -353,7 +353,7 @@ public class Redirector { /** * Controls whether error output of exec is logged. This is only useful when * output is being redirected and error output is desired in the Ant log - * + * * @param logError * if true the standard error is sent to the Ant log system and * not sent to output. @@ -368,7 +368,7 @@ public class Redirector { * This Redirector's subordinate * PropertyOutputStreams will not set their respective * properties while (appendProperties && append). - * + * * @param appendProperties * whether to append properties. */ @@ -380,7 +380,7 @@ public class Redirector { /** * Set the file to which standard error is to be redirected. - * + * * @param error * the file to which error is to be written */ @@ -390,7 +390,7 @@ public class Redirector { /** * Set the files to which standard error is to be redirected. - * + * * @param error * the file to which error is to be written */ @@ -406,7 +406,7 @@ public class Redirector { /** * Property name whose value should be set to the output of the process. - * + * * @param outputProperty * the name of the property to be set with the task's output. */ @@ -423,7 +423,7 @@ public class Redirector { /** * Whether output should be appended to or overwrite an existing file. * Defaults to false. - * + * * @param append * if true output and error streams are appended to their * respective files, if specified. @@ -441,7 +441,7 @@ public class Redirector { * If true, (error and non-error) output will be "teed", redirected as * specified while being sent to Ant's logging mechanism as if no * redirection had taken place. Defaults to false. - * + * * @param alwaysLog * boolean * @since Ant 1.6.3 @@ -458,7 +458,7 @@ public class Redirector { /** * Whether output and error files should be created even when empty. * Defaults to true. - * + * * @param createEmptyFiles * boolean. */ @@ -473,7 +473,7 @@ public class Redirector { /** * Property name whose value should be set to the error of the process. - * + * * @param errorProperty * the name of the property to be set with the error output. */ @@ -489,11 +489,11 @@ public class Redirector { /** * Set the input FilterChains. - * + * * @param inputFilterChains * Vector containing FilterChain. */ - public void setInputFilterChains(Vector inputFilterChains) { + public void setInputFilterChains(Vector inputFilterChains) { synchronized (inMutex) { this.inputFilterChains = inputFilterChains; } @@ -501,11 +501,11 @@ public class Redirector { /** * Set the output FilterChains. - * + * * @param outputFilterChains * Vector containing FilterChain. */ - public void setOutputFilterChains(Vector outputFilterChains) { + public void setOutputFilterChains(Vector outputFilterChains) { synchronized (outMutex) { this.outputFilterChains = outputFilterChains; } @@ -513,11 +513,11 @@ public class Redirector { /** * Set the error FilterChains. - * + * * @param errorFilterChains * Vector containing FilterChain. */ - public void setErrorFilterChains(Vector errorFilterChains) { + public void setErrorFilterChains(Vector errorFilterChains) { synchronized (errMutex) { this.errorFilterChains = errorFilterChains; } @@ -525,12 +525,12 @@ public class Redirector { /** * Set a property from a ByteArrayOutputStream - * + * * @param baos * contains the property value. * @param propertyName * the property name. - * + * * @exception IOException * if the value cannot be read form the stream. */ @@ -746,10 +746,10 @@ public class Redirector { /** * Create the StreamHandler to use with our Execute instance. - * + * * @return the execute stream handler to manage the input, output and error * streams. - * + * * @throws BuildException * if the execute stream handler cannot be created. */ @@ -762,7 +762,7 @@ public class Redirector { /** * Pass output sent to System.out to specified output. - * + * * @param output * the data to be output */ @@ -777,16 +777,16 @@ public class Redirector { /** * Handle an input request - * + * * @param buffer * the buffer into which data is to be read. * @param offset * the offset into the buffer at which data is stored. * @param length * the amount of data to read - * + * * @return the number of bytes read - * + * * @exception IOException * if the data cannot be read */ @@ -804,7 +804,7 @@ public class Redirector { /** * Process data due to a flush operation. - * + * * @param output * the data being flushed. */ @@ -820,7 +820,7 @@ public class Redirector { /** * Process error output - * + * * @param output * the error output data. */ @@ -835,7 +835,7 @@ public class Redirector { /** * Handle a flush operation on the error stream - * + * * @param output * the error information being flushed. */ @@ -851,7 +851,7 @@ public class Redirector { /** * Get the output stream for the redirector - * + * * @return the redirector's output stream or null if no output has been * configured */ @@ -863,7 +863,7 @@ public class Redirector { /** * Get the error stream for the redirector - * + * * @return the redirector's error stream or null if no output has been * configured */ @@ -875,7 +875,7 @@ public class Redirector { /** * Get the input stream for the redirector - * + * * @return the redirector's input stream or null if no output has been * configured */ @@ -887,10 +887,10 @@ public class Redirector { /** * Complete redirection. - * + * * This operation will close any streams and create any specified property * values. - * + * * @throws IOException * if the output properties cannot be read from their output * streams. diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java b/src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java index cf415c9ed..3e729639b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java @@ -49,24 +49,24 @@ public class AntAnalyzer extends AbstractAnalyzer { * @param classes a vector to be populated with the names of the * dependency classes. */ - protected void determineDependencies(Vector files, Vector classes) { + protected void determineDependencies(Vector files, Vector classes) { // we get the root classes and build up a set of // classes upon which they depend - Hashtable dependencies = new Hashtable(); - Hashtable containers = new Hashtable(); - Hashtable toAnalyze = new Hashtable(); - for (Enumeration e = getRootClasses(); e.hasMoreElements();) { - String classname = (String) e.nextElement(); + Hashtable dependencies = new Hashtable(); + Hashtable containers = new Hashtable(); + Hashtable toAnalyze = new Hashtable(); + for (Enumeration e = getRootClasses(); e.hasMoreElements();) { + String classname = e.nextElement(); toAnalyze.put(classname, classname); } int count = 0; int maxCount = isClosureRequired() ? MAX_LOOPS : 1; - Hashtable analyzedDeps = null; + Hashtable analyzedDeps = null; while (toAnalyze.size() != 0 && count++ < maxCount) { - analyzedDeps = new Hashtable(); - for (Enumeration e = toAnalyze.keys(); e.hasMoreElements();) { - String classname = (String) e.nextElement(); + analyzedDeps = new Hashtable(); + for (Enumeration e = toAnalyze.keys(); e.hasMoreElements();) { + String classname = e.nextElement(); dependencies.put(classname, classname); try { File container = getClassContainer(classname); @@ -90,10 +90,7 @@ public class AntAnalyzer extends AbstractAnalyzer { } ClassFile classFile = new ClassFile(); classFile.read(inStream); - Vector dependencyList = classFile.getClassRefs(); - Enumeration depEnum = dependencyList.elements(); - while (depEnum.hasMoreElements()) { - String dependency = (String) depEnum.nextElement(); + for (String dependency : classFile.getClassRefs()) { analyzedDeps.put(dependency, dependency); } } finally { @@ -110,9 +107,7 @@ public class AntAnalyzer extends AbstractAnalyzer { toAnalyze.clear(); // now recover all the dependencies collected and add to the list. - Enumeration depsEnum = analyzedDeps.elements(); - while (depsEnum.hasMoreElements()) { - String className = (String) depsEnum.nextElement(); + for (String className : analyzedDeps.values()) { if (!dependencies.containsKey(className)) { toAnalyze.put(className, className); } @@ -120,20 +115,18 @@ public class AntAnalyzer extends AbstractAnalyzer { } // pick up the last round of dependencies that were determined - Enumeration depsEnum = analyzedDeps.elements(); - while (depsEnum.hasMoreElements()) { - String className = (String) depsEnum.nextElement(); + for (String className : analyzedDeps.values()) { dependencies.put(className, className); } files.removeAllElements(); - for (Enumeration e = containers.keys(); e.hasMoreElements();) { - files.addElement((File) e.nextElement()); + for (File f : containers.keySet()) { + files.add(f); } classes.removeAllElements(); - for (Enumeration e = dependencies.keys(); e.hasMoreElements();) { - classes.addElement((String) e.nextElement()); + for (String dependency :dependencies.keySet()) { + classes.add(dependency); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/depend/ClassFile.java b/src/main/org/apache/tools/ant/taskdefs/optional/depend/ClassFile.java index 1435d63da..209e6b394 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/depend/ClassFile.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/depend/ClassFile.java @@ -86,9 +86,9 @@ public class ClassFile { * * @return a vector of class names which this class references */ - public Vector getClassRefs() { + public Vector getClassRefs() { - Vector classRefs = new Vector(); + Vector classRefs = new Vector(); final int size = constantPool.size(); for (int i = 0; i < size; ++i) { @@ -99,7 +99,7 @@ public class ClassFile { ClassCPInfo classEntry = (ClassCPInfo) entry; if (!classEntry.getClassName().equals(className)) { - classRefs.addElement( + classRefs.add( ClassFileUtils.convertSlashName(classEntry.getClassName())); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPool.java b/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPool.java index 70168a098..67d366b8f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPool.java @@ -19,9 +19,10 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; import java.io.DataInputStream; import java.io.IOException; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * The constant pool of a Java class. The constant pool is a collection of @@ -34,23 +35,19 @@ import java.util.Vector; public class ConstantPool { /** The entries in the constant pool. */ - private Vector entries; + private final List entries = new ArrayList(); /** * A Hashtable of UTF8 entries - used to get constant pool indexes of * the UTF8 values quickly */ - private Hashtable utf8Indexes; + private final Map utf8Indexes = new HashMap(); /** Initialise the constant pool. */ public ConstantPool() { - entries = new Vector(); - // The zero index is never present in the constant pool itself so // we add a null entry for it - entries.addElement(null); - - utf8Indexes = new Hashtable(); + entries.add(null); } /** @@ -92,13 +89,13 @@ public class ConstantPool { public int addEntry(ConstantPoolEntry entry) { int index = entries.size(); - entries.addElement(entry); + entries.add(entry); int numSlots = entry.getNumEntries(); // add null entries for any additional slots required. for (int j = 0; j < numSlots - 1; ++j) { - entries.addElement(null); + entries.add(null); } if (entry instanceof Utf8CPInfo) { @@ -116,9 +113,7 @@ public class ConstantPool { * into the actual data for that entry. */ public void resolve() { - for (Enumeration i = entries.elements(); i.hasMoreElements();) { - ConstantPoolEntry poolInfo = (ConstantPoolEntry) i.nextElement(); - + for (ConstantPoolEntry poolInfo : entries) { if (poolInfo != null && !poolInfo.isResolved()) { poolInfo.resolve(this); } @@ -133,7 +128,7 @@ public class ConstantPool { * @return the constant pool entry at that index. */ public ConstantPoolEntry getEntry(int index) { - return (ConstantPoolEntry) entries.elementAt(index); + return entries.get(index); } /** @@ -145,7 +140,7 @@ public class ConstantPool { */ public int getUTF8Entry(String value) { int index = -1; - Integer indexInteger = (Integer) utf8Indexes.get(value); + Integer indexInteger = utf8Indexes.get(value); if (indexInteger != null) { index = indexInteger.intValue(); @@ -167,7 +162,7 @@ public class ConstantPool { final int size = entries.size(); for (int i = 0; i < size && index == -1; ++i) { - Object element = entries.elementAt(i); + Object element = entries.get(i); if (element instanceof ClassCPInfo) { ClassCPInfo classinfo = (ClassCPInfo) element; @@ -194,7 +189,7 @@ public class ConstantPool { final int size = entries.size(); for (int i = 0; i < size && index == -1; ++i) { - Object element = entries.elementAt(i); + Object element = entries.get(i); if (element instanceof ConstantCPInfo) { ConstantCPInfo constantEntry = (ConstantCPInfo) element; @@ -225,7 +220,7 @@ public class ConstantPool { final int size = entries.size(); for (int i = 0; i < size && index == -1; ++i) { - Object element = entries.elementAt(i); + Object element = entries.get(i); if (element instanceof MethodRefCPInfo) { MethodRefCPInfo methodRefEntry = (MethodRefCPInfo) element; @@ -260,7 +255,7 @@ public class ConstantPool { final int size = entries.size(); for (int i = 0; i < size && index == -1; ++i) { - Object element = entries.elementAt(i); + Object element = entries.get(i); if (element instanceof InterfaceMethodRefCPInfo) { InterfaceMethodRefCPInfo interfaceMethodRefEntry @@ -297,7 +292,7 @@ public class ConstantPool { final int size = entries.size(); for (int i = 0; i < size && index == -1; ++i) { - Object element = entries.elementAt(i); + Object element = entries.get(i); if (element instanceof FieldRefCPInfo) { FieldRefCPInfo fieldRefEntry = (FieldRefCPInfo) element; @@ -327,7 +322,7 @@ public class ConstantPool { final int size = entries.size(); for (int i = 0; i < size && index == -1; ++i) { - Object element = entries.elementAt(i); + Object element = entries.get(i); if (element instanceof NameAndTypeCPInfo) { NameAndTypeCPInfo nameAndTypeEntry @@ -349,7 +344,7 @@ public class ConstantPool { * @return the constant pool entries as strings */ public String toString() { - StringBuffer sb = new StringBuffer("\n"); + StringBuilder sb = new StringBuilder("\n"); final int size = entries.size(); for (int i = 0; i < size; ++i) { diff --git a/src/main/org/apache/tools/ant/types/AbstractFileSet.java b/src/main/org/apache/tools/ant/types/AbstractFileSet.java index 60e0b900a..5b8da5434 100644 --- a/src/main/org/apache/tools/ant/types/AbstractFileSet.java +++ b/src/main/org/apache/tools/ant/types/AbstractFileSet.java @@ -18,10 +18,11 @@ package org.apache.tools.ant.types; import java.io.File; +import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; -import java.util.Iterator; +import java.util.List; import java.util.Stack; -import java.util.Vector; import org.apache.tools.ant.Project; import org.apache.tools.ant.FileScanner; @@ -62,8 +63,8 @@ public abstract class AbstractFileSet extends DataType implements Cloneable, SelectorContainer { private PatternSet defaultPatterns = new PatternSet(); - private Vector additionalPatterns = new Vector(); - private Vector selectors = new Vector(); + private List additionalPatterns = new ArrayList(); + private List selectors = new ArrayList(); private File dir; private boolean useDefaultExcludes = true; @@ -165,7 +166,7 @@ public abstract class AbstractFileSet extends DataType throw noChildrenAllowed(); } PatternSet patterns = new PatternSet(); - additionalPatterns.addElement(patterns); + additionalPatterns.add(patterns); directoryScanner = null; return patterns; } @@ -579,9 +580,7 @@ public abstract class AbstractFileSet extends DataType if (defaultPatterns.hasPatterns(getProject())) { return true; } - Enumeration e = additionalPatterns.elements(); - while (e.hasMoreElements()) { - PatternSet ps = (PatternSet) e.nextElement(); + for (PatternSet ps : additionalPatterns) { if (ps.hasPatterns(getProject())) { return true; } @@ -621,12 +620,12 @@ public abstract class AbstractFileSet extends DataType * * @return an Enumeration of selectors. */ - public synchronized Enumeration selectorElements() { + public synchronized Enumeration selectorElements() { if (isReference()) { return getRef(getProject()).selectorElements(); } dieOnCircularReference(); - return selectors.elements(); + return Collections.enumeration(selectors); } /** @@ -638,7 +637,7 @@ public abstract class AbstractFileSet extends DataType if (isReference()) { throw noChildrenAllowed(); } - selectors.addElement(selector); + selectors.add(selector); directoryScanner = null; setChecked(false); } @@ -844,13 +843,11 @@ public abstract class AbstractFileSet extends DataType try { AbstractFileSet fs = (AbstractFileSet) super.clone(); fs.defaultPatterns = (PatternSet) defaultPatterns.clone(); - fs.additionalPatterns = new Vector(additionalPatterns.size()); - Enumeration e = additionalPatterns.elements(); - while (e.hasMoreElements()) { - fs.additionalPatterns - .addElement(((PatternSet) e.nextElement()).clone()); + fs.additionalPatterns = new ArrayList(additionalPatterns.size()); + for (PatternSet ps : additionalPatterns) { + fs.additionalPatterns.add((PatternSet) ps.clone()); } - fs.selectors = new Vector(selectors); + fs.selectors = new ArrayList(selectors); return fs; } catch (CloneNotSupportedException e) { throw new BuildException(e); @@ -898,13 +895,12 @@ public abstract class AbstractFileSet extends DataType PatternSet ps = (PatternSet) defaultPatterns.clone(); final int count = additionalPatterns.size(); for (int i = 0; i < count; i++) { - Object o = additionalPatterns.elementAt(i); - ps.append((PatternSet) o, p); + ps.append(additionalPatterns.get(i), p); } return ps; } - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -912,14 +908,12 @@ public abstract class AbstractFileSet extends DataType if (isReference()) { super.dieOnCircularReference(stk, p); } else { - for (Iterator i = selectors.iterator(); i.hasNext(); ) { - Object o = i.next(); - if (o instanceof DataType) { - pushAndInvokeCircularReferenceCheck((DataType) o, stk, p); + for (FileSelector fileSelector : selectors) { + if (fileSelector instanceof DataType) { + pushAndInvokeCircularReferenceCheck((DataType) fileSelector, stk, p); } } - for (Iterator i = additionalPatterns.iterator(); i.hasNext(); ) { - PatternSet ps = (PatternSet) i.next(); + for (PatternSet ps : additionalPatterns) { pushAndInvokeCircularReferenceCheck(ps, stk, p); } setChecked(true); diff --git a/src/main/org/apache/tools/ant/types/ArchiveFileSet.java b/src/main/org/apache/tools/ant/types/ArchiveFileSet.java index 4f77bc737..da8914bd4 100644 --- a/src/main/org/apache/tools/ant/types/ArchiveFileSet.java +++ b/src/main/org/apache/tools/ant/types/ArchiveFileSet.java @@ -207,6 +207,7 @@ public abstract class ArchiveFileSet extends FileSet { * @throws BuildException if the reference is invalid (circular ref, wrong class, etc). * @since Ant 1.8 */ + // TODO is the above true? AFAICT the calls look circular :/ protected Object getCheckedRef(Project p) { return getRef(p); } @@ -475,7 +476,7 @@ public abstract class ArchiveFileSet extends FileSet { */ public Object clone() { if (isReference()) { - return ((ArchiveFileSet) getRef(getProject())).clone(); + return getCheckedRef(ArchiveFileSet.class, getDataTypeName(), getProject()).clone(); } return super.clone(); } @@ -545,7 +546,7 @@ public abstract class ArchiveFileSet extends FileSet { } } - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; diff --git a/src/main/org/apache/tools/ant/types/ArchiveScanner.java b/src/main/org/apache/tools/ant/types/ArchiveScanner.java index 4d2f3ad81..67ff09c27 100644 --- a/src/main/org/apache/tools/ant/types/ArchiveScanner.java +++ b/src/main/org/apache/tools/ant/types/ArchiveScanner.java @@ -20,7 +20,6 @@ package org.apache.tools.ant.types; import java.io.File; import java.util.Map; -import java.util.Set; import java.util.TreeMap; import java.util.Iterator; @@ -62,22 +61,22 @@ public abstract class ArchiveScanner extends DirectoryScanner { /** * record list of all file zip entries */ - private TreeMap fileEntries = new TreeMap(); + private Map fileEntries = new TreeMap(); /** * record list of all directory zip entries */ - private TreeMap dirEntries = new TreeMap(); + private Map dirEntries = new TreeMap(); /** * record list of matching file zip entries */ - private TreeMap matchFileEntries = new TreeMap(); + private Map matchFileEntries = new TreeMap(); /** * record list of matching directory zip entries */ - private TreeMap matchDirEntries = new TreeMap(); + private Map matchDirEntries = new TreeMap(); /** * encoding of file names. @@ -159,8 +158,7 @@ public abstract class ArchiveScanner extends DirectoryScanner { return super.getIncludedFiles(); } scanme(); - Set s = matchFileEntries.keySet(); - return (String[]) (s.toArray(new String[s.size()])); + return matchFileEntries.keySet().toArray(new String[matchFileEntries.size()]); } /** @@ -189,8 +187,7 @@ public abstract class ArchiveScanner extends DirectoryScanner { return super.getIncludedDirectories(); } scanme(); - Set s = matchDirEntries.keySet(); - return (String[]) (s.toArray(new String[s.size()])); + return matchDirEntries.keySet().toArray(new String[matchDirEntries.size()]); } /** @@ -212,7 +209,7 @@ public abstract class ArchiveScanner extends DirectoryScanner { * @return an Iterator of Resources. * @since Ant 1.7 */ - /* package-private for now */ Iterator getResourceFiles(Project project) { + /* package-private for now */ Iterator getResourceFiles(Project project) { if (src == null) { return new FileResourceIterator(project, getBasedir(), getIncludedFiles()); } @@ -226,7 +223,7 @@ public abstract class ArchiveScanner extends DirectoryScanner { * @return an Iterator of Resources. * @since Ant 1.7 */ - /* package-private for now */ Iterator getResourceDirectories(Project project) { + /* package-private for now */ Iterator getResourceDirectories(Project project) { if (src == null) { return new FileResourceIterator(project, getBasedir(), getIncludedDirectories()); } @@ -280,12 +277,12 @@ public abstract class ArchiveScanner extends DirectoryScanner { // first check if the archive needs to be scanned again scanme(); if (fileEntries.containsKey(name)) { - return (Resource) fileEntries.get(name); + return fileEntries.get(name); } name = trimSeparator(name); if (dirEntries.containsKey(name)) { - return (Resource) dirEntries.get(name); + return dirEntries.get(name); } return new Resource(name); } @@ -308,10 +305,10 @@ public abstract class ArchiveScanner extends DirectoryScanner { */ protected abstract void fillMapsFromArchive(Resource archive, String encoding, - Map fileEntries, - Map matchFileEntries, - Map dirEntries, - Map matchDirEntries); + Map fileEntries, + Map matchFileEntries, + Map dirEntries, + Map matchDirEntries); /** * if the datetime of the archive did not change since diff --git a/src/main/org/apache/tools/ant/types/Assertions.java b/src/main/org/apache/tools/ant/types/Assertions.java index af40d1e80..baf3ee1e2 100644 --- a/src/main/org/apache/tools/ant/types/Assertions.java +++ b/src/main/org/apache/tools/ant/types/Assertions.java @@ -22,7 +22,6 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -76,7 +75,7 @@ public class Assertions extends DataType implements Cloneable { /** * list of type BaseAssertion */ - private ArrayList assertionList = new ArrayList(); + private ArrayList assertionList = new ArrayList(); /** @@ -163,7 +162,7 @@ public class Assertions extends DataType implements Cloneable { * for adding to a command line * @param commandList the command line to format */ - public void applyAssertions(List commandList) { + public void applyAssertions(List commandList) { getProject().log("Applying assertions", Project.MSG_DEBUG); Assertions clause = getFinalReference(); //do the system assertions @@ -176,9 +175,7 @@ public class Assertions extends DataType implements Cloneable { } //now any inner assertions - Iterator it = clause.assertionList.iterator(); - while (it.hasNext()) { - BaseAssertion assertion = (BaseAssertion) it.next(); + for (BaseAssertion assertion : clause.assertionList) { String arg = assertion.toCommand(); getProject().log("adding assertion " + arg, Project.MSG_DEBUG); commandList.add(arg); @@ -199,9 +196,7 @@ public class Assertions extends DataType implements Cloneable { } //now any inner assertions - Iterator it = clause.assertionList.iterator(); - while (it.hasNext()) { - BaseAssertion assertion = (BaseAssertion) it.next(); + for (BaseAssertion assertion : clause.assertionList) { String arg = assertion.toCommand(); addVmArgument(command, arg); } @@ -212,7 +207,7 @@ public class Assertions extends DataType implements Cloneable { * for adding to a command line * @param commandIterator list of commands */ - public void applyAssertions(final ListIterator commandIterator) { + public void applyAssertions(final ListIterator commandIterator) { getProject().log("Applying assertions", Project.MSG_DEBUG); Assertions clause = getFinalReference(); //do the system assertions @@ -225,9 +220,7 @@ public class Assertions extends DataType implements Cloneable { } //now any inner assertions - Iterator it = clause.assertionList.iterator(); - while (it.hasNext()) { - BaseAssertion assertion = (BaseAssertion) it.next(); + for (BaseAssertion assertion : clause.assertionList) { String arg = assertion.toCommand(); getProject().log("adding assertion " + arg, Project.MSG_DEBUG); commandIterator.add(arg); @@ -254,7 +247,7 @@ public class Assertions extends DataType implements Cloneable { */ public Object clone() throws CloneNotSupportedException { Assertions that = (Assertions) super.clone(); - that.assertionList = (ArrayList) assertionList.clone(); + that.assertionList = new ArrayList(assertionList); return that; } diff --git a/src/main/org/apache/tools/ant/types/Commandline.java b/src/main/org/apache/tools/ant/types/Commandline.java index ad68f1c57..d157c15ac 100644 --- a/src/main/org/apache/tools/ant/types/Commandline.java +++ b/src/main/org/apache/tools/ant/types/Commandline.java @@ -20,7 +20,6 @@ package org.apache.tools.ant.types; import java.io.File; import java.util.StringTokenizer; -import java.util.Vector; import java.util.ArrayList; import java.util.List; import java.util.ListIterator; @@ -59,7 +58,7 @@ public class Commandline implements Cloneable { /** * The arguments of the command */ - private Vector arguments = new Vector(); + private List arguments = new ArrayList(); /** * the program to execute @@ -232,7 +231,7 @@ public class Commandline implements Cloneable { if (realPos == -1) { realPos = (executable == null ? 0 : 1); for (int i = 0; i < position; i++) { - Argument arg = (Argument) arguments.elementAt(i); + Argument arg = (Argument) arguments.get(i); realPos += arg.getParts().length; } } @@ -306,9 +305,9 @@ public class Commandline implements Cloneable { public Argument createArgument(boolean insertAtStart) { Argument argument = new Argument(); if (insertAtStart) { - arguments.insertElementAt(argument, 0); + arguments.add(0, argument); } else { - arguments.addElement(argument); + arguments.add(argument); } return argument; } @@ -349,11 +348,9 @@ public class Commandline implements Cloneable { * @return the commandline as an array of strings. */ public String[] getCommandline() { - List commands = new LinkedList(); - ListIterator list = commands.listIterator(); - addCommandToList(list); - final String[] result = new String[commands.size()]; - return (String[]) commands.toArray(result); + final List commands = new LinkedList(); + addCommandToList(commands.listIterator()); + return commands.toArray(new String[commands.size()]); } /** @@ -361,7 +358,7 @@ public class Commandline implements Cloneable { * @param list the list to add to. * @since Ant 1.6 */ - public void addCommandToList(ListIterator list) { + public void addCommandToList(ListIterator list) { if (executable != null) { list.add(executable); } @@ -374,10 +371,9 @@ public class Commandline implements Cloneable { * @return the arguments as an array of strings. */ public String[] getArguments() { - List result = new ArrayList(arguments.size() * 2); + List result = new ArrayList(arguments.size() * 2); addArgumentsToList(result.listIterator()); - String [] res = new String[result.size()]; - return (String[]) result.toArray(res); + return result.toArray(new String[result.size()]); } /** @@ -385,10 +381,10 @@ public class Commandline implements Cloneable { * @param list the list of arguments. * @since Ant 1.6 */ - public void addArgumentsToList(ListIterator list) { + public void addArgumentsToList(ListIterator list) { final int size = arguments.size(); for (int i = 0; i < size; i++) { - Argument arg = (Argument) arguments.elementAt(i); + Argument arg = arguments.get(i); String[] s = arg.getParts(); if (s != null) { for (int j = 0; j < s.length; j++) { @@ -448,7 +444,7 @@ public class Commandline implements Cloneable { return ""; } // path containing one or more elements - final StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); for (int i = 0; i < line.length; i++) { if (i > 0) { result.append(' '); @@ -475,9 +471,9 @@ public class Commandline implements Cloneable { final int inQuote = 1; final int inDoubleQuote = 2; int state = normal; - StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true); - Vector v = new Vector(); - StringBuffer current = new StringBuffer(); + final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true); + final ArrayList result = new ArrayList(); + final StringBuilder current = new StringBuilder(); boolean lastTokenHasBeenQuoted = false; while (tok.hasMoreTokens()) { @@ -506,8 +502,8 @@ public class Commandline implements Cloneable { state = inDoubleQuote; } else if (" ".equals(nextTok)) { if (lastTokenHasBeenQuoted || current.length() != 0) { - v.addElement(current.toString()); - current = new StringBuffer(); + result.add(current.toString()); + current.setLength(0); } } else { current.append(nextTok); @@ -517,14 +513,12 @@ public class Commandline implements Cloneable { } } if (lastTokenHasBeenQuoted || current.length() != 0) { - v.addElement(current.toString()); + result.add(current.toString()); } if (state == inQuote || state == inDoubleQuote) { throw new BuildException("unbalanced quotes in " + toProcess); } - String[] args = new String[v.size()]; - v.copyInto(args); - return args; + return result.toArray(new String[result.size()]); } /** @@ -543,7 +537,7 @@ public class Commandline implements Cloneable { public Object clone() { try { Commandline c = (Commandline) super.clone(); - c.arguments = (Vector) arguments.clone(); + c.arguments = new ArrayList(arguments); return c; } catch (CloneNotSupportedException e) { throw new BuildException(e); @@ -555,7 +549,7 @@ public class Commandline implements Cloneable { */ public void clear() { executable = null; - arguments.removeAllElements(); + arguments.clear(); } /** @@ -563,7 +557,7 @@ public class Commandline implements Cloneable { * another operation. */ public void clearArgs() { - arguments.removeAllElements(); + arguments.clear(); } /** @@ -689,7 +683,7 @@ public class Commandline implements Cloneable { * @since Ant 1.7 * @return an Iterator. */ - public Iterator iterator() { + public Iterator iterator() { return arguments.iterator(); } } diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index 94461fc62..4e1f12cc7 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -79,7 +79,7 @@ public class CommandlineJava implements Cloneable { /** the system properties. */ Properties sys = null; // CheckStyle:VisibilityModifier ON - private Vector propertySets = new Vector(); + private Vector propertySets = new Vector(); /** * Get the properties as an array; this is an override of the @@ -89,13 +89,12 @@ public class CommandlineJava implements Cloneable { */ public String[] getVariables() throws BuildException { - List definitions = new LinkedList(); - ListIterator list = definitions.listIterator(); - addDefinitionsToList(list); + List definitions = new LinkedList(); + addDefinitionsToList(definitions.listIterator()); if (definitions.size() == 0) { return null; } else { - return (String[]) definitions.toArray(new String[definitions.size()]); + return definitions.toArray(new String[definitions.size()]); } } @@ -103,7 +102,7 @@ public class CommandlineJava implements Cloneable { * Add all definitions (including property sets) to a list. * @param listIt list iterator supporting add method. */ - public void addDefinitionsToList(ListIterator listIt) { + public void addDefinitionsToList(ListIterator listIt) { String[] props = super.getVariables(); if (props != null) { for (int i = 0; i < props.length; i++) { @@ -111,7 +110,7 @@ public class CommandlineJava implements Cloneable { } } Properties propertySetProperties = mergePropertySets(); - for (Enumeration e = propertySetProperties.keys(); + for (Enumeration e = propertySetProperties.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); String value = propertySetProperties.getProperty(key); @@ -138,7 +137,7 @@ public class CommandlineJava implements Cloneable { try { sys = System.getProperties(); Properties p = new Properties(); - for (Enumeration e = sys.propertyNames(); e.hasMoreElements();) { + for (Enumeration e = sys.propertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); String value = sys.getProperty(name); if (name != null && value != null) { @@ -146,8 +145,7 @@ public class CommandlineJava implements Cloneable { } } p.putAll(mergePropertySets()); - for (Enumeration e = variables.elements(); e.hasMoreElements();) { - Environment.Variable v = (Environment.Variable) e.nextElement(); + for (Environment.Variable v : variables) { v.validate(); p.put(v.getKey(), v.getValue()); } @@ -180,11 +178,12 @@ public class CommandlineJava implements Cloneable { * @return a cloned instance of SysProperties. * @exception CloneNotSupportedException for signature. */ + @SuppressWarnings("unchecked") public Object clone() throws CloneNotSupportedException { try { SysProperties c = (SysProperties) super.clone(); - c.variables = (Vector) variables.clone(); - c.propertySets = (Vector) propertySets.clone(); + c.variables = (Vector) variables.clone(); + c.propertySets = (Vector) propertySets.clone(); return c; } catch (CloneNotSupportedException e) { return null; @@ -215,9 +214,7 @@ public class CommandlineJava implements Cloneable { */ private Properties mergePropertySets() { Properties p = new Properties(); - for (Enumeration e = propertySets.elements(); - e.hasMoreElements();) { - PropertySet ps = (PropertySet) e.nextElement(); + for (PropertySet ps : propertySets) { p.putAll(ps.getProperties()); } return p; @@ -399,12 +396,11 @@ public class CommandlineJava implements Cloneable { */ public String[] getCommandline() { //create the list - List commands = new LinkedList(); - final ListIterator listIterator = commands.listIterator(); + List commands = new LinkedList(); //fill it - addCommandsToList(listIterator); + addCommandsToList(commands.listIterator()); //convert to an array - return (String[]) commands.toArray(new String[commands.size()]); + return commands.toArray(new String[commands.size()]); } /** @@ -412,7 +408,7 @@ public class CommandlineJava implements Cloneable { * @param listIterator an iterator that supports the add method. * @since Ant 1.6 */ - private void addCommandsToList(final ListIterator listIterator) { + private void addCommandsToList(final ListIterator listIterator) { //create the command to run Java, including user specified options getActualVMCommand().addCommandToList(listIterator); // properties are part of the vm options... diff --git a/src/main/org/apache/tools/ant/types/Description.java b/src/main/org/apache/tools/ant/types/Description.java index 6f8fb4891..2ed49c9c2 100644 --- a/src/main/org/apache/tools/ant/types/Description.java +++ b/src/main/org/apache/tools/ant/types/Description.java @@ -25,7 +25,8 @@ import org.apache.tools.ant.UnknownElement; import org.apache.tools.ant.Target; import org.apache.tools.ant.helper.ProjectHelperImpl; -import java.util.Vector; +import java.util.ArrayList; +import java.util.List; /** @@ -50,7 +51,7 @@ public class Description extends DataType { */ public void addText(String text) { - ProjectHelper ph = (ProjectHelper) getProject().getReference(ProjectHelper.PROJECTHELPER_REFERENCE); + ProjectHelper ph = getProject().getReference(ProjectHelper.PROJECTHELPER_REFERENCE); if (!(ph instanceof ProjectHelperImpl)) { // New behavior for delayed task creation. Description // will be evaluated in Project.getDescription() @@ -73,31 +74,23 @@ public class Description extends DataType { * the targets. */ public static String getDescription(Project project) { - Vector targets = (Vector) project.getReference(ProjectHelper2.REFID_TARGETS); + List targets = project.getReference(ProjectHelper2.REFID_TARGETS); if (targets == null) { return null; } - StringBuffer description = new StringBuffer(); - final int size = targets.size(); - for (int i = 0; i < size; i++) { - Target t = (Target) targets.elementAt(i); + StringBuilder description = new StringBuilder(); + for (Target t : targets) { concatDescriptions(project, t, description); } return description.toString(); } private static void concatDescriptions(Project project, Target t, - StringBuffer description) { + StringBuilder description) { if (t == null) { return; } - Vector tasks = findElementInTarget(project, t, "description"); - if (tasks == null) { - return; - } - final int size = tasks.size(); - for (int i = 0; i < size; i++) { - Task task = (Task) tasks.elementAt(i); + for (Task task : findElementInTarget(project, t, "description")) { if (!(task instanceof UnknownElement)) { continue; } @@ -109,13 +102,12 @@ public class Description extends DataType { } } - private static Vector findElementInTarget(Project project, + private static List findElementInTarget(Project project, Target t, String name) { - Task[] tasks = t.getTasks(); - Vector elems = new Vector(); - for (int i = 0; i < tasks.length; i++) { - if (name.equals(tasks[i].getTaskName())) { - elems.addElement(tasks[i]); + final List elems = new ArrayList(); + for (Task task : t.getTasks()) { + if (name.equals(task.getTaskName())) { + elems.add(task); } } return elems; diff --git a/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java b/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java index 26e794a64..bc893d8d8 100644 --- a/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java +++ b/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java @@ -67,7 +67,7 @@ public abstract class EnumeratedAttribute { * http://issues.apache.org/bugzilla/show_bug.cgi?id=14831 */ public static EnumeratedAttribute getInstance( - Class/**/ clazz, + Class clazz, String value) throws BuildException { if (!EnumeratedAttribute.class.isAssignableFrom(clazz)) { throw new BuildException( @@ -75,7 +75,7 @@ public abstract class EnumeratedAttribute { } EnumeratedAttribute ea = null; try { - ea = (EnumeratedAttribute) clazz.newInstance(); + ea = clazz.newInstance(); } catch (Exception e) { throw new BuildException(e); } diff --git a/src/main/org/apache/tools/ant/types/FileList.java b/src/main/org/apache/tools/ant/types/FileList.java index 3f127382c..2c2c68f7f 100644 --- a/src/main/org/apache/tools/ant/types/FileList.java +++ b/src/main/org/apache/tools/ant/types/FileList.java @@ -19,8 +19,9 @@ package org.apache.tools.ant.types; import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.StringTokenizer; -import java.util.Vector; import java.util.Iterator; import org.apache.tools.ant.Project; @@ -36,7 +37,7 @@ import org.apache.tools.ant.types.resources.FileResourceIterator; */ public class FileList extends DataType implements ResourceCollection { - private Vector filenames = new Vector(); + private List filenames = new ArrayList(); private File dir; /** @@ -108,7 +109,7 @@ public class FileList extends DataType implements ResourceCollection { StringTokenizer tok = new StringTokenizer( filenames, ", \t\n\r\f", false); while (tok.hasMoreTokens()) { - this.filenames.addElement(tok.nextToken()); + this.filenames.add(tok.nextToken()); } } } @@ -131,9 +132,7 @@ public class FileList extends DataType implements ResourceCollection { throw new BuildException("No files specified for filelist."); } - String[] result = new String[filenames.size()]; - filenames.copyInto(result); - return result; + return filenames.toArray(new String[filenames.size()]); } /** @@ -180,7 +179,7 @@ public class FileList extends DataType implements ResourceCollection { throw new BuildException( "No name specified in nested file element"); } - filenames.addElement(name.getName()); + filenames.add(name.getName()); } /** @@ -190,10 +189,10 @@ public class FileList extends DataType implements ResourceCollection { */ public Iterator iterator() { if (isReference()) { - return ((FileList) getRef(getProject())).iterator(); + return getRef(getProject()).iterator(); } return new FileResourceIterator(getProject(), dir, - (String[]) (filenames.toArray(new String[filenames.size()]))); + filenames.toArray(new String[filenames.size()])); } /** diff --git a/src/main/org/apache/tools/ant/types/FilterSetCollection.java b/src/main/org/apache/tools/ant/types/FilterSetCollection.java index 1faba6890..8afb9631f 100644 --- a/src/main/org/apache/tools/ant/types/FilterSetCollection.java +++ b/src/main/org/apache/tools/ant/types/FilterSetCollection.java @@ -17,18 +17,8 @@ */ package org.apache.tools.ant.types; -// java io classes - - - - -// java util classes -import java.util.Enumeration; -import java.util.Vector; - -// ant classes - - +import java.util.ArrayList; +import java.util.List; /** @@ -38,7 +28,7 @@ import java.util.Vector; */ public class FilterSetCollection { - private Vector filterSets = new Vector(); + private List filterSets = new ArrayList(); /** * Constructor for a FilterSetCollection. @@ -61,7 +51,7 @@ public class FilterSetCollection { * @param filterSet a FilterSet value */ public void addFilterSet(FilterSet filterSet) { - filterSets.addElement(filterSet); + filterSets.add(filterSet); } /** @@ -73,8 +63,7 @@ public class FilterSetCollection { */ public String replaceTokens(String line) { String replacedLine = line; - for (Enumeration e = filterSets.elements(); e.hasMoreElements();) { - FilterSet filterSet = (FilterSet) e.nextElement(); + for (FilterSet filterSet : filterSets) { replacedLine = filterSet.replaceTokens(replacedLine); } return replacedLine; @@ -86,8 +75,7 @@ public class FilterSetCollection { * @return Return true if there are filter in this set otherwise false. */ public boolean hasFilters() { - for (Enumeration e = filterSets.elements(); e.hasMoreElements();) { - FilterSet filterSet = (FilterSet) e.nextElement(); + for (FilterSet filterSet : filterSets) { if (filterSet.hasFilters()) { return true; } diff --git a/src/main/org/apache/tools/ant/types/Mapper.java b/src/main/org/apache/tools/ant/types/Mapper.java index 90396271f..9b0a6dd46 100644 --- a/src/main/org/apache/tools/ant/types/Mapper.java +++ b/src/main/org/apache/tools/ant/types/Mapper.java @@ -230,8 +230,7 @@ public class Mapper extends DataType implements Cloneable { } try { - FileNameMapper m - = (FileNameMapper) (getImplementationClass().newInstance()); + FileNameMapper m = getImplementationClass().newInstance(); final Project p = getProject(); if (p != null) { p.setProjectReference(m); @@ -252,7 +251,7 @@ public class Mapper extends DataType implements Cloneable { * @return Class. * @throws ClassNotFoundException if the class cannot be found */ - protected Class getImplementationClass() throws ClassNotFoundException { + protected Class getImplementationClass() throws ClassNotFoundException { String cName = this.classname; if (type != null) { @@ -264,7 +263,7 @@ public class Mapper extends DataType implements Cloneable { // Memory leak in line below : getProject().createClassLoader(classpath); - return Class.forName(cName, true, loader); + return Class.forName(cName, true, loader).asSubclass(FileNameMapper.class); } /** @@ -275,7 +274,7 @@ public class Mapper extends DataType implements Cloneable { * @return the referenced Mapper */ protected Mapper getRef() { - return (Mapper) getCheckedRef(); + return getCheckedRef(Mapper.class, getDataTypeName()); } /** diff --git a/src/main/org/apache/tools/ant/types/PatternSet.java b/src/main/org/apache/tools/ant/types/PatternSet.java index 62006b13c..aeb171c0d 100644 --- a/src/main/org/apache/tools/ant/types/PatternSet.java +++ b/src/main/org/apache/tools/ant/types/PatternSet.java @@ -21,9 +21,9 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.util.Enumeration; +import java.util.ArrayList; +import java.util.List; import java.util.StringTokenizer; -import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.PropertyHelper; @@ -37,10 +37,10 @@ import org.apache.tools.ant.util.FileUtils; * */ public class PatternSet extends DataType implements Cloneable { - private Vector includeList = new Vector(); - private Vector excludeList = new Vector(); - private Vector includesFileList = new Vector(); - private Vector excludesFileList = new Vector(); + private List includeList = new ArrayList(); + private List excludeList = new ArrayList(); + private List includesFileList = new ArrayList(); + private List excludesFileList = new ArrayList(); /** * inner class to hold a name on list. "If" and "Unless" attributes @@ -318,9 +318,9 @@ public class PatternSet extends DataType implements Cloneable { /** * add a name entry to the given list */ - private NameEntry addPatternToList(Vector list) { + private NameEntry addPatternToList(List list) { NameEntry result = new NameEntry(); - list.addElement(result); + list.add(result); return result; } @@ -354,7 +354,7 @@ public class PatternSet extends DataType implements Cloneable { * Reads path matching patterns from a file and adds them to the * includes or excludes list (as appropriate). */ - private void readPatterns(File patternfile, Vector patternlist, Project p) + private void readPatterns(File patternfile, List patternlist, Project p) throws BuildException { BufferedReader patternReader = null; @@ -458,21 +458,18 @@ public class PatternSet extends DataType implements Cloneable { /** * Convert a vector of NameEntry elements into an array of Strings. */ - private String[] makeArray(Vector list, Project p) { + private String[] makeArray(List list, Project p) { if (list.size() == 0) { return null; } - Vector tmpNames = new Vector(); - for (Enumeration e = list.elements(); e.hasMoreElements();) { - NameEntry ne = (NameEntry) e.nextElement(); + ArrayList tmpNames = new ArrayList(); + for (NameEntry ne : list) { String pattern = ne.evalName(p); if (pattern != null && pattern.length() > 0) { - tmpNames.addElement(pattern); + tmpNames.add(pattern); } } - String[] result = new String[tmpNames.size()]; - tmpNames.copyInto(result); - return result; + return tmpNames.toArray(new String[tmpNames.size()]); } /** @@ -480,9 +477,7 @@ public class PatternSet extends DataType implements Cloneable { */ private void readFiles(Project p) { if (includesFileList.size() > 0) { - Enumeration e = includesFileList.elements(); - while (e.hasMoreElements()) { - NameEntry ne = (NameEntry) e.nextElement(); + for (NameEntry ne : includesFileList) { String fileName = ne.evalName(p); if (fileName != null) { File inclFile = p.resolveFile(fileName); @@ -493,12 +488,10 @@ public class PatternSet extends DataType implements Cloneable { readPatterns(inclFile, includeList, p); } } - includesFileList.removeAllElements(); + includesFileList.clear(); } if (excludesFileList.size() > 0) { - Enumeration e = excludesFileList.elements(); - while (e.hasMoreElements()) { - NameEntry ne = (NameEntry) e.nextElement(); + for (NameEntry ne : excludesFileList) { String fileName = ne.evalName(p); if (fileName != null) { File exclFile = p.resolveFile(fileName); @@ -509,7 +502,7 @@ public class PatternSet extends DataType implements Cloneable { readPatterns(exclFile, excludeList, p); } } - excludesFileList.removeAllElements(); + excludesFileList.clear(); } } @@ -527,10 +520,10 @@ public class PatternSet extends DataType implements Cloneable { public Object clone() { try { PatternSet ps = (PatternSet) super.clone(); - ps.includeList = (Vector) includeList.clone(); - ps.excludeList = (Vector) excludeList.clone(); - ps.includesFileList = (Vector) includesFileList.clone(); - ps.excludesFileList = (Vector) excludesFileList.clone(); + ps.includeList = new ArrayList(includeList); + ps.excludeList = new ArrayList(excludeList); + ps.includesFileList = new ArrayList(includesFileList); + ps.excludesFileList = new ArrayList(excludesFileList); return ps; } catch (CloneNotSupportedException e) { throw new BuildException(e); diff --git a/src/main/org/apache/tools/ant/types/Permissions.java b/src/main/org/apache/tools/ant/types/Permissions.java index ca25b08a5..2ee0cf2e1 100644 --- a/src/main/org/apache/tools/ant/types/Permissions.java +++ b/src/main/org/apache/tools/ant/types/Permissions.java @@ -21,7 +21,6 @@ package org.apache.tools.ant.types; import java.lang.reflect.Constructor; import java.security.UnresolvedPermission; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -45,15 +44,15 @@ import org.apache.tools.ant.ExitException; */ public class Permissions { - private List grantedPermissions = new LinkedList(); - private List revokedPermissions = new LinkedList(); + private List grantedPermissions = new LinkedList(); + private List revokedPermissions = new LinkedList(); private java.security.Permissions granted = null; private SecurityManager origSm = null; private boolean active = false; private boolean delegateToOldSM; // Mandatory constructor for permission object. - private static final Class[] PARAMS = {String.class, String.class}; + private static final Class[] PARAMS = {String.class, String.class}; /** * Create a set of Permissions. Equivalent to calling @@ -108,14 +107,12 @@ public class Permissions { */ private void init() throws BuildException { granted = new java.security.Permissions(); - for (Iterator i = revokedPermissions.listIterator(); i.hasNext();) { - Permissions.Permission p = (Permissions.Permission) i.next(); + for (Permissions.Permission p : revokedPermissions) { if (p.getClassName() == null) { throw new BuildException("Revoked permission " + p + " does not contain a class."); } } - for (Iterator i = grantedPermissions.listIterator(); i.hasNext();) { - Permissions.Permission p = (Permissions.Permission) i.next(); + for (Permissions.Permission p : grantedPermissions) { if (p.getClassName() == null) { throw new BuildException("Granted permission " + p + " does not contain a class."); @@ -153,12 +150,12 @@ public class Permissions { try { // First add explicitly already resolved permissions will not be // resolved when added as unresolved permission. - Class clazz = Class.forName(permission.getClassName()); + Class clazz = Class.forName( + permission.getClassName()).asSubclass(java.security.Permission.class); String name = permission.getName(); String actions = permission.getActions(); - Constructor ctr = clazz.getConstructor(PARAMS); - return (java.security.Permission) ctr.newInstance(new Object[] { - name, actions }); + Constructor ctr = clazz.getConstructor(PARAMS); + return ctr.newInstance(new Object[] { name, actions }); } catch (Exception e) { // Let the UnresolvedPermission handle it. return new UnresolvedPermission(permission.getClassName(), @@ -232,12 +229,11 @@ public class Permissions { * @param perm the permission being checked */ private void checkRevoked(java.security.Permission perm) { - for (Iterator i = revokedPermissions.listIterator(); i.hasNext();) { - if (((Permissions.Permission) i.next()).matches(perm)) { + for (Permissions.Permission revoked : revokedPermissions) { + if (revoked.matches(perm)) { throw new SecurityException("Permission " + perm + " was revoked."); } } - } } @@ -246,14 +242,14 @@ public class Permissions { private String className; private String name; private String actionString; - private Set actions; + private Set actions; /** * Set the class, mandatory. * @param aClass The class name of the permission. */ public void setClass(String aClass) { - className = aClass.trim(); + className = aClass.trim(); } /** @@ -319,7 +315,7 @@ public class Permissions { } } if (actions != null) { - Set as = parseActions(perm.getActions()); + Set as = parseActions(perm.getActions()); int size = as.size(); as.removeAll(actions); if (as.size() == size) { @@ -334,8 +330,8 @@ public class Permissions { * Parses the actions into a set of separate strings. * @param actions The actions to be parsed. */ - private Set parseActions(String actions) { - Set result = new HashSet(); + private Set parseActions(String actions) { + Set result = new HashSet(); StringTokenizer tk = new StringTokenizer(actions, ","); while (tk.hasMoreTokens()) { String item = tk.nextToken().trim(); diff --git a/src/main/org/apache/tools/ant/types/PropertySet.java b/src/main/org/apache/tools/ant/types/PropertySet.java index bed52a240..fd4879da7 100644 --- a/src/main/org/apache/tools/ant/types/PropertySet.java +++ b/src/main/org/apache/tools/ant/types/PropertySet.java @@ -18,16 +18,19 @@ package org.apache.tools.ant.types; +import java.util.ArrayList; import java.util.Enumeration; +import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.HashSet; +import java.util.Map.Entry; import java.util.Set; import java.util.Stack; import java.util.TreeMap; import java.util.Hashtable; import java.util.Properties; -import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -46,9 +49,9 @@ public class PropertySet extends DataType implements ResourceCollection { private boolean dynamic = true; private boolean negate = false; - private Set cachedNames; - private Vector ptyRefs = new Vector(); - private Vector setRefs = new Vector(); + private Set cachedNames; + private List ptyRefs = new ArrayList(); + private List setRefs = new ArrayList(); private Mapper mapper; /** @@ -184,7 +187,7 @@ public class PropertySet extends DataType implements ResourceCollection { public void addPropertyref(PropertyRef ref) { assertNotReference(); setChecked(false); - ptyRefs.addElement(ref); + ptyRefs.add(ref); } /** @@ -194,7 +197,7 @@ public class PropertySet extends DataType implements ResourceCollection { public void addPropertyset(PropertySet ref) { assertNotReference(); setChecked(false); - setRefs.addElement(ref); + setRefs.add(ref); } /** @@ -274,9 +277,9 @@ public class PropertySet extends DataType implements ResourceCollection { * Use propertynames to get the list of properties (including * default ones). */ - private Hashtable getAllSystemProperties() { - Hashtable ret = new Hashtable(); - for (Enumeration e = System.getProperties().propertyNames(); + private Hashtable getAllSystemProperties() { + Hashtable ret = new Hashtable(); + for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); ret.put(name, System.getProperties().getProperty(name)); @@ -289,23 +292,33 @@ public class PropertySet extends DataType implements ResourceCollection { * @return the properties for this propertyset. */ public Properties getProperties() { + final Properties result = new Properties(); + result.putAll(getPropertyMap()); + return result; + } + + /** + * + * @return Map + * @since 1.9.0 + */ + private Map getPropertyMap() { if (isReference()) { - return getRef().getProperties(); + return getRef().getPropertyMap(); } dieOnCircularReference(); - Hashtable props = getEffectiveProperties(); - Set names = getPropertyNames(props); + final Mapper myMapper = getMapper(); + final FileNameMapper m = myMapper == null ? null : myMapper.getImplementation(); + + final Map effectiveProperties = getEffectiveProperties(); + final Set propertyNames = getPropertyNames(effectiveProperties); + final Map result = new HashMap(); - FileNameMapper m = null; - Mapper myMapper = getMapper(); - if (myMapper != null) { - m = myMapper.getImplementation(); - } - Properties properties = new Properties(); //iterate through the names, get the matching values - for (Iterator iter = names.iterator(); iter.hasNext();) { - String name = (String) iter.next(); - String value = (String) props.get(name); + for (String name : propertyNames) { + Object value = effectiveProperties.get(name); + // TODO should we include null properties? + // TODO should we query the PropertyHelper for property value to grab potentially shadowed values? if (value != null) { // may be null if a system property has been added // after the project instance has been initialized @@ -316,36 +329,35 @@ public class PropertySet extends DataType implements ResourceCollection { name = newname[0]; } } - properties.setProperty(name, value); + result.put(name, value); } } - return properties; + return result; + } - private Hashtable getEffectiveProperties() { - Project prj = getProject(); - Hashtable result = prj == null ? getAllSystemProperties() : prj.getProperties(); + private Map getEffectiveProperties() { + final Project prj = getProject(); + final Map result = prj == null ? getAllSystemProperties() : prj.getProperties(); //quick & dirty, to make nested mapped p-sets work: - for (Enumeration e = setRefs.elements(); e.hasMoreElements();) { - PropertySet set = (PropertySet) e.nextElement(); - result.putAll(set.getProperties()); + for (PropertySet set : setRefs) { + result.putAll(set.getPropertyMap()); } return result; } - private Set getPropertyNames(Hashtable props) { - Set names; + private Set getPropertyNames(Map props) { + Set names; if (getDynamic() || cachedNames == null) { - names = new HashSet(); + names = new HashSet(); addPropertyNames(names, props); // Add this PropertySet's nested PropertySets' property names. - for (Enumeration e = setRefs.elements(); e.hasMoreElements();) { - PropertySet set = (PropertySet) e.nextElement(); - names.addAll(set.getProperties().keySet()); + for (PropertySet set : setRefs) { + names.addAll(set.getPropertyMap().keySet()); } if (negate) { //make a copy... - HashSet complement = new HashSet(props.keySet()); + HashSet complement = new HashSet(props.keySet()); complement.removeAll(names); names = complement; } @@ -361,24 +373,22 @@ public class PropertySet extends DataType implements ResourceCollection { /** * @param names the output Set to fill with the property names * matching this PropertySet selection criteria. - * @param properties the current Project properties, passed in to + * @param props the current Project properties, passed in to * avoid needless duplication of the Hashtable during recursion. */ - private void addPropertyNames(Set names, Hashtable properties) { + private void addPropertyNames(Set names, Map props) { if (isReference()) { - getRef().addPropertyNames(names, properties); + getRef().addPropertyNames(names, props); } dieOnCircularReference(); // Add this PropertySet's property names. - for (Enumeration e = ptyRefs.elements(); e.hasMoreElements();) { - PropertyRef r = (PropertyRef) e.nextElement(); + for (PropertyRef r : ptyRefs) { if (r.name != null) { - if (properties.get(r.name) != null) { + if (props.get(r.name) != null) { names.add(r.name); } } else if (r.prefix != null) { - for (Enumeration p = properties.keys(); p.hasMoreElements();) { - String name = (String) p.nextElement(); + for (String name : props.keySet()) { if (name.startsWith(r.prefix)) { names.add(name); } @@ -387,8 +397,7 @@ public class PropertySet extends DataType implements ResourceCollection { RegexpMatcherFactory matchMaker = new RegexpMatcherFactory(); RegexpMatcher matcher = matchMaker.newRegexpMatcher(); matcher.setPattern(r.regex); - for (Enumeration p = properties.keys(); p.hasMoreElements();) { - String name = (String) p.nextElement(); + for (String name : props.keySet()) { if (matcher.matches(name)) { names.add(name); } @@ -396,9 +405,9 @@ public class PropertySet extends DataType implements ResourceCollection { } else if (r.builtin != null) { if (r.builtin.equals(BuiltinPropertySetName.ALL)) { - names.addAll(properties.keySet()); + names.addAll(props.keySet()); } else if (r.builtin.equals(BuiltinPropertySetName.SYSTEM)) { - names.addAll(System.getProperties().keySet()); + names.addAll(getAllSystemProperties().keySet()); } else if (r.builtin.equals(BuiltinPropertySetName .COMMANDLINE)) { names.addAll(getProject().getUserProperties().keySet()); @@ -483,16 +492,15 @@ public class PropertySet extends DataType implements ResourceCollection { return getRef().toString(); } dieOnCircularReference(); - StringBuffer b = new StringBuffer(); - TreeMap sorted = new TreeMap(getProperties()); - for (Iterator i = sorted.entrySet().iterator(); i.hasNext();) { - Map.Entry e = (Map.Entry) i.next(); + StringBuilder b = new StringBuilder(); + TreeMap sorted = new TreeMap(getPropertyMap()); + for (Entry e : sorted.entrySet()) { if (b.length() != 0) { b.append(", "); } - b.append(e.getKey().toString()); + b.append(e.getKey()); b.append("="); - b.append(e.getValue().toString()); + b.append(e.getValue()); } return b.toString(); } @@ -507,19 +515,18 @@ public class PropertySet extends DataType implements ResourceCollection { return getRef().iterator(); } dieOnCircularReference(); - Hashtable props = getEffectiveProperties(); - Set names = getPropertyNames(props); + final Set names = getPropertyNames(getEffectiveProperties()); Mapper myMapper = getMapper(); final FileNameMapper m = myMapper == null ? null : myMapper.getImplementation(); - final Iterator iter = names.iterator(); + final Iterator iter = names.iterator(); return new Iterator() { public boolean hasNext() { return iter.hasNext(); } public Resource next() { - PropertyResource p = new PropertyResource(getProject(), (String) iter.next()); + PropertyResource p = new PropertyResource(getProject(), iter.next()); return m == null ? (Resource) p : new MappedResource(p, m); } public void remove() { @@ -548,7 +555,7 @@ public class PropertySet extends DataType implements ResourceCollection { return false; } - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -559,8 +566,8 @@ public class PropertySet extends DataType implements ResourceCollection { if (mapper != null) { pushAndInvokeCircularReferenceCheck(mapper, stk, p); } - for (Iterator i = setRefs.iterator(); i.hasNext(); ) { - pushAndInvokeCircularReferenceCheck((PropertySet) i.next(), stk, + for (PropertySet propertySet : setRefs) { + pushAndInvokeCircularReferenceCheck(propertySet, stk, p); } setChecked(true); diff --git a/src/main/org/apache/tools/ant/types/RedirectorElement.java b/src/main/org/apache/tools/ant/types/RedirectorElement.java index 479ff2a70..a611f59ec 100644 --- a/src/main/org/apache/tools/ant/types/RedirectorElement.java +++ b/src/main/org/apache/tools/ant/types/RedirectorElement.java @@ -18,9 +18,10 @@ package org.apache.tools.ant.types; import java.io.File; +import java.util.Arrays; +import java.util.List; import java.util.Stack; import java.util.Vector; -import java.util.Iterator; import java.util.ArrayList; import org.apache.tools.ant.Project; @@ -83,13 +84,13 @@ public class RedirectorElement extends DataType { private Mapper errorMapper; /** input filter chains. */ - private Vector inputFilterChains = new Vector(); + private Vector inputFilterChains = new Vector(); /** output filter chains. */ - private Vector outputFilterChains = new Vector(); + private Vector outputFilterChains = new Vector(); /** error filter chains. */ - private Vector errorFilterChains = new Vector(); + private Vector errorFilterChains = new Vector(); /** The output encoding */ private String outputEncoding; @@ -554,7 +555,7 @@ public class RedirectorElement extends DataType { return null; } //remove any null elements - ArrayList list = new ArrayList(name.length); + ArrayList list = new ArrayList(name.length); for (int i = 0; i < name.length; i++) { if (name[i] != null) { list.add(getProject().resolveFile(name[i])); @@ -570,7 +571,7 @@ public class RedirectorElement extends DataType { * @param p the project to use to dereference the references. * @throws BuildException on error. */ - protected void dieOnCircularReference(Stack stk, Project p) + protected void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -586,12 +587,13 @@ public class RedirectorElement extends DataType { stk.pop(); } } - Vector[] v = new Vector[] - {inputFilterChains, outputFilterChains, errorFilterChains}; - for (int i = 0; i < v.length; i++) { - if (v[i] != null) { - for (Iterator fci = v[i].iterator(); fci.hasNext();) { - FilterChain fc = (FilterChain) fci.next(); + @SuppressWarnings("unchecked") + final List> filterChainLists = Arrays + .> asList(inputFilterChains, outputFilterChains, + errorFilterChains); + for (List filterChains : filterChainLists) { + if (filterChains != null) { + for (FilterChain fc : filterChains) { pushAndInvokeCircularReferenceCheck(fc, stk, p); } } diff --git a/src/main/org/apache/tools/ant/types/TarScanner.java b/src/main/org/apache/tools/ant/types/TarScanner.java index 5eb0d6869..1bac2f404 100644 --- a/src/main/org/apache/tools/ant/types/TarScanner.java +++ b/src/main/org/apache/tools/ant/types/TarScanner.java @@ -50,8 +50,9 @@ public class TarScanner extends ArchiveScanner { * patterns and didn't match any exclude patterns. */ protected void fillMapsFromArchive(Resource src, String encoding, - Map fileEntries, Map matchFileEntries, - Map dirEntries, Map matchDirEntries) { + Map fileEntries, Map matchFileEntries, + Map dirEntries, Map matchDirEntries) { + TarEntry entry = null; TarInputStream ti = null; diff --git a/src/main/org/apache/tools/ant/types/XMLCatalog.java b/src/main/org/apache/tools/ant/types/XMLCatalog.java index 1edc10011..a05305741 100644 --- a/src/main/org/apache/tools/ant/types/XMLCatalog.java +++ b/src/main/org/apache/tools/ant/types/XMLCatalog.java @@ -26,7 +26,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; -import java.util.Enumeration; import java.util.Stack; import java.util.Vector; import javax.xml.parsers.ParserConfigurationException; @@ -126,7 +125,7 @@ public class XMLCatalog extends DataType //-- Fields ---------------------------------------------------------------- /** Holds dtd/entity objects until needed. */ - private Vector elements = new Vector(); + private Vector elements = new Vector(); /** * Classpath in which to attempt to resolve resources. @@ -166,7 +165,7 @@ public class XMLCatalog extends DataType * * @return the elements of the catalog - ResourceLocation objects */ - private Vector getElements() { + private Vector getElements() { return getRef().elements; } @@ -331,12 +330,7 @@ public class XMLCatalog extends DataType } // Add all nested elements to our catalog - Vector newElements = catalog.getElements(); - Vector ourElements = getElements(); - Enumeration e = newElements.elements(); - while (e.hasMoreElements()) { - ourElements.addElement(e.nextElement()); - } + getElements().addAll(catalog.getElements()); // Append the classpath of the nested catalog Path nestedClasspath = catalog.getClasspath(); @@ -452,7 +446,7 @@ public class XMLCatalog extends DataType return source; } - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -477,7 +471,7 @@ public class XMLCatalog extends DataType if (!isReference()) { return this; } - return (XMLCatalog) getCheckedRef(XMLCatalog.class, "xmlcatalog"); + return getCheckedRef(XMLCatalog.class, "xmlcatalog"); } /** @@ -504,7 +498,7 @@ public class XMLCatalog extends DataType loader = getProject().createClassLoader(Path.systemClasspath); try { - Class clazz = Class.forName(APACHE_RESOLVER, true, loader); + Class clazz = Class.forName(APACHE_RESOLVER, true, loader); // The Apache resolver is present - Need to check if it can // be seen by the catalog resolver class. Start by getting @@ -512,7 +506,7 @@ public class XMLCatalog extends DataType ClassLoader apacheResolverLoader = clazz.getClassLoader(); // load the base class through this loader. - Class baseResolverClass + Class baseResolverClass = Class.forName(CATALOG_RESOLVER, true, apacheResolverLoader); // and find its actual loader @@ -594,15 +588,9 @@ public class XMLCatalog extends DataType * of the Resource or null if no such information is available. */ private ResourceLocation findMatchingEntry(String publicId) { - Enumeration e = getElements().elements(); - ResourceLocation element = null; - while (e.hasMoreElements()) { - Object o = e.nextElement(); - if (o instanceof ResourceLocation) { - element = (ResourceLocation) o; - if (element.getPublicId().equals(publicId)) { - return element; - } + for (ResourceLocation element : getElements()) { + if (element.getPublicId().equals(publicId)) { + return element; } } return null; @@ -917,7 +905,7 @@ public class XMLCatalog extends DataType private boolean externalCatalogsProcessed = false; - public ExternalResolver(Class resolverImplClass, + public ExternalResolver(Class resolverImplClass, Object resolverImpl) { this.resolverImpl = resolverImpl; diff --git a/src/main/org/apache/tools/ant/types/ZipScanner.java b/src/main/org/apache/tools/ant/types/ZipScanner.java index 3011bef2b..d0f7193f8 100644 --- a/src/main/org/apache/tools/ant/types/ZipScanner.java +++ b/src/main/org/apache/tools/ant/types/ZipScanner.java @@ -53,8 +53,8 @@ public class ZipScanner extends ArchiveScanner { * patterns and didn't match any exclude patterns. */ protected void fillMapsFromArchive(Resource src, String encoding, - Map fileEntries, Map matchFileEntries, - Map dirEntries, Map matchDirEntries) { + Map fileEntries, Map matchFileEntries, + Map dirEntries, Map matchDirEntries) { ZipEntry entry = null; ZipFile zf = null; @@ -74,9 +74,9 @@ public class ZipScanner extends ArchiveScanner { } catch (IOException ex) { throw new BuildException("Problem opening " + srcFile, ex); } - Enumeration e = zf.getEntries(); + Enumeration e = zf.getEntries(); while (e.hasMoreElements()) { - entry = (ZipEntry) e.nextElement(); + entry = e.nextElement(); Resource r = new ZipResource(srcFile, encoding, entry); String name = entry.getName(); if (entry.isDirectory()) { diff --git a/src/main/org/apache/tools/ant/types/mappers/FilterMapper.java b/src/main/org/apache/tools/ant/types/mappers/FilterMapper.java index 391a3f7b0..12b2bca57 100644 --- a/src/main/org/apache/tools/ant/types/mappers/FilterMapper.java +++ b/src/main/org/apache/tools/ant/types/mappers/FilterMapper.java @@ -70,7 +70,7 @@ public class FilterMapper extends FilterChain implements FileNameMapper { helper.setBufferSize(BUFFER_SIZE); helper.setPrimaryReader(stringReader); helper.setProject(getProject()); - Vector filterChains = new Vector(); + Vector filterChains = new Vector(); filterChains.add(this); helper.setFilterChains(filterChains); String result = FileUtils.safeReadFully(helper.getAssembledReader()); diff --git a/src/main/org/apache/tools/ant/types/optional/ScriptMapper.java b/src/main/org/apache/tools/ant/types/optional/ScriptMapper.java index dff711567..8f42216a7 100644 --- a/src/main/org/apache/tools/ant/types/optional/ScriptMapper.java +++ b/src/main/org/apache/tools/ant/types/optional/ScriptMapper.java @@ -27,9 +27,7 @@ import java.util.ArrayList; */ public class ScriptMapper extends AbstractScriptComponent implements FileNameMapper { - - private ArrayList files; - static final String[] EMPTY_STRING_ARRAY = new String[0]; + private ArrayList files; /** @@ -54,7 +52,7 @@ public class ScriptMapper extends AbstractScriptComponent implements FileNameMap * Reset the list of files */ public void clear() { - files = new ArrayList(1); + files = new ArrayList(1); } /** @@ -87,7 +85,7 @@ public class ScriptMapper extends AbstractScriptComponent implements FileNameMap if (files.size() == 0) { return null; } else { - return (String[]) files.toArray(EMPTY_STRING_ARRAY); + return files.toArray(new String[files.size()]); } } } diff --git a/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java b/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java index 727ae6c24..f34d3f4a8 100644 --- a/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java +++ b/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java @@ -17,7 +17,8 @@ */ package org.apache.tools.ant.types.optional.depend; -import java.util.Enumeration; +import java.util.ArrayList; +import java.util.List; import java.util.Stack; import java.util.Vector; import org.apache.tools.ant.Project; @@ -39,12 +40,12 @@ public class ClassfileSet extends FileSet { * classes which must be included in the fileset and which are the * starting point for the dependency search. */ - private Vector rootClasses = new Vector(); + private List rootClasses = new ArrayList(); /** * The list of filesets which contain root classes. */ - private Vector rootFileSets = new Vector(); + private List rootFileSets = new ArrayList(); /** * Inner class used to contain info about root classes. @@ -86,7 +87,7 @@ public class ClassfileSet extends FileSet { * classes. */ public void addRootFileset(FileSet rootFileSet) { - rootFileSets.addElement(rootFileSet); + rootFileSets.add(rootFileSet); setChecked(false); } @@ -97,7 +98,7 @@ public class ClassfileSet extends FileSet { */ protected ClassfileSet(ClassfileSet s) { super(s); - rootClasses = (Vector) s.rootClasses.clone(); + rootClasses.addAll(s.rootClasses); } /** @@ -106,7 +107,7 @@ public class ClassfileSet extends FileSet { * @param rootClass the name of the root class. */ public void setRootClass(String rootClass) { - rootClasses.addElement(rootClass); + rootClasses.add(rootClass); } /** @@ -123,9 +124,8 @@ public class ClassfileSet extends FileSet { dieOnCircularReference(p); DirectoryScanner parentScanner = super.getDirectoryScanner(p); DependScanner scanner = new DependScanner(parentScanner); - Vector allRootClasses = (Vector) rootClasses.clone(); - for (Enumeration e = rootFileSets.elements(); e.hasMoreElements();) { - FileSet additionalRootSet = (FileSet) e.nextElement(); + final Vector allRootClasses = new Vector(rootClasses); + for (FileSet additionalRootSet : rootFileSets) { DirectoryScanner additionalScanner = additionalRootSet.getDirectoryScanner(p); String[] files = additionalScanner.getIncludedFiles(); @@ -151,7 +151,7 @@ public class ClassfileSet extends FileSet { * @param root the configured class root. */ public void addConfiguredRoot(ClassRoot root) { - rootClasses.addElement(root.getClassname()); + rootClasses.add(root.getClassname()); } /** @@ -164,7 +164,7 @@ public class ClassfileSet extends FileSet { ? (ClassfileSet) (getRef(getProject())) : this); } - protected synchronized void dieOnCircularReference(Stack stk, Project p) { + protected synchronized void dieOnCircularReference(Stack stk, Project p) { if (isChecked()) { return; } @@ -173,9 +173,7 @@ public class ClassfileSet extends FileSet { super.dieOnCircularReference(stk, p); if (!isReference()) { - for (Enumeration e = rootFileSets.elements(); - e.hasMoreElements();) { - FileSet additionalRootSet = (FileSet) e.nextElement(); + for (FileSet additionalRootSet : rootFileSets) { pushAndInvokeCircularReferenceCheck(additionalRootSet, stk, p); } setChecked(true); diff --git a/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java b/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java index d3b58f88b..de4c7faf4 100644 --- a/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java +++ b/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java @@ -40,14 +40,14 @@ public class DependScanner extends DirectoryScanner { /** * The root classes to drive the search for dependent classes. */ - private Vector rootClasses; + private Vector rootClasses; /** * The names of the classes to include in the fileset. */ - private Vector included; + private Vector included; - private Vector additionalBaseDirs = new Vector(); + private Vector additionalBaseDirs = new Vector(); /** * The parent scanner which gives the basic set of files. Only files which @@ -72,7 +72,7 @@ public class DependScanner extends DirectoryScanner { * * @param rootClasses the rootClasses to be used for this scan. */ - public synchronized void setRootClasses(Vector rootClasses) { + public synchronized void setRootClasses(Vector rootClasses) { this.rootClasses = rootClasses; } @@ -103,30 +103,31 @@ public class DependScanner extends DirectoryScanner { * @exception IllegalStateException when basedir was set incorrectly. */ public synchronized void scan() throws IllegalStateException { - included = new Vector(); + included = new Vector(); String analyzerClassName = DEFAULT_ANALYZER_CLASS; DependencyAnalyzer analyzer = null; try { - Class analyzerClass = Class.forName(analyzerClassName); - analyzer = (DependencyAnalyzer) analyzerClass.newInstance(); + Class analyzerClass = Class.forName(analyzerClassName) + .asSubclass(DependencyAnalyzer.class); + analyzer = analyzerClass.newInstance(); } catch (Exception e) { throw new BuildException("Unable to load dependency analyzer: " + analyzerClassName, e); } analyzer.addClassPath(new Path(null, basedir.getPath())); - for (Enumeration e = additionalBaseDirs.elements(); e.hasMoreElements();) { - File additionalBaseDir = (File) e.nextElement(); + for (Enumeration e = additionalBaseDirs.elements(); e.hasMoreElements();) { + File additionalBaseDir = e.nextElement(); analyzer.addClassPath(new Path(null, additionalBaseDir.getPath())); } - for (Enumeration e = rootClasses.elements(); e.hasMoreElements();) { - String rootClass = (String) e.nextElement(); + for (Enumeration e = rootClasses.elements(); e.hasMoreElements();) { + String rootClass = e.nextElement(); analyzer.addRootClass(rootClass); } - Enumeration e = analyzer.getClassDependencies(); + Enumeration e = analyzer.getClassDependencies(); String[] parentFiles = parentScanner.getIncludedFiles(); - Hashtable parentSet = new Hashtable(); + Hashtable parentSet = new Hashtable(); for (int i = 0; i < parentFiles.length; ++i) { parentSet.put(parentFiles[i], parentFiles[i]); } diff --git a/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java b/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java index df6c84812..fa917342c 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java +++ b/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java @@ -26,7 +26,7 @@ import java.util.Vector; */ public abstract class ImageOperation extends DataType { // CheckStyle:VisibilityModifier OFF - bc - protected Vector instructions = new Vector(); + protected Vector instructions = new Vector(); // CheckStyle:VisibilityModifier ON /** diff --git a/src/main/org/apache/tools/ant/types/optional/image/Rotate.java b/src/main/org/apache/tools/ant/types/optional/image/Rotate.java index f925ec759..bfe6982fe 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/Rotate.java +++ b/src/main/org/apache/tools/ant/types/optional/image/Rotate.java @@ -22,7 +22,6 @@ import javax.media.jai.InterpolationNearest; import javax.media.jai.JAI; import java.awt.image.renderable.ParameterBlock; import java.awt.image.BufferedImage; -import java.awt.Graphics2D; /** * ImageOperation to rotate an image by a certain degree @@ -69,7 +68,6 @@ public class Rotate extends TransformOperation implements DrawOperation { */ public PlanarImage executeTransformOperation(PlanarImage image) { BufferedImage bi = null; - Graphics2D graphics = null; final int size = instructions.size(); for (int i = 0; i < size; i++) { ImageOperation instr = ((ImageOperation) instructions.elementAt(i)); @@ -82,7 +80,6 @@ public class Rotate extends TransformOperation implements DrawOperation { return image; } else if (instr instanceof TransformOperation) { bi = image.getAsBufferedImage(); - graphics = (Graphics2D) bi.getGraphics(); System.out.println("Execing Transforms"); image = ((TransformOperation) instr) .executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); diff --git a/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java b/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java index 336b3d6c8..0aeaf9e31 100644 --- a/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java +++ b/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java @@ -232,7 +232,7 @@ public abstract class AbstractClasspathResource extends Resource { */ protected abstract InputStream openInputStream(ClassLoader cl) throws IOException; - protected synchronized void dieOnCircularReference(Stack stk, Project p) { + protected synchronized void dieOnCircularReference(Stack stk, Project p) { if (isChecked()) { return; } diff --git a/src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java b/src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java index fa1178203..5e4c3a3fb 100644 --- a/src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java +++ b/src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java @@ -98,7 +98,7 @@ public abstract class AbstractResourceCollectionWrapper * of the iterator is allowed to not be thread safe whereas the iterator * itself should. The returned iterator will be wrapped into the FailFast * one. - * + * * @return the iterator on the resource collection */ protected abstract Iterator createIterator(); @@ -118,7 +118,7 @@ public abstract class AbstractResourceCollectionWrapper /** * Do compute the size of the resource collection. The implementation of * this function is allowed to be not thread safe. - * + * * @return size of resource collection. */ protected abstract int getSize(); @@ -138,8 +138,7 @@ public abstract class AbstractResourceCollectionWrapper } /* now check each Resource in case the child only lets through files from any children IT may have: */ - for (Iterator i = createIterator(); i.hasNext();) { - Resource r = (Resource) i.next(); + for (Resource r : this) { if (r.as(FileProvider.class) == null) { return false; } @@ -154,7 +153,7 @@ public abstract class AbstractResourceCollectionWrapper * @param p the project to use to dereference the references. * @throws BuildException on error. */ - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -193,12 +192,12 @@ public abstract class AbstractResourceCollectionWrapper if (getSize() == 0) { return ""; } - StringBuffer sb = new StringBuffer(); - for (Iterator i = createIterator(); i.hasNext();) { + StringBuilder sb = new StringBuilder(); + for (Resource resource : this) { if (sb.length() > 0) { sb.append(File.pathSeparatorChar); } - sb.append(i.next()); + sb.append(resource); } return sb.toString(); } diff --git a/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java b/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java index 2afa455e7..6fea79238 100644 --- a/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java +++ b/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java @@ -244,7 +244,7 @@ public abstract class ArchiveResource extends Resource { /** * Validate settings and ensure that the represented "archive entry" - * has been established. + * has been established. */ protected final synchronized void checkEntry() throws BuildException { dieOnCircularReference(); @@ -277,7 +277,7 @@ public abstract class ArchiveResource extends Resource { /** * {@inheritDoc} */ - protected synchronized void dieOnCircularReference(Stack stk, Project p) { + protected synchronized void dieOnCircularReference(Stack stk, Project p) { if (isChecked()) { return; } diff --git a/src/main/org/apache/tools/ant/types/resources/Archives.java b/src/main/org/apache/tools/ant/types/resources/Archives.java index 76862b32b..3667c8d50 100644 --- a/src/main/org/apache/tools/ant/types/resources/Archives.java +++ b/src/main/org/apache/tools/ant/types/resources/Archives.java @@ -77,8 +77,8 @@ public class Archives extends DataType } dieOnCircularReference(); int total = 0; - for (Iterator i = grabArchives(); i.hasNext(); ) { - total += ((ResourceCollection) i.next()).size(); + for (Iterator i = grabArchives(); i.hasNext(); ) { + total += i.next().size(); } return total; } @@ -173,7 +173,7 @@ public class Archives extends DataType * @param p the project to use to dereference the references. * @throws BuildException on error. */ - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; diff --git a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java index 6be0a70c8..27af1c876 100644 --- a/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java +++ b/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java @@ -47,7 +47,7 @@ public abstract class BaseResourceCollectionContainer public BaseResourceCollectionContainer() { // TODO Auto-generated constructor stub } - + /** * Create a new BaseResourceCollectionContainer. * @since Ant 1.8 @@ -115,13 +115,13 @@ public abstract class BaseResourceCollectionContainer * @param c the Collection whose elements to add. * @throws BuildException on error. */ - public synchronized void addAll(Collection c) throws BuildException { + public synchronized void addAll(Collection c) throws BuildException { if (isReference()) { throw noChildrenAllowed(); } try { - for (Iterator i = c.iterator(); i.hasNext();) { - add((ResourceCollection) i.next()); + for (ResourceCollection resourceCollection : c) { + add(resourceCollection); } } catch (ClassCastException e) { throw new BuildException(e); @@ -148,7 +148,7 @@ public abstract class BaseResourceCollectionContainer */ public synchronized int size() { if (isReference()) { - return ((BaseResourceCollectionContainer) getCheckedRef()).size(); + return getCheckedRef(BaseResourceCollectionContainer.class, getDataTypeName()).size(); } dieOnCircularReference(); return cacheCollection().size(); @@ -165,16 +165,15 @@ public abstract class BaseResourceCollectionContainer dieOnCircularReference(); //first the easy way, if all children are filesystem-only, return true: boolean goEarly = true; - for (Iterator i = rc.iterator(); goEarly && i.hasNext();) { - goEarly = ((ResourceCollection) i.next()).isFilesystemOnly(); + for (Iterator i = rc.iterator(); goEarly && i.hasNext();) { + goEarly = i.next().isFilesystemOnly(); } if (goEarly) { return true; } /* now check each Resource in case the child only lets through files from any children IT may have: */ - for (Iterator i = cacheCollection().iterator(); i.hasNext();) { - Resource r = (Resource) i.next(); + for (Resource r : cacheCollection()) { if (r.as(FileProvider.class) == null) { return false; } @@ -189,7 +188,7 @@ public abstract class BaseResourceCollectionContainer * @param p the project to use to dereference the references. * @throws BuildException on error. */ - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -197,10 +196,9 @@ public abstract class BaseResourceCollectionContainer if (isReference()) { super.dieOnCircularReference(stk, p); } else { - for (Iterator i = rc.iterator(); i.hasNext();) { - Object o = i.next(); - if (o instanceof DataType) { - pushAndInvokeCircularReferenceCheck((DataType) o, stk, p); + for (ResourceCollection resourceCollection : rc) { + if (resourceCollection instanceof DataType) { + pushAndInvokeCircularReferenceCheck((DataType) resourceCollection, stk, p); } } setChecked(true); @@ -231,7 +229,7 @@ public abstract class BaseResourceCollectionContainer try { BaseResourceCollectionContainer c = (BaseResourceCollectionContainer) super.clone(); - c.rc = new ArrayList(rc); + c.rc = new ArrayList(rc); c.coll = null; return c; } catch (CloneNotSupportedException e) { @@ -250,12 +248,12 @@ public abstract class BaseResourceCollectionContainer if (cacheCollection().size() == 0) { return ""; } - StringBuffer sb = new StringBuffer(); - for (Iterator i = coll.iterator(); i.hasNext();) { + StringBuilder sb = new StringBuilder(); + for (Resource resource : coll) { if (sb.length() > 0) { sb.append(File.pathSeparatorChar); } - sb.append(i.next()); + sb.append(resource); } return sb.toString(); } diff --git a/src/main/org/apache/tools/ant/types/resources/FailFast.java b/src/main/org/apache/tools/ant/types/resources/FailFast.java index 8703768b5..e95bc81dc 100644 --- a/src/main/org/apache/tools/ant/types/resources/FailFast.java +++ b/src/main/org/apache/tools/ant/types/resources/FailFast.java @@ -31,43 +31,43 @@ import org.apache.tools.ant.types.Resource; * @since Ant 1.7 */ /*package-private*/ class FailFast implements Iterator { - private static final WeakHashMap MAP = new WeakHashMap(); + private static final WeakHashMap> MAP = new WeakHashMap>(); /** * Invalidate any in-use Iterators from the specified Object. * @param o the parent Object. */ static synchronized void invalidate(Object o) { - Set s = (Set) (MAP.get(o)); + Set s = MAP.get(o); if (s != null) { s.clear(); } } private static synchronized void add(FailFast f) { - Set s = (Set) (MAP.get(f.parent)); + Set s = MAP.get(f.parent); if (s == null) { - s = new HashSet(); + s = new HashSet(); MAP.put(f.parent, s); } s.add(f); } private static synchronized void remove(FailFast f) { - Set s = (Set) (MAP.get(f.parent)); + Set s = MAP.get(f.parent); if (s != null) { s.remove(f); } } private static synchronized void failFast(FailFast f) { - Set s = (Set) (MAP.get(f.parent)); + Set s = MAP.get(f.parent); if (!s.contains(f)) { throw new ConcurrentModificationException(); } } - private Object parent; + private final Object parent; private Iterator wrapped; /** diff --git a/src/main/org/apache/tools/ant/types/resources/Files.java b/src/main/org/apache/tools/ant/types/resources/Files.java index f9481d966..4dc682b89 100644 --- a/src/main/org/apache/tools/ant/types/resources/Files.java +++ b/src/main/org/apache/tools/ant/types/resources/Files.java @@ -43,7 +43,7 @@ public class Files extends AbstractSelectorContainer = Collections.emptySet().iterator(); private PatternSet defaultPatterns = new PatternSet(); - private Vector additionalPatterns = new Vector(); + private Vector additionalPatterns = new Vector(); private boolean useDefaultExcludes = true; private boolean caseSensitive = true; @@ -357,8 +357,8 @@ public class Files extends AbstractSelectorContainer if (hasPatterns(defaultPatterns)) { return true; } - for (Iterator i = additionalPatterns.iterator(); i.hasNext();) { - if (hasPatterns((PatternSet) i.next())) { + for (PatternSet patternSet : additionalPatterns) { + if (hasPatterns(patternSet)) { return true; } } @@ -411,10 +411,9 @@ public class Files extends AbstractSelectorContainer } Files f = (Files) super.clone(); f.defaultPatterns = (PatternSet) defaultPatterns.clone(); - f.additionalPatterns = new Vector(additionalPatterns.size()); - for (Iterator iter = additionalPatterns.iterator(); iter.hasNext();) { - PatternSet ps = (PatternSet) iter.next(); - f.additionalPatterns.add(ps.clone()); + f.additionalPatterns = new Vector(additionalPatterns.size()); + for (PatternSet ps : additionalPatterns) { + f.additionalPatterns.add((PatternSet) ps.clone()); } return f; } diff --git a/src/main/org/apache/tools/ant/types/resources/ImmutableResourceException.java b/src/main/org/apache/tools/ant/types/resources/ImmutableResourceException.java index 4b7ccf48b..9dce7154f 100644 --- a/src/main/org/apache/tools/ant/types/resources/ImmutableResourceException.java +++ b/src/main/org/apache/tools/ant/types/resources/ImmutableResourceException.java @@ -26,6 +26,7 @@ import java.io.IOException; * @since Ant 1.7 */ public class ImmutableResourceException extends IOException { + private static final long serialVersionUID = 1L; /** * Default constructor. diff --git a/src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java b/src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java index 0ad14071e..63b617118 100644 --- a/src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java +++ b/src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java @@ -37,7 +37,7 @@ public class JavaConstantResource extends AbstractClasspathResource { * @throws IOException if an error occurs. */ protected InputStream openInputStream(ClassLoader cl) throws IOException { - Class clazz; + Class clazz; String constant = getName(); int index1 = constant.lastIndexOf('.'); if (index1 < 0) { diff --git a/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java b/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java index 74539ffbf..84581cdd8 100644 --- a/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java +++ b/src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java @@ -185,7 +185,7 @@ public class MappedResourceCollection * @param p the project to use to dereference the references. * @throws BuildException on error. */ - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java b/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java index 714fb75aa..0de40524e 100644 --- a/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java +++ b/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java @@ -203,7 +203,7 @@ public abstract class ResourceDecorator extends Resource { /** * {@inheritDoc} */ - protected void dieOnCircularReference(final Stack stack, + protected void dieOnCircularReference(final Stack stack, final Project project) throws BuildException { if (isChecked()) { diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceList.java b/src/main/org/apache/tools/ant/types/resources/ResourceList.java index 9a39ac24d..8b77e1bbf 100644 --- a/src/main/org/apache/tools/ant/types/resources/ResourceList.java +++ b/src/main/org/apache/tools/ant/types/resources/ResourceList.java @@ -44,8 +44,8 @@ import org.apache.tools.ant.util.FileUtils; * @since Ant 1.8.0 */ public class ResourceList extends DataType implements ResourceCollection { - private final Vector filterChains = new Vector(); - private final ArrayList textDocuments = new ArrayList(); + private final Vector filterChains = new Vector(); + private final ArrayList textDocuments = new ArrayList(); private final Union cachedResources = new Union(); private volatile boolean cached = false; private String encoding = null; @@ -148,7 +148,7 @@ public class ResourceList extends DataType implements ResourceCollection { * @param p the project to use to dereference the references. * @throws BuildException on error. */ - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -156,25 +156,22 @@ public class ResourceList extends DataType implements ResourceCollection { if (isReference()) { super.dieOnCircularReference(stk, p); } else { - for (Iterator iter = textDocuments.iterator(); iter.hasNext(); ) { - Object o = (Object) iter.next(); - if (o instanceof DataType) { - pushAndInvokeCircularReferenceCheck((DataType) o, stk, p); + for (ResourceCollection resourceCollection : textDocuments) { + if (resourceCollection instanceof DataType) { + pushAndInvokeCircularReferenceCheck((DataType) resourceCollection, stk, p); } } - for (Iterator iter = filterChains.iterator(); iter.hasNext(); ) { - FilterChain fc = (FilterChain) iter.next(); - pushAndInvokeCircularReferenceCheck(fc, stk, p); + for (FilterChain filterChain : filterChains) { + pushAndInvokeCircularReferenceCheck(filterChain, stk, p); } setChecked(true); } } - + private synchronized ResourceCollection cache() { if (!cached) { dieOnCircularReference(); - for (Iterator iter = textDocuments.iterator(); iter.hasNext(); ) { - ResourceCollection rc = (ResourceCollection) iter.next(); + for (ResourceCollection rc : textDocuments) { for (Resource r : rc) { cachedResources.add(read(r)); } diff --git a/src/main/org/apache/tools/ant/types/resources/Restrict.java b/src/main/org/apache/tools/ant/types/resources/Restrict.java index 16b67c557..2ea1a8619 100644 --- a/src/main/org/apache/tools/ant/types/resources/Restrict.java +++ b/src/main/org/apache/tools/ant/types/resources/Restrict.java @@ -40,8 +40,8 @@ public class Restrict * Restrict the nested ResourceCollection based on the nested selectors. */ protected boolean filterResource(Resource r) { - for (Iterator i = getSelectors(); i.hasNext();) { - if (!((ResourceSelector) (i.next())).isSelected(r)) { + for (Iterator i = getSelectors(); i.hasNext();) { + if (!i.next().isSelected(r)) { return true; } } @@ -140,7 +140,7 @@ public class Restrict return w.toString(); } - protected synchronized void dieOnCircularReference(Stack stk, Project p) { + protected synchronized void dieOnCircularReference(Stack stk, Project p) { if (isChecked()) { return; } diff --git a/src/main/org/apache/tools/ant/types/resources/Sort.java b/src/main/org/apache/tools/ant/types/resources/Sort.java index 89ae7dbf0..50f50327c 100644 --- a/src/main/org/apache/tools/ant/types/resources/Sort.java +++ b/src/main/org/apache/tools/ant/types/resources/Sort.java @@ -80,12 +80,12 @@ public class Sort extends BaseResourceCollectionWrapper { * @param p the project to use to dereference the references. * @throws BuildException on error. */ - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; } - + // check nested collection super.dieOnCircularReference(stk, p); diff --git a/src/main/org/apache/tools/ant/types/resources/Tokens.java b/src/main/org/apache/tools/ant/types/resources/Tokens.java index d717596d9..185e4844b 100644 --- a/src/main/org/apache/tools/ant/types/resources/Tokens.java +++ b/src/main/org/apache/tools/ant/types/resources/Tokens.java @@ -28,8 +28,10 @@ import java.util.Collections; import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.DataType; +import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.util.ConcatResourceInputStream; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.LineTokenizer; import org.apache.tools.ant.util.Tokenizer; @@ -47,10 +49,10 @@ public class Tokens extends BaseResourceCollectionWrapper { * Sort the contained elements. * @return a Collection of Resources. */ - protected synchronized Collection getCollection() { + protected synchronized Collection getCollection() { ResourceCollection rc = getResourceCollection(); if (rc.size() == 0) { - return Collections.EMPTY_SET; + return Collections.emptySet(); } if (tokenizer == null) { tokenizer = new LineTokenizer(); @@ -58,27 +60,29 @@ public class Tokens extends BaseResourceCollectionWrapper { ConcatResourceInputStream cat = new ConcatResourceInputStream(rc); cat.setManagingComponent(this); - InputStreamReader rdr = null; - if (encoding == null) { - rdr = new InputStreamReader(cat); - } else { - try { - rdr = new InputStreamReader(cat, encoding); - } catch (UnsupportedEncodingException e) { - throw new BuildException(e); - } - } - ArrayList result = new ArrayList(); try { + InputStreamReader rdr = null; + if (encoding == null) { + rdr = new InputStreamReader(cat); + } else { + try { + rdr = new InputStreamReader(cat, encoding); + } catch (UnsupportedEncodingException e) { + throw new BuildException(e); + } + } + ArrayList result = new ArrayList(); for (String s = tokenizer.getToken(rdr); s != null; s = tokenizer.getToken(rdr)) { StringResource resource = new StringResource(s); resource.setProject(getProject()); result.add(resource); } + return result; } catch (IOException e) { throw new BuildException("Error reading tokens", e); + } finally { + FileUtils.close(cat); } - return result; } /** @@ -112,7 +116,7 @@ public class Tokens extends BaseResourceCollectionWrapper { * @param p the project to use to dereference the references. * @throws BuildException on error. */ - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; diff --git a/src/main/org/apache/tools/ant/types/resources/Union.java b/src/main/org/apache/tools/ant/types/resources/Union.java index 99f518054..be485e6d2 100644 --- a/src/main/org/apache/tools/ant/types/resources/Union.java +++ b/src/main/org/apache/tools/ant/types/resources/Union.java @@ -17,11 +17,12 @@ */ package org.apache.tools.ant.types.resources; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Resource; @@ -63,7 +64,7 @@ public class Union extends BaseResourceCollectionContainer { public Union(ResourceCollection rc) { this(Project.getProject(rc), rc); } - + /** * Convenience constructor. * @param project owning Project @@ -81,10 +82,10 @@ public class Union extends BaseResourceCollectionContainer { */ public String[] list() { if (isReference()) { - return ((Union) getCheckedRef()).list(); + return getCheckedRef(Union.class, getDataTypeName()).list(); } - Collection result = getCollection(true); - return (String[]) (result.toArray(new String[result.size()])); + final Collection result = getAllToStrings(); + return result.toArray(new String[result.size()]); } /** @@ -93,18 +94,18 @@ public class Union extends BaseResourceCollectionContainer { */ public Resource[] listResources() { if (isReference()) { - return ((Union) getCheckedRef()).listResources(); + return getCheckedRef(Union.class, getDataTypeName()).listResources(); } - Collection result = getCollection(); - return (Resource[]) (result.toArray(new Resource[result.size()])); + final Collection result = getAllResources(); + return result.toArray(new Resource[result.size()]); } /** * Unify the contained Resources. * @return a Collection of Resources. */ - protected Collection getCollection() { - return getCollection(false); + protected Collection getCollection() { + return getAllResources(); } /** @@ -113,26 +114,43 @@ public class Union extends BaseResourceCollectionContainer { * should contain Strings instead of Resources. * @return a Collection of Resources. */ - protected Collection getCollection(boolean asString) { // XXX untypable - List rc = getResourceCollections(); - if (rc.isEmpty()) { - return Collections.EMPTY_LIST; + @Deprecated + @SuppressWarnings("unchecked") + protected Collection getCollection(boolean asString) { // XXX untypable + return asString ? (Collection) getAllToStrings() : (Collection) getAllResources(); + } + + /** + * Get a collection of strings representing the unified resource set (strings may duplicate). + * @return Collection + */ + protected Collection getAllToStrings() { + final Set allResources = getAllResources(); + final ArrayList result = new ArrayList(allResources.size()); + for (Resource r : allResources) { + result.add(r.toString()); } - LinkedHashSet set = new LinkedHashSet(rc.size() * 2); - for (Iterator rcIter = rc.iterator(); rcIter.hasNext();) { - for (Iterator r = nextRC(rcIter).iterator(); r.hasNext();) { - Object o = r.next(); - if (asString) { - o = o.toString(); - } - set.add(o); + return result; + } + + /** + * Get the unified set of contained Resources. + * @return Set + */ + protected Set getAllResources() { + final List resourceCollections = getResourceCollections(); + if (resourceCollections.isEmpty()) { + return Collections.emptySet(); + } + final LinkedHashSet result = new LinkedHashSet( + resourceCollections.size() * 2); + for (ResourceCollection resourceCollection : resourceCollections) { + for (Resource r : resourceCollection) { + result.add(r); } } - return set; + return result; } - private static ResourceCollection nextRC(Iterator i) { - return (ResourceCollection) i.next(); - } } diff --git a/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java b/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java index 8e75970d4..edc308ffc 100644 --- a/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java +++ b/src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java @@ -17,6 +17,7 @@ */ package org.apache.tools.ant.types.resources.comparators; +import java.util.List; import java.util.Stack; import java.util.Vector; import java.util.Iterator; @@ -33,7 +34,7 @@ import org.apache.tools.ant.types.Resource; */ public class DelegatedResourceComparator extends ResourceComparator { - private Vector v = null; + private List resourceComparators = null; /** * Add a delegate ResourceComparator. @@ -46,8 +47,8 @@ public class DelegatedResourceComparator extends ResourceComparator { if (c == null) { return; } - v = (v == null) ? new Vector() : v; - v.add(c); + resourceComparators = (resourceComparators == null) ? new Vector() : resourceComparators; + resourceComparators.add(c); setChecked(false); } @@ -67,8 +68,8 @@ public class DelegatedResourceComparator extends ResourceComparator { if (!(o instanceof DelegatedResourceComparator)) { return false; } - Vector ov = ((DelegatedResourceComparator) o).v; - return v == null ? ov == null : v.equals(ov); + List ov = ((DelegatedResourceComparator) o).resourceComparators; + return resourceComparators == null ? ov == null : resourceComparators.equals(ov); } /** @@ -79,18 +80,18 @@ public class DelegatedResourceComparator extends ResourceComparator { if (isReference()) { return getCheckedRef().hashCode(); } - return v == null ? 0 : v.hashCode(); + return resourceComparators == null ? 0 : resourceComparators.hashCode(); } /** {@inheritDoc} */ protected synchronized int resourceCompare(Resource foo, Resource bar) { //if no nested, natural order: - if (v == null || v.isEmpty()) { + if (resourceComparators == null || resourceComparators.isEmpty()) { return foo.compareTo(bar); } int result = 0; - for (Iterator i = v.iterator(); result == 0 && i.hasNext();) { - result = ((ResourceComparator) i.next()).resourceCompare(foo, bar); + for (Iterator i = resourceComparators.iterator(); result == 0 && i.hasNext();) { + result = i.next().resourceCompare(foo, bar); } return result; } @@ -102,7 +103,7 @@ s. * @param p the Project to resolve against. * @throws BuildException on error. */ - protected void dieOnCircularReference(Stack stk, Project p) + protected void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -110,11 +111,10 @@ s. if (isReference()) { super.dieOnCircularReference(stk, p); } else { - if (!(v == null || v.isEmpty())) { - for (Iterator i = v.iterator(); i.hasNext();) { - Object o = i.next(); - if (o instanceof DataType) { - pushAndInvokeCircularReferenceCheck((DataType) o, stk, + if (!(resourceComparators == null || resourceComparators.isEmpty())) { + for (ResourceComparator resourceComparator : resourceComparators) { + if (resourceComparator instanceof DataType) { + pushAndInvokeCircularReferenceCheck((DataType) resourceComparator, stk, p); } } diff --git a/src/main/org/apache/tools/ant/types/resources/comparators/Reverse.java b/src/main/org/apache/tools/ant/types/resources/comparators/Reverse.java index 2c9e62384..70e6cd820 100644 --- a/src/main/org/apache/tools/ant/types/resources/comparators/Reverse.java +++ b/src/main/org/apache/tools/ant/types/resources/comparators/Reverse.java @@ -72,7 +72,7 @@ public class Reverse extends ResourceComparator { ? foo.compareTo(bar) : nested.compare(foo, bar)); } - protected void dieOnCircularReference(Stack stk, Project p) + protected void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; diff --git a/src/main/org/apache/tools/ant/types/resources/selectors/And.java b/src/main/org/apache/tools/ant/types/resources/selectors/And.java index 0dbb295b3..409ed6618 100644 --- a/src/main/org/apache/tools/ant/types/resources/selectors/And.java +++ b/src/main/org/apache/tools/ant/types/resources/selectors/And.java @@ -47,8 +47,8 @@ public class And extends ResourceSelectorContainer implements ResourceSelector { * @return whether the Resource was selected. */ public boolean isSelected(Resource r) { - for (Iterator i = getSelectors(); i.hasNext();) { - if (!((ResourceSelector) i.next()).isSelected(r)) { + for (Iterator i = getSelectors(); i.hasNext();) { + if (!i.next().isSelected(r)) { return false; } } diff --git a/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java b/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java index 7704e89e0..08c88ceb2 100644 --- a/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java +++ b/src/main/org/apache/tools/ant/types/resources/selectors/Compare.java @@ -18,7 +18,6 @@ package org.apache.tools.ant.types.resources.selectors; import java.util.Stack; -import java.util.Iterator; import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildException; @@ -128,7 +127,7 @@ public class Compare extends DataType implements ResourceSelector { * @param p the project to use to dereference the references. * @throws BuildException on error. */ - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; diff --git a/src/main/org/apache/tools/ant/types/resources/selectors/InstanceOf.java b/src/main/org/apache/tools/ant/types/resources/selectors/InstanceOf.java index 1e7b16bd4..bb663f0a3 100644 --- a/src/main/org/apache/tools/ant/types/resources/selectors/InstanceOf.java +++ b/src/main/org/apache/tools/ant/types/resources/selectors/InstanceOf.java @@ -33,7 +33,7 @@ public class InstanceOf implements ResourceSelector { private static final String ONE_ONLY = "Exactly one of class|type must be set."; private Project project; - private Class clazz; + private Class clazz; private String type; private String uri; @@ -49,7 +49,7 @@ public class InstanceOf implements ResourceSelector { * Set the class to compare against. * @param c the class. */ - public void setClass(Class c) { + public void setClass(Class c) { if (clazz != null) { throw new BuildException("The class attribute has already been set."); } @@ -76,7 +76,7 @@ public class InstanceOf implements ResourceSelector { * Get the comparison class. * @return the Class object. */ - public Class getCheckClass() { + public Class getCheckClass() { return clazz; } @@ -106,7 +106,7 @@ public class InstanceOf implements ResourceSelector { if ((clazz == null) == (type == null)) { throw new BuildException(ONE_ONLY); } - Class c = clazz; + Class c = clazz; if (type != null) { if (project == null) { throw new BuildException( diff --git a/src/main/org/apache/tools/ant/types/resources/selectors/Majority.java b/src/main/org/apache/tools/ant/types/resources/selectors/Majority.java index 92b0d2642..5a7a95c09 100644 --- a/src/main/org/apache/tools/ant/types/resources/selectors/Majority.java +++ b/src/main/org/apache/tools/ant/types/resources/selectors/Majority.java @@ -64,8 +64,8 @@ public class Majority boolean even = count % 2 == 0; int threshold = count / 2; - for (Iterator i = getSelectors(); i.hasNext();) { - if (((ResourceSelector) i.next()).isSelected(r)) { + for (Iterator i = getSelectors(); i.hasNext();) { + if (i.next().isSelected(r)) { ++passed; if (passed > threshold || (even && tie && passed == threshold)) { return true; diff --git a/src/main/org/apache/tools/ant/types/resources/selectors/None.java b/src/main/org/apache/tools/ant/types/resources/selectors/None.java index 16a1b62e0..0de86236e 100644 --- a/src/main/org/apache/tools/ant/types/resources/selectors/None.java +++ b/src/main/org/apache/tools/ant/types/resources/selectors/None.java @@ -48,11 +48,12 @@ public class None * @return whether the Resource was selected. */ public boolean isSelected(Resource r) { - boolean none = true; - for (Iterator i = getSelectors(); none && i.hasNext();) { - none = !((ResourceSelector) i.next()).isSelected(r); + for (Iterator i = getSelectors(); i.hasNext();) { + if (i.next().isSelected(r)) { + return false; + } } - return none; + return true; } } diff --git a/src/main/org/apache/tools/ant/types/resources/selectors/Or.java b/src/main/org/apache/tools/ant/types/resources/selectors/Or.java index d1438c932..b22303a4a 100644 --- a/src/main/org/apache/tools/ant/types/resources/selectors/Or.java +++ b/src/main/org/apache/tools/ant/types/resources/selectors/Or.java @@ -47,8 +47,8 @@ public class Or extends ResourceSelectorContainer implements ResourceSelector { * @return whether the Resource was selected. */ public boolean isSelected(Resource r) { - for (Iterator i = getSelectors(); i.hasNext();) { - if (((ResourceSelector) i.next()).isSelected(r)) { + for (Iterator i = getSelectors(); i.hasNext();) { + if (i.next().isSelected(r)) { return true; } } diff --git a/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java b/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java index d519750f7..6fd2e0608 100644 --- a/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java +++ b/src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java @@ -17,8 +17,9 @@ */ package org.apache.tools.ant.types.resources.selectors; +import java.util.ArrayList; +import java.util.List; import java.util.Stack; -import java.util.Vector; import java.util.Iterator; import java.util.Collections; @@ -32,7 +33,7 @@ import org.apache.tools.ant.types.DataType; */ public class ResourceSelectorContainer extends DataType { - private Vector v = new Vector(); + private final List resourceSelectors = new ArrayList(); /** * Default constructor. @@ -61,7 +62,7 @@ public class ResourceSelectorContainer extends DataType { if (s == null) { return; } - v.add(s); + resourceSelectors.add(s); setChecked(false); } @@ -74,7 +75,7 @@ public class ResourceSelectorContainer extends DataType { return ((ResourceSelectorContainer) getCheckedRef()).hasSelectors(); } dieOnCircularReference(); - return !v.isEmpty(); + return !resourceSelectors.isEmpty(); } /** @@ -86,19 +87,19 @@ public class ResourceSelectorContainer extends DataType { return ((ResourceSelectorContainer) getCheckedRef()).selectorCount(); } dieOnCircularReference(); - return v.size(); + return resourceSelectors.size(); } /** * Return an Iterator over the nested selectors. * @return Iterator of ResourceSelectors. */ - public Iterator getSelectors() { + public Iterator getSelectors() { if (isReference()) { return ((ResourceSelectorContainer) getCheckedRef()).getSelectors(); } dieOnCircularReference(); - return Collections.unmodifiableList(v).iterator(); + return Collections.unmodifiableList(resourceSelectors).iterator(); } /** @@ -107,7 +108,7 @@ public class ResourceSelectorContainer extends DataType { * @param p the Project to resolve against. * @throws BuildException on error. */ - protected void dieOnCircularReference(Stack stk, Project p) + protected void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -115,10 +116,9 @@ public class ResourceSelectorContainer extends DataType { if (isReference()) { super.dieOnCircularReference(stk, p); } else { - for (Iterator i = v.iterator(); i.hasNext();) { - Object o = i.next(); - if (o instanceof DataType) { - pushAndInvokeCircularReferenceCheck((DataType) o, stk, p); + for (ResourceSelector resourceSelector : resourceSelectors) { + if (resourceSelector instanceof DataType) { + pushAndInvokeCircularReferenceCheck((DataType) resourceSelector, stk, p); } } setChecked(true); diff --git a/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java b/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java index 999adf301..b80816dac 100644 --- a/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java +++ b/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java @@ -19,7 +19,6 @@ package org.apache.tools.ant.types.selectors; import java.util.Enumeration; -import java.util.Iterator; import java.util.Stack; import java.util.Vector; @@ -37,7 +36,7 @@ import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector; public abstract class AbstractSelectorContainer extends DataType implements Cloneable, SelectorContainer { - private Vector selectorsList = new Vector(); + private Vector selectorsList = new Vector(); /** * Indicates whether there are any selectors here. @@ -83,7 +82,7 @@ public abstract class AbstractSelectorContainer extends DataType * Returns an enumerator for accessing the set of selectors. * @return an enumerator for the selectors */ - public Enumeration selectorElements() { + public Enumeration selectorElements() { if (isReference()) { return ((AbstractSelectorContainer) getCheckedRef()) .selectorElements(); @@ -100,8 +99,8 @@ public abstract class AbstractSelectorContainer extends DataType * @return comma separated list of Selectors contained in this one */ public String toString() { - StringBuffer buf = new StringBuffer(); - Enumeration e = selectorElements(); + StringBuilder buf = new StringBuilder(); + Enumeration e = selectorElements(); if (e.hasMoreElements()) { while (e.hasMoreElements()) { buf.append(e.nextElement().toString()); @@ -148,7 +147,7 @@ public abstract class AbstractSelectorContainer extends DataType ((AbstractSelectorContainer) getCheckedRef()).validate(); } dieOnCircularReference(); - Enumeration e = selectorElements(); + Enumeration e = selectorElements(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (o instanceof BaseSelector) { @@ -322,17 +321,16 @@ public abstract class AbstractSelectorContainer extends DataType appendSelector(selector); } - protected synchronized void dieOnCircularReference(Stack stk, Project p) { + protected synchronized void dieOnCircularReference(Stack stk, Project p) { if (isChecked()) { return; } if (isReference()) { super.dieOnCircularReference(stk, p); } else { - for (Iterator i = selectorsList.iterator(); i.hasNext(); ) { - Object o = i.next(); - if (o instanceof DataType) { - pushAndInvokeCircularReferenceCheck((DataType) o, stk, p); + for (FileSelector fileSelector : selectorsList) { + if (fileSelector instanceof DataType) { + pushAndInvokeCircularReferenceCheck((DataType) fileSelector, stk, p); } } setChecked(true); @@ -346,7 +344,7 @@ public abstract class AbstractSelectorContainer extends DataType try { AbstractSelectorContainer sc = (AbstractSelectorContainer) super.clone(); - sc.selectorsList = new Vector(selectorsList); + sc.selectorsList = new Vector(selectorsList); return sc; } catch (CloneNotSupportedException e) { throw new BuildException(e); diff --git a/src/main/org/apache/tools/ant/types/selectors/AndSelector.java b/src/main/org/apache/tools/ant/types/selectors/AndSelector.java index 48849e090..c8e96a04d 100644 --- a/src/main/org/apache/tools/ant/types/selectors/AndSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/AndSelector.java @@ -39,7 +39,7 @@ public class AndSelector extends BaseSelectorContainer { * @return a string representation of the selector */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); if (hasSelectors()) { buf.append("{andselect: "); buf.append(super.toString()); @@ -60,13 +60,10 @@ public class AndSelector extends BaseSelectorContainer { */ public boolean isSelected(File basedir, String filename, File file) { validate(); - Enumeration e = selectorElements(); - boolean result; + Enumeration e = selectorElements(); while (e.hasMoreElements()) { - result = ((FileSelector) e.nextElement()).isSelected(basedir, - filename, file); - if (!result) { + if (!e.nextElement().isSelected(basedir, filename, file)) { return false; } } diff --git a/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java b/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java index 6d9d2696b..1edf08574 100644 --- a/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java +++ b/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java @@ -20,7 +20,6 @@ package org.apache.tools.ant.types.selectors; import java.io.File; import java.util.Enumeration; -import java.util.Iterator; import java.util.Stack; import java.util.Vector; @@ -37,7 +36,7 @@ import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector; public abstract class BaseSelectorContainer extends BaseSelector implements SelectorContainer { - private Vector selectorsList = new Vector(); + private Vector selectorsList = new Vector(); /** * Default constructor. @@ -79,7 +78,7 @@ public abstract class BaseSelectorContainer extends BaseSelector * Returns an enumerator for accessing the set of selectors. * @return an enumerator for the selectors */ - public Enumeration selectorElements() { + public Enumeration selectorElements() { dieOnCircularReference(); return selectorsList.elements(); } @@ -93,17 +92,14 @@ public abstract class BaseSelectorContainer extends BaseSelector */ public String toString() { dieOnCircularReference(); - StringBuffer buf = new StringBuffer(); - Enumeration e = selectorElements(); - if (e.hasMoreElements()) { - while (e.hasMoreElements()) { - buf.append(e.nextElement().toString()); - if (e.hasMoreElements()) { - buf.append(", "); - } + StringBuilder buf = new StringBuilder(); + Enumeration e = selectorElements(); + while (e.hasMoreElements()) { + buf.append(e.nextElement().toString()); + if (e.hasMoreElements()) { + buf.append(", "); } } - return buf.toString(); } @@ -140,7 +136,7 @@ public abstract class BaseSelectorContainer extends BaseSelector if (errmsg != null) { throw new BuildException(errmsg); } - Enumeration e = selectorElements(); + Enumeration e = selectorElements(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (o instanceof BaseSelector) { @@ -328,7 +324,7 @@ public abstract class BaseSelectorContainer extends BaseSelector appendSelector(selector); } - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack stk, Project p) throws BuildException { if (isChecked()) { return; @@ -336,10 +332,9 @@ public abstract class BaseSelectorContainer extends BaseSelector if (isReference()) { super.dieOnCircularReference(stk, p); } else { - for (Iterator i = selectorsList.iterator(); i.hasNext();) { - Object o = i.next(); - if (o instanceof DataType) { - pushAndInvokeCircularReferenceCheck((DataType) o, stk, p); + for (FileSelector fileSelector : selectorsList) { + if (fileSelector instanceof DataType) { + pushAndInvokeCircularReferenceCheck((DataType) fileSelector, stk, p); } } setChecked(true); diff --git a/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java b/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java index 987fa4d25..4da3b6ffe 100644 --- a/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java @@ -66,7 +66,7 @@ public class ContainsRegexpSelector extends BaseExtendSelector * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer( + StringBuilder buf = new StringBuilder( "{containsregexpselector expression: "); buf.append(userProvidedExpression); buf.append("}"); diff --git a/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java b/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java index 31c5c5a65..66080b7c9 100644 --- a/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java @@ -63,7 +63,7 @@ public class ContainsSelector extends BaseExtendSelector implements ResourceSele * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer("{containsselector text: "); + StringBuilder buf = new StringBuilder("{containsselector text: "); buf.append('"').append(contains).append('"'); buf.append(" casesensitive: "); buf.append(casesensitive ? "true" : "false"); diff --git a/src/main/org/apache/tools/ant/types/selectors/DateSelector.java b/src/main/org/apache/tools/ant/types/selectors/DateSelector.java index 76c1d167f..e0cf072f0 100644 --- a/src/main/org/apache/tools/ant/types/selectors/DateSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/DateSelector.java @@ -71,7 +71,7 @@ public class DateSelector extends BaseExtendSelector { * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer("{dateselector date: "); + StringBuilder buf = new StringBuilder("{dateselector date: "); buf.append(dateTime); buf.append(" compare: ").append(when.getValue()); buf.append(" granularity: "); diff --git a/src/main/org/apache/tools/ant/types/selectors/DependSelector.java b/src/main/org/apache/tools/ant/types/selectors/DependSelector.java index f22ad297c..01ac23790 100644 --- a/src/main/org/apache/tools/ant/types/selectors/DependSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/DependSelector.java @@ -42,7 +42,7 @@ public class DependSelector extends MappingSelector { * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer("{dependselector targetdir: "); + StringBuilder buf = new StringBuilder("{dependselector targetdir: "); if (targetdir == null) { buf.append("NOT YET SET"); } else { diff --git a/src/main/org/apache/tools/ant/types/selectors/DepthSelector.java b/src/main/org/apache/tools/ant/types/selectors/DepthSelector.java index 9d6165000..a80f9aa96 100644 --- a/src/main/org/apache/tools/ant/types/selectors/DepthSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/DepthSelector.java @@ -57,7 +57,7 @@ public class DepthSelector extends BaseExtendSelector { * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer("{depthselector min: "); + StringBuilder buf = new StringBuilder("{depthselector min: "); buf.append(min); buf.append(" max: "); buf.append(max); diff --git a/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java b/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java index 6c29abe62..d55768454 100644 --- a/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java @@ -37,7 +37,7 @@ public class ExtendSelector extends BaseSelector { private String classname = null; private FileSelector dynselector = null; - private Vector paramVec = new Vector(); + private Vector paramVec = new Vector(); private Path classpath = null; /** @@ -61,7 +61,7 @@ public class ExtendSelector extends BaseSelector { public void selectorCreate() { if (classname != null && classname.length() > 0) { try { - Class c = null; + Class c = null; if (classpath == null) { c = Class.forName(classname); } else { @@ -70,7 +70,7 @@ public class ExtendSelector extends BaseSelector { = getProject().createClassLoader(classpath); c = Class.forName(classname, true, al); } - dynselector = (FileSelector) c.newInstance(); + dynselector = c.asSubclass(FileSelector.class).newInstance(); final Project p = getProject(); if (p != null) { p.setProjectReference(dynselector); diff --git a/src/main/org/apache/tools/ant/types/selectors/FilenameSelector.java b/src/main/org/apache/tools/ant/types/selectors/FilenameSelector.java index d94fa6f11..1b998f9f3 100644 --- a/src/main/org/apache/tools/ant/types/selectors/FilenameSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/FilenameSelector.java @@ -62,7 +62,7 @@ public class FilenameSelector extends BaseExtendSelector { * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer("{filenameselector name: "); + StringBuilder buf = new StringBuilder("{filenameselector name: "); if (pattern != null) { buf.append(pattern); } diff --git a/src/main/org/apache/tools/ant/types/selectors/MajoritySelector.java b/src/main/org/apache/tools/ant/types/selectors/MajoritySelector.java index 137ee8e20..842258fba 100644 --- a/src/main/org/apache/tools/ant/types/selectors/MajoritySelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/MajoritySelector.java @@ -46,7 +46,7 @@ public class MajoritySelector extends BaseSelectorContainer { * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); if (hasSelectors()) { buf.append("{majorityselect: "); buf.append(super.toString()); @@ -81,16 +81,14 @@ public class MajoritySelector extends BaseSelectorContainer { validate(); int yesvotes = 0; int novotes = 0; - Enumeration e = selectorElements(); - boolean result; + Enumeration e = selectorElements(); while (e.hasMoreElements()) { - result = ((FileSelector) e.nextElement()).isSelected(basedir, - filename, file); - if (result) { - yesvotes = yesvotes + 1; + if (e.nextElement().isSelected(basedir, + filename, file)) { + yesvotes++; } else { - novotes = novotes + 1; + novotes++; } } if (yesvotes > novotes) { diff --git a/src/main/org/apache/tools/ant/types/selectors/NoneSelector.java b/src/main/org/apache/tools/ant/types/selectors/NoneSelector.java index 441f00101..536b5b5f2 100644 --- a/src/main/org/apache/tools/ant/types/selectors/NoneSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/NoneSelector.java @@ -40,7 +40,7 @@ public class NoneSelector extends BaseSelectorContainer { * @return a string representation of the selector */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); if (hasSelectors()) { buf.append("{noneselect: "); buf.append(super.toString()); @@ -61,13 +61,10 @@ public class NoneSelector extends BaseSelectorContainer { */ public boolean isSelected(File basedir, String filename, File file) { validate(); - Enumeration e = selectorElements(); - boolean result; + Enumeration e = selectorElements(); while (e.hasMoreElements()) { - result = ((FileSelector) e.nextElement()).isSelected(basedir, - filename, file); - if (result) { + if (e.nextElement().isSelected(basedir, filename, file)) { return false; } } diff --git a/src/main/org/apache/tools/ant/types/selectors/NotSelector.java b/src/main/org/apache/tools/ant/types/selectors/NotSelector.java index d5ff97b7a..71c3940ff 100644 --- a/src/main/org/apache/tools/ant/types/selectors/NotSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/NotSelector.java @@ -49,7 +49,7 @@ public class NotSelector extends NoneSelector { * @return a string representation of the selector */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); if (hasSelectors()) { buf.append("{notselect: "); buf.append(super.toString()); diff --git a/src/main/org/apache/tools/ant/types/selectors/OrSelector.java b/src/main/org/apache/tools/ant/types/selectors/OrSelector.java index 71833ff6d..b07774458 100644 --- a/src/main/org/apache/tools/ant/types/selectors/OrSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/OrSelector.java @@ -39,7 +39,7 @@ public class OrSelector extends BaseSelectorContainer { * @return a string representation of the selector */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); if (hasSelectors()) { buf.append("{orselect: "); buf.append(super.toString()); @@ -60,14 +60,11 @@ public class OrSelector extends BaseSelectorContainer { */ public boolean isSelected(File basedir, String filename, File file) { validate(); - Enumeration e = selectorElements(); - boolean result; + Enumeration e = selectorElements(); // First, check that all elements are correctly configured while (e.hasMoreElements()) { - result = ((FileSelector) e.nextElement()).isSelected(basedir, - filename, file); - if (result) { + if (e.nextElement().isSelected(basedir, filename, file)) { return true; } } diff --git a/src/main/org/apache/tools/ant/types/selectors/PresentSelector.java b/src/main/org/apache/tools/ant/types/selectors/PresentSelector.java index 633b128ae..f9efce397 100644 --- a/src/main/org/apache/tools/ant/types/selectors/PresentSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/PresentSelector.java @@ -52,7 +52,7 @@ public class PresentSelector extends BaseSelector { * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer("{presentselector targetdir: "); + StringBuilder buf = new StringBuilder("{presentselector targetdir: "); if (targetdir == null) { buf.append("NOT YET SET"); } else { @@ -108,7 +108,7 @@ public class PresentSelector extends BaseSelector { } this.map = fileNameMapper; } - + /** * This sets whether to select a file if its dest file is present. * It could be a negate boolean, but by doing things diff --git a/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java b/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java index 2e64cab11..d0bf593a8 100644 --- a/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java @@ -114,7 +114,7 @@ public class SelectSelector extends BaseSelectorContainer { * Returns an enumerator for accessing the set of selectors. * @return an enumerator that goes through each of the selectors */ - public Enumeration selectorElements() { + public Enumeration selectorElements() { if (isReference()) { return getRef().selectorElements(); } @@ -220,11 +220,11 @@ public class SelectSelector extends BaseSelectorContainer { return false; } - Enumeration e = selectorElements(); - if (!(e.hasMoreElements())) { + Enumeration e = selectorElements(); + if (!e.hasMoreElements()) { return true; } - FileSelector f = (FileSelector) e.nextElement(); + FileSelector f = e.nextElement(); return f.isSelected(basedir, filename, file); } } diff --git a/src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java b/src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java index 1d11cf5bc..089e132a9 100644 --- a/src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java +++ b/src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java @@ -55,7 +55,7 @@ public interface SelectorContainer { * * @return an enumerator that goes through each of the selectors */ - Enumeration selectorElements(); + Enumeration selectorElements(); /** * Add a new selector into this container. diff --git a/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java b/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java index 34e23ed1f..277470b7f 100644 --- a/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java +++ b/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java @@ -172,11 +172,11 @@ public final class SelectorUtils { /** * Tests whether or not a given path matches a given pattern. * - * If you need to call this method multiple times with the same + * If you need to call this method multiple times with the same * pattern you should rather use TokenizedPath * * @see TokenizedPath - * + * * @param pattern The pattern to match against. Must not be * null. * @param str The path to match, as a String. Must not be @@ -192,12 +192,12 @@ public final class SelectorUtils { /** * Tests whether or not a given path matches a given pattern. - * - * If you need to call this method multiple times with the same + * + * If you need to call this method multiple times with the same * pattern you should rather use TokenizedPattern * * @see TokenizedPattern - * + * * @param pattern The pattern to match against. Must not be * null. * @param str The path to match, as a String. Must not be @@ -509,7 +509,7 @@ public final class SelectorUtils { * * @return a Vector of path elements from the tokenized path */ - public static Vector tokenizePath (String path) { + public static Vector tokenizePath(String path) { return tokenizePath(path, File.separator); } @@ -522,8 +522,8 @@ public final class SelectorUtils { * @return a Vector of path elements from the tokenized path * @since Ant 1.6 */ - public static Vector tokenizePath (String path, String separator) { - Vector ret = new Vector(); + public static Vector tokenizePath(String path, String separator) { + Vector ret = new Vector(); if (FileUtils.isAbsolutePath(path)) { String[] s = FILE_UTILS.dissect(path); ret.add(s[0]); diff --git a/src/main/org/apache/tools/ant/types/selectors/SizeSelector.java b/src/main/org/apache/tools/ant/types/selectors/SizeSelector.java index 3248647f6..9ff91ad92 100644 --- a/src/main/org/apache/tools/ant/types/selectors/SizeSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/SizeSelector.java @@ -75,7 +75,7 @@ public class SizeSelector extends BaseExtendSelector { * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer("{sizeselector value: "); + StringBuilder buf = new StringBuilder("{sizeselector value: "); buf.append(sizelimit); buf.append("compare: ").append(when.getValue()); buf.append("}"); diff --git a/src/main/org/apache/tools/ant/types/selectors/TokenizedPattern.java b/src/main/org/apache/tools/ant/types/selectors/TokenizedPattern.java index f13266072..ee5a38ee6 100644 --- a/src/main/org/apache/tools/ant/types/selectors/TokenizedPattern.java +++ b/src/main/org/apache/tools/ant/types/selectors/TokenizedPattern.java @@ -41,14 +41,14 @@ public class TokenizedPattern { private final String tokenizedPattern[]; /** - * Initialize the PathPattern by parsing it. + * Initialize the PathPattern by parsing it. * @param pattern The pattern to match against. Must not be * null. */ public TokenizedPattern(String pattern) { this(pattern, SelectorUtils.tokenizePathAsArray(pattern)); } - + TokenizedPattern(String pattern, String[] tokens) { this.pattern = pattern; this.tokenizedPattern = tokens; @@ -69,7 +69,7 @@ public class TokenizedPattern { return SelectorUtils.matchPath(tokenizedPattern, path.getTokens(), isCaseSensitive); } - + /** * Tests whether or not this pattern matches the start of * a path. @@ -86,7 +86,7 @@ public class TokenizedPattern { public String toString() { return pattern; } - + public String getPattern() { return pattern; } @@ -128,7 +128,7 @@ public class TokenizedPattern { * @return the leftmost part of the pattern without wildcards */ public TokenizedPath rtrimWildcardTokens() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int newLen = 0; for (; newLen < tokenizedPattern.length; newLen++) { if (SelectorUtils.hasWildcards(tokenizedPattern[newLen])) { @@ -173,5 +173,5 @@ public class TokenizedPattern { return new TokenizedPattern(pattern.substring(0, index), tokens); } } - + } diff --git a/src/main/org/apache/tools/ant/types/selectors/TypeSelector.java b/src/main/org/apache/tools/ant/types/selectors/TypeSelector.java index 33ac443b7..fd3684d6e 100644 --- a/src/main/org/apache/tools/ant/types/selectors/TypeSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/TypeSelector.java @@ -46,7 +46,7 @@ public class TypeSelector extends BaseExtendSelector { * @return a string describing this object */ public String toString() { - StringBuffer buf = new StringBuffer("{typeselector type: "); + StringBuilder buf = new StringBuilder("{typeselector type: "); buf.append(type); buf.append("}"); return buf.toString(); diff --git a/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java b/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java index ad881a973..219b9d32a 100644 --- a/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java @@ -40,9 +40,6 @@ public class WritableSelector implements FileSelector, ResourceSelector { public boolean isSelected(Resource r) { FileProvider fp = r.as(FileProvider.class); - if (fp != null) { - return isSelected(null, null, fp.getFile()); - } - return false; + return fp != null && isSelected(null, null, fp.getFile()); } } \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/Cache.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/Cache.java index 7aa61fa72..13c74c2b0 100644 --- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/Cache.java +++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/Cache.java @@ -68,5 +68,5 @@ public interface Cache { * Returns an iterator over the keys in the cache. * @return An iterator over the keys. */ - Iterator iterator(); + Iterator iterator(); } diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ChecksumAlgorithm.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ChecksumAlgorithm.java index e930beeb0..d05803a3a 100644 --- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ChecksumAlgorithm.java +++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ChecksumAlgorithm.java @@ -141,7 +141,7 @@ public class ChecksumAlgorithm implements Algorithm { * @return some information about this algorithm. */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append(""); diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java index 38ccddf3e..a421b6f91 100644 --- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java +++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java @@ -197,7 +197,7 @@ public class DigestAlgorithm implements Algorithm { * @return some information about this algorithm. */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append(" 0) { + for (Parameter parameter : configParameter) { + if (parameter.getName().indexOf(".") > 0) { // this is a *.* parameter for later use - specialParameter.add(par); + specialParameter.add(parameter); } else { - useParameter(par); + useParameter(parameter); } } - configParameter = new Vector(); + configParameter = new Vector(); // specify the algorithm classname if (algoName != null) { @@ -368,10 +367,9 @@ public class ModifiedSelector extends BaseExtendSelector } else { if (comparatorClass != null) { // use Algorithm specified by classname - comparator = (Comparator) loadClass( - comparatorClass, - "is not a Comparator.", - Comparator.class); + @SuppressWarnings("unchecked") + Comparator localComparator = loadClass(comparatorClass, "is not a Comparator.", Comparator.class); + comparator = localComparator; } else { // nothing specified - use default comparator = defaultComparator; @@ -381,11 +379,11 @@ public class ModifiedSelector extends BaseExtendSelector // // ----- Set the special attributes, pattern '*.*' ----- // - for (Iterator itSpecial = specialParameter.iterator(); itSpecial.hasNext();) { - Parameter par = (Parameter) itSpecial.next(); + for (Iterator itSpecial = specialParameter.iterator(); itSpecial.hasNext();) { + Parameter par = itSpecial.next(); useParameter(par); } - specialParameter = new Vector(); + specialParameter = new Vector(); } @@ -398,18 +396,18 @@ public class ModifiedSelector extends BaseExtendSelector * @param type the type to check against * @return a castable object */ - protected Object loadClass(String classname, String msg, Class type) { + protected T loadClass(String classname, String msg, Class type) { try { // load the specified class ClassLoader cl = getClassLoader(); - Class clazz = null; + Class clazz = null; if (cl != null) { clazz = cl.loadClass(classname); } else { clazz = Class.forName(classname); } - Object rv = clazz.newInstance(); + T rv = clazz.asSubclass(type).newInstance(); if (!type.isInstance(rv)) { throw new BuildException("Specified class (" + classname + ") " + msg); @@ -944,7 +942,7 @@ public class ModifiedSelector extends BaseExtendSelector * Get the comparator type to use. * @return the enumerated comparator type */ - public Comparator getComparator() { + public Comparator getComparator() { return comparator; } diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java index cbfcd9772..4a8caa263 100644 --- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java +++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java @@ -208,11 +208,11 @@ public class PropertiesfileCache implements Cache { * Returns an iterator over the keys in the cache. * @return An iterator over the keys. */ - public Iterator iterator() { - Vector v = new java.util.Vector(); - Enumeration en = cache.propertyNames(); + public Iterator iterator() { + Vector v = new Vector(); + Enumeration en = cache.propertyNames(); while (en.hasMoreElements()) { - v.add(en.nextElement()); + v.add(en.nextElement().toString()); } return v.iterator(); } diff --git a/src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java b/src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java index 7d3b364b1..c198c8dc2 100644 --- a/src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java +++ b/src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java @@ -40,15 +40,15 @@ public abstract class AbstractAnalyzer implements DependencyAnalyzer { private Path classPath = new Path(null); /** The list of root classes */ - private final Vector rootClasses = new VectorSet(); + private final Vector rootClasses = new VectorSet(); /** true if dependencies have been determined */ private boolean determined = false; /** the list of File objects that the root classes depend upon */ - private Vector fileDependencies; + private Vector fileDependencies; /** the list of java classes the root classes depend upon */ - private Vector classDependencies; + private Vector classDependencies; /** true if indirect dependencies should be gathered */ private boolean closure = true; @@ -77,7 +77,7 @@ public abstract class AbstractAnalyzer implements DependencyAnalyzer { * * @return an enumeration of File instances. */ - public Enumeration getFileDependencies() { + public Enumeration getFileDependencies() { if (!supportsFileDependencies()) { throw new RuntimeException("File dependencies are not supported " + "by this analyzer"); @@ -95,7 +95,7 @@ public abstract class AbstractAnalyzer implements DependencyAnalyzer { * @return an enumeration of Strings, each being the name of a Java * class in dot notation. */ - public Enumeration getClassDependencies() { + public Enumeration getClassDependencies() { if (!determined) { determineDependencies(fileDependencies, classDependencies); } @@ -201,8 +201,8 @@ public abstract class AbstractAnalyzer implements DependencyAnalyzer { public void reset() { rootClasses.removeAllElements(); determined = false; - fileDependencies = new Vector(); - classDependencies = new Vector(); + fileDependencies = new Vector(); + classDependencies = new Vector(); } /** @@ -211,7 +211,7 @@ public abstract class AbstractAnalyzer implements DependencyAnalyzer { * @return an enumeration of Strings, each of which is a class name * for a root class. */ - protected Enumeration getRootClasses() { + protected Enumeration getRootClasses() { return rootClasses.elements(); } @@ -233,7 +233,7 @@ public abstract class AbstractAnalyzer implements DependencyAnalyzer { * @param classes a vector of Strings into which the names of classes * upon which the root classes depend should be placed. */ - protected abstract void determineDependencies(Vector files, Vector classes); + protected abstract void determineDependencies(Vector files, Vector classes); /** * Indicate if the particular subclass supports file dependency diff --git a/src/main/org/apache/tools/ant/util/depend/DependencyAnalyzer.java b/src/main/org/apache/tools/ant/util/depend/DependencyAnalyzer.java index f2d1933b9..997ef9099 100644 --- a/src/main/org/apache/tools/ant/util/depend/DependencyAnalyzer.java +++ b/src/main/org/apache/tools/ant/util/depend/DependencyAnalyzer.java @@ -68,7 +68,7 @@ public interface DependencyAnalyzer { * * @return an enumeration of File instances. */ - Enumeration getFileDependencies(); + Enumeration getFileDependencies(); /** * Get the list of classes upon which root classes depend. This is a @@ -77,7 +77,7 @@ public interface DependencyAnalyzer { * @return an enumeration of Strings, each being the name of a Java * class in dot notation. */ - Enumeration getClassDependencies(); + Enumeration getClassDependencies(); /** diff --git a/src/main/org/apache/tools/ant/util/depend/bcel/AncestorAnalyzer.java b/src/main/org/apache/tools/ant/util/depend/bcel/AncestorAnalyzer.java index 664f3b0b7..2bd2a6cf6 100644 --- a/src/main/org/apache/tools/ant/util/depend/bcel/AncestorAnalyzer.java +++ b/src/main/org/apache/tools/ant/util/depend/bcel/AncestorAnalyzer.java @@ -61,15 +61,16 @@ public class AncestorAnalyzer extends AbstractAnalyzer { * @param classes a vector to be populated with the names of the * dependency classes. */ - protected void determineDependencies(Vector files, Vector classes) { + protected void determineDependencies(Vector files, Vector classes) { // we get the root classes and build up a set of // classes upon which they depend - Hashtable dependencies = new Hashtable(); - Hashtable containers = new Hashtable(); - Hashtable toAnalyze = new Hashtable(); - Hashtable nextAnalyze = new Hashtable(); - for (Enumeration e = getRootClasses(); e.hasMoreElements();) { - String classname = (String) e.nextElement(); + Hashtable dependencies = new Hashtable(); + Hashtable containers = new Hashtable(); + Hashtable toAnalyze = new Hashtable(); + Hashtable nextAnalyze = new Hashtable(); + + for (Enumeration e = getRootClasses(); e.hasMoreElements();) { + String classname = e.nextElement(); toAnalyze.put(classname, classname); } @@ -77,8 +78,7 @@ public class AncestorAnalyzer extends AbstractAnalyzer { int maxCount = isClosureRequired() ? MAX_LOOPS : 2; while (toAnalyze.size() != 0 && count++ < maxCount) { nextAnalyze.clear(); - for (Enumeration e = toAnalyze.keys(); e.hasMoreElements();) { - String classname = (String) e.nextElement(); + for (String classname : toAnalyze.keySet()) { dependencies.put(classname, classname); try { File container = getClassContainer(classname); @@ -115,19 +115,19 @@ public class AncestorAnalyzer extends AbstractAnalyzer { } } - Hashtable temp = toAnalyze; + Hashtable temp = toAnalyze; toAnalyze = nextAnalyze; nextAnalyze = temp; } files.removeAllElements(); - for (Enumeration e = containers.keys(); e.hasMoreElements();) { - files.addElement((File) e.nextElement()); + for (File f : containers.keySet()) { + files.add(f); } classes.removeAllElements(); - for (Enumeration e = dependencies.keys(); e.hasMoreElements();) { - classes.addElement((String) e.nextElement()); + for (String dependency : dependencies.keySet()) { + classes.add(dependency); } } diff --git a/src/main/org/apache/tools/ant/util/depend/bcel/DependencyVisitor.java b/src/main/org/apache/tools/ant/util/depend/bcel/DependencyVisitor.java index 5fd59a6ab..61dade918 100644 --- a/src/main/org/apache/tools/ant/util/depend/bcel/DependencyVisitor.java +++ b/src/main/org/apache/tools/ant/util/depend/bcel/DependencyVisitor.java @@ -33,8 +33,8 @@ import org.apache.bcel.classfile.ConstantNameAndType; * */ public class DependencyVisitor extends EmptyVisitor { - /** The collectd dependencies */ - private Hashtable dependencies = new Hashtable(); + /** The collected dependencies */ + private Hashtable dependencies = new Hashtable(); /** * The current class's constant pool - used to determine class names * from class references. @@ -47,7 +47,7 @@ public class DependencyVisitor extends EmptyVisitor { * @return a Enumeration of classnames, being the classes upon which the * visited classes depend. */ - public Enumeration getDependencies() { + public Enumeration getDependencies() { return dependencies.keys(); } diff --git a/src/main/org/apache/tools/ant/util/depend/bcel/FullAnalyzer.java b/src/main/org/apache/tools/ant/util/depend/bcel/FullAnalyzer.java index 5e964c842..f270fd48e 100644 --- a/src/main/org/apache/tools/ant/util/depend/bcel/FullAnalyzer.java +++ b/src/main/org/apache/tools/ant/util/depend/bcel/FullAnalyzer.java @@ -60,14 +60,14 @@ public class FullAnalyzer extends AbstractAnalyzer { * @param classes a vector to be populated with the names of the * dependency classes. */ - protected void determineDependencies(Vector files, Vector classes) { + protected void determineDependencies(Vector files, Vector classes) { // we get the root classes and build up a set of // classes upon which they depend - Hashtable dependencies = new Hashtable(); - Hashtable containers = new Hashtable(); - Hashtable toAnalyze = new Hashtable(); - for (Enumeration e = getRootClasses(); e.hasMoreElements();) { - String classname = (String) e.nextElement(); + Hashtable dependencies = new Hashtable(); + Hashtable containers = new Hashtable(); + Hashtable toAnalyze = new Hashtable(); + for (Enumeration e = getRootClasses(); e.hasMoreElements();) { + String classname = e.nextElement(); toAnalyze.put(classname, classname); } @@ -75,8 +75,7 @@ public class FullAnalyzer extends AbstractAnalyzer { int maxCount = isClosureRequired() ? MAX_LOOPS : 2; while (toAnalyze.size() != 0 && count++ < maxCount) { DependencyVisitor dependencyVisitor = new DependencyVisitor(); - for (Enumeration e = toAnalyze.keys(); e.hasMoreElements();) { - String classname = (String) e.nextElement(); + for (String classname : toAnalyze.keySet()) { dependencies.put(classname, classname); try { File container = getClassContainer(classname); @@ -105,9 +104,9 @@ public class FullAnalyzer extends AbstractAnalyzer { toAnalyze.clear(); // now recover all the dependencies collected and add to the list. - Enumeration depsEnum = dependencyVisitor.getDependencies(); + Enumeration depsEnum = dependencyVisitor.getDependencies(); while (depsEnum.hasMoreElements()) { - String className = (String) depsEnum.nextElement(); + String className = depsEnum.nextElement(); if (!dependencies.containsKey(className)) { toAnalyze.put(className, className); } @@ -115,13 +114,13 @@ public class FullAnalyzer extends AbstractAnalyzer { } files.removeAllElements(); - for (Enumeration e = containers.keys(); e.hasMoreElements();) { - files.addElement((File) e.nextElement()); + for (File f : containers.keySet()) { + files.add(f); } classes.removeAllElements(); - for (Enumeration e = dependencies.keys(); e.hasMoreElements();) { - classes.addElement((String) e.nextElement()); + for (String dependency : dependencies.keySet()) { + classes.add(dependency); } }