diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 27260b408..2a6a9fe5c 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -843,17 +843,19 @@ public class Main implements AntMain { project.init(); // resolve properties - PropertyHelper propertyHelper = (PropertyHelper) PropertyHelper - .getPropertyHelper(project); - HashMap props = new HashMap(definedProps); + PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(project); + @SuppressWarnings({ "rawtypes", "unchecked" }) + Map raw = new HashMap(definedProps); + @SuppressWarnings("unchecked") + Map props = raw; ResolvePropertyMap resolver = new ResolvePropertyMap(project, NOPROPERTIES, propertyHelper.getExpanders()); resolver.resolveAllProperties(props, null, false); // set user-define properties - for (Entry ent : props.entrySet()) { - String arg = (String) ent.getKey(); + for (Entry ent : props.entrySet()) { + String arg = ent.getKey(); Object value = ent.getValue(); project.setUserProperty(arg, String.valueOf(value)); } diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 78eeb760c..2c54d757c 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -2022,7 +2022,7 @@ public class Project implements ResourceFactory { * Must not be null. * * @return the reference with the specified ID, or null if - * there is no such reference in the project. + * there is no such reference in the project, with type inference. */ public T getReference(String key) { @SuppressWarnings("unchecked") diff --git a/src/main/org/apache/tools/ant/dispatch/DispatchUtils.java b/src/main/org/apache/tools/ant/dispatch/DispatchUtils.java index 5614be27d..be4b625b9 100644 --- a/src/main/org/apache/tools/ant/dispatch/DispatchUtils.java +++ b/src/main/org/apache/tools/ant/dispatch/DispatchUtils.java @@ -58,7 +58,7 @@ public class DispatchUtils { if (name.length() > 1) { mName += name.substring(1); } - final Class c = dispatchable.getClass(); + final Class c = dispatchable.getClass(); final Method actionM = c.getMethod(mName, new Class[0]); if (actionM != null) { final Object o = actionM.invoke(dispatchable, (Object[]) null); diff --git a/src/main/org/apache/tools/ant/filters/ClassConstants.java b/src/main/org/apache/tools/ant/filters/ClassConstants.java index 01085d9b4..0e92f4836 100644 --- a/src/main/org/apache/tools/ant/filters/ClassConstants.java +++ b/src/main/org/apache/tools/ant/filters/ClassConstants.java @@ -106,10 +106,10 @@ public final class ClassConstants } else { final byte[] bytes = clazz.getBytes(ResourceUtils.ISO_8859_1); try { - final Class javaClassHelper = + final Class javaClassHelper = Class.forName(JAVA_CLASS_HELPER); if (javaClassHelper != null) { - final Class[] params = { + final Class[] params = { byte[].class }; final Method getConstants = diff --git a/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java b/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java index 11583d7d2..182e76c92 100644 --- a/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java +++ b/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java @@ -435,10 +435,6 @@ public final class FixCrLfFilter extends BaseParamFilterReader implements Chaina push(cs, 0, cs.length); } - public void push(String s) { - push(s.toCharArray()); - } - /** * Does this filter want to block edits on the last character returned * by read()? diff --git a/src/main/org/apache/tools/ant/filters/LineContains.java b/src/main/org/apache/tools/ant/filters/LineContains.java index fdfc03d6b..453667bc2 100644 --- a/src/main/org/apache/tools/ant/filters/LineContains.java +++ b/src/main/org/apache/tools/ant/filters/LineContains.java @@ -55,7 +55,7 @@ public final class LineContains private static final String NEGATE_KEY = "negate"; /** Vector that holds the strings that input lines must contain. */ - private Vector contains = new Vector(); + private Vector contains = new Vector(); /** * Remaining line to be read from this filter, or null if @@ -163,7 +163,7 @@ public final class LineContains * @param contains A vector of words which must be contained within a line * in order for it to match in this filter. Must not be null. */ - private void setContains(final Vector contains) { + private void setContains(final Vector contains) { this.contains = contains; } @@ -176,7 +176,7 @@ public final class LineContains * returned object is "live" - in other words, changes made to the * returned object are mirrored in the filter. */ - private Vector getContains() { + private Vector getContains() { return contains; } diff --git a/src/main/org/apache/tools/ant/filters/LineContainsRegExp.java b/src/main/org/apache/tools/ant/filters/LineContainsRegExp.java index be5f2bc19..a597d0b23 100644 --- a/src/main/org/apache/tools/ant/filters/LineContainsRegExp.java +++ b/src/main/org/apache/tools/ant/filters/LineContainsRegExp.java @@ -57,7 +57,7 @@ public final class LineContainsRegExp private static final String CS_KEY = "casesensitive"; /** Vector that holds the expressions that input lines must contain. */ - private Vector regexps = new Vector(); + private Vector regexps = new Vector(); /** * Remaining line to be read from this filter, or null if @@ -155,7 +155,7 @@ public final class LineContainsRegExp * within a line in order for it to match in this filter. Must not be * null. */ - private void setRegexps(final Vector regexps) { + private void setRegexps(final Vector regexps) { this.regexps = regexps; } @@ -169,7 +169,7 @@ public final class LineContainsRegExp * filter. The returned object is "live" - in other words, changes made to * the returned object are mirrored in the filter. */ - private Vector getRegexps() { + private Vector getRegexps() { return regexps; } diff --git a/src/main/org/apache/tools/ant/filters/ReplaceTokens.java b/src/main/org/apache/tools/ant/filters/ReplaceTokens.java index b11edeb9c..c414dcacb 100644 --- a/src/main/org/apache/tools/ant/filters/ReplaceTokens.java +++ b/src/main/org/apache/tools/ant/filters/ReplaceTokens.java @@ -70,7 +70,7 @@ public final class ReplaceTokens private int queueIndex = -1; /** Hashtable to hold the replacee-replacer pairs (String to String). */ - private Hashtable hash = new Hashtable(); + private Hashtable hash = new Hashtable(); /** Character marking the beginning of a token. */ private char beginToken = DEFAULT_BEGIN_TOKEN; @@ -266,7 +266,7 @@ public final class ReplaceTokens * @param hash A map (String->String) of token keys to replacement * values. Must not be null. */ - private void setTokens(final Hashtable hash) { + private void setTokens(final Hashtable hash) { this.hash = hash; } @@ -276,7 +276,7 @@ public final class ReplaceTokens * @return a map (String->String) of token keys to replacement * values */ - private Hashtable getTokens() { + private Hashtable getTokens() { return hash; } @@ -339,7 +339,7 @@ public final class ReplaceTokens private void makeTokensFromProperties(Resource r) { Properties props = getProperties(r); - for (Enumeration e = props.keys(); e.hasMoreElements();) { + for (Enumeration e = props.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); String value = props.getProperty(key); hash.put(key, value); diff --git a/src/main/org/apache/tools/ant/filters/SortFilter.java b/src/main/org/apache/tools/ant/filters/SortFilter.java index 7c5099190..62bf3c6c8 100644 --- a/src/main/org/apache/tools/ant/filters/SortFilter.java +++ b/src/main/org/apache/tools/ant/filters/SortFilter.java @@ -32,11 +32,11 @@ import org.apache.tools.ant.types.Parameter; *

* Sort a file before and/or after the file. *

- * + * *

* Examples: *

- * + * *
  *   <copy todir="build">
  *       <fileset dir="input" includes="*.txt"/>
@@ -45,14 +45,14 @@ import org.apache.tools.ant.types.Parameter;
  *       </filterchain>
  *   </copy>
  * 
- * + * *

* Sort all files *.txt from src location and copy * them into build location. The lines of each file are sorted * in ascendant order comparing the lines via the * String.compareTo(Object o) method. *

- * + * *
  *   <copy todir="build">
  *       <fileset dir="input" includes="*.txt"/>
@@ -61,14 +61,14 @@ import org.apache.tools.ant.types.Parameter;
  *       </filterchain>
  *   </copy>
  * 
- * + * *

* Sort all files *.txt from src location into reverse * order and copy them into build location. If reverse parameter has * value true (default value), then the output line of the files * will be in ascendant order. *

- * + * *
  *   <copy todir="build">
  *       <fileset dir="input" includes="*.txt"/>
@@ -79,7 +79,7 @@ import org.apache.tools.ant.types.Parameter;
  *       </filterchain>
  *   </copy>
  * 
- * + * *

* Sort all files *.txt from src location using as * sorting criterium EvenFirstCmp class, that sorts the file @@ -89,7 +89,7 @@ import org.apache.tools.ant.types.Parameter; * therefore in case of inner class has to be static. It also has to * implement java.util.Comparator interface, for example: *

- * + * *
  *         package org.apache.tools.ant.filters;
  *         ...(omitted)
@@ -99,9 +99,9 @@ import org.apache.tools.ant.types.Parameter;
  *             }
  *           }
  * 
- * + * *

The example above is equivalent to:

- * + * *
  *   <componentdef name="evenfirst"
  *                 classname="org.apache.tools.ant.filters.EvenFirstCmp"/>
@@ -114,10 +114,10 @@ import org.apache.tools.ant.types.Parameter;
  *       </filterchain>
  *   </copy>
  * 
- * + * *

If parameter comparator is present, then * reverse parameter will not be taken into account.

- * + * * @since Ant 1.8.0 */ public final class SortFilter extends BaseParamFilterReader @@ -135,7 +135,7 @@ public final class SortFilter extends BaseParamFilterReader /** * Instance of comparator class to be used for sorting. */ - private Comparator comparator = null; + private Comparator comparator = null; /** * Controls if the sorting process will be in ascendant/descendant order. If @@ -148,7 +148,7 @@ public final class SortFilter extends BaseParamFilterReader /** * Stores the lines to be sorted. */ - private List lines; + private List lines; /** * Remaining line to be read from this filter, or null if the @@ -157,11 +157,11 @@ public final class SortFilter extends BaseParamFilterReader */ private String line = null; - private Iterator iterator = null; + private Iterator iterator = null; /** * Constructor for "dummy" instances. - * + * * @see BaseFilterReader#BaseFilterReader() */ public SortFilter() { @@ -170,7 +170,7 @@ public final class SortFilter extends BaseParamFilterReader /** * Creates a new filtered reader. - * + * * @param in * A Reader object providing the underlying stream. Must not be * null. @@ -184,10 +184,10 @@ public final class SortFilter extends BaseParamFilterReader * of lines have already been read, the resulting stream is effectively at * an end. Otherwise, the next character from the underlying stream is read * and returned. - * + * * @return the next character in the resulting stream, or -1 if the end of * the resulting stream has been reached - * + * * @exception IOException * if the underlying stream throws an IOException during * reading @@ -213,7 +213,7 @@ public final class SortFilter extends BaseParamFilterReader } else { if (lines == null) { // We read all lines and sort them - lines = new ArrayList(); + lines = new ArrayList(); for (line = readLine(); line != null; line = readLine()) { lines.add(line); } @@ -237,11 +237,11 @@ public final class SortFilter extends BaseParamFilterReader /** * Creates a new SortReader using the passed in Reader for instantiation. - * + * * @param rdr * A Reader object providing the underlying stream. Must not be * null. - * + * * @return a new filter based on this configuration, but filtering the * specified reader */ @@ -256,7 +256,7 @@ public final class SortFilter extends BaseParamFilterReader /** * Returns true if the sorting process will be in reverse * order, otherwise the sorting process will be in ascendant order. - * + * * @return true if the sorting process will be in reverse * order, otherwise the sorting process will be in ascendant order. */ @@ -267,7 +267,7 @@ public final class SortFilter extends BaseParamFilterReader /** * Sets the sorting process will be in ascendant (reverse=false) * or to descendant (reverse=true). - * + * * @param reverse * Boolean representing reverse ordering process. */ @@ -277,30 +277,30 @@ public final class SortFilter extends BaseParamFilterReader /** * Returns the comparator to be used for sorting. - * + * * @return the comparator */ - public Comparator getComparator() { + public Comparator getComparator() { return comparator; } /** * Set the comparator to be used as sorting criterium. - * + * * @param comparator * the comparator to set */ - public void setComparator(Comparator comparator) { + public void setComparator(Comparator comparator) { this.comparator = comparator; } /** - * Set the comparator to be used as sorting criterium as nested element. - * + * Set the comparator to be used as sorting criterion as nested element. + * * @param comparator * the comparator to set */ - public void add(Comparator comparator) { + public void add(Comparator comparator) { if (this.comparator != null && comparator != null) { throw new BuildException("can't have more than one comparator"); } @@ -324,8 +324,10 @@ public final class SortFilter extends BaseParamFilterReader if (COMPARATOR_KEY.equals(paramName)) { try { String className = (String) params[i].getValue(); - setComparator((Comparator) (Class.forName(className) - .newInstance())); + @SuppressWarnings("unchecked") + final Comparator comparatorInstance = (Comparator) (Class + .forName(className).newInstance()); + setComparator(comparatorInstance); continue; } catch (InstantiationException e) { throw new BuildException(e); @@ -353,15 +355,13 @@ public final class SortFilter extends BaseParamFilterReader /** * Sorts the read lines (lines)acording to the sorting * criteria defined by the user. - * + * */ private void sort() { if (comparator == null) { if (reverse) { - Collections.sort(lines, new Comparator() { - public int compare(Object o1, Object o2) { - String s1 = (String) o1; - String s2 = (String) o2; + Collections.sort(lines, new Comparator() { + public int compare(String s1, String s2) { return (-s1.compareTo(s2)); } }); diff --git a/src/main/org/apache/tools/ant/filters/StripLineComments.java b/src/main/org/apache/tools/ant/filters/StripLineComments.java index 54888496d..f2a2f6e02 100644 --- a/src/main/org/apache/tools/ant/filters/StripLineComments.java +++ b/src/main/org/apache/tools/ant/filters/StripLineComments.java @@ -54,7 +54,7 @@ public final class StripLineComments private static final String COMMENTS_KEY = "comment"; /** Vector that holds the comment prefixes. */ - private Vector comments = new Vector(); + private Vector comments = new Vector(); /** The line that has been read ahead. */ private String line = null; @@ -110,7 +110,7 @@ public final class StripLineComments while (line != null) { for (int i = 0; i < commentsSize; i++) { - String comment = (String) comments.elementAt(i); + String comment = comments.elementAt(i); if (line.startsWith(comment)) { line = null; break; @@ -149,7 +149,7 @@ public final class StripLineComments * @param comments A list of strings, each of which is a prefix * for a comment line. Must not be null. */ - private void setComments(final Vector comments) { + private void setComments(final Vector comments) { this.comments = comments; } @@ -158,7 +158,7 @@ public final class StripLineComments * * @return the list of comment prefixes to strip. */ - private Vector getComments() { + private Vector getComments() { return comments; } diff --git a/src/main/org/apache/tools/ant/filters/TailFilter.java b/src/main/org/apache/tools/ant/filters/TailFilter.java index 09281f336..0134f976d 100644 --- a/src/main/org/apache/tools/ant/filters/TailFilter.java +++ b/src/main/org/apache/tools/ant/filters/TailFilter.java @@ -65,7 +65,7 @@ public final class TailFilter extends BaseParamFilterReader /** the position in the current line */ private int linePos = 0; - private LinkedList lineList = new LinkedList(); + private LinkedList lineList = new LinkedList(); /** * Constructor for "dummy" instances. @@ -212,7 +212,7 @@ public final class TailFilter extends BaseParamFilterReader lineList.add(line); if (lines == -1) { if (lineList.size() > skip) { - return (String) lineList.removeFirst(); + return lineList.removeFirst(); } } else { long linesToKeep = lines + (skip > 0 ? skip : 0); @@ -235,7 +235,7 @@ public final class TailFilter extends BaseParamFilterReader } } if (lineList.size() > 0) { - return (String) lineList.removeFirst(); + return lineList.removeFirst(); } return null; } diff --git a/src/main/org/apache/tools/ant/filters/TokenFilter.java b/src/main/org/apache/tools/ant/filters/TokenFilter.java index 3cf53a67a..c90cce595 100644 --- a/src/main/org/apache/tools/ant/filters/TokenFilter.java +++ b/src/main/org/apache/tools/ant/filters/TokenFilter.java @@ -58,7 +58,7 @@ public class TokenFilter extends BaseFilterReader /** string filters */ - private Vector filters = new Vector(); + private Vector filters = new Vector(); /** the tokenizer to use on the input stream */ private Tokenizer tokenizer = null; /** the output token termination */ @@ -109,8 +109,8 @@ public class TokenFilter extends BaseFilterReader if (line == null) { return -1; } - for (Enumeration e = filters.elements(); e.hasMoreElements();) { - Filter filter = (Filter) e.nextElement(); + for (Enumeration e = filters.elements(); e.hasMoreElements();) { + Filter filter = e.nextElement(); line = filter.filter(line); if (line == null) { break; diff --git a/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java b/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java index 22b3480a4..199003168 100644 --- a/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java +++ b/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java @@ -60,7 +60,7 @@ public final class ChainReaderHelper { /** * Chain of filters */ - public Vector filterChains = new Vector(); + public Vector filterChains = new Vector(); /** The Ant project */ private Project project = null; @@ -106,7 +106,7 @@ public final class ChainReaderHelper { * * @param fchain the filter chains collection */ - public void setFilterChains(Vector fchain) { + public void setFilterChains(Vector fchain) { filterChains = fchain; } @@ -122,14 +122,14 @@ public final class ChainReaderHelper { Reader instream = primaryReader; final int filterReadersCount = filterChains.size(); - final Vector finalFilters = new Vector(); - final ArrayList/**/ classLoadersToCleanUp = - new ArrayList/**/(); + final Vector finalFilters = new Vector(); + final ArrayList classLoadersToCleanUp = + new ArrayList(); for (int i = 0; i < filterReadersCount; i++) { final FilterChain filterchain = - (FilterChain) filterChains.elementAt(i); - final Vector filterReaders = filterchain.getFilterReaders(); + filterChains.elementAt(i); + final Vector filterReaders = filterchain.getFilterReaders(); final int readerCount = filterReaders.size(); for (int j = 0; j < readerCount; j++) { finalFilters.addElement(filterReaders.elementAt(j)); @@ -197,9 +197,9 @@ public final class ChainReaderHelper { /** * Deregisters Classloaders from the project so GC can remove them later. */ - private static void cleanUpClassLoaders(List/**/ loaders) { - for (Iterator it = loaders.iterator(); it.hasNext(); ) { - ((AntClassLoader) it.next()).cleanup(); + private static void cleanUpClassLoaders(List loaders) { + for (Iterator it = loaders.iterator(); it.hasNext(); ) { + it.next().cleanup(); } } @@ -223,13 +223,13 @@ public final class ChainReaderHelper { */ private Reader expandReader(final AntFilterReader filter, final Reader ancestor, - final List/**/ classLoadersToCleanUp) { + final List classLoadersToCleanUp) { final String className = filter.getClassName(); final Path classpath = filter.getClasspath(); final Project pro = filter.getProject(); if (className != null) { try { - Class clazz = null; + Class clazz = null; if (classpath == null) { clazz = Class.forName(className); } else { @@ -242,11 +242,11 @@ public final class ChainReaderHelper { throw new BuildException(className + " does not extend" + " java.io.FilterReader"); } - final Constructor[] constructors = clazz.getConstructors(); + final Constructor[] constructors = clazz.getConstructors(); int j = 0; boolean consPresent = false; for (; j < constructors.length; j++) { - Class[] types = constructors[j].getParameterTypes(); + Class[] types = constructors[j].getParameterTypes(); if (types.length == 1 && types[0].isAssignableFrom(Reader.class)) { consPresent = true; diff --git a/src/main/org/apache/tools/ant/helper/AntXMLContext.java b/src/main/org/apache/tools/ant/helper/AntXMLContext.java index 496303922..a8c373224 100644 --- a/src/main/org/apache/tools/ant/helper/AntXMLContext.java +++ b/src/main/org/apache/tools/ant/helper/AntXMLContext.java @@ -54,7 +54,7 @@ public class AntXMLContext { * defined. Project maintains a Hashtable, which is not ordered. * This will allow description to know the original order. */ - private Vector targetVector = new Vector(); + private Vector targetVector = new Vector(); /** * Parent directory of the build file. Used for resolving entities @@ -92,7 +92,7 @@ public class AntXMLContext { /** The stack of RuntimeConfigurable2 wrapping the objects. */ - private Vector wStack = new Vector(); + private Vector wStack = new Vector(); /** * Indicates whether the project tag attributes are to be ignored @@ -101,11 +101,11 @@ public class AntXMLContext { private boolean ignoreProjectTag = false; /** Keeps track of prefix -> uri mapping during parsing */ - private Map prefixMapping = new HashMap(); + private Map> prefixMapping = new HashMap>(); /** Keeps track of targets in files */ - private Map currentTargets = null; + private Map currentTargets = null; /** * constructor @@ -253,7 +253,7 @@ public class AntXMLContext { * access the stack of wrappers * @return the stack of wrappers */ - public Vector getWrapperStack() { + public Vector getWrapperStack() { return wStack; } @@ -302,7 +302,7 @@ public class AntXMLContext { * access the vector of targets * @return vector of targets */ - public Vector getTargets() { + public Vector getTargets() { return targetVector; } @@ -362,9 +362,9 @@ public class AntXMLContext { * @param uri a namespace uri */ public void startPrefixMapping(String prefix, String uri) { - List list = (List) prefixMapping.get(prefix); + List list = prefixMapping.get(prefix); if (list == null) { - list = new ArrayList(); + list = new ArrayList(); prefixMapping.put(prefix, list); } list.add(uri); @@ -376,7 +376,7 @@ public class AntXMLContext { * @param prefix the namespace prefix */ public void endPrefixMapping(String prefix) { - List list = (List) prefixMapping.get(prefix); + List list = prefixMapping.get(prefix); if (list == null || list.size() == 0) { return; // Should not happen } @@ -390,7 +390,7 @@ public class AntXMLContext { * @return the uri for this prefix, null if not present */ public String getPrefixMapping(String prefix) { - List list = (List) prefixMapping.get(prefix); + List list = prefixMapping.get(prefix); if (list == null || list.size() == 0) { return null; } @@ -401,7 +401,7 @@ public class AntXMLContext { * Get the targets in the current source file. * @return the current targets. */ - public Map getCurrentTargets() { + public Map getCurrentTargets() { return currentTargets; } @@ -409,7 +409,7 @@ public class AntXMLContext { * Set the map of the targets in the current source file. * @param currentTargets a map of targets. */ - public void setCurrentTargets(Map currentTargets) { + public void setCurrentTargets(Map currentTargets) { this.currentTargets = currentTargets; } diff --git a/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java b/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java index 7ab8727aa..da85dba75 100644 --- a/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java +++ b/src/main/org/apache/tools/ant/helper/IgnoreDependenciesExecutor.java @@ -40,11 +40,11 @@ public class IgnoreDependenciesExecutor implements Executor { /** {@inheritDoc}. */ public void executeTargets(Project project, String[] targetNames) throws BuildException { - Hashtable targets = project.getTargets(); + Hashtable targets = project.getTargets(); BuildException thrownException = null; for (int i = 0; i < targetNames.length; i++) { try { - Target t = (Target) targets.get(targetNames[i]); + Target t = targets.get(targetNames[i]); if (t == null) { throw new BuildException("Unknown target " + targetNames[i]); } diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java index 07d3e1679..517f1ca5b 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java @@ -50,7 +50,6 @@ import java.io.UnsupportedEncodingException; import java.net.URL; import java.util.HashMap; import java.util.Hashtable; -import java.util.Iterator; import java.util.Map; import java.util.Stack; @@ -157,13 +156,13 @@ public class ProjectHelper2 extends ProjectHelper { context.setIgnoreProjectTag(true); Target currentTarget = context.getCurrentTarget(); Target currentImplicit = context.getImplicitTarget(); - Map currentTargets = context.getCurrentTargets(); + Map currentTargets = context.getCurrentTargets(); try { Target newCurrent = new Target(); newCurrent.setProject(project); newCurrent.setName(""); context.setCurrentTarget(newCurrent); - context.setCurrentTargets(new HashMap()); + context.setCurrentTargets(new HashMap()); context.setImplicitTarget(newCurrent); parse(project, source, new RootHandler(context, mainHandler)); newCurrent.execute(); @@ -174,7 +173,7 @@ public class ProjectHelper2 extends ProjectHelper { } } else { // top level file - context.setCurrentTargets(new HashMap()); + context.setCurrentTargets(new HashMap()); parse(project, source, new RootHandler(context, mainHandler)); // Execute the top-level target context.getImplicitTarget().execute(); @@ -485,7 +484,7 @@ public class ProjectHelper2 extends ProjectHelper { * with the implicit execution stack ) */ public static class RootHandler extends DefaultHandler { - private Stack antHandlers = new Stack(); + private Stack antHandlers = new Stack(); private AntHandler currentHandler = null; private AntXMLContext context; @@ -962,7 +961,7 @@ public class ProjectHelper2 extends ProjectHelper { throw new BuildException("Duplicate target '" + name + "'", target.getLocation()); } - Hashtable projectTargets = project.getTargets(); + Hashtable projectTargets = project.getTargets(); boolean usedTarget = false; // If the name has not already been defined define it if (projectTargets.containsKey(name)) { @@ -979,12 +978,9 @@ public class ProjectHelper2 extends ProjectHelper { if (!isInIncludeMode) { target.setDepends(depends); } else { - for (Iterator iter = - Target.parseDepends(depends, name, "depends") - .iterator(); - iter.hasNext(); ) { - target.addDependency(prefix + sep + iter.next()); - } + for (String string : Target.parseDepends(depends, name, "depends")) { + target.addDependency(prefix + sep + string); + } } } if (!isInIncludeMode && context.isIgnoringProjectTag() @@ -1003,7 +999,7 @@ public class ProjectHelper2 extends ProjectHelper { } if (extensionPointMissing != null && extensionPoint == null) { throw new BuildException("onMissingExtensionPoint attribute cannot " + - "be specified unless extensionOf is specified", + "be specified unless extensionOf is specified", target.getLocation()); } diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java index 9f122b934..c1d418572 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java @@ -855,7 +855,7 @@ public class ProjectHelperImpl extends ProjectHelper { * BuildException being thrown during configuration. */ public void init(String propType, AttributeList attrs) throws SAXParseException { - Class parentClass = parent.getClass(); + Class parentClass = parent.getClass(); IntrospectionHelper ih = IntrospectionHelper.getHelper(helperImpl.project, parentClass); try { diff --git a/src/main/org/apache/tools/ant/input/DefaultInputHandler.java b/src/main/org/apache/tools/ant/input/DefaultInputHandler.java index 2212c3673..efbee84d6 100644 --- a/src/main/org/apache/tools/ant/input/DefaultInputHandler.java +++ b/src/main/org/apache/tools/ant/input/DefaultInputHandler.java @@ -22,7 +22,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.Enumeration; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.util.KeepAliveInputStream; @@ -86,16 +85,12 @@ public class DefaultInputHandler implements InputHandler { String prompt = request.getPrompt(); String def = request.getDefaultValue(); if (request instanceof MultipleChoiceInputRequest) { - StringBuffer sb = new StringBuffer(prompt); - sb.append(" ("); - Enumeration e = - ((MultipleChoiceInputRequest) request).getChoices().elements(); + StringBuilder sb = new StringBuilder(prompt).append(" ("); boolean first = true; - while (e.hasMoreElements()) { + for (String next : ((MultipleChoiceInputRequest) request).getChoices()) { if (!first) { sb.append(", "); } - String next = (String) e.nextElement(); if (next.equals(def)) { sb.append('['); } diff --git a/src/main/org/apache/tools/ant/input/MultipleChoiceInputRequest.java b/src/main/org/apache/tools/ant/input/MultipleChoiceInputRequest.java index 94b8532ce..4baab8f54 100644 --- a/src/main/org/apache/tools/ant/input/MultipleChoiceInputRequest.java +++ b/src/main/org/apache/tools/ant/input/MultipleChoiceInputRequest.java @@ -27,26 +27,26 @@ import java.util.Vector; * @since Ant 1.5 */ public class MultipleChoiceInputRequest extends InputRequest { - private final LinkedHashSet choices; + private final LinkedHashSet choices; /** * @param prompt The prompt to show to the user. Must not be null. * @param choices holds all input values that are allowed. * Must not be null. */ - public MultipleChoiceInputRequest(String prompt, Vector choices) { + public MultipleChoiceInputRequest(String prompt, Vector choices) { super(prompt); if (choices == null) { throw new IllegalArgumentException("choices must not be null"); } - this.choices = new LinkedHashSet(choices); + this.choices = new LinkedHashSet(choices); } /** * @return The possible values. */ - public Vector getChoices() { - return new Vector(choices); + public Vector getChoices() { + return new Vector(choices); } /** diff --git a/src/main/org/apache/tools/ant/input/SecureInputHandler.java b/src/main/org/apache/tools/ant/input/SecureInputHandler.java index 30a1bc5b3..51f8b95ef 100644 --- a/src/main/org/apache/tools/ant/input/SecureInputHandler.java +++ b/src/main/org/apache/tools/ant/input/SecureInputHandler.java @@ -42,8 +42,7 @@ public class SecureInputHandler extends DefaultInputHandler { public void handleInput(InputRequest request) throws BuildException { String prompt = getPrompt(request); try { - Class system = Class.forName("java.lang.System"); - Object console = ReflectUtil.invokeStatic(system, "console"); + Object console = ReflectUtil.invokeStatic(System.class, "console"); do { char[] input = (char[]) ReflectUtil.invoke( console, "readPassword", String.class, prompt, diff --git a/src/main/org/apache/tools/ant/launch/LaunchException.java b/src/main/org/apache/tools/ant/launch/LaunchException.java index 41b0fc5f6..1bb37f8f1 100644 --- a/src/main/org/apache/tools/ant/launch/LaunchException.java +++ b/src/main/org/apache/tools/ant/launch/LaunchException.java @@ -23,6 +23,7 @@ package org.apache.tools.ant.launch; * @since Ant 1.6 */ public class LaunchException extends Exception { + private static final long serialVersionUID = 1L; /** * Constructs an exception with the given descriptive message. diff --git a/src/main/org/apache/tools/ant/launch/Launcher.java b/src/main/org/apache/tools/ant/launch/Launcher.java index 82bf7a118..e86614edd 100644 --- a/src/main/org/apache/tools/ant/launch/Launcher.java +++ b/src/main/org/apache/tools/ant/launch/Launcher.java @@ -24,7 +24,6 @@ import java.io.File; import java.util.StringTokenizer; import java.util.List; import java.util.ArrayList; -import java.util.Iterator; @@ -133,7 +132,7 @@ public class Launcher { * @param libPathURLs the list of paths to add to * @throws MalformedURLException if we can't create a URL */ - private void addPath(String path, boolean getJars, List libPathURLs) + private void addPath(String path, boolean getJars, List libPathURLs) throws MalformedURLException { StringTokenizer tokenizer = new StringTokenizer(path, File.pathSeparator); while (tokenizer.hasMoreElements()) { @@ -190,9 +189,9 @@ public class Launcher { + "ant could not be located (estimated value="+antHome.getAbsolutePath()+")"); } - List libPaths = new ArrayList(); + List libPaths = new ArrayList(); String cpString = null; - List argList = new ArrayList(); + List argList = new ArrayList(); String[] newArgs; boolean noUserLib = false; boolean noClassPath = false; @@ -271,7 +270,7 @@ public class Launcher { URLClassLoader loader = new URLClassLoader(jars, Launcher.class.getClassLoader()); Thread.currentThread().setContextClassLoader(loader); - Class mainClass = null; + Class mainClass = null; int exitCode = 0; Throwable thrown=null; try { @@ -311,20 +310,19 @@ public class Launcher { * @return an array of URLs. * @throws MalformedURLException if the URLs cannot be created. */ - private URL[] getLibPathURLs(String cpString, List libPaths) + private URL[] getLibPathURLs(String cpString, List libPaths) throws MalformedURLException { - List libPathURLs = new ArrayList(); + List libPathURLs = new ArrayList(); if (cpString != null) { addPath(cpString, false, libPathURLs); } - for (Iterator i = libPaths.iterator(); i.hasNext();) { - String libPath = (String) i.next(); + for (String libPath : libPaths) { addPath(libPath, true, libPathURLs); } - return (URL[]) libPathURLs.toArray(new URL[libPathURLs.size()]); + return libPathURLs.toArray(new URL[libPathURLs.size()]); } /** diff --git a/src/main/org/apache/tools/ant/launch/Locator.java b/src/main/org/apache/tools/ant/launch/Locator.java index 62a9b7692..57d5fccf9 100644 --- a/src/main/org/apache/tools/ant/launch/Locator.java +++ b/src/main/org/apache/tools/ant/launch/Locator.java @@ -113,7 +113,7 @@ public final class Locator { * * @since Ant 1.6 */ - public static File getClassSource(Class c) { + public static File getClassSource(Class c) { String classResource = c.getName().replace('.', '/') + ".class"; return getResourceSource(c.getClassLoader(), classResource); } diff --git a/src/main/org/apache/tools/ant/listener/MailLogger.java b/src/main/org/apache/tools/ant/listener/MailLogger.java index 1be1a2288..653470808 100644 --- a/src/main/org/apache/tools/ant/listener/MailLogger.java +++ b/src/main/org/apache/tools/ant/listener/MailLogger.java @@ -17,6 +17,7 @@ */ package org.apache.tools.ant.listener; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -32,6 +33,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.email.EmailAddress; +import org.apache.tools.ant.taskdefs.email.Header; import org.apache.tools.ant.taskdefs.email.Message; import org.apache.tools.ant.taskdefs.email.Mailer; import org.apache.tools.ant.util.ClasspathUtils; @@ -100,7 +102,7 @@ public class MailLogger extends DefaultLogger { super.buildFinished(event); Project project = event.getProject(); - Hashtable properties = project.getProperties(); + Hashtable properties = project.getProperties(); // overlay specified properties file (if any), which overrides project // settings @@ -118,7 +120,7 @@ public class MailLogger extends DefaultLogger { } } - for (Enumeration e = fileProperties.keys(); e.hasMoreElements();) { + for (Enumeration e = fileProperties.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); String value = fileProperties.getProperty(key); properties.put(key, project.replaceProperties(value)); @@ -298,7 +300,7 @@ public class MailLogger extends DefaultLogger { * @exception Exception thrown if no default value is specified and the * property is not present in properties. */ - private String getValue(Hashtable properties, String name, + private String getValue(Hashtable properties, String name, String defaultValue) throws Exception { String propertyName = "MailLogger." + name; String value = (String) properties.get(propertyName); @@ -371,7 +373,7 @@ public class MailLogger extends DefaultLogger { return; } // convert the replyTo string into a vector of emailaddresses - Vector replyToList = vectorizeEmailAddresses(values.replytoList()); + Vector replyToList = vectorizeEmailAddresses(values.replytoList()); mailer.setHost(values.mailhost()); mailer.setPort(values.port()); mailer.setUser(values.user()); @@ -388,17 +390,17 @@ public class MailLogger extends DefaultLogger { mailer.setMessage(mymessage); mailer.setFrom(new EmailAddress(values.from())); mailer.setReplyToList(replyToList); - Vector toList = vectorizeEmailAddresses(values.toList()); + Vector toList = vectorizeEmailAddresses(values.toList()); mailer.setToList(toList); - mailer.setCcList(new Vector()); - mailer.setBccList(new Vector()); - mailer.setFiles(new Vector()); + mailer.setCcList(new Vector()); + mailer.setBccList(new Vector()); + mailer.setFiles(new Vector()); mailer.setSubject(values.subject()); - mailer.setHeaders(new Vector()); + mailer.setHeaders(new Vector
()); mailer.send(); } - private Vector vectorizeEmailAddresses(String listString) { - Vector emailList = new Vector(); + private Vector vectorizeEmailAddresses(String listString) { + Vector emailList = new Vector(); StringTokenizer tokens = new StringTokenizer(listString, ","); while (tokens.hasMoreTokens()) { emailList.addElement(new EmailAddress(tokens.nextToken())); diff --git a/src/main/org/apache/tools/ant/listener/ProfileLogger.java b/src/main/org/apache/tools/ant/listener/ProfileLogger.java index 43a3db914..86cc8604d 100644 --- a/src/main/org/apache/tools/ant/listener/ProfileLogger.java +++ b/src/main/org/apache/tools/ant/listener/ProfileLogger.java @@ -32,7 +32,7 @@ import org.apache.tools.ant.util.StringUtils; */ public class ProfileLogger extends DefaultLogger { - private Map profileData = new HashMap(); // + private Map profileData = new HashMap(); /** * Logs a message to say that the target has started. diff --git a/src/main/org/apache/tools/ant/loader/AntClassLoader5.java b/src/main/org/apache/tools/ant/loader/AntClassLoader5.java index a7f8b42b1..f41cef398 100644 --- a/src/main/org/apache/tools/ant/loader/AntClassLoader5.java +++ b/src/main/org/apache/tools/ant/loader/AntClassLoader5.java @@ -21,6 +21,8 @@ package org.apache.tools.ant.loader; import java.util.Enumeration; import java.io.Closeable; import java.io.IOException; +import java.net.URL; + import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Path; @@ -52,7 +54,7 @@ public class AntClassLoader5 extends AntClassLoader implements Closeable { } /** {@inheritDoc} */ - public Enumeration getResources(String name) throws IOException { + public Enumeration getResources(String name) throws IOException { return getNamedResources(name); } diff --git a/src/main/org/apache/tools/ant/property/ParseProperties.java b/src/main/org/apache/tools/ant/property/ParseProperties.java index 45399000f..a1f6f3cc1 100644 --- a/src/main/org/apache/tools/ant/property/ParseProperties.java +++ b/src/main/org/apache/tools/ant/property/ParseProperties.java @@ -19,7 +19,6 @@ package org.apache.tools.ant.property; import java.text.ParsePosition; import java.util.Collection; -import java.util.Iterator; import org.apache.tools.ant.Project; /** @@ -31,7 +30,7 @@ public class ParseProperties implements ParseNextProperty { private final Project project; private final GetProperty getProperty; - private final Collection expanders; + private final Collection expanders; /** * Constructor with a getProperty. @@ -39,7 +38,7 @@ public class ParseProperties implements ParseNextProperty { * @param expanders a sequence of expanders * @param getProperty property resolver. */ - public ParseProperties(Project project, Collection expanders, GetProperty getProperty) { + public ParseProperties(Project project, Collection expanders, GetProperty getProperty) { this.project = project; this.expanders = expanders; this.getProperty = getProperty; @@ -183,9 +182,8 @@ public class ParseProperties implements ParseNextProperty { } private String parsePropertyName(String value, ParsePosition pos) { - for (Iterator iter = expanders.iterator(); iter.hasNext();) { - String propertyName = ((PropertyExpander) iter.next()) - .parsePropertyName(value, pos, this); + for (PropertyExpander propertyExpander : expanders) { + String propertyName = propertyExpander.parsePropertyName(value, pos, this); if (propertyName == null) { continue; } diff --git a/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java b/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java index e93605e9a..3da3e5d67 100644 --- a/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java +++ b/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java @@ -17,7 +17,6 @@ */ package org.apache.tools.ant.property; -import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.HashSet; @@ -31,10 +30,10 @@ import org.apache.tools.ant.BuildException; * @since Ant 1.8.0 */ public class ResolvePropertyMap implements GetProperty { - private final Set seen = new HashSet(); + private final Set seen = new HashSet(); private final ParseProperties parseProperties; private final GetProperty master; - private Map map; + private Map map; private String prefix; // whether properties of the value side of the map should be // expanded @@ -49,7 +48,7 @@ public class ResolvePropertyMap implements GetProperty { * @param master the master property holder (usually PropertyHelper) * @param expanders a collection of expanders (usually from PropertyHelper). */ - public ResolvePropertyMap(Project project, GetProperty master, Collection expanders) { + public ResolvePropertyMap(Project project, GetProperty master, Collection expanders) { this.master = master; this.parseProperties = new ParseProperties(project, expanders, this); } @@ -102,7 +101,7 @@ public class ResolvePropertyMap implements GetProperty { * @param map the map to resolve properties in. * @deprecated since Ant 1.8.2, use the three-arg method instead. */ - public void resolveAllProperties(Map map) { + public void resolveAllProperties(Map map) { resolveAllProperties(map, null, false); } @@ -113,7 +112,7 @@ public class ResolvePropertyMap implements GetProperty { * will finally receive - may be null. * @deprecated since Ant 1.8.2, use the three-arg method instead. */ - public void resolveAllProperties(Map map, String prefix) { + public void resolveAllProperties(Map map, String prefix) { resolveAllProperties(map, null, false); } @@ -125,7 +124,7 @@ public class ResolvePropertyMap implements GetProperty { * @param prefixValues - whether the prefix will be applied * to properties on the value side of the map as well. */ - public void resolveAllProperties(Map map, String prefix, + public void resolveAllProperties(Map map, String prefix, boolean prefixValues) { // The map, prefix and prefixValues flag get used in the // getProperty callback @@ -133,9 +132,8 @@ public class ResolvePropertyMap implements GetProperty { this.prefix = prefix; this.prefixValues = prefixValues; - for (Iterator i = map.keySet().iterator(); i.hasNext();) { + for (String key : map.keySet()) { expandingLHS = true; - String key = (String) i.next(); Object result = getProperty(key); String value = result == null ? "" : result.toString(); map.put(key, value); diff --git a/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java b/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java index dd4025dd8..833bb946e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Vector; import org.apache.tools.ant.BuildException; @@ -55,10 +54,10 @@ public abstract class AbstractCvsTask extends Task { private Commandline cmd = new Commandline(); - private ArrayList modules = new ArrayList(); + private ArrayList modules = new ArrayList(); /** list of Commandline children */ - private Vector vecCommandlines = new Vector(); + private Vector vecCommandlines = new Vector(); /** * the CVSROOT variable. @@ -769,8 +768,7 @@ public abstract class AbstractCvsTask extends Task { if (cvsPackage != null) { c.createArgument().setLine(cvsPackage); } - for (Iterator iter = modules.iterator(); iter.hasNext(); ) { - Module m = (Module) iter.next(); + for (Module m : modules) { c.createArgument().setValue(m.getName()); } if (this.compression > 0 @@ -855,8 +853,10 @@ public abstract class AbstractCvsTask extends Task { modules.add(m); } - protected List getModules() { - return (List) modules.clone(); + protected List getModules() { + @SuppressWarnings("unchecked") + final List clone = (List) modules.clone(); + return clone; } public static final class Module { diff --git a/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java b/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java index aa9497dc1..a61ff8f0f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java @@ -19,7 +19,6 @@ package org.apache.tools.ant.taskdefs; import java.io.File; -import java.util.Enumeration; import java.util.Vector; import org.apache.tools.ant.BuildException; @@ -74,7 +73,7 @@ public abstract class AbstractJarSignerTask extends Task { /** * the filesets of the jars to sign */ - protected Vector filesets = new Vector(); + protected Vector filesets = new Vector(); /** * name of JDK program we are looking for */ @@ -291,10 +290,7 @@ public abstract class AbstractJarSignerTask extends Task { } //now patch in all system properties - Vector props = sysProperties.getVariablesVector(); - Enumeration e = props.elements(); - while (e.hasMoreElements()) { - Environment.Variable variable = (Environment.Variable) e.nextElement(); + for (Environment.Variable variable : sysProperties.getVariablesVector()) { declareSysProperty(cmd, variable); } } @@ -358,8 +354,9 @@ public abstract class AbstractJarSignerTask extends Task { * fileset, if is defined * @return a vector of FileSet instances */ - protected Vector createUnifiedSources() { - Vector sources = (Vector) filesets.clone(); + protected Vector createUnifiedSources() { + @SuppressWarnings("unchecked") + Vector sources = (Vector) filesets.clone(); if (jar != null) { //we create a fileset with the source file. //this lets us combine our logic for handling output directories, @@ -382,10 +379,8 @@ public abstract class AbstractJarSignerTask extends Task { */ protected Path createUnifiedSourcePath() { Path p = path == null ? new Path(getProject()) : (Path) path.clone(); - Vector s = createUnifiedSources(); - Enumeration e = s.elements(); - while (e.hasMoreElements()) { - p.add((FileSet) e.nextElement()); + for (FileSet fileSet : createUnifiedSources()) { + p.add(fileSet); } return p; } diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java index 0ea9e2b89..8c52f919f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ant.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java @@ -87,10 +87,10 @@ public class Ant extends Task { private boolean inheritRefs = false; /** the properties to pass to the new project */ - private Vector properties = new Vector(); + private Vector properties = new Vector(); /** the references to pass to the new project */ - private Vector references = new Vector(); + private Vector references = new Vector(); /** the temporary project created to run the build file */ private Project newProject; @@ -99,10 +99,10 @@ public class Ant extends Task { private PrintStream out = null; /** the sets of properties to pass to the new project */ - private Vector propertySets = new Vector(); + private Vector propertySets = new Vector(); /** the targets to call on the new project */ - private Vector targets = new Vector(); + private Vector targets = new Vector(); /** whether the target attribute was specified **/ private boolean targetAttributeSet = false; @@ -192,7 +192,7 @@ public class Ant extends Task { private void initializeProject() { newProject.setInputHandler(getProject().getInputHandler()); - Iterator iter = getBuildListeners(); + Iterator iter = getBuildListeners(); while (iter.hasNext()) { newProject.addBuildListener((BuildListener) iter.next()); } @@ -232,9 +232,7 @@ public class Ant extends Task { addAlmostAll(getProject().getProperties(), PropertyType.PLAIN); } - Enumeration e = propertySets.elements(); - while (e.hasMoreElements()) { - PropertySet ps = (PropertySet) e.nextElement(); + for (PropertySet ps : propertySets) { addAlmostAll(ps.getProperties(), PropertyType.PLAIN); } } @@ -334,7 +332,7 @@ public class Ant extends Task { public void execute() throws BuildException { File savedDir = dir; String savedAntFile = antFile; - Vector locals = new VectorSet(targets); + Vector locals = new VectorSet(targets); try { getNewProject(); @@ -414,10 +412,10 @@ public class Ant extends Task { + "its own parent target."); } boolean circular = false; - for (Iterator it = locals.iterator(); + for (Iterator it = locals.iterator(); !circular && it.hasNext();) { Target other = - (Target) (getProject().getTargets().get(it.next())); + getProject().getTargets().get(it.next()); circular |= (other != null && other.dependsOn(owningTargetName)); } @@ -452,9 +450,7 @@ public class Ant extends Task { } finally { // help the gc newProject = null; - Enumeration e = properties.elements(); - while (e.hasMoreElements()) { - Property p = (Property) e.nextElement(); + for (Property p : properties) { p.setProject(null); } @@ -475,7 +471,7 @@ public class Ant extends Task { *

* This function may be overrided by providers of custom ProjectHelper so they can implement easily their sub * launcher. - * + * * @return the name of the default file * @since Ant 1.8.0 */ @@ -491,9 +487,9 @@ public class Ant extends Task { private void overrideProperties() throws BuildException { // remove duplicate properties - last property wins // Needed for backward compatibility - Set set = new HashSet(); + Set set = new HashSet(); for (int i = properties.size() - 1; i >= 0; --i) { - Property p = (Property) properties.get(i); + Property p = properties.get(i); if (p.getName() != null && !p.getName().equals("")) { if (set.contains(p.getName())) { properties.remove(i); @@ -502,9 +498,9 @@ public class Ant extends Task { } } } - Enumeration e = properties.elements(); + Enumeration e = properties.elements(); while (e.hasMoreElements()) { - Property p = (Property) e.nextElement(); + Property p = e.nextElement(); p.setProject(newProject); p.execute(); } @@ -524,39 +520,35 @@ public class Ant extends Task { * @throws BuildException if a reference does not have a refid. */ private void addReferences() throws BuildException { - Hashtable thisReferences - = (Hashtable) getProject().getReferences().clone(); - Hashtable newReferences = newProject.getReferences(); - Enumeration e; - if (references.size() > 0) { - for (e = references.elements(); e.hasMoreElements();) { - Reference ref = (Reference) e.nextElement(); - String refid = ref.getRefId(); - if (refid == null) { - throw new BuildException("the refid attribute is required" - + " for reference elements"); - } - if (!thisReferences.containsKey(refid)) { - log("Parent project doesn't contain any reference '" - + refid + "'", - Project.MSG_WARN); - continue; - } + @SuppressWarnings("unchecked") + Hashtable thisReferences + = (Hashtable) getProject().getReferences().clone(); + for (Reference ref : references) { + String refid = ref.getRefId(); + if (refid == null) { + throw new BuildException("the refid attribute is required" + + " for reference elements"); + } + if (!thisReferences.containsKey(refid)) { + log("Parent project doesn't contain any reference '" + + refid + "'", + Project.MSG_WARN); + continue; + } - thisReferences.remove(refid); - String toRefid = ref.getToRefid(); - if (toRefid == null) { - toRefid = refid; - } - copyReference(refid, toRefid); + thisReferences.remove(refid); + String toRefid = ref.getToRefid(); + if (toRefid == null) { + toRefid = refid; } + copyReference(refid, toRefid); } // Now add all references that are not defined in the // subproject, if inheritRefs is true if (inheritRefs) { - for (e = thisReferences.keys(); e.hasMoreElements();) { - String key = (String) e.nextElement(); + Hashtable newReferences = newProject.getReferences(); + for (String key : thisReferences.keySet()) { if (newReferences.containsKey(key)) { continue; } @@ -584,7 +576,7 @@ public class Ant extends Task { return; } - Class c = orig.getClass(); + Class c = orig.getClass(); Object copy = orig; try { Method cloneM = c.getMethod("clone", new Class[0]); @@ -628,8 +620,8 @@ public class Ant extends Task { * user property or an inherited property). * @since Ant 1.8.0 */ - private void addAlmostAll(Hashtable props, PropertyType type) { - Enumeration e = props.keys(); + private void addAlmostAll(Hashtable props, PropertyType type) { + Enumeration e = props.keys(); while (e.hasMoreElements()) { String key = e.nextElement().toString(); if (MagicNames.PROJECT_BASEDIR.equals(key) @@ -763,7 +755,7 @@ public class Ant extends Task { /** * @since Ant 1.6.2 */ - private Iterator getBuildListeners() { + private Iterator getBuildListeners() { return getProject().getBuildListeners().iterator(); } @@ -776,7 +768,7 @@ public class Ant extends Task { /** Creates a reference to be configured by Ant. */ public Reference() { - super(); + super(); } private String targetid = null; diff --git a/src/main/org/apache/tools/ant/taskdefs/AntStructure.java b/src/main/org/apache/tools/ant/taskdefs/AntStructure.java index 8176bcb0f..8cbfc4bd3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/AntStructure.java +++ b/src/main/org/apache/tools/ant/taskdefs/AntStructure.java @@ -27,7 +27,6 @@ import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.Hashtable; -import java.util.Iterator; import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.IntrospectionHelper; @@ -96,26 +95,21 @@ public class AntStructure extends Task { } printer.printHead(out, getProject(), - new Hashtable(getProject().getTaskDefinitions()), - new Hashtable(getProject().getDataTypeDefinitions())); + new Hashtable>(getProject().getTaskDefinitions()), + new Hashtable>(getProject().getDataTypeDefinitions())); printer.printTargetDecl(out); - Iterator dataTypes = getProject().getCopyOfDataTypeDefinitions() - .keySet().iterator(); - while (dataTypes.hasNext()) { - String typeName = (String) dataTypes.next(); + for (String typeName : getProject().getCopyOfDataTypeDefinitions() + .keySet()) { printer.printElementDecl( - out, getProject(), typeName, - (Class) getProject().getDataTypeDefinitions().get(typeName)); + out, getProject(), typeName, + getProject().getDataTypeDefinitions().get(typeName)); } - Iterator tasks = getProject().getCopyOfTaskDefinitions().keySet() - .iterator(); - while (tasks.hasNext()) { - String tName = (String) tasks.next(); + for (String tName : getProject().getCopyOfTaskDefinitions().keySet()) { printer.printElementDecl(out, getProject(), tName, - (Class) getProject().getTaskDefinitions().get(tName)); + getProject().getTaskDefinitions().get(tName)); } printer.printTail(out); @@ -151,8 +145,8 @@ public class AntStructure extends Task { * @param types map (name to implementing class) * data types. */ - void printHead(PrintWriter out, Project p, Hashtable tasks, - Hashtable types); + void printHead(PrintWriter out, Project p, Hashtable> tasks, + Hashtable> types); /** * Prints the definition for the target element. @@ -169,7 +163,7 @@ public class AntStructure extends Task { * @param element class of the defined element. */ void printElementDecl(PrintWriter out, Project p, String name, - Class element); + Class element); /** * Prints the trailer. @@ -184,13 +178,14 @@ public class AntStructure extends Task { private static final String TASKS = "%tasks;"; private static final String TYPES = "%types;"; - private Hashtable visited = new Hashtable(); + private Hashtable visited = new Hashtable(); public void printTail(PrintWriter out) { visited.clear(); } - public void printHead(PrintWriter out, Project p, Hashtable tasks, Hashtable types) { + public void printHead(PrintWriter out, Project p, Hashtable> tasks, + Hashtable> types) { printHead(out, tasks.keys(), types.keys()); } @@ -201,14 +196,14 @@ public class AntStructure extends Task { *

Basically this prints the XML declaration, defines some * entities and the project element.

*/ - private void printHead(PrintWriter out, Enumeration tasks, - Enumeration types) { + private void printHead(PrintWriter out, Enumeration tasks, + Enumeration types) { out.println(""); out.println(""); out.print(" element) { if (visited.containsKey(name)) { return; @@ -313,7 +308,7 @@ public class AntStructure extends Task { return; } - Vector v = new Vector(); + Vector v = new Vector(); if (ih.supportsCharacters()) { v.addElement("#PCDATA"); } @@ -322,7 +317,7 @@ public class AntStructure extends Task { v.addElement(TASKS); } - Enumeration e = ih.getNestedElements(); + Enumeration e = ih.getNestedElements(); while (e.hasMoreElements()) { v.addElement(e.nextElement()); } @@ -359,7 +354,7 @@ public class AntStructure extends Task { sb.append(LINE_SEP).append(" ") .append(attrName).append(" "); - Class type = ih.getAttributeType(attrName); + Class type = ih.getAttributeType(attrName); if (type.equals(java.lang.Boolean.class) || type.equals(java.lang.Boolean.TYPE)) { sb.append(BOOLEAN).append(" "); diff --git a/src/main/org/apache/tools/ant/taskdefs/Antlib.java b/src/main/org/apache/tools/ant/taskdefs/Antlib.java index 801f60496..d4eb23f13 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Antlib.java +++ b/src/main/org/apache/tools/ant/taskdefs/Antlib.java @@ -113,7 +113,7 @@ public class Antlib extends Task implements TaskContainer { // private ClassLoader classLoader; private String uri = ""; - private List tasks = new ArrayList(); + private List tasks = new ArrayList(); /** * Set the class loader for this antlib. @@ -155,7 +155,8 @@ public class Antlib extends Task implements TaskContainer { * any tasks that derive from Definer. */ public void execute() { - for (Iterator i = tasks.iterator(); i.hasNext();) { + //TODO handle tasks added via #addTask() + for (Iterator i = tasks.iterator(); i.hasNext();) { UnknownElement ue = (UnknownElement) i.next(); setLocation(ue.getLocation()); ue.maybeConfigure(); diff --git a/src/main/org/apache/tools/ant/taskdefs/Apt.java b/src/main/org/apache/tools/ant/taskdefs/Apt.java index 6827a6abb..d49ee47e4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Apt.java +++ b/src/main/org/apache/tools/ant/taskdefs/Apt.java @@ -41,7 +41,7 @@ public class Apt private boolean compile = true; private String factory; private Path factoryPath; - private Vector options = new Vector(); + private Vector