diff --git a/src/etc/testcases/taskdefs/length.xml b/src/etc/testcases/taskdefs/length.xml
index e9faf919a..b0ab47f24 100644
--- a/src/etc/testcases/taskdefs/length.xml
+++ b/src/etc/testcases/taskdefs/length.xml
@@ -2,6 +2,7 @@
This is a dummy, used for not existing resources.
* @@ -50,18 +54,20 @@ public class Resource implements Cloneable, Comparable { } /** - * sets the name, lastmodified flag, and exists flag + * Sets the name, lastmodified flag, and exists flag. * * @param name relative path of the resource. Expects * "/" to be used as the directory separator. - * @param exists if true, this resource exists - * @param lastmodified the last modification time of this resource + * @param exists if true, this resource exists. + * @param lastmodified the last modification time of this resource. */ public Resource(String name, boolean exists, long lastmodified) { this(name, exists, lastmodified, false); } /** + * Sets the name, lastmodified flag, exists flag, and directory flag. + * * @param name relative path of the resource. Expects * "/" to be used as the directory separator. * @param exists if true the resource exists @@ -70,14 +76,31 @@ public class Resource implements Cloneable, Comparable { */ public Resource(String name, boolean exists, long lastmodified, boolean directory) { + this(name, exists, lastmodified, directory, UNKNOWN_SIZE); + } + + /** + * Sets the name, lastmodified flag, exists flag, directory flag, and size. + * + * @param name relative path of the resource. Expects + * "/" to be used as the directory separator. + * @param exists if true the resource exists + * @param lastmodified the last modification time of the resource + * @param directory if true, this resource is a directory + * @param size the size of this resource. + */ + public Resource(String name, boolean exists, long lastmodified, + boolean directory, long size) { this.name = name; - this.exists = exists; - this.lastmodified = lastmodified; - this.directory = directory; + setName(name); + setExists(exists); + setLastModified(lastmodified); + setDirectory(directory); + setSize(size); } /** - * name attribute will contain the path of a file relative to the + * Name attribute will contain the path of a file relative to the * root directory of its fileset or the recorded path of a zip * entry. * @@ -86,13 +109,14 @@ public class Resource implements Cloneable, Comparable { * adm/resource.txt. * *"/" will be used as the directory separator.
- * @return the name of this resource + * @return the name of this resource. */ public String getName() { return name; } /** + * Set the name of this Resource. * @param name relative path of the resource. Expects * "/" to be used as the directory separator. */ @@ -101,8 +125,8 @@ public class Resource implements Cloneable, Comparable { } /** - * The exists attribute tells whether a file exists - * @return true if this resource exists + * The exists attribute tells whether a file exists. + * @return true if this resource exists. */ public boolean isExists() { return exists; @@ -110,33 +134,33 @@ public class Resource implements Cloneable, Comparable { /** * Set the exists attribute. - * @param exists if true, this resource exists + * @param exists if true, this resource exists. */ public void setExists(boolean exists) { this.exists = exists; } /** - * tells the modification time in milliseconds since 01.01.1970 of + * Tells the modification time in milliseconds since 01.01.1970 . * * @return 0 if the resource does not exist to mirror the behavior * of {@link java.io.File File}. */ public long getLastModified() { - return !exists || lastmodified < 0 ? 0 : lastmodified; + return !exists || lastmodified < 0 ? 0L : lastmodified; } /** * Set the last modification attribute. - * @param lastmodified the modification time in milliseconds since 01.01.1970 + * @param lastmodified the modification time in milliseconds since 01.01.1970. */ public void setLastModified(long lastmodified) { this.lastmodified = lastmodified; } /** - * tells if the resource is a directory - * @return boolean flag indicating if the resource is a directory + * Tells if the resource is a directory. + * @return boolean flag indicating if the resource is a directory. */ public boolean isDirectory() { return directory; @@ -144,14 +168,34 @@ public class Resource implements Cloneable, Comparable { /** * Set the directory attribute. - * @param directory if true, this resource is a directory + * @param directory if true, this resource is a directory. */ public void setDirectory(boolean directory) { this.directory = directory; } /** - * @return copy of this + * Set the size of this Resource. + * @param size the size, as a long. + * @since Ant 1.7 + */ + public void setSize(long size) { + this.size = (size > UNKNOWN_SIZE) ? size : UNKNOWN_SIZE; + } + + /** + * Get the size of this Resource. + * @return the size, as a long, 0 if the Resource does not exist (for + * compatibility with java.io.File), or UNKNOWN_SIZE if not known. + * @since Ant 1.7 + */ + public long getSize() { + return (exists) ? size : 0L; + } + + /** + * Clone this Resource. + * @return copy of this. */ public Object clone() { try { @@ -163,9 +207,10 @@ public class Resource implements Cloneable, Comparable { } /** - * delegates to a comparison of names. - * @param other the object to compare to - * @return true if this object's name is the same as the other object's name + * Delegates to a comparison of names. + * @param other the object to compare to. + * @return a negative integer, zero, or a positive integer as this Resource + * is less than, equal to, or greater than the specified Resource. * @since Ant 1.6 */ public int compareTo(Object other) { @@ -176,4 +221,5 @@ public class Resource implements Cloneable, Comparable { Resource r = (Resource) other; return getName().compareTo(r.getName()); } + } diff --git a/src/main/org/apache/tools/ant/types/ZipScanner.java b/src/main/org/apache/tools/ant/types/ZipScanner.java index bbcf3bc02..aeda8454c 100644 --- a/src/main/org/apache/tools/ant/types/ZipScanner.java +++ b/src/main/org/apache/tools/ant/types/ZipScanner.java @@ -226,7 +226,8 @@ public class ZipScanner extends DirectoryScanner { myentries.put(new String(entry.getName()), new Resource(entry.getName(), true, entry.getTime(), - entry.isDirectory())); + entry.isDirectory(), + entry.getSize())); } } finally { if (zf != null) { diff --git a/src/testcases/org/apache/tools/ant/taskdefs/LengthTest.java b/src/testcases/org/apache/tools/ant/taskdefs/LengthTest.java index d9470125c..e9b741c99 100755 --- a/src/testcases/org/apache/tools/ant/taskdefs/LengthTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/LengthTest.java @@ -71,4 +71,7 @@ public class LengthTest extends BuildFileTest { executeTarget("testImmutable"); } + public void testZipFileSet() { + executeTarget("testZipFileSet"); + } }