git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1326760 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -104,7 +104,7 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| */ | |||
| public UnknownElement parseAntlibDescriptor(Project containingProject, | |||
| Resource resource) { | |||
| URLProvider up = (URLProvider) resource.as(URLProvider.class); | |||
| URLProvider up = resource.as(URLProvider.class); | |||
| if (up == null) { | |||
| throw new BuildException("Unsupported resource type: " + resource); | |||
| } | |||
| @@ -235,12 +235,12 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| url = (URL) source; | |||
| } else if (source instanceof Resource) { | |||
| FileProvider fp = | |||
| (FileProvider) ((Resource) source).as(FileProvider.class); | |||
| ((Resource) source).as(FileProvider.class); | |||
| if (fp != null) { | |||
| buildFile = fp.getFile(); | |||
| } else { | |||
| URLProvider up = | |||
| (URLProvider) ((Resource) source).as(URLProvider.class); | |||
| ((Resource) source).as(URLProvider.class); | |||
| if (up != null) { | |||
| url = up.getURL(); | |||
| } | |||
| @@ -30,7 +30,6 @@ import java.io.IOException; | |||
| import java.util.Comparator; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import java.util.Iterator; | |||
| import java.util.Hashtable; | |||
| import java.util.Enumeration; | |||
| import java.util.Set; | |||
| @@ -394,9 +393,8 @@ public class Checksum extends MatchingTask implements Condition { | |||
| } | |||
| try { | |||
| if (resources != null) { | |||
| for (Iterator i = resources.iterator(); i.hasNext();) { | |||
| Resource r = (Resource) i.next(); | |||
| File src = ((FileProvider) r.as(FileProvider.class)) | |||
| for (Resource r : resources) { | |||
| File src = r.as(FileProvider.class) | |||
| .getFile(); | |||
| if (totalproperty != null || todir != null) { | |||
| // Use '/' to calculate digest based on file name. | |||
| @@ -20,7 +20,6 @@ package org.apache.tools.ant.taskdefs; | |||
| import java.io.IOException; | |||
| import java.net.URL; | |||
| import java.util.Iterator; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| @@ -44,9 +43,8 @@ public class CloseResources extends Task { | |||
| } | |||
| public void execute() { | |||
| for (Iterator it = resources.iterator(); it.hasNext(); ) { | |||
| Resource r = (Resource) it.next(); | |||
| URLProvider up = (URLProvider) r.as(URLProvider.class); | |||
| for (Resource r : resources) { | |||
| URLProvider up = r.as(URLProvider.class); | |||
| if (up != null) { | |||
| URL u = up.getURL(); | |||
| try { | |||
| @@ -814,9 +814,9 @@ public class Concat extends Task implements ResourceCollection { | |||
| * Implement ResourceCollection. | |||
| * @return Iterator<Resource>. | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| validate(); | |||
| return Collections.singletonList(new ConcatResource(getResources())).iterator(); | |||
| return Collections.<Resource>singletonList(new ConcatResource(getResources())).iterator(); | |||
| } | |||
| /** | |||
| @@ -905,8 +905,8 @@ public class Concat extends Task implements ResourceCollection { | |||
| Restrict noexistRc = new Restrict(); | |||
| noexistRc.add(NOT_EXISTS); | |||
| noexistRc.add(rc); | |||
| for (Iterator i = noexistRc.iterator(); i.hasNext();) { | |||
| log(i.next() + " does not exist.", Project.MSG_ERR); | |||
| for (Resource r : noexistRc) { | |||
| log(r + " does not exist.", Project.MSG_ERR); | |||
| } | |||
| Restrict result = new Restrict(); | |||
| result.add(EXISTS); | |||
| @@ -918,8 +918,7 @@ public class Concat extends Task implements ResourceCollection { | |||
| if (dest == null || forceOverwrite) { | |||
| return false; | |||
| } | |||
| for (Iterator i = c.iterator(); i.hasNext();) { | |||
| Resource r = (Resource) i.next(); | |||
| for (Resource r : c) { | |||
| if (SelectorUtils.isOutOfDate(r, dest, FILE_UTILS.getFileTimestampGranularity())) { | |||
| return false; | |||
| } | |||
| @@ -517,9 +517,7 @@ public class Copy extends Task { | |||
| "Only FileSystem resources are supported."); | |||
| } | |||
| Iterator resources = rc.iterator(); | |||
| while (resources.hasNext()) { | |||
| Resource r = (Resource) resources.next(); | |||
| for (Resource r : rc) { | |||
| if (!r.isExists()) { | |||
| String message = "Warning: Could not find resource " | |||
| + r.toLongString() + " to copy."; | |||
| @@ -535,7 +533,7 @@ public class Copy extends Task { | |||
| File baseDir = NULL_FILE_PLACEHOLDER; | |||
| String name = r.getName(); | |||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||
| FileProvider fp = r.as(FileProvider.class); | |||
| if (fp != null) { | |||
| FileResource fr = ResourceUtils.asFileResource(fp); | |||
| baseDir = getKeyFile(fr.getBaseDir()); | |||
| @@ -702,8 +700,8 @@ public class Copy extends Task { | |||
| if (rc.size() == 0) { | |||
| throw new BuildException(MSG_WHEN_COPYING_EMPTY_RC_TO_FILE); | |||
| } else if (rc.size() == 1) { | |||
| Resource res = (Resource) rc.iterator().next(); | |||
| FileProvider r = (FileProvider) res.as(FileProvider.class); | |||
| Resource res = rc.iterator().next(); | |||
| FileProvider r = res.as(FileProvider.class); | |||
| if (file == null) { | |||
| if (r != null) { | |||
| file = r.getFile(); | |||
| @@ -95,7 +95,7 @@ public class Delete extends MatchingTask { | |||
| this.dirs = dirs; | |||
| Arrays.sort(this.dirs, REVERSE); | |||
| } | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| return new FileResourceIterator(project, basedir, dirs); | |||
| } | |||
| public boolean isFilesystemOnly() { return true; } | |||
| @@ -640,7 +640,7 @@ public class Delete extends MatchingTask { | |||
| public int size() { | |||
| return files.length; | |||
| } | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| return new FileResourceIterator(getProject(), | |||
| fsDir, files); | |||
| } | |||
| @@ -683,11 +683,10 @@ public class Delete extends MatchingTask { | |||
| } | |||
| try { | |||
| if (resourcesToDelete.isFilesystemOnly()) { | |||
| for (Iterator iter = resourcesToDelete.iterator(); iter.hasNext();) { | |||
| for (Resource r : resourcesToDelete) { | |||
| // nonexistent resources could only occur if we already | |||
| // deleted something from a fileset: | |||
| Resource r = (Resource) iter.next(); | |||
| File f = ((FileProvider) r.as(FileProvider.class)) | |||
| File f = r.as(FileProvider.class) | |||
| .getFile(); | |||
| if (!f.exists()) { | |||
| continue; | |||
| @@ -101,7 +101,7 @@ public class DependSet extends MatchingTask { | |||
| private HideMissingBasedir(FileSet fs) { | |||
| this.fs = fs; | |||
| } | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| return basedirExists() ? fs.iterator() : Resources.EMPTY_ITERATOR; | |||
| } | |||
| public int size() { | |||
| @@ -252,20 +252,20 @@ public class DependSet extends MatchingTask { | |||
| Restrict r = new Restrict(); | |||
| r.add(rsel); | |||
| r.add(rc); | |||
| for (Iterator i = r.iterator(); i.hasNext();) { | |||
| log("Warning: " + i.next() + " modified in the future.", Project.MSG_WARN); | |||
| for (Resource res : r) { | |||
| log("Warning: " + res + " modified in the future.", Project.MSG_WARN); | |||
| } | |||
| } | |||
| private Resource getXest(ResourceCollection rc, ResourceComparator c) { | |||
| Iterator i = rc.iterator(); | |||
| Iterator<Resource> i = rc.iterator(); | |||
| if (!i.hasNext()) { | |||
| return null; | |||
| } | |||
| Resource xest = (Resource) i.next(); | |||
| Resource xest = i.next(); | |||
| while (i.hasNext()) { | |||
| Resource next = (Resource) i.next(); | |||
| Resource next = i.next(); | |||
| if (c.compare(xest, next) < 0) { | |||
| xest = next; | |||
| } | |||
| @@ -289,8 +289,7 @@ public class DependSet extends MatchingTask { | |||
| private void logMissing(ResourceCollection missing, String what) { | |||
| if (verbose) { | |||
| for (Iterator i = missing.iterator(); i.hasNext(); ) { | |||
| Resource r = (Resource) i.next(); | |||
| for (Resource r : missing) { | |||
| log("Expected " + what + " " + r.toLongString() | |||
| + " is missing."); | |||
| } | |||
| @@ -103,7 +103,7 @@ public class Echo extends Task { | |||
| throw new BuildException("Cannot set > 1 output target"); | |||
| } | |||
| this.output = output; | |||
| FileProvider fp = (FileProvider) output.as(FileProvider.class); | |||
| FileProvider fp = output.as(FileProvider.class); | |||
| this.file = fp != null ? fp.getFile() : null; | |||
| } | |||
| @@ -21,7 +21,6 @@ package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.util.HashSet; | |||
| import java.util.Iterator; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| @@ -417,9 +416,7 @@ public class ExecuteOn extends ExecTask { | |||
| } | |||
| if (resources != null) { | |||
| Iterator iter = resources.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource res = (Resource) iter.next(); | |||
| for (Resource res : resources) { | |||
| if (!res.isExists() && ignoreMissing) { | |||
| continue; | |||
| @@ -427,7 +424,7 @@ public class ExecuteOn extends ExecTask { | |||
| File base = null; | |||
| String name = res.getName(); | |||
| FileProvider fp = (FileProvider) res.as(FileProvider.class); | |||
| FileProvider fp = res.as(FileProvider.class); | |||
| if (fp != null) { | |||
| FileResource fr = ResourceUtils.asFileResource(fp); | |||
| base = fr.getBaseDir(); | |||
| @@ -132,15 +132,13 @@ public class Expand extends Task { | |||
| expandFile(FILE_UTILS, source, dest); | |||
| } | |||
| } | |||
| Iterator iter = resources.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| for (Resource r : resources) { | |||
| if (!r.isExists()) { | |||
| log("Skipping '" + r.getName() + "' because it doesn't exist."); | |||
| continue; | |||
| } | |||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||
| FileProvider fp = r.as(FileProvider.class); | |||
| if (fp != null) { | |||
| expandFile(FILE_UTILS, fp.getFile(), dest); | |||
| } else { | |||
| @@ -29,7 +29,6 @@ import java.net.HttpURLConnection; | |||
| import java.net.URL; | |||
| import java.net.URLConnection; | |||
| import java.util.Date; | |||
| import java.util.Iterator; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| @@ -84,9 +83,8 @@ public class Get extends Task { | |||
| public void execute() throws BuildException { | |||
| checkAttributes(); | |||
| for (Iterator iter = sources.iterator(); iter.hasNext(); ) { | |||
| Resource r = (Resource) iter.next(); | |||
| URLProvider up = (URLProvider) r.as(URLProvider.class); | |||
| for (Resource r : sources) { | |||
| URLProvider up = r.as(URLProvider.class); | |||
| URL source = up.getURL(); | |||
| File dest = destination; | |||
| @@ -157,9 +155,8 @@ public class Get extends Task { | |||
| public boolean doGet(int logLevel, DownloadProgress progress) | |||
| throws IOException { | |||
| checkAttributes(); | |||
| for (Iterator iter = sources.iterator(); iter.hasNext(); ) { | |||
| Resource r = (Resource) iter.next(); | |||
| URLProvider up = (URLProvider) r.as(URLProvider.class); | |||
| for (Resource r : sources) { | |||
| URLProvider up = r.as(URLProvider.class); | |||
| URL source = up.getURL(); | |||
| return doGet(source, destination, logLevel, progress); | |||
| } | |||
| @@ -251,8 +248,8 @@ public class Get extends Task { | |||
| throw new BuildException("at least one source is required", | |||
| getLocation()); | |||
| } | |||
| for (Iterator iter = sources.iterator(); iter.hasNext(); ) { | |||
| Object up = ((Resource) iter.next()).as(URLProvider.class); | |||
| for (Resource r : sources) { | |||
| URLProvider up = r.as(URLProvider.class); | |||
| if (up == null) { | |||
| throw new BuildException("Only URLProvider resources are" | |||
| + " supported", getLocation()); | |||
| @@ -159,8 +159,8 @@ public class ImportTask extends Task { | |||
| if (fromFileAttribute != null) { | |||
| resources.add(fromFileAttribute); | |||
| } | |||
| for (Iterator i = resourcesToImport.iterator(); i.hasNext(); ) { | |||
| importResource(helper, (Resource) i.next()); | |||
| for (Resource r : resourcesToImport) { | |||
| importResource(helper, r); | |||
| } | |||
| } | |||
| @@ -184,7 +184,7 @@ public class ImportTask extends Task { | |||
| } | |||
| File importedFile = null; | |||
| FileProvider fp = (FileProvider) importedResource.as(FileProvider.class); | |||
| FileProvider fp = importedResource.as(FileProvider.class); | |||
| if (fp != null) { | |||
| importedFile = fp.getFile(); | |||
| } | |||
| @@ -2307,11 +2307,8 @@ public class Javadoc extends Task { | |||
| rc = fs2; | |||
| } | |||
| } | |||
| Iterator iter = rc.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| sf.addElement(new SourceFile(((FileProvider) r.as(FileProvider.class)) | |||
| .getFile())); | |||
| for (Resource r : rc) { | |||
| sf.addElement(new SourceFile(r.as(FileProvider.class).getFile())); | |||
| } | |||
| } | |||
| } | |||
| @@ -230,8 +230,7 @@ public class Length extends Task implements Condition { | |||
| } | |||
| private void handleResources(Handler h) { | |||
| for (Iterator i = resources.iterator(); i.hasNext();) { | |||
| Resource r = (Resource) i.next(); | |||
| for (Resource r : resources) { | |||
| if (!r.isExists()) { | |||
| log(r + " does not exist", Project.MSG_WARN); | |||
| } | |||
| @@ -232,7 +232,7 @@ public class LoadProperties extends Task { | |||
| throw new BuildException( | |||
| "only single-element resource collections are supported"); | |||
| } | |||
| src = (Resource) a.iterator().next(); | |||
| src = a.iterator().next(); | |||
| } | |||
| private synchronized JavaResource getRequiredJavaResource() { | |||
| @@ -229,7 +229,7 @@ public class LoadResource extends Task { | |||
| throw new BuildException("only single argument resource collections" | |||
| + " are supported"); | |||
| } | |||
| src = (Resource) a.iterator().next(); | |||
| src = a.iterator().next(); | |||
| } | |||
| } | |||
| @@ -75,7 +75,7 @@ public abstract class Pack extends Task { | |||
| if (src.isDirectory()) { | |||
| throw new BuildException("the source can't be a directory"); | |||
| } | |||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||
| FileProvider fp = src.as(FileProvider.class); | |||
| if (fp != null) { | |||
| source = fp.getFile(); | |||
| } else if (!supportsNonFileResources()) { | |||
| @@ -98,7 +98,7 @@ public abstract class Pack extends Task { | |||
| + " cannot handle multiple resources at once. (" + a.size() | |||
| + " resources were selected.)"); | |||
| } | |||
| setSrcResource((Resource) a.iterator().next()); | |||
| setSrcResource(a.iterator().next()); | |||
| } | |||
| /** | |||
| @@ -32,6 +32,7 @@ import org.apache.tools.ant.types.Mapper; | |||
| import org.apache.tools.ant.types.Reference; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.resources.Resources; | |||
| import org.apache.tools.ant.types.resources.Union; | |||
| import org.apache.tools.ant.util.FileNameMapper; | |||
| @@ -361,8 +362,8 @@ public class PathConvert extends Task { | |||
| ResourceCollection resources = isPreserveDuplicates() ? (ResourceCollection) path : new Union(path); | |||
| List ret = new ArrayList(); | |||
| FileNameMapper mapperImpl = mapper == null ? new IdentityMapper() : mapper.getImplementation(); | |||
| for (Iterator iter = resources.iterator(); iter.hasNext(); ) { | |||
| String[] mapped = mapperImpl.mapFileName(String.valueOf(iter.next())); | |||
| for (Resource r : resources) { | |||
| String[] mapped = mapperImpl.mapFileName(String.valueOf(r)); | |||
| for (int m = 0; mapped != null && m < mapped.length; ++m) { | |||
| ret.add(mapped[m]); | |||
| } | |||
| @@ -541,10 +541,9 @@ public class Replace extends MatchingTask { | |||
| } | |||
| if (resources != null) { | |||
| for (Iterator i = resources.iterator(); i.hasNext(); ) { | |||
| for (Resource r : resources) { | |||
| FileProvider fp = | |||
| (FileProvider) ((Resource) i.next()) | |||
| .as(FileProvider.class); | |||
| r.as(FileProvider.class); | |||
| processFile(fp.getFile()); | |||
| } | |||
| } | |||
| @@ -597,9 +597,7 @@ public class SQLExec extends JDBCTask { | |||
| if (resources != null) { | |||
| // deal with the resources | |||
| Iterator iter = resources.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| for (Resource r : resources) { | |||
| // Make a transaction for each resource | |||
| Transaction t = createTransaction(); | |||
| t.setSrcResource(r); | |||
| @@ -623,13 +621,13 @@ public class SQLExec extends JDBCTask { | |||
| log("Opening PrintStream to output Resource " + output, Project.MSG_VERBOSE); | |||
| OutputStream os = null; | |||
| FileProvider fp = | |||
| (FileProvider) output.as(FileProvider.class); | |||
| output.as(FileProvider.class); | |||
| if (fp != null) { | |||
| os = new FileOutputStream(fp.getFile(), append); | |||
| } else { | |||
| if (append) { | |||
| Appendable a = | |||
| (Appendable) output.as(Appendable.class); | |||
| output.as(Appendable.class); | |||
| if (a != null) { | |||
| os = a.getAppendOutputStream(); | |||
| } | |||
| @@ -1030,7 +1028,7 @@ public class SQLExec extends JDBCTask { | |||
| throw new BuildException("only single argument resource " | |||
| + "collections are supported."); | |||
| } | |||
| setSrcResource((Resource) a.iterator().next()); | |||
| setSrcResource(a.iterator().next()); | |||
| } | |||
| /** | |||
| @@ -385,11 +385,9 @@ public class SignJar extends AbstractJarSignerTask { | |||
| //and the mapper is ready to map from source dirs to dest files | |||
| //now we iterate through every JAR giving source and dest names | |||
| // deal with the paths | |||
| Iterator iter = sources.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| for (Resource r : sources) { | |||
| FileResource fr = ResourceUtils | |||
| .asFileResource((FileProvider) r.as(FileProvider.class)); | |||
| .asFileResource(r.as(FileProvider.class)); | |||
| //calculate our destination directory; it is either the destDir | |||
| //attribute, or the base dir of the fileset (for in situ updates) | |||
| @@ -568,11 +568,9 @@ public class Tar extends MatchingTask { | |||
| } else if (rc.isFilesystemOnly()) { | |||
| HashSet basedirs = new HashSet(); | |||
| HashMap basedirToFilesMap = new HashMap(); | |||
| Iterator iter = rc.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource res = (Resource) iter.next(); | |||
| for (Resource res : rc) { | |||
| FileResource r = ResourceUtils | |||
| .asFileResource((FileProvider) res.as(FileProvider.class)); | |||
| .asFileResource(res.as(FileProvider.class)); | |||
| File base = r.getBaseDir(); | |||
| if (base == null) { | |||
| base = Copy.NULL_FILE_PLACEHOLDER; | |||
| @@ -589,7 +587,7 @@ public class Tar extends MatchingTask { | |||
| files.add(r.getName()); | |||
| } | |||
| } | |||
| iter = basedirs.iterator(); | |||
| Iterator iter = basedirs.iterator(); | |||
| while (iter.hasNext()) { | |||
| File base = (File) iter.next(); | |||
| Vector f = (Vector) basedirToFilesMap.get(base); | |||
| @@ -599,9 +597,9 @@ public class Tar extends MatchingTask { | |||
| files); | |||
| } | |||
| } else { // non-file resources | |||
| Iterator iter = rc.iterator(); | |||
| Iterator<Resource> iter = rc.iterator(); | |||
| while (upToDate && iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| Resource r = iter.next(); | |||
| upToDate = archiveIsUpToDate(r); | |||
| } | |||
| } | |||
| @@ -667,16 +665,12 @@ public class Tar extends MatchingTask { | |||
| tarFile(f, tOut, name, tfs); | |||
| } | |||
| } else if (rc.isFilesystemOnly()) { | |||
| Iterator iter = rc.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| File f = ((FileProvider) r.as(FileProvider.class)).getFile(); | |||
| for (Resource r : rc) { | |||
| File f = r.as(FileProvider.class).getFile(); | |||
| tarFile(f, tOut, f.getName(), tfs); | |||
| } | |||
| } else { // non-file resources | |||
| Iterator iter = rc.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| for (Resource r : rc) { | |||
| tarResource(r, tOut, r.getName(), tfs); | |||
| } | |||
| } | |||
| @@ -296,10 +296,8 @@ public class Touch extends Task { | |||
| return; | |||
| } | |||
| // deal with the resource collections | |||
| Iterator iter = resources.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| Touchable t = (Touchable) r.as(Touchable.class); | |||
| for (Resource r : resources) { | |||
| Touchable t = r.as(Touchable.class); | |||
| if (t == null) { | |||
| throw new BuildException("Can't touch " + r); | |||
| } | |||
| @@ -341,12 +339,12 @@ public class Touch extends Task { | |||
| private void touch(Resource r, long defaultTimestamp) { | |||
| if (fileNameMapper == null) { | |||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||
| FileProvider fp = r.as(FileProvider.class); | |||
| if (fp != null) { | |||
| // use this to create file and deal with non-writable files | |||
| touch(fp.getFile(), defaultTimestamp); | |||
| } else { | |||
| ((Touchable) r.as(Touchable.class)).touch(defaultTimestamp); | |||
| r.as(Touchable.class).touch(defaultTimestamp); | |||
| } | |||
| } else { | |||
| String[] mapped = fileNameMapper.mapFileName(r.getName()); | |||
| @@ -126,9 +126,8 @@ public class Truncate extends Task { | |||
| if (path == null) { | |||
| throw new BuildException(NO_CHILD); | |||
| } | |||
| for (Iterator it = path.iterator(); it.hasNext();) { | |||
| Resource r = (Resource) it.next(); | |||
| File f = ((FileProvider) r.as(FileProvider.class)).getFile(); | |||
| for (Resource r : path) { | |||
| File f = r.as(FileProvider.class).getFile(); | |||
| if (shouldProcess(f)) { | |||
| process(f); | |||
| } | |||
| @@ -91,7 +91,7 @@ public abstract class Unpack extends Task { | |||
| throw new BuildException( | |||
| "the archive " + src.getName() + " can't be a directory"); | |||
| } | |||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||
| FileProvider fp = src.as(FileProvider.class); | |||
| if (fp != null) { | |||
| source = fp.getFile(); | |||
| } else if (!supportsNonFileResources()) { | |||
| @@ -113,7 +113,7 @@ public abstract class Unpack extends Task { | |||
| throw new BuildException("only single argument resource collections" | |||
| + " are supported as archives"); | |||
| } | |||
| setSrcResource((Resource) a.iterator().next()); | |||
| setSrcResource(a.iterator().next()); | |||
| } | |||
| /** | |||
| @@ -89,10 +89,8 @@ public class VerifyJar extends AbstractJarSignerTask { | |||
| try { | |||
| Path sources = createUnifiedSourcePath(); | |||
| Iterator iter = sources.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| FileProvider fr = (FileProvider) r.as(FileProvider.class); | |||
| for (Resource r : sources) { | |||
| FileProvider fr = r.as(FileProvider.class); | |||
| verifyOneJar(fr.getFile()); | |||
| } | |||
| @@ -19,7 +19,6 @@ package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.util.Enumeration; | |||
| import java.util.Iterator; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.AntClassLoader; | |||
| import org.apache.tools.ant.BuildException; | |||
| @@ -277,7 +276,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
| handleError("The style element must be specified with exactly one" | |||
| + " nested resource."); | |||
| } else { | |||
| setXslResource((Resource) rc.iterator().next()); | |||
| setXslResource(rc.iterator().next()); | |||
| } | |||
| } | |||
| @@ -749,15 +748,13 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
| * @since Ant 1.7 | |||
| */ | |||
| private void processResources(Resource stylesheet) { | |||
| Iterator iter = resources.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| for (Resource r : resources) { | |||
| if (!r.isExists()) { | |||
| continue; | |||
| } | |||
| File base = baseDir; | |||
| String name = r.getName(); | |||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||
| FileProvider fp = r.as(FileProvider.class); | |||
| if (fp != null) { | |||
| FileResource f = ResourceUtils.asFileResource(fp); | |||
| base = f.getBaseDir(); | |||
| @@ -1173,7 +1170,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
| // a resource, but we can set it as a file. So, | |||
| // we make an attempt to get it as a file | |||
| FileProvider fp = | |||
| (FileProvider) stylesheet.as(FileProvider.class); | |||
| stylesheet.as(FileProvider.class); | |||
| if (fp != null) { | |||
| liaison.setStylesheet(fp.getFile()); | |||
| } else { | |||
| @@ -244,7 +244,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
| DocumentBuilder builder = factory.newDocumentBuilder(); | |||
| builder.setEntityResolver(getEntityResolver()); | |||
| Document document = null; | |||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||
| FileProvider fp = src.as(FileProvider.class); | |||
| if (fp != null) { | |||
| document = builder.parse(fp.getFile()); | |||
| } else { | |||
| @@ -591,7 +591,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
| throw new BuildException( | |||
| "only single argument resource collections are supported as archives"); | |||
| } | |||
| setSrcResource((Resource) a.iterator().next()); | |||
| setSrcResource(a.iterator().next()); | |||
| } | |||
| /** | |||
| @@ -670,7 +670,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
| * @return the file attribute. | |||
| */ | |||
| protected File getFile () { | |||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||
| FileProvider fp = src.as(FileProvider.class); | |||
| return fp != null ? fp.getFile() : null; | |||
| } | |||
| @@ -681,7 +681,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
| // delegate this way around to support subclasses that | |||
| // overwrite getFile | |||
| File f = getFile(); | |||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||
| FileProvider fp = src.as(FileProvider.class); | |||
| return f == null ? src : fp != null | |||
| && fp.getFile().equals(f) ? src : new FileResource(f); | |||
| } | |||
| @@ -1077,7 +1077,7 @@ public class Zip extends MatchingTask { | |||
| continue; | |||
| } | |||
| File base = null; | |||
| FileProvider fp = (FileProvider) resources[i].as(FileProvider.class); | |||
| FileProvider fp = resources[i].as(FileProvider.class); | |||
| if (fp != null) { | |||
| base = ResourceUtils.asFileResource(fp).getBaseDir(); | |||
| } | |||
| @@ -1481,7 +1481,7 @@ public class Zip extends MatchingTask { | |||
| for (int j = 0; j < initialResources[i].length; j++) { | |||
| FileProvider fp = | |||
| (FileProvider) initialResources[i][j].as(FileProvider.class); | |||
| initialResources[i][j].as(FileProvider.class); | |||
| if (fp != null && zipFile.equals(fp.getFile())) { | |||
| throw new BuildException("A zip file cannot include " | |||
| + "itself", getLocation()); | |||
| @@ -1585,11 +1585,9 @@ public class Zip extends MatchingTask { | |||
| protected Resource[][] grabNonFileSetResources(ResourceCollection[] rcs) { | |||
| Resource[][] result = new Resource[rcs.length][]; | |||
| for (int i = 0; i < rcs.length; i++) { | |||
| Iterator iter = rcs[i].iterator(); | |||
| ArrayList dirs = new ArrayList(); | |||
| ArrayList files = new ArrayList(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| for (Resource r : rcs[i]) { | |||
| if (r.isExists()) { | |||
| if (r.isDirectory()) { | |||
| dirs.add(r); | |||
| @@ -71,7 +71,7 @@ public class ResourcesMatch implements Condition { | |||
| "You must specify one or more nested resource collections"); | |||
| } | |||
| if (resources.size() > 1) { | |||
| Iterator i = resources.iterator(); | |||
| Iterator<Resource> i = resources.iterator(); | |||
| Resource r1 = (Resource) i.next(); | |||
| Resource r2 = null; | |||
| @@ -531,11 +531,8 @@ public class EmailTask extends Task { | |||
| // identify which files should be attached | |||
| Vector files = new Vector(); | |||
| if (attachments != null) { | |||
| Iterator iter = attachments.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| files.addElement(((FileProvider) r.as(FileProvider.class)) | |||
| for (Resource r : attachments) { | |||
| files.addElement(r.as(FileProvider.class) | |||
| .getFile()); | |||
| } | |||
| } | |||
| @@ -520,9 +520,9 @@ public class ReplaceRegExp extends Task { | |||
| } | |||
| if (resources != null) { | |||
| for (Iterator i = resources.iterator(); i.hasNext(); ) { | |||
| for (Resource r : resources) { | |||
| FileProvider fp = | |||
| (FileProvider) ((Resource) i.next()).as(FileProvider.class); | |||
| r.as(FileProvider.class); | |||
| File f = fp.getFile(); | |||
| if (f.exists()) { | |||
| @@ -267,11 +267,11 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware | |||
| } | |||
| private String resourceToURI(Resource resource) { | |||
| FileProvider fp = (FileProvider) resource.as(FileProvider.class); | |||
| FileProvider fp = resource.as(FileProvider.class); | |||
| if (fp != null) { | |||
| return FILE_UTILS.toURI(fp.getFile().getAbsolutePath()); | |||
| } | |||
| URLProvider up = (URLProvider) resource.as(URLProvider.class); | |||
| URLProvider up = resource.as(URLProvider.class); | |||
| if (up != null) { | |||
| URL u = up.getURL(); | |||
| return String.valueOf(u); | |||
| @@ -144,9 +144,7 @@ public final class BatchTest extends BaseTest { | |||
| */ | |||
| private String[] getFilenames() { | |||
| Vector v = new Vector(); | |||
| Iterator iter = resources.iterator(); | |||
| while (iter.hasNext()) { | |||
| Resource r = (Resource) iter.next(); | |||
| for (Resource r : resources) { | |||
| if (r.isExists()) { | |||
| String pathname = r.getName(); | |||
| if (pathname.endsWith(".java")) { | |||
| @@ -126,7 +126,7 @@ public abstract class ArchiveFileSet extends FileSet { | |||
| throw new BuildException("only single argument resource collections" | |||
| + " are supported as archives"); | |||
| } | |||
| setSrcResource((Resource) a.iterator().next()); | |||
| setSrcResource(a.iterator().next()); | |||
| } | |||
| /** | |||
| @@ -188,7 +188,7 @@ public abstract class ArchiveFileSet extends FileSet { | |||
| } | |||
| dieOnCircularReference(); | |||
| if (src != null) { | |||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||
| FileProvider fp = src.as(FileProvider.class); | |||
| if (fp != null) { | |||
| return fp.getFile(); | |||
| } | |||
| @@ -308,7 +308,7 @@ public abstract class ArchiveFileSet extends FileSet { | |||
| * @return Iterator of Resources. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((ResourceCollection) (getRef(getProject()))).iterator(); | |||
| } | |||
| @@ -131,7 +131,7 @@ public abstract class ArchiveScanner extends DirectoryScanner { | |||
| */ | |||
| public void setSrc(Resource src) { | |||
| this.src = src; | |||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||
| FileProvider fp = src.as(FileProvider.class); | |||
| if (fp != null) { | |||
| srcFile = fp.getFile(); | |||
| } | |||
| @@ -63,7 +63,7 @@ public class DirSet extends AbstractFileSet implements ResourceCollection { | |||
| * @return an Iterator of Resources. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((DirSet) getRef(getProject())).iterator(); | |||
| } | |||
| @@ -188,7 +188,7 @@ public class FileList extends DataType implements ResourceCollection { | |||
| * @return an Iterator of Resources. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((FileList) getRef(getProject())).iterator(); | |||
| } | |||
| @@ -62,7 +62,7 @@ public class FileSet extends AbstractFileSet implements ResourceCollection { | |||
| * @return an Iterator of Resources. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((FileSet) getRef(getProject())).iterator(); | |||
| } | |||
| @@ -121,7 +121,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection { | |||
| * Create an iterator. | |||
| * @return an iterator. | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| return new FileResourceIterator(getProject(), null, parts); | |||
| } | |||
| @@ -701,7 +701,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection { | |||
| * are added to this container while the Iterator is in use. | |||
| * @return a "fail-fast" Iterator. | |||
| */ | |||
| public final synchronized Iterator iterator() { | |||
| public final synchronized Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((Path) getCheckedRef()).iterator(); | |||
| } | |||
| @@ -502,7 +502,7 @@ public class PropertySet extends DataType implements ResourceCollection { | |||
| * @return an Iterator of Resources. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return getRef().iterator(); | |||
| } | |||
| @@ -514,11 +514,11 @@ public class PropertySet extends DataType implements ResourceCollection { | |||
| final FileNameMapper m = myMapper == null ? null : myMapper.getImplementation(); | |||
| final Iterator iter = names.iterator(); | |||
| return new Iterator() { | |||
| return new Iterator<Resource>() { | |||
| public boolean hasNext() { | |||
| return iter.hasNext(); | |||
| } | |||
| public Object next() { | |||
| public Resource next() { | |||
| PropertyResource p = new PropertyResource(getProject(), (String) iter.next()); | |||
| return m == null ? (Resource) p : new MappedResource(p, m); | |||
| } | |||
| @@ -36,7 +36,7 @@ import org.apache.tools.ant.types.resources.FileProvider; | |||
| * @since Ant 1.5.2 | |||
| * @see org.apache.tools.ant.types.resources.Touchable | |||
| */ | |||
| public class Resource extends DataType implements Cloneable, Comparable, ResourceCollection { | |||
| public class Resource extends DataType implements Comparable<Resource>, ResourceCollection { | |||
| /** Constant unknown size */ | |||
| public static final long UNKNOWN_SIZE = -1; | |||
| @@ -270,13 +270,9 @@ public class Resource extends DataType implements Cloneable, Comparable, Resourc | |||
| * is less than, equal to, or greater than the specified Resource. | |||
| * @since Ant 1.6 | |||
| */ | |||
| public int compareTo(Object other) { | |||
| public int compareTo(Resource other) { | |||
| if (isReference()) { | |||
| return ((Comparable) getCheckedRef()).compareTo(other); | |||
| } | |||
| if (!(other instanceof Resource)) { | |||
| throw new IllegalArgumentException( | |||
| "Can only be compared with Resources"); | |||
| return ((Resource) getCheckedRef()).compareTo(other); | |||
| } | |||
| return toString().compareTo(other.toString()); | |||
| } | |||
| @@ -291,7 +287,7 @@ public class Resource extends DataType implements Cloneable, Comparable, Resourc | |||
| if (isReference()) { | |||
| return getCheckedRef().equals(other); | |||
| } | |||
| return other.getClass().equals(getClass()) && compareTo(other) == 0; | |||
| return other.getClass().equals(getClass()) && compareTo((Resource) other) == 0; | |||
| } | |||
| /** | |||
| @@ -344,14 +340,14 @@ public class Resource extends DataType implements Cloneable, Comparable, Resourc | |||
| * @return an Iterator of Resources. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| return isReference() ? ((Resource) getCheckedRef()).iterator() | |||
| : new Iterator() { | |||
| : new Iterator<Resource>() { | |||
| private boolean done = false; | |||
| public boolean hasNext() { | |||
| return !done; | |||
| } | |||
| public Object next() { | |||
| public Resource next() { | |||
| if (done) { | |||
| throw new NoSuchElementException(); | |||
| } | |||
| @@ -436,7 +432,7 @@ public class Resource extends DataType implements Cloneable, Comparable, Resourc | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| public Object as(Class clazz) { | |||
| return clazz.isAssignableFrom(getClass()) ? this : null; | |||
| public <T> T as(Class<T> clazz) { | |||
| return clazz.isAssignableFrom(getClass()) ? clazz.cast(this) : null; | |||
| } | |||
| } | |||
| @@ -24,14 +24,13 @@ import org.apache.tools.ant.types.resources.FileProvider; | |||
| * Interface describing a collection of Resources. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public interface ResourceCollection { | |||
| public interface ResourceCollection extends Iterable<Resource> { | |||
| /** | |||
| * Get an Iterator over the contents of this ResourceCollection, whose elements | |||
| * are {@link Resource} instances. | |||
| * @return an Iterator of Resources. | |||
| * Gets the contents of this collection. | |||
| * @return all resources in the collection | |||
| */ | |||
| Iterator iterator(); | |||
| Iterator<Resource> iterator(); | |||
| /** | |||
| * Learn the number of contained Resources. | |||
| @@ -59,7 +59,7 @@ public class ZipScanner extends ArchiveScanner { | |||
| ZipFile zf = null; | |||
| File srcFile = null; | |||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||
| FileProvider fp = src.as(FileProvider.class); | |||
| if (fp != null) { | |||
| srcFile = fp.getFile(); | |||
| } else { | |||
| @@ -85,7 +85,7 @@ public abstract class AbstractResourceCollectionWrapper | |||
| * Fulfill the ResourceCollection contract. | |||
| * @return an Iterator of Resources. | |||
| */ | |||
| public final synchronized Iterator iterator() { | |||
| public final synchronized Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((AbstractResourceCollectionWrapper) getCheckedRef()).iterator(); | |||
| } | |||
| @@ -101,7 +101,7 @@ public abstract class AbstractResourceCollectionWrapper | |||
| * | |||
| * @return the iterator on the resource collection | |||
| */ | |||
| protected abstract Iterator createIterator(); | |||
| protected abstract Iterator<Resource> createIterator(); | |||
| /** | |||
| * Fulfill the ResourceCollection contract. | |||
| @@ -110,7 +110,7 @@ public abstract class ArchiveResource extends Resource { | |||
| throw new BuildException("only single argument resource collections" | |||
| + " are supported as archives"); | |||
| } | |||
| archive = (Resource) a.iterator().next(); | |||
| archive = a.iterator().next(); | |||
| } | |||
| /** | |||
| @@ -199,7 +199,7 @@ public abstract class ArchiveResource extends Resource { | |||
| * @return a negative integer, zero, or a positive integer as this Resource | |||
| * is less than, equal to, or greater than the specified Resource. | |||
| */ | |||
| public int compareTo(Object another) { | |||
| public int compareTo(Resource another) { | |||
| return this.equals(another) ? 0 : super.compareTo(another); | |||
| } | |||
| @@ -86,15 +86,15 @@ public class Archives extends DataType | |||
| /** | |||
| * Merges the nested collections. | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((Archives) getCheckedRef()).iterator(); | |||
| } | |||
| dieOnCircularReference(); | |||
| List l = new LinkedList(); | |||
| for (Iterator i = grabArchives(); i.hasNext(); ) { | |||
| List<Resource> l = new LinkedList<Resource>(); | |||
| for (Iterator<ArchiveFileSet> i = grabArchives(); i.hasNext(); ) { | |||
| l.addAll(CollectionUtils | |||
| .asCollection(((ResourceCollection) i.next()).iterator())); | |||
| .asCollection(i.next().iterator())); | |||
| } | |||
| return l.iterator(); | |||
| } | |||
| @@ -144,15 +144,13 @@ public class Archives extends DataType | |||
| * Turns all nested resources into corresponding ArchiveFileSets | |||
| * and returns an iterator over the collected archives. | |||
| */ | |||
| protected Iterator/*<ArchiveFileset>*/ grabArchives() { | |||
| List l = new LinkedList(); | |||
| for (Iterator iter = zips.iterator(); iter.hasNext(); ) { | |||
| l.add(configureArchive(new ZipFileSet(), | |||
| (Resource) iter.next())); | |||
| protected Iterator<ArchiveFileSet> grabArchives() { | |||
| List<ArchiveFileSet> l = new LinkedList<ArchiveFileSet>(); | |||
| for (Resource r : zips) { | |||
| l.add(configureArchive(new ZipFileSet(), r)); | |||
| } | |||
| for (Iterator iter = tars.iterator(); iter.hasNext(); ) { | |||
| l.add(configureArchive(new TarFileSet(), | |||
| (Resource) iter.next())); | |||
| for (Resource r : tars) { | |||
| l.add(configureArchive(new TarFileSet(), r)); | |||
| } | |||
| return l.iterator(); | |||
| } | |||
| @@ -20,6 +20,7 @@ package org.apache.tools.ant.types.resources; | |||
| import java.util.Iterator; | |||
| import org.apache.tools.ant.types.FileSet; | |||
| import org.apache.tools.ant.types.Resource; | |||
| /** | |||
| * Utility FileSet that includes directories for backwards-compatibility | |||
| @@ -46,7 +47,7 @@ public class BCFileSet extends FileSet { | |||
| * @return an Iterator of Resources. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((FileSet) getRef(getProject())).iterator(); | |||
| } | |||
| @@ -37,8 +37,8 @@ import org.apache.tools.ant.types.ResourceCollection; | |||
| */ | |||
| public abstract class BaseResourceCollectionContainer | |||
| extends DataType implements ResourceCollection, Cloneable { | |||
| private List rc = new ArrayList(); | |||
| private Collection coll = null; | |||
| private List<ResourceCollection> rc = new ArrayList<ResourceCollection>(); | |||
| private Collection<Resource> coll = null; | |||
| private boolean cache = true; | |||
| /** | |||
| @@ -134,7 +134,7 @@ public abstract class BaseResourceCollectionContainer | |||
| * are added to this container while the Iterator is in use. | |||
| * @return a "fail-fast" Iterator. | |||
| */ | |||
| public final synchronized Iterator iterator() { | |||
| public final synchronized Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((BaseResourceCollectionContainer) getCheckedRef()).iterator(); | |||
| } | |||
| @@ -211,7 +211,7 @@ public abstract class BaseResourceCollectionContainer | |||
| * Get the nested ResourceCollections. | |||
| * @return List. | |||
| */ | |||
| public final synchronized List getResourceCollections() { | |||
| public final synchronized List<ResourceCollection> getResourceCollections() { | |||
| dieOnCircularReference(); | |||
| return Collections.unmodifiableList(rc); | |||
| } | |||
| @@ -220,7 +220,7 @@ public abstract class BaseResourceCollectionContainer | |||
| * Template method for subclasses to return a Collection object of Resources. | |||
| * @return Collection. | |||
| */ | |||
| protected abstract Collection getCollection(); | |||
| protected abstract Collection<Resource> getCollection(); | |||
| /** | |||
| * Implement clone. The set of nested resource | |||
| @@ -260,7 +260,7 @@ public abstract class BaseResourceCollectionContainer | |||
| return sb.toString(); | |||
| } | |||
| private synchronized Collection cacheCollection() { | |||
| private synchronized Collection<Resource> cacheCollection() { | |||
| if (coll == null || !isCache()) { | |||
| coll = getCollection(); | |||
| } | |||
| @@ -19,6 +19,7 @@ package org.apache.tools.ant.types.resources; | |||
| import java.util.Collection; | |||
| import java.util.Iterator; | |||
| import org.apache.tools.ant.types.Resource; | |||
| /** | |||
| * Base class for a ResourceCollection that wraps a single nested | |||
| @@ -28,9 +29,9 @@ import java.util.Iterator; | |||
| public abstract class BaseResourceCollectionWrapper | |||
| extends AbstractResourceCollectionWrapper { | |||
| private Collection coll = null; | |||
| private Collection<Resource> coll = null; | |||
| protected Iterator createIterator() { | |||
| protected Iterator<Resource> createIterator() { | |||
| return cacheCollection().iterator(); | |||
| } | |||
| @@ -42,9 +43,9 @@ public abstract class BaseResourceCollectionWrapper | |||
| * Template method for subclasses to return a Collection of Resources. | |||
| * @return Collection. | |||
| */ | |||
| protected abstract Collection getCollection(); | |||
| protected abstract Collection<Resource> getCollection(); | |||
| private synchronized Collection cacheCollection() { | |||
| private synchronized Collection<Resource> cacheCollection() { | |||
| if (coll == null || !isCache()) { | |||
| coll = getCollection(); | |||
| } | |||
| @@ -113,13 +113,13 @@ public abstract class ContentTransformingResource extends ResourceDecorator { | |||
| /** | |||
| * Suppress FileProvider, re-implement Appendable | |||
| */ | |||
| public Object as(Class clazz) { | |||
| public <T> T as(Class<T> clazz) { | |||
| if (Appendable.class.isAssignableFrom(clazz)) { | |||
| if (isAppendSupported()) { | |||
| final Appendable a = | |||
| (Appendable) getResource().as(Appendable.class); | |||
| getResource().as(Appendable.class); | |||
| if (a != null) { | |||
| return new Appendable() { | |||
| return clazz.cast(new Appendable() { | |||
| public OutputStream getAppendOutputStream() | |||
| throws IOException { | |||
| OutputStream out = a.getAppendOutputStream(); | |||
| @@ -128,7 +128,7 @@ public abstract class ContentTransformingResource extends ResourceDecorator { | |||
| } | |||
| return out; | |||
| } | |||
| }; | |||
| }); | |||
| } | |||
| } | |||
| return null; | |||
| @@ -17,13 +17,13 @@ | |||
| */ | |||
| package org.apache.tools.ant.types.resources; | |||
| import java.util.List; | |||
| import java.util.HashSet; | |||
| import java.util.Iterator; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.HashSet; | |||
| import java.util.List; | |||
| import java.util.Set; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| /** | |||
| @@ -37,31 +37,26 @@ public class Difference extends BaseResourceCollectionContainer { | |||
| * Calculate the difference of the nested ResourceCollections. | |||
| * @return a Collection of Resources. | |||
| */ | |||
| protected Collection getCollection() { | |||
| List rc = getResourceCollections(); | |||
| int size = rc.size(); | |||
| protected Collection<Resource> getCollection() { | |||
| List<ResourceCollection> rcs = getResourceCollections(); | |||
| int size = rcs.size(); | |||
| if (size < 2) { | |||
| throw new BuildException("The difference of " + size | |||
| + " resource collection" + ((size == 1) ? "" : "s") | |||
| + " is undefined."); | |||
| } | |||
| HashSet hs = new HashSet(); | |||
| ArrayList al = new ArrayList(); | |||
| for (Iterator rcIter = rc.iterator(); rcIter.hasNext();) { | |||
| for (Iterator r = nextRC(rcIter).iterator(); r.hasNext();) { | |||
| Object next = r.next(); | |||
| if (hs.add(next)) { | |||
| al.add(next); | |||
| Set<Resource> hs = new HashSet<Resource>(); | |||
| List<Resource> al = new ArrayList<Resource>(); | |||
| for (ResourceCollection rc : rcs) { | |||
| for (Resource r : rc) { | |||
| if (hs.add(r)) { | |||
| al.add(r); | |||
| } else { | |||
| al.remove(next); | |||
| al.remove(r); | |||
| } | |||
| } | |||
| } | |||
| return al; | |||
| } | |||
| private static ResourceCollection nextRC(Iterator i) { | |||
| return (ResourceCollection) i.next(); | |||
| } | |||
| } | |||
| @@ -23,13 +23,14 @@ import java.util.Iterator; | |||
| import java.util.WeakHashMap; | |||
| import java.util.NoSuchElementException; | |||
| import java.util.ConcurrentModificationException; | |||
| import org.apache.tools.ant.types.Resource; | |||
| /** | |||
| * Helper class for ResourceCollections to return Iterators | |||
| * that fail on changes to the object. | |||
| * @since Ant 1.7 | |||
| */ | |||
| /*package-private*/ class FailFast implements Iterator { | |||
| /*package-private*/ class FailFast implements Iterator<Resource> { | |||
| private static final WeakHashMap MAP = new WeakHashMap(); | |||
| /** | |||
| @@ -67,7 +68,7 @@ import java.util.ConcurrentModificationException; | |||
| } | |||
| private Object parent; | |||
| private Iterator wrapped; | |||
| private Iterator<Resource> wrapped; | |||
| /** | |||
| * Construct a new FailFast Iterator wrapping the specified Iterator | |||
| @@ -75,7 +76,7 @@ import java.util.ConcurrentModificationException; | |||
| * @param o the parent Object. | |||
| * @param i the wrapped Iterator. | |||
| */ | |||
| FailFast(Object o, Iterator i) { | |||
| FailFast(Object o, Iterator<Resource> i) { | |||
| if (o == null) { | |||
| throw new IllegalArgumentException("parent object is null"); | |||
| } | |||
| @@ -106,7 +107,7 @@ import java.util.ConcurrentModificationException; | |||
| * @return the next element. | |||
| * @throws NoSuchElementException if no more elements. | |||
| */ | |||
| public Object next() { | |||
| public Resource next() { | |||
| if (wrapped == null || !wrapped.hasNext()) { | |||
| throw new NoSuchElementException(); | |||
| } | |||
| @@ -262,27 +262,24 @@ public class FileResource extends Resource implements Touchable, FileProvider, | |||
| * @return a negative integer, zero, or a positive integer as this FileResource | |||
| * is less than, equal to, or greater than the specified Resource. | |||
| */ | |||
| public int compareTo(Object another) { | |||
| public int compareTo(Resource another) { | |||
| if (isReference()) { | |||
| return ((Comparable) getCheckedRef()).compareTo(another); | |||
| return ((Resource) getCheckedRef()).compareTo(another); | |||
| } | |||
| if (this.equals(another)) { | |||
| return 0; | |||
| } | |||
| if (another instanceof Resource) { | |||
| Resource r = (Resource) another; | |||
| FileProvider otherFP = (FileProvider) r.as(FileProvider.class); | |||
| if (otherFP != null) { | |||
| File f = getFile(); | |||
| if (f == null) { | |||
| return -1; | |||
| } | |||
| File of = otherFP.getFile(); | |||
| if (of == null) { | |||
| return 1; | |||
| } | |||
| return f.compareTo(of); | |||
| FileProvider otherFP = another.as(FileProvider.class); | |||
| if (otherFP != null) { | |||
| File f = getFile(); | |||
| if (f == null) { | |||
| return -1; | |||
| } | |||
| File of = otherFP.getFile(); | |||
| if (of == null) { | |||
| return 1; | |||
| } | |||
| return f.compareTo(of); | |||
| } | |||
| return super.compareTo(another); | |||
| } | |||
| @@ -22,12 +22,13 @@ import java.util.Iterator; | |||
| import java.util.NoSuchElementException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.types.Resource; | |||
| /** | |||
| * Iterator of FileResources from filenames. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public class FileResourceIterator implements Iterator { | |||
| public class FileResourceIterator implements Iterator<Resource> { | |||
| private Project project; | |||
| private File basedir; | |||
| private String[] files; | |||
| @@ -121,7 +122,7 @@ public class FileResourceIterator implements Iterator { | |||
| * Get the next element from this FileResourceIterator. | |||
| * @return the next Object. | |||
| */ | |||
| public Object next() { | |||
| public Resource next() { | |||
| return nextResource(); | |||
| } | |||
| @@ -27,6 +27,7 @@ import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| import org.apache.tools.ant.types.Reference; | |||
| import org.apache.tools.ant.types.PatternSet; | |||
| import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| import org.apache.tools.ant.types.selectors.FileSelector; | |||
| import org.apache.tools.ant.types.selectors.AbstractSelectorContainer; | |||
| @@ -38,8 +39,8 @@ import org.apache.tools.ant.types.selectors.AbstractSelectorContainer; | |||
| public class Files extends AbstractSelectorContainer | |||
| implements ResourceCollection { | |||
| private static final Iterator EMPTY_ITERATOR | |||
| = Collections.EMPTY_SET.iterator(); | |||
| private static final Iterator<Resource> EMPTY_ITERATOR | |||
| = Collections.<Resource>emptySet().iterator(); | |||
| private PatternSet defaultPatterns = new PatternSet(); | |||
| private Vector additionalPatterns = new Vector(); | |||
| @@ -309,7 +310,7 @@ public class Files extends AbstractSelectorContainer | |||
| * Fulfill the ResourceCollection contract. | |||
| * @return an Iterator of Resources. | |||
| */ | |||
| public synchronized Iterator iterator() { | |||
| public synchronized Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return getRef().iterator(); | |||
| } | |||
| @@ -385,7 +386,7 @@ public class Files extends AbstractSelectorContainer | |||
| if (isReference()) { | |||
| return getRef().toString(); | |||
| } | |||
| Iterator i = iterator(); | |||
| Iterator<Resource> i = iterator(); | |||
| if (!i.hasNext()) { | |||
| return ""; | |||
| } | |||
| @@ -20,6 +20,8 @@ package org.apache.tools.ant.types.resources; | |||
| import java.util.Iterator; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.List; | |||
| import org.apache.tools.ant.types.Resource; | |||
| /** | |||
| * ResourceCollection that contains the first <code>count</code> elements of | |||
| @@ -32,10 +34,10 @@ public class First extends SizeLimitCollection { | |||
| * Take the first <code>count</code> elements. | |||
| * @return a Collection of Resources. | |||
| */ | |||
| protected Collection getCollection() { | |||
| protected Collection<Resource> getCollection() { | |||
| int ct = getValidCount(); | |||
| Iterator iter = getResourceCollection().iterator(); | |||
| ArrayList al = new ArrayList(ct); | |||
| Iterator<Resource> iter = getResourceCollection().iterator(); | |||
| List<Resource> al = new ArrayList<Resource>(ct); | |||
| for (int i = 0; i < ct && iter.hasNext(); i++) { | |||
| al.add(iter.next()); | |||
| } | |||
| @@ -23,6 +23,7 @@ import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| /** | |||
| @@ -36,16 +37,16 @@ public class Intersect extends BaseResourceCollectionContainer { | |||
| * Calculate the intersection of the nested ResourceCollections. | |||
| * @return a Collection of Resources. | |||
| */ | |||
| protected Collection getCollection() { | |||
| List rcs = getResourceCollections(); | |||
| protected Collection<Resource> getCollection() { | |||
| List<ResourceCollection> rcs = getResourceCollections(); | |||
| int size = rcs.size(); | |||
| if (size < 2) { | |||
| throw new BuildException("The intersection of " + size | |||
| + " resource collection" + ((size == 1) ? "" : "s") | |||
| + " is undefined."); | |||
| } | |||
| ArrayList al = new ArrayList(); | |||
| Iterator rc = rcs.iterator(); | |||
| List<Resource> al = new ArrayList<Resource>(); | |||
| Iterator<ResourceCollection> rc = rcs.iterator(); | |||
| al.addAll(collect(rc.next())); | |||
| while (rc.hasNext()) { | |||
| al.retainAll(collect(rc.next())); | |||
| @@ -53,10 +54,10 @@ public class Intersect extends BaseResourceCollectionContainer { | |||
| return al; | |||
| } | |||
| private ArrayList collect(Object o) { | |||
| ArrayList result = new ArrayList(); | |||
| for (Iterator i = ((ResourceCollection) o).iterator(); i.hasNext();) { | |||
| result.add(i.next()); | |||
| private List<Resource> collect(ResourceCollection rc) { | |||
| List<Resource> result = new ArrayList<Resource>(); | |||
| for (Resource r : rc) { | |||
| result.add(r); | |||
| } | |||
| return result; | |||
| } | |||
| @@ -23,6 +23,7 @@ import java.io.InputStream; | |||
| import java.net.URL; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.Resource; | |||
| /** | |||
| * A Resource representation of something loadable via a Java classloader. | |||
| @@ -102,9 +103,9 @@ public class JavaResource extends AbstractClasspathResource | |||
| * JavaResource is less than, equal to, or greater than the | |||
| * specified Resource. | |||
| */ | |||
| public int compareTo(Object another) { | |||
| public int compareTo(Resource another) { | |||
| if (isReference()) { | |||
| return ((Comparable) getCheckedRef()).compareTo(another); | |||
| return ((Resource) getCheckedRef()).compareTo(another); | |||
| } | |||
| if (another.getClass().equals(getClass())) { | |||
| JavaResource otherjr = (JavaResource) another; | |||
| @@ -20,9 +20,11 @@ package org.apache.tools.ant.types.resources; | |||
| import java.util.Iterator; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.List; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| /** | |||
| @@ -36,17 +38,17 @@ public class Last extends SizeLimitCollection { | |||
| * Take the last <code>count</code> elements. | |||
| * @return a Collection of Resources. | |||
| */ | |||
| protected Collection getCollection() { | |||
| protected Collection<Resource> getCollection() { | |||
| int count = getValidCount(); | |||
| ResourceCollection rc = getResourceCollection(); | |||
| int i = count; | |||
| Iterator iter = rc.iterator(); | |||
| Iterator<Resource> iter = rc.iterator(); | |||
| int size = rc.size(); | |||
| for (; i < size; i++) { | |||
| iter.next(); | |||
| } | |||
| ArrayList al = new ArrayList(count); | |||
| List<Resource> al = new ArrayList<Resource>(count); | |||
| for (; iter.hasNext(); i++) { | |||
| al.add(iter.next()); | |||
| } | |||
| @@ -4,7 +4,6 @@ import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import java.util.List; | |||
| import java.util.NoSuchElementException; | |||
| import org.apache.tools.ant.types.Resource; | |||
| /** | |||
| @@ -15,12 +14,12 @@ public class LazyResourceCollectionWrapper extends | |||
| AbstractResourceCollectionWrapper { | |||
| /** List of cached resources */ | |||
| private List cachedResources = new ArrayList(); | |||
| private final List<Resource> cachedResources = new ArrayList<Resource>(); | |||
| private FilteringIterator filteringIterator; | |||
| protected Iterator createIterator() { | |||
| Iterator iterator; | |||
| protected Iterator<Resource> createIterator() { | |||
| Iterator<Resource> iterator; | |||
| if (isCache()) { | |||
| if (filteringIterator == null) { | |||
| // no worry of thread safety here, see function's contract | |||
| @@ -37,7 +36,7 @@ public class LazyResourceCollectionWrapper extends | |||
| protected int getSize() { | |||
| // to compute the size, just iterate: the iterator will take care of | |||
| // caching | |||
| Iterator it = createIterator(); | |||
| Iterator<Resource> it = createIterator(); | |||
| int size = 0; | |||
| while (it.hasNext()) { | |||
| it.next(); | |||
| @@ -57,15 +56,15 @@ public class LazyResourceCollectionWrapper extends | |||
| return false; | |||
| } | |||
| private class FilteringIterator implements Iterator { | |||
| private class FilteringIterator implements Iterator<Resource> { | |||
| Resource next = null; | |||
| boolean ended = false; | |||
| protected final Iterator it; | |||
| protected final Iterator<Resource> it; | |||
| public FilteringIterator(Iterator it) { | |||
| public FilteringIterator(Iterator<Resource> it) { | |||
| this.it = it; | |||
| } | |||
| @@ -78,7 +77,7 @@ public class LazyResourceCollectionWrapper extends | |||
| ended = true; | |||
| return false; | |||
| } | |||
| next = (Resource) it.next(); | |||
| next = it.next(); | |||
| if (filterResource(next)) { | |||
| next = null; | |||
| } | |||
| @@ -86,7 +85,7 @@ public class LazyResourceCollectionWrapper extends | |||
| return true; | |||
| } | |||
| public Object next() { | |||
| public Resource next() { | |||
| if (!hasNext()) { | |||
| throw new UnsupportedOperationException(); | |||
| } | |||
| @@ -104,11 +103,11 @@ public class LazyResourceCollectionWrapper extends | |||
| * Iterator that will put in the shared cache array list the selected | |||
| * resources | |||
| */ | |||
| private class CachedIterator implements Iterator { | |||
| private class CachedIterator implements Iterator<Resource> { | |||
| int cusrsor = 0; | |||
| private final Iterator it; | |||
| private final Iterator<Resource> it; | |||
| /** | |||
| * Default constructor | |||
| @@ -117,7 +116,7 @@ public class LazyResourceCollectionWrapper extends | |||
| * the iterator which will provide the resources to put in | |||
| * cache | |||
| */ | |||
| public CachedIterator(Iterator it) { | |||
| public CachedIterator(Iterator<Resource> it) { | |||
| this.it = it; | |||
| } | |||
| @@ -132,13 +131,13 @@ public class LazyResourceCollectionWrapper extends | |||
| return false; | |||
| } | |||
| // put in cache the next resource | |||
| Resource r = (Resource) it.next(); | |||
| Resource r = it.next(); | |||
| cachedResources.add(r); | |||
| } | |||
| return true; | |||
| } | |||
| public Object next() { | |||
| public Resource next() { | |||
| // first check that we have some to deliver | |||
| if (!hasNext()) { | |||
| throw new NoSuchElementException(); | |||
| @@ -70,7 +70,7 @@ public class MappedResource extends ResourceDecorator { | |||
| * Suppress FileProvider | |||
| * @param clazz the type to implement | |||
| */ | |||
| public Object as(Class clazz) { | |||
| public <T> T as(Class<T> clazz) { | |||
| return FileProvider.class.isAssignableFrom(clazz) | |||
| ? null : getResource().as(clazz); | |||
| } | |||
| @@ -44,7 +44,7 @@ public class MappedResourceCollection | |||
| private Mapper mapper = null; | |||
| private boolean enableMultipleMappings = false; | |||
| private boolean cache = false; | |||
| private Collection cachedColl = null; | |||
| private Collection<Resource> cachedColl = null; | |||
| /** | |||
| * Adds the required nested ResourceCollection. | |||
| @@ -142,7 +142,7 @@ public class MappedResourceCollection | |||
| /** | |||
| * {@inheritDoc} | |||
| */ | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((MappedResourceCollection) getCheckedRef()).iterator(); | |||
| } | |||
| @@ -212,19 +212,18 @@ public class MappedResourceCollection | |||
| dieOnCircularReference(); | |||
| } | |||
| private synchronized Collection cacheCollection() { | |||
| private synchronized Collection<Resource> cacheCollection() { | |||
| if (cachedColl == null || !cache) { | |||
| cachedColl = getCollection(); | |||
| } | |||
| return cachedColl; | |||
| } | |||
| private Collection getCollection() { | |||
| Collection collected = new ArrayList(); | |||
| private Collection<Resource> getCollection() { | |||
| Collection<Resource> collected = new ArrayList<Resource>(); | |||
| FileNameMapper m = | |||
| mapper != null ? mapper.getImplementation() : new IdentityMapper(); | |||
| for (Iterator iter = nested.iterator(); iter.hasNext(); ) { | |||
| Resource r = (Resource) iter.next(); | |||
| for (Resource r : nested) { | |||
| if (enableMultipleMappings) { | |||
| String[] n = m.mapFileName(r.getName()); | |||
| if (n != null) { | |||
| @@ -67,7 +67,7 @@ public abstract class ResourceDecorator extends Resource { | |||
| + " are supported"); | |||
| } | |||
| setChecked(false); | |||
| resource = (Resource) a.iterator().next(); | |||
| resource = a.iterator().next(); | |||
| } | |||
| /** | |||
| @@ -159,14 +159,14 @@ public abstract class ResourceDecorator extends Resource { | |||
| /** | |||
| * {@inheritDoc} | |||
| */ | |||
| public Object as(Class clazz) { | |||
| public <T> T as(Class<T> clazz) { | |||
| return getResource().as(clazz); | |||
| } | |||
| /** | |||
| * {@inheritDoc} | |||
| */ | |||
| public int compareTo(Object other) { | |||
| public int compareTo(Resource other) { | |||
| if (other == this) { | |||
| return 0; | |||
| } | |||
| @@ -112,7 +112,7 @@ public class ResourceList extends DataType implements ResourceCollection { | |||
| * are added to this container while the Iterator is in use. | |||
| * @return a "fail-fast" Iterator. | |||
| */ | |||
| public final synchronized Iterator iterator() { | |||
| public final synchronized Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((ResourceList) getCheckedRef()).iterator(); | |||
| } | |||
| @@ -175,8 +175,8 @@ public class ResourceList extends DataType implements ResourceCollection { | |||
| dieOnCircularReference(); | |||
| for (Iterator iter = textDocuments.iterator(); iter.hasNext(); ) { | |||
| ResourceCollection rc = (ResourceCollection) iter.next(); | |||
| for (Iterator r = rc.iterator(); r.hasNext(); ) { | |||
| cachedResources.add(read((Resource) r.next())); | |||
| for (Resource r : rc) { | |||
| cachedResources.add(read(r)); | |||
| } | |||
| } | |||
| cached = true; | |||
| @@ -31,6 +31,7 @@ import java.util.NoSuchElementException; | |||
| 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.CollectionUtils; | |||
| @@ -45,7 +46,7 @@ public class Resources extends DataType implements ResourceCollection { | |||
| public boolean isFilesystemOnly() { | |||
| return true; | |||
| } | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| return EMPTY_ITERATOR; | |||
| } | |||
| public int size() { | |||
| @@ -54,8 +55,8 @@ public class Resources extends DataType implements ResourceCollection { | |||
| }; | |||
| /** static empty Iterator */ | |||
| public static final Iterator EMPTY_ITERATOR = new Iterator() { | |||
| public Object next() { | |||
| public static final Iterator<Resource> EMPTY_ITERATOR = new Iterator<Resource>() { | |||
| public Resource next() { | |||
| throw new NoSuchElementException(); | |||
| } | |||
| public boolean hasNext() { | |||
| @@ -66,19 +67,19 @@ public class Resources extends DataType implements ResourceCollection { | |||
| } | |||
| }; | |||
| private class MyCollection extends AbstractCollection { | |||
| private Collection cached; | |||
| private class MyCollection extends AbstractCollection<Resource> { | |||
| private Collection<Resource> cached; | |||
| MyCollection() { | |||
| } | |||
| public int size() { | |||
| return getCache().size(); | |||
| } | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| return getCache().iterator(); | |||
| } | |||
| private synchronized Collection getCache() { | |||
| Collection coll = cached; | |||
| private synchronized Collection<Resource> getCache() { | |||
| Collection<Resource> coll = cached; | |||
| if (coll == null) { | |||
| coll = CollectionUtils.asCollection(new MyIterator()); | |||
| if (cache) { | |||
| @@ -87,9 +88,9 @@ public class Resources extends DataType implements ResourceCollection { | |||
| } | |||
| return coll; | |||
| } | |||
| private class MyIterator implements Iterator { | |||
| private class MyIterator implements Iterator<Resource> { | |||
| private Iterator rci = getNested().iterator(); | |||
| private Iterator ri = null; | |||
| private Iterator<Resource> ri = null; | |||
| public boolean hasNext() { | |||
| boolean result = ri != null && ri.hasNext(); | |||
| @@ -99,7 +100,7 @@ public class Resources extends DataType implements ResourceCollection { | |||
| } | |||
| return result; | |||
| } | |||
| public Object next() { | |||
| public Resource next() { | |||
| if (!hasNext()) { | |||
| throw new NoSuchElementException(); | |||
| } | |||
| @@ -112,7 +113,7 @@ public class Resources extends DataType implements ResourceCollection { | |||
| } | |||
| private Vector rc; | |||
| private Collection coll; | |||
| private Collection<Resource> coll; | |||
| private boolean cache = false; | |||
| /** | |||
| @@ -162,7 +163,7 @@ public class Resources extends DataType implements ResourceCollection { | |||
| * Fulfill the ResourceCollection contract. | |||
| * @return an Iterator of Resources. | |||
| */ | |||
| public synchronized Iterator iterator() { | |||
| public synchronized Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return getRef().iterator(); | |||
| } | |||
| @@ -213,11 +214,11 @@ public class Resources extends DataType implements ResourceCollection { | |||
| return ""; | |||
| } | |||
| StringBuffer sb = new StringBuffer(); | |||
| for (Iterator i = coll.iterator(); i.hasNext();) { | |||
| for (Resource r : coll) { | |||
| if (sb.length() > 0) { | |||
| sb.append(File.pathSeparatorChar); | |||
| } | |||
| sb.append(i.next()); | |||
| sb.append(r); | |||
| } | |||
| return sb.toString(); | |||
| } | |||
| @@ -96,7 +96,7 @@ public class Restrict | |||
| * Fulfill the ResourceCollection contract. | |||
| * @return an Iterator of Resources. | |||
| */ | |||
| public final synchronized Iterator iterator() { | |||
| public final synchronized Iterator<Resource> iterator() { | |||
| if (isReference()) { | |||
| return ((Restrict) getCheckedRef()).iterator(); | |||
| } | |||
| @@ -26,6 +26,7 @@ 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.types.resources.comparators.ResourceComparator; | |||
| import org.apache.tools.ant.types.resources.comparators.DelegatedResourceComparator; | |||
| @@ -47,13 +48,13 @@ public class Sort extends BaseResourceCollectionWrapper { | |||
| * Sort the contained elements. | |||
| * @return a Collection of Resources. | |||
| */ | |||
| protected synchronized Collection getCollection() { | |||
| protected synchronized Collection<Resource> getCollection() { | |||
| ResourceCollection rc = getResourceCollection(); | |||
| Iterator iter = rc.iterator(); | |||
| Iterator<Resource> iter = rc.iterator(); | |||
| if (!(iter.hasNext())) { | |||
| return Collections.EMPTY_SET; | |||
| return Collections.emptySet(); | |||
| } | |||
| List result = (List) CollectionUtils.asCollection(iter); | |||
| List<Resource> result = (List<Resource>) CollectionUtils.asCollection(iter); | |||
| Collections.sort(result, comp); | |||
| return result; | |||
| } | |||
| @@ -113,7 +113,7 @@ public class Union extends BaseResourceCollectionContainer { | |||
| * should contain Strings instead of Resources. | |||
| * @return a Collection of Resources. | |||
| */ | |||
| protected Collection getCollection(boolean asString) { | |||
| protected Collection getCollection(boolean asString) { // XXX untypable | |||
| List rc = getResourceCollections(); | |||
| if (rc.isEmpty()) { | |||
| return Collections.EMPTY_LIST; | |||
| @@ -75,7 +75,7 @@ public class ZipResource extends ArchiveResource { | |||
| * @return the zipfile as a File. | |||
| */ | |||
| public File getZipfile() { | |||
| FileProvider fp = (FileProvider) getArchive().as(FileProvider.class); | |||
| FileProvider fp = getArchive().as(FileProvider.class); | |||
| return fp.getFile(); | |||
| } | |||
| @@ -38,13 +38,13 @@ public class FileSystem extends ResourceComparator { | |||
| * @throws ClassCastException if either resource is not an instance of FileResource. | |||
| */ | |||
| protected int resourceCompare(Resource foo, Resource bar) { | |||
| FileProvider fooFP = (FileProvider) foo.as(FileProvider.class); | |||
| FileProvider fooFP = foo.as(FileProvider.class); | |||
| if (fooFP == null) { | |||
| throw new ClassCastException(foo.getClass() | |||
| + " doesn't provide files"); | |||
| } | |||
| File foofile = fooFP.getFile(); | |||
| FileProvider barFP = (FileProvider) bar.as(FileProvider.class); | |||
| FileProvider barFP = bar.as(FileProvider.class); | |||
| if (barFP == null) { | |||
| throw new ClassCastException(bar.getClass() | |||
| + " doesn't provide files"); | |||
| @@ -26,7 +26,7 @@ import org.apache.tools.ant.types.Resource; | |||
| * Abstract Resource Comparator. | |||
| * @since Ant 1.7 | |||
| */ | |||
| public abstract class ResourceComparator extends DataType implements Comparator { | |||
| public abstract class ResourceComparator extends DataType implements Comparator<Resource> { | |||
| /** | |||
| * Compare two objects. | |||
| @@ -36,11 +36,11 @@ public abstract class ResourceComparator extends DataType implements Comparator | |||
| * argument is less than, equal to, or greater than the second. | |||
| * @throws ClassCastException if either argument is null. | |||
| */ | |||
| public final int compare(Object foo, Object bar) { | |||
| public final int compare(Resource foo, Resource bar) { | |||
| dieOnCircularReference(); | |||
| ResourceComparator c = | |||
| isReference() ? (ResourceComparator) getCheckedRef() : this; | |||
| return c.resourceCompare((Resource) foo, (Resource) bar); | |||
| return c.resourceCompare(foo, bar); | |||
| } | |||
| /** | |||
| @@ -111,8 +111,8 @@ public class Compare extends DataType implements ResourceSelector { | |||
| } | |||
| dieOnCircularReference(); | |||
| int t = 0, f = 0; | |||
| for (Iterator it = control.iterator(); it.hasNext();) { | |||
| if (when.evaluate(comp.compare(r, (Resource) it.next()))) { | |||
| for (Resource res : control) { | |||
| if (when.evaluate(comp.compare(r, res))) { | |||
| t++; | |||
| } else { | |||
| f++; | |||
| @@ -39,7 +39,7 @@ public class ReadableSelector implements FileSelector, ResourceSelector { | |||
| } | |||
| public boolean isSelected(Resource r) { | |||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||
| FileProvider fp = r.as(FileProvider.class); | |||
| if (fp != null) { | |||
| return isSelected(null, null, fp.getFile()); | |||
| } | |||
| @@ -39,7 +39,7 @@ public class WritableSelector implements FileSelector, ResourceSelector { | |||
| } | |||
| public boolean isSelected(Resource r) { | |||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||
| FileProvider fp = r.as(FileProvider.class); | |||
| if (fp != null) { | |||
| return isSelected(null, null, fp.getFile()); | |||
| } | |||
| @@ -213,8 +213,8 @@ public class CollectionUtils { | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| public static Collection asCollection(final Iterator iter) { | |||
| List l = new ArrayList(); | |||
| public static <T> Collection<T> asCollection(final Iterator<? extends T> iter) { | |||
| List<T> l = new ArrayList<T>(); | |||
| while (iter.hasNext()) { | |||
| l.add(iter.next()); | |||
| } | |||
| @@ -37,7 +37,7 @@ public class ConcatResourceInputStream extends InputStream { | |||
| private static final int EOF = -1; | |||
| private boolean eof = false; | |||
| private Iterator iter; | |||
| private Iterator<Resource> iter; | |||
| private InputStream currentStream; | |||
| private ProjectComponent managingPc; | |||
| private boolean ignoreErrors = false; | |||
| @@ -189,8 +189,7 @@ public class ResourceUtils { | |||
| source = Union.getInstance(source); | |||
| Union result = new Union(); | |||
| for (Iterator iter = source.iterator(); iter.hasNext();) { | |||
| final Resource sr = (Resource) iter.next(); | |||
| for (Resource sr : source) { | |||
| String srName = sr.getName(); | |||
| srName = srName == null | |||
| ? srName : srName.replace('/', File.separatorChar); | |||
| @@ -223,7 +222,7 @@ public class ResourceUtils { | |||
| r.add(targetColl); | |||
| if (r.size() > 0) { | |||
| result.add(sr); | |||
| Resource t = (Resource) (r.iterator().next()); | |||
| Resource t = r.iterator().next(); | |||
| logTo.log(sr.getName() + " added as " + t.getName() | |||
| + (t.isExists() ? " is outdated." : " doesn\'t exist."), | |||
| Project.MSG_VERBOSE); | |||
| @@ -397,7 +396,7 @@ public class ResourceUtils { | |||
| File destFile = null; | |||
| if (dest.as(FileProvider.class) != null) { | |||
| destFile = ((FileProvider) dest.as(FileProvider.class)).getFile(); | |||
| destFile = dest.as(FileProvider.class).getFile(); | |||
| } | |||
| if (destFile != null && destFile.isFile() && !destFile.canWrite()) { | |||
| if (!force) { | |||
| @@ -504,7 +503,7 @@ public class ResourceUtils { | |||
| } else if (source.as(FileProvider.class) != null | |||
| && destFile != null) { | |||
| File sourceFile = | |||
| ((FileProvider) source.as(FileProvider.class)).getFile(); | |||
| source.as(FileProvider.class).getFile(); | |||
| File parent = destFile.getParentFile(); | |||
| if (parent != null && !parent.isDirectory() | |||
| @@ -557,7 +556,7 @@ public class ResourceUtils { | |||
| } | |||
| } | |||
| if (preserveLastModified) { | |||
| Touchable t = (Touchable) dest.as(Touchable.class); | |||
| Touchable t = dest.as(Touchable.class); | |||
| if (t != null) { | |||
| setLastModified(t, source.getLastModified()); | |||
| } | |||
| @@ -759,16 +758,15 @@ public class ResourceUtils { | |||
| Restrict future = new Restrict(); | |||
| future.add(sel); | |||
| future.add(rc); | |||
| for (Iterator iter = future.iterator(); iter.hasNext();) { | |||
| logTo.log("Warning: " + ((Resource) iter.next()).getName() | |||
| + " modified in the future.", Project.MSG_WARN); | |||
| for (Resource r : future) { | |||
| logTo.log("Warning: " + r.getName() + " modified in the future.", Project.MSG_WARN); | |||
| } | |||
| } | |||
| private static OutputStream getOutputStream(Resource resource, boolean append, Project project) | |||
| throws IOException { | |||
| if (append) { | |||
| Appendable a = (Appendable) resource.as(Appendable.class); | |||
| Appendable a = resource.as(Appendable.class); | |||
| if (a != null) { | |||
| return a.getAppendOutputStream(); | |||
| } | |||
| @@ -249,9 +249,7 @@ public abstract class ScriptRunnerBase { | |||
| * @throws BuildException if a resource cannot be read | |||
| */ | |||
| public void loadResources(ResourceCollection collection) { | |||
| Iterator resources = collection.iterator(); | |||
| while (resources.hasNext()) { | |||
| Resource resource = (Resource) resources.next(); | |||
| for (Resource resource : collection) { | |||
| loadResource(resource); | |||
| } | |||
| } | |||
| @@ -23,9 +23,11 @@ import java.io.File; | |||
| import java.io.InputStream; | |||
| import java.io.IOException; | |||
| import java.util.ArrayList; | |||
| import java.util.Collections; | |||
| import java.util.Iterator; | |||
| import junit.framework.TestCase; | |||
| import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| import org.apache.tools.ant.types.resources.ZipResource; | |||
| @@ -68,10 +70,8 @@ public class ZipExtraFieldTest extends TestCase { | |||
| testInstance.add(new ResourceCollection() { | |||
| public boolean isFilesystemOnly() { return false; } | |||
| public int size() { return 1; } | |||
| public Iterator iterator() { | |||
| ArrayList l = new ArrayList(); | |||
| l.add(r); | |||
| return l.iterator(); | |||
| public Iterator<Resource> iterator() { | |||
| return Collections.<Resource>singleton(r).iterator(); | |||
| } | |||
| }); | |||
| testInstance.execute(); | |||
| @@ -39,7 +39,7 @@ public class LazyResourceCollectionTest extends TestCase { | |||
| return resources.size(); | |||
| } | |||
| public Iterator iterator() { | |||
| public Iterator<Resource> iterator() { | |||
| StringResourceIterator it = new StringResourceIterator(); | |||
| createdIterators.add(it); | |||
| return it; | |||
| @@ -75,7 +75,7 @@ public class LazyResourceCollectionTest extends TestCase { | |||
| LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); | |||
| lazyCollection.add(collectionTest); | |||
| Iterator it = lazyCollection.iterator(); | |||
| Iterator<Resource> it = lazyCollection.iterator(); | |||
| assertOneCreatedIterator(collectionTest); | |||
| StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators | |||
| .get(0); | |||
| @@ -120,9 +120,9 @@ public class LazyResourceCollectionTest extends TestCase { | |||
| lazyCollection.add(collectionTest); | |||
| assertTrue(lazyCollection.isCache()); | |||
| Iterator it1 = lazyCollection.iterator(); | |||
| Iterator<Resource> it1 = lazyCollection.iterator(); | |||
| assertOneCreatedIterator(collectionTest); | |||
| Iterator it2 = lazyCollection.iterator(); | |||
| Iterator<Resource> it2 = lazyCollection.iterator(); | |||
| assertOneCreatedIterator(collectionTest); | |||
| StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators | |||