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