diff --git a/WHATSNEW b/WHATSNEW
index 6d4d327ad..51a4e4d13 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -20,6 +20,9 @@ Fixed bugs:
* possible NPE in Jar.java.
Bugzilla 40847
+* regression in attribute prefix (+ others) for refid in zipfileset and tarfileset.
+ Bugzilla 41004, 30498
+
Other changes:
--------------
diff --git a/src/main/org/apache/tools/ant/types/ArchiveFileSet.java b/src/main/org/apache/tools/ant/types/ArchiveFileSet.java
index 5876efc0d..bd6541076 100755
--- a/src/main/org/apache/tools/ant/types/ArchiveFileSet.java
+++ b/src/main/org/apache/tools/ant/types/ArchiveFileSet.java
@@ -130,7 +130,6 @@ public abstract class ArchiveFileSet extends FileSet {
* @param srcFile The archive from which to extract entries.
*/
public void setSrc(File srcFile) {
- checkAttributesAllowed();
setSrcResource(new FileResource(srcFile));
}
@@ -141,7 +140,7 @@ public abstract class ArchiveFileSet extends FileSet {
* @param src The archive from which to extract entries.
*/
public void setSrcResource(Resource src) {
- checkAttributesAllowed();
+ checkArchiveAttributesAllowed();
if (hasDir) {
throw new BuildException("Cannot set both dir and src attributes");
}
@@ -178,7 +177,7 @@ public abstract class ArchiveFileSet extends FileSet {
* @param prefix The prefix to prepend to entries in the archive file.
*/
public void setPrefix(String prefix) {
- checkAttributesAllowed();
+ checkArchiveAttributesAllowed();
if (!prefix.equals("") && !fullpath.equals("")) {
throw new BuildException("Cannot set both fullpath and prefix attributes");
}
@@ -204,7 +203,7 @@ public abstract class ArchiveFileSet extends FileSet {
* @param fullpath the full pathname of the single entry in this fileset.
*/
public void setFullpath(String fullpath) {
- checkAttributesAllowed();
+ checkArchiveAttributesAllowed();
if (!prefix.equals("") && !fullpath.equals("")) {
throw new BuildException("Cannot set both fullpath and prefix attributes");
}
@@ -308,7 +307,7 @@ public abstract class ArchiveFileSet extends FileSet {
* @param octalString a String
value
*/
public void setFileMode(String octalString) {
- checkAttributesAllowed();
+ checkArchiveAttributesAllowed();
integerSetFileMode(Integer.parseInt(octalString, BASE_OCTAL));
}
@@ -357,7 +356,7 @@ public abstract class ArchiveFileSet extends FileSet {
* @param octalString a String
value
*/
public void setDirMode(String octalString) {
- checkAttributesAllowed();
+ checkArchiveAttributesAllowed();
integerSetDirMode(Integer.parseInt(octalString, BASE_OCTAL));
}
@@ -477,4 +476,21 @@ public abstract class ArchiveFileSet extends FileSet {
return dirMode;
}
+ /**
+ * A check attributes for archiveFileSet.
+ * If there is a reference, and
+ * it is a ArchiveFileSet, the archive fileset attributes
+ * cannot be used.
+ * (Note, we can only see if the reference is an archive
+ * fileset if the project has been set).
+ */
+ private void checkArchiveAttributesAllowed() {
+ if (getProject() == null
+ || (isReference()
+ && (getRefid().getReferencedObject(
+ getProject())
+ instanceof ArchiveFileSet))) {
+ checkAttributesAllowed();
+ }
+ }
}
diff --git a/src/main/org/apache/tools/ant/types/TarFileSet.java b/src/main/org/apache/tools/ant/types/TarFileSet.java
index 57e7b253d..7d61ae119 100755
--- a/src/main/org/apache/tools/ant/types/TarFileSet.java
+++ b/src/main/org/apache/tools/ant/types/TarFileSet.java
@@ -68,7 +68,7 @@ public class TarFileSet extends ArchiveFileSet {
* @param userName the user name for the tar entry.
*/
public void setUserName(String userName) {
- checkAttributesAllowed();
+ checkTarFileSetAttributesAllowed();
userNameSet = true;
this.userName = userName;
}
@@ -96,7 +96,7 @@ public class TarFileSet extends ArchiveFileSet {
* @param uid the id of the user for the tar entry.
*/
public void setUid(int uid) {
- checkAttributesAllowed();
+ checkTarFileSetAttributesAllowed();
userIdSet = true;
this.uid = uid;
}
@@ -124,7 +124,7 @@ public class TarFileSet extends ArchiveFileSet {
* @param groupName the group name string.
*/
public void setGroup(String groupName) {
- checkAttributesAllowed();
+ checkTarFileSetAttributesAllowed();
groupNameSet = true;
this.groupName = groupName;
}
@@ -152,7 +152,7 @@ public class TarFileSet extends ArchiveFileSet {
* @param gid the group id.
*/
public void setGid(int gid) {
- checkAttributesAllowed();
+ checkTarFileSetAttributesAllowed();
groupIdSet = true;
this.gid = gid;
}
@@ -248,4 +248,21 @@ public class TarFileSet extends ArchiveFileSet {
return super.clone();
}
}
+
+ /**
+ * A check attributes for TarFileSet.
+ * If there is a reference, and
+ * it is a TarFileSet, the tar fileset attributes
+ * cannot be used.
+ */
+ private void checkTarFileSetAttributesAllowed() {
+ if (getProject() == null
+ || (isReference()
+ && (getRefid().getReferencedObject(
+ getProject())
+ instanceof TarFileSet))) {
+ checkAttributesAllowed();
+ }
+ }
+
}
diff --git a/src/main/org/apache/tools/ant/types/ZipFileSet.java b/src/main/org/apache/tools/ant/types/ZipFileSet.java
index bf364b7c2..6fcc66560 100644
--- a/src/main/org/apache/tools/ant/types/ZipFileSet.java
+++ b/src/main/org/apache/tools/ant/types/ZipFileSet.java
@@ -63,7 +63,7 @@ public class ZipFileSet extends ArchiveFileSet {
* @since Ant 1.7
*/
public void setEncoding(String enc) {
- checkAttributesAllowed();
+ checkZipFileSetAttributesAllowed();
this.encoding = enc;
}
@@ -127,4 +127,21 @@ public class ZipFileSet extends ArchiveFileSet {
return super.clone();
}
}
+
+ /**
+ * A check attributes for zipFileSet.
+ * If there is a reference, and
+ * it is a ZipFileSet, the zip fileset attributes
+ * cannot be used.
+ */
+ private void checkZipFileSetAttributesAllowed() {
+ if (getProject() == null
+ || (isReference()
+ && (getRefid().getReferencedObject(
+ getProject())
+ instanceof ZipFileSet))) {
+ checkAttributesAllowed();
+ }
+ }
+
}