git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@718387 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -394,7 +394,8 @@ public class Checksum extends MatchingTask implements Condition { | |||||
| if (resources != null) { | if (resources != null) { | ||||
| for (Iterator i = resources.iterator(); i.hasNext();) { | for (Iterator i = resources.iterator(); i.hasNext();) { | ||||
| Resource r = (Resource) i.next(); | Resource r = (Resource) i.next(); | ||||
| File src = ((FileProvider) r).getFile(); | |||||
| File src = ((FileProvider) r.as(FileProvider.class)) | |||||
| .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. | ||||
| // This is required in order to get the same result | // This is required in order to get the same result | ||||
| @@ -469,8 +469,9 @@ public class Copy extends Task { | |||||
| File baseDir = NULL_FILE_PLACEHOLDER; | File baseDir = NULL_FILE_PLACEHOLDER; | ||||
| String name = r.getName(); | String name = r.getName(); | ||||
| if (r instanceof FileProvider) { | |||||
| FileResource fr = ResourceUtils.asFileResource((FileProvider) r); | |||||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| FileResource fr = ResourceUtils.asFileResource(fp); | |||||
| baseDir = getKeyFile(fr.getBaseDir()); | baseDir = getKeyFile(fr.getBaseDir()); | ||||
| if (fr.getBaseDir() == null) { | if (fr.getBaseDir() == null) { | ||||
| name = fr.getFile().getAbsolutePath(); | name = fr.getFile().getAbsolutePath(); | ||||
| @@ -480,7 +481,7 @@ public class Copy extends Task { | |||||
| // copying of dirs is trivial and can be done | // copying of dirs is trivial and can be done | ||||
| // for non-file resources as well as for real | // for non-file resources as well as for real | ||||
| // files. | // files. | ||||
| if (r.isDirectory() || r instanceof FileProvider) { | |||||
| if (r.isDirectory() || fp != null) { | |||||
| add(baseDir, name, | add(baseDir, name, | ||||
| r.isDirectory() ? dirsByBasedir | r.isDirectory() ? dirsByBasedir | ||||
| : filesByBasedir); | : filesByBasedir); | ||||
| @@ -626,7 +627,8 @@ public class Copy extends Task { | |||||
| throw new BuildException( | throw new BuildException( | ||||
| "Cannot perform operation from directory to file."); | "Cannot perform operation from directory to file."); | ||||
| } else if (rc.size() == 1) { | } else if (rc.size() == 1) { | ||||
| FileProvider r = (FileProvider) rc.iterator().next(); | |||||
| Resource res = (Resource) rc.iterator().next(); | |||||
| FileProvider r = (FileProvider) res.as(FileProvider.class); | |||||
| if (file == null) { | if (file == null) { | ||||
| file = r.getFile(); | file = r.getFile(); | ||||
| rcs.removeElementAt(0); | rcs.removeElementAt(0); | ||||
| @@ -30,6 +30,7 @@ import org.apache.tools.ant.DirectoryScanner; | |||||
| import org.apache.tools.ant.taskdefs.condition.Os; | import org.apache.tools.ant.taskdefs.condition.Os; | ||||
| import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
| 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.resources.FileProvider; | import org.apache.tools.ant.types.resources.FileProvider; | ||||
| import org.apache.tools.ant.types.resources.Sort; | import org.apache.tools.ant.types.resources.Sort; | ||||
| @@ -646,7 +647,9 @@ public class Delete extends MatchingTask { | |||||
| for (Iterator iter = resourcesToDelete.iterator(); iter.hasNext();) { | for (Iterator iter = resourcesToDelete.iterator(); iter.hasNext();) { | ||||
| // 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: | ||||
| File f = ((FileProvider) iter.next()).getFile(); | |||||
| Resource r = (Resource) iter.next(); | |||||
| File f = ((FileProvider) r.as(FileProvider.class)) | |||||
| .getFile(); | |||||
| if (!f.exists()) { | if (!f.exists()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| @@ -99,7 +99,8 @@ 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; | ||||
| this.file = output instanceof FileProvider ? ((FileProvider) output).getFile() : null; | |||||
| FileProvider fp = (FileProvider) output.as(FileProvider.class); | |||||
| this.file = fp != null ? fp.getFile() : null; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -426,8 +426,9 @@ public class ExecuteOn extends ExecTask { | |||||
| File base = null; | File base = null; | ||||
| String name = res.getName(); | String name = res.getName(); | ||||
| if (res instanceof FileProvider) { | |||||
| FileResource fr = ResourceUtils.asFileResource((FileProvider) res); | |||||
| FileProvider fp = (FileProvider) res.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| FileResource fr = ResourceUtils.asFileResource(fp); | |||||
| base = fr.getBaseDir(); | base = fr.getBaseDir(); | ||||
| if (base == null) { | if (base == null) { | ||||
| name = fr.getFile().getAbsolutePath(); | name = fr.getFile().getAbsolutePath(); | ||||
| @@ -139,8 +139,9 @@ public class Expand extends Task { | |||||
| continue; | continue; | ||||
| } | } | ||||
| if (r instanceof FileProvider) { | |||||
| expandFile(FILE_UTILS, ((FileProvider) r).getFile(), dest); | |||||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| expandFile(FILE_UTILS, fp.getFile(), dest); | |||||
| } else { | } else { | ||||
| expandResource(r, dest); | expandResource(r, dest); | ||||
| } | } | ||||
| @@ -45,6 +45,7 @@ import org.apache.tools.ant.types.FileSet; | |||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.types.PatternSet; | import org.apache.tools.ant.types.PatternSet; | ||||
| import org.apache.tools.ant.types.Reference; | import org.apache.tools.ant.types.Reference; | ||||
| 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.FileProvider; | import org.apache.tools.ant.types.resources.FileProvider; | ||||
| import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
| @@ -2313,7 +2314,8 @@ public class Javadoc extends Task { | |||||
| } | } | ||||
| Iterator iter = rc.iterator(); | Iterator iter = rc.iterator(); | ||||
| while (iter.hasNext()) { | while (iter.hasNext()) { | ||||
| sf.addElement(new SourceFile(((FileProvider) iter.next()) | |||||
| Resource r = (Resource) iter.next(); | |||||
| sf.addElement(new SourceFile(((FileProvider) r.as(FileProvider.class)) | |||||
| .getFile())); | .getFile())); | ||||
| } | } | ||||
| } | } | ||||
| @@ -75,8 +75,9 @@ 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"); | ||||
| } | } | ||||
| if (src instanceof FileProvider) { | |||||
| source = ((FileProvider) src).getFile(); | |||||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| source = fp.getFile(); | |||||
| } else if (!supportsNonFileResources()) { | } else if (!supportsNonFileResources()) { | ||||
| throw new BuildException("Only FileSystem resources are supported."); | throw new BuildException("Only FileSystem resources are supported."); | ||||
| } | } | ||||
| @@ -570,9 +570,12 @@ public class SQLExec extends JDBCTask { | |||||
| if (output != null) { | if (output != null) { | ||||
| log("Opening PrintStream to output Resource " + output, Project.MSG_VERBOSE); | log("Opening PrintStream to output Resource " + output, Project.MSG_VERBOSE); | ||||
| OutputStream os; | OutputStream os; | ||||
| if (output instanceof FileProvider) { | |||||
| os = new FileOutputStream(((FileProvider) output).getFile(), append); | |||||
| FileProvider fp = | |||||
| (FileProvider) output.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| os = new FileOutputStream(fp.getFile(), append); | |||||
| } else { | } else { | ||||
| // TODO use Appendable | |||||
| os = output.getOutputStream(); | os = output.getOutputStream(); | ||||
| if (append) { | if (append) { | ||||
| log("Ignoring append=true for non-file resource " + output, Project.MSG_WARN); | log("Ignoring append=true for non-file resource " + output, Project.MSG_WARN); | ||||
| @@ -26,6 +26,7 @@ import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.taskdefs.condition.IsSigned; | import org.apache.tools.ant.taskdefs.condition.IsSigned; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.types.Resource; | |||||
| import org.apache.tools.ant.types.resources.FileProvider; | import org.apache.tools.ant.types.resources.FileProvider; | ||||
| import org.apache.tools.ant.types.resources.FileResource; | import org.apache.tools.ant.types.resources.FileResource; | ||||
| import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
| @@ -322,7 +323,9 @@ public class SignJar extends AbstractJarSignerTask { | |||||
| // deal with the paths | // deal with the paths | ||||
| Iterator iter = sources.iterator(); | Iterator iter = sources.iterator(); | ||||
| while (iter.hasNext()) { | while (iter.hasNext()) { | ||||
| FileResource fr = ResourceUtils.asFileResource((FileProvider) iter.next()); | |||||
| Resource r = (Resource) iter.next(); | |||||
| FileResource fr = ResourceUtils | |||||
| .asFileResource((FileProvider) 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) | ||||
| @@ -561,7 +561,9 @@ public class Tar extends MatchingTask { | |||||
| HashMap basedirToFilesMap = new HashMap(); | HashMap basedirToFilesMap = new HashMap(); | ||||
| Iterator iter = rc.iterator(); | Iterator iter = rc.iterator(); | ||||
| while (iter.hasNext()) { | while (iter.hasNext()) { | ||||
| FileResource r = ResourceUtils.asFileResource((FileProvider) iter.next()); | |||||
| Resource res = (Resource) iter.next(); | |||||
| FileResource r = ResourceUtils | |||||
| .asFileResource((FileProvider) 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; | ||||
| @@ -654,7 +656,8 @@ public class Tar extends MatchingTask { | |||||
| } else if (rc.isFilesystemOnly()) { | } else if (rc.isFilesystemOnly()) { | ||||
| Iterator iter = rc.iterator(); | Iterator iter = rc.iterator(); | ||||
| while (iter.hasNext()) { | while (iter.hasNext()) { | ||||
| File f = ((FileProvider) iter.next()).getFile(); | |||||
| Resource r = (Resource) iter.next(); | |||||
| File f = ((FileProvider) 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 | ||||
| @@ -340,9 +340,10 @@ 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) { | ||||
| if (r instanceof FileProvider) { | |||||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||||
| 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(((FileProvider) r).getFile(), defaultTimestamp); | |||||
| touch(fp.getFile(), defaultTimestamp); | |||||
| } else { | } else { | ||||
| ((Touchable) r.as(Touchable.class)).touch(defaultTimestamp); | ((Touchable) r.as(Touchable.class)).touch(defaultTimestamp); | ||||
| } | } | ||||
| @@ -26,6 +26,7 @@ import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| 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.FileProvider; | import org.apache.tools.ant.types.resources.FileProvider; | ||||
| import org.apache.tools.ant.types.resources.FileResource; | import org.apache.tools.ant.types.resources.FileResource; | ||||
| @@ -126,7 +127,8 @@ public class Truncate extends Task { | |||||
| throw new BuildException(NO_CHILD); | throw new BuildException(NO_CHILD); | ||||
| } | } | ||||
| for (Iterator it = path.iterator(); it.hasNext();) { | for (Iterator it = path.iterator(); it.hasNext();) { | ||||
| File f = ((FileProvider) it.next()).getFile(); | |||||
| Resource r = (Resource) it.next(); | |||||
| File f = ((FileProvider) r.as(FileProvider.class)).getFile(); | |||||
| if (shouldProcess(f)) { | if (shouldProcess(f)) { | ||||
| process(f); | process(f); | ||||
| } | } | ||||
| @@ -91,8 +91,9 @@ 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"); | ||||
| } | } | ||||
| if (src instanceof FileProvider) { | |||||
| source = ((FileProvider) src).getFile(); | |||||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| source = fp.getFile(); | |||||
| } else if (!supportsNonFileResources()) { | } else if (!supportsNonFileResources()) { | ||||
| throw new BuildException( | throw new BuildException( | ||||
| "The source " + src.getName() | "The source " + src.getName() | ||||
| @@ -24,6 +24,7 @@ import org.apache.tools.ant.filters.ChainableReader; | |||||
| import org.apache.tools.ant.types.RedirectorElement; | import org.apache.tools.ant.types.RedirectorElement; | ||||
| import org.apache.tools.ant.types.FilterChain; | import org.apache.tools.ant.types.FilterChain; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.types.Resource; | |||||
| import org.apache.tools.ant.types.resources.FileProvider; | import org.apache.tools.ant.types.resources.FileProvider; | ||||
| import org.apache.tools.ant.types.resources.FileResource; | import org.apache.tools.ant.types.resources.FileResource; | ||||
| @@ -91,7 +92,8 @@ public class VerifyJar extends AbstractJarSignerTask { | |||||
| Path sources = createUnifiedSourcePath(); | Path sources = createUnifiedSourcePath(); | ||||
| Iterator iter = sources.iterator(); | Iterator iter = sources.iterator(); | ||||
| while (iter.hasNext()) { | while (iter.hasNext()) { | ||||
| FileProvider fr = (FileProvider) iter.next(); | |||||
| Resource r = (Resource) iter.next(); | |||||
| FileProvider fr = (FileProvider) r.as(FileProvider.class); | |||||
| verifyOneJar(fr.getFile()); | verifyOneJar(fr.getFile()); | ||||
| } | } | ||||
| @@ -592,8 +592,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| } | } | ||||
| File base = baseDir; | File base = baseDir; | ||||
| String name = r.getName(); | String name = r.getName(); | ||||
| if (r instanceof FileProvider) { | |||||
| FileResource f = ResourceUtils.asFileResource((FileProvider) r); | |||||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| FileResource f = ResourceUtils.asFileResource(fp); | |||||
| base = f.getBaseDir(); | base = f.getBaseDir(); | ||||
| if (base == null) { | if (base == null) { | ||||
| name = f.getFile().getAbsolutePath(); | name = f.getFile().getAbsolutePath(); | ||||
| @@ -989,8 +990,10 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| // If we are here we cannot set the stylesheet as | // If we are here we cannot set the stylesheet as | ||||
| // 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 | ||||
| if (stylesheet instanceof FileProvider) { | |||||
| liaison.setStylesheet(((FileProvider) stylesheet).getFile()); | |||||
| FileProvider fp = | |||||
| (FileProvider) stylesheet.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| liaison.setStylesheet(fp.getFile()); | |||||
| } else { | } else { | ||||
| throw new BuildException(liaison.getClass().toString() | throw new BuildException(liaison.getClass().toString() | ||||
| + " accepts the stylesheet only as a file", getLocation()); | + " accepts the stylesheet only as a file", getLocation()); | ||||
| @@ -244,8 +244,9 @@ 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; | ||||
| if (src instanceof FileProvider) { | |||||
| document = builder.parse(((FileProvider) src).getFile()); | |||||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| document = builder.parse(fp.getFile()); | |||||
| } else { | } else { | ||||
| document = builder.parse(src.getInputStream()); | document = builder.parse(src.getInputStream()); | ||||
| } | } | ||||
| @@ -574,7 +575,7 @@ public class XmlProperty extends org.apache.tools.ant.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"); | ||||
| } | } | ||||
| if (src instanceof FileProvider || supportsNonFileResources()) { | |||||
| if (src.as(FileProvider.class) != null || supportsNonFileResources()) { | |||||
| this.src = src; | this.src = src; | ||||
| } else { | } else { | ||||
| throw new BuildException("Only FileSystem resources are supported."); | throw new BuildException("Only FileSystem resources are supported."); | ||||
| @@ -669,7 +670,8 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| * @return the file attribute. | * @return the file attribute. | ||||
| */ | */ | ||||
| protected File getFile () { | protected File getFile () { | ||||
| return src instanceof FileProvider ? ((FileProvider) src).getFile() : null; | |||||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||||
| return fp != null ? fp.getFile() : null; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -679,8 +681,9 @@ 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(); | ||||
| return f == null ? src : src instanceof FileProvider | |||||
| && ((FileProvider) src).getFile().equals(f) ? src : new FileResource(f); | |||||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||||
| return f == null ? src : fp != null | |||||
| && fp.getFile().equals(f) ? src : new FileResource(f); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -927,8 +927,9 @@ public class Zip extends MatchingTask { | |||||
| continue; | continue; | ||||
| } | } | ||||
| File base = null; | File base = null; | ||||
| if (resources[i] instanceof FileProvider) { | |||||
| base = ResourceUtils.asFileResource((FileProvider) resources[i]).getBaseDir(); | |||||
| FileProvider fp = (FileProvider) resources[i].as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| base = ResourceUtils.asFileResource(fp).getBaseDir(); | |||||
| } | } | ||||
| if (resources[i].isDirectory()) { | if (resources[i].isDirectory()) { | ||||
| if (!name.endsWith("/")) { | if (!name.endsWith("/")) { | ||||
| @@ -940,8 +941,8 @@ public class Zip extends MatchingTask { | |||||
| ArchiveFileSet.DEFAULT_DIR_MODE); | ArchiveFileSet.DEFAULT_DIR_MODE); | ||||
| if (!resources[i].isDirectory()) { | if (!resources[i].isDirectory()) { | ||||
| if (resources[i] instanceof FileProvider) { | |||||
| File f = ((FileProvider) resources[i]).getFile(); | |||||
| if (fp != null) { | |||||
| File f = (fp).getFile(); | |||||
| zipFile(f, zOut, name, ArchiveFileSet.DEFAULT_FILE_MODE); | zipFile(f, zOut, name, ArchiveFileSet.DEFAULT_FILE_MODE); | ||||
| } else { | } else { | ||||
| InputStream is = null; | InputStream is = null; | ||||
| @@ -1321,9 +1322,9 @@ public class Zip extends MatchingTask { | |||||
| } | } | ||||
| for (int j = 0; j < initialResources[i].length; j++) { | for (int j = 0; j < initialResources[i].length; j++) { | ||||
| if (initialResources[i][j] instanceof FileProvider | |||||
| && zipFile.equals(((FileProvider) | |||||
| initialResources[i][j]).getFile())) { | |||||
| FileProvider fp = | |||||
| (FileProvider) initialResources[i][j].as(FileProvider.class); | |||||
| 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()); | ||||
| } | } | ||||
| @@ -28,6 +28,7 @@ import org.apache.tools.ant.Task; | |||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.types.Resource; | |||||
| import org.apache.tools.ant.types.resources.FileProvider; | import org.apache.tools.ant.types.resources.FileProvider; | ||||
| import org.apache.tools.ant.types.resources.FileResource; | import org.apache.tools.ant.types.resources.FileResource; | ||||
| import org.apache.tools.ant.util.ClasspathUtils; | import org.apache.tools.ant.util.ClasspathUtils; | ||||
| @@ -533,7 +534,9 @@ public class EmailTask extends Task { | |||||
| Iterator iter = attachments.iterator(); | Iterator iter = attachments.iterator(); | ||||
| while (iter.hasNext()) { | while (iter.hasNext()) { | ||||
| files.addElement(((FileProvider) iter.next()).getFile()); | |||||
| Resource r = (Resource) iter.next(); | |||||
| files.addElement(((FileProvider) r.as(FileProvider.class)) | |||||
| .getFile()); | |||||
| } | } | ||||
| } | } | ||||
| // let the user know what's going to happen | // let the user know what's going to happen | ||||
| @@ -272,9 +272,10 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware | |||||
| } | } | ||||
| private String resourceToURI(Resource resource) { | private String resourceToURI(Resource resource) { | ||||
| if (resource instanceof FileProvider) { | |||||
| File f = ((FileProvider) resource).getFile(); | |||||
| return FILE_UTILS.toURI(f.getAbsolutePath()); | |||||
| // TODO turn URLResource into Provider | |||||
| FileProvider fp = (FileProvider) resource.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| return FILE_UTILS.toURI(fp.getFile().getAbsolutePath()); | |||||
| } | } | ||||
| if (resource instanceof URLResource) { | if (resource instanceof URLResource) { | ||||
| URL u = ((URLResource) resource).getURL(); | URL u = ((URLResource) resource).getURL(); | ||||
| @@ -166,8 +166,11 @@ public abstract class ArchiveFileSet extends FileSet { | |||||
| * @return the archive in case the archive is a file, null otherwise. | * @return the archive in case the archive is a file, null otherwise. | ||||
| */ | */ | ||||
| public File getSrc() { | public File getSrc() { | ||||
| if (src instanceof FileProvider) { | |||||
| return ((FileProvider) src).getFile(); | |||||
| if (src != null) { | |||||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| return fp.getFile(); | |||||
| } | |||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| @@ -115,8 +115,9 @@ public abstract class ArchiveScanner extends DirectoryScanner { | |||||
| */ | */ | ||||
| public void setSrc(Resource src) { | public void setSrc(Resource src) { | ||||
| this.src = src; | this.src = src; | ||||
| if (src instanceof FileProvider) { | |||||
| srcFile = ((FileProvider) src).getFile(); | |||||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| srcFile = fp.getFile(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -380,7 +380,7 @@ public class Resource extends DataType implements Cloneable, Comparable, Resourc | |||||
| */ | */ | ||||
| public boolean isFilesystemOnly() { | public boolean isFilesystemOnly() { | ||||
| return (isReference() && ((Resource) getCheckedRef()).isFilesystemOnly()) | return (isReference() && ((Resource) getCheckedRef()).isFilesystemOnly()) | ||||
| || this instanceof FileProvider; | |||||
| || this.as(FileProvider.class) != null; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -60,8 +60,9 @@ public class ZipScanner extends ArchiveScanner { | |||||
| ZipFile zf = null; | ZipFile zf = null; | ||||
| File srcFile = null; | File srcFile = null; | ||||
| if (src instanceof FileProvider) { | |||||
| srcFile = ((FileProvider) src).getFile(); | |||||
| FileProvider fp = (FileProvider) src.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| srcFile = fp.getFile(); | |||||
| } else { | } else { | ||||
| throw new BuildException("Only file provider resources are supported"); | throw new BuildException("Only file provider resources are supported"); | ||||
| } | } | ||||
| @@ -28,6 +28,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; | ||||
| /** | /** | ||||
| @@ -158,7 +159,8 @@ public abstract class BaseResourceCollectionContainer | |||||
| /* now check each Resource in case the child only | /* now check each Resource in case the child only | ||||
| lets through files from any children IT may have: */ | lets through files from any children IT may have: */ | ||||
| for (Iterator i = cacheCollection().iterator(); i.hasNext();) { | for (Iterator i = cacheCollection().iterator(); i.hasNext();) { | ||||
| if (!(i.next() instanceof FileProvider)) { | |||||
| Resource r = (Resource) i.next(); | |||||
| if (r.as(FileProvider.class) == null) { | |||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| @@ -25,6 +25,7 @@ import java.util.Collection; | |||||
| 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; | ||||
| /** | /** | ||||
| @@ -122,7 +123,8 @@ public abstract class BaseResourceCollectionWrapper | |||||
| /* now check each Resource in case the child only | /* now check each Resource in case the child only | ||||
| lets through files from any children IT may have: */ | lets through files from any children IT may have: */ | ||||
| for (Iterator i = cacheCollection().iterator(); i.hasNext();) { | for (Iterator i = cacheCollection().iterator(); i.hasNext();) { | ||||
| if (!(i.next() instanceof FileProvider)) { | |||||
| Resource r = (Resource) i.next(); | |||||
| if (r.as(FileProvider.class) == null) { | |||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| @@ -252,16 +252,20 @@ public class FileResource extends Resource implements Touchable, FileProvider, | |||||
| if (this.equals(another)) { | if (this.equals(another)) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| if (another instanceof FileProvider) { | |||||
| File f = getFile(); | |||||
| if (f == null) { | |||||
| return -1; | |||||
| 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); | |||||
| } | } | ||||
| File of = ((FileProvider) another).getFile(); | |||||
| if (of == null) { | |||||
| return 1; | |||||
| } | |||||
| return f.compareTo(of); | |||||
| } | } | ||||
| return super.compareTo(another); | return super.compareTo(another); | ||||
| } | } | ||||
| @@ -38,8 +38,8 @@ 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) { | ||||
| File foofile = ((FileProvider) foo).getFile(); | |||||
| File barfile = ((FileProvider) bar).getFile(); | |||||
| File foofile = ((FileProvider) foo.as(FileProvider.class)).getFile(); | |||||
| File barfile = ((FileProvider) bar.as(FileProvider.class)).getFile(); | |||||
| return foofile.equals(barfile) ? 0 | return foofile.equals(barfile) ? 0 | ||||
| : FILE_UTILS.isLeadingPath(foofile, barfile) ? -1 | : FILE_UTILS.isLeadingPath(foofile, barfile) ? -1 | ||||
| : FILE_UTILS.normalize(foofile.getAbsolutePath()).compareTo( | : FILE_UTILS.normalize(foofile.getAbsolutePath()).compareTo( | ||||
| @@ -39,8 +39,9 @@ public class ReadableSelector implements FileSelector, ResourceSelector { | |||||
| } | } | ||||
| public boolean isSelected(Resource r) { | public boolean isSelected(Resource r) { | ||||
| if (r instanceof FileProvider) { | |||||
| return isSelected(null, null, ((FileProvider) r).getFile()); | |||||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| return isSelected(null, null, fp.getFile()); | |||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| @@ -39,8 +39,9 @@ public class WritableSelector implements FileSelector, ResourceSelector { | |||||
| } | } | ||||
| public boolean isSelected(Resource r) { | public boolean isSelected(Resource r) { | ||||
| if (r instanceof FileProvider) { | |||||
| return isSelected(null, null, ((FileProvider) r).getFile()); | |||||
| FileProvider fp = (FileProvider) r.as(FileProvider.class); | |||||
| if (fp != null) { | |||||
| return isSelected(null, null, fp.getFile()); | |||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| @@ -521,10 +521,12 @@ public class ResourceUtils { | |||||
| } | } | ||||
| /** | /** | ||||
| * Convenience method to turn any fileProvider into a basic FileResource with the | |||||
| * file's immediate parent as the basedir, for tasks that need one. | |||||
| * Convenience method to turn any fileProvider into a basic | |||||
| * FileResource with the file's immediate parent as the basedir, | |||||
| * for tasks that need one. | |||||
| * @param fileProvider input | * @param fileProvider input | ||||
| * @return fileProvider if it is a FileResource instance, or a new FileResource with fileProvider's file. | |||||
| * @return fileProvider if it is a FileResource instance, or a new | |||||
| * FileResource with fileProvider's file. | |||||
| * @since Ant 1.8 | * @since Ant 1.8 | ||||
| */ | */ | ||||
| public static FileResource asFileResource(FileProvider fileProvider) { | public static FileResource asFileResource(FileProvider fileProvider) { | ||||