From de5b4058b9bb039cdb17082fc543098de598ece2 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Sun, 22 May 2016 16:33:24 +0200
Subject: [PATCH] must not set file and dir in
https://bz.apache.org/bugzilla/show_bug.cgi?id=59402
---
WHATSNEW | 5 +++++
manual/Types/fileset.html | 2 +-
.../ant/taskdefs/AbstractJarSignerTask.java | 1 -
.../tools/ant/types/AbstractFileSet.java | 12 ++++++++++++
src/tests/antunit/types/fileset-test.xml | 18 ++++++++++++++++++
5 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index e01128c18..25a0464f1 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -4,6 +4,11 @@ Changes from Ant 1.9.7 TO Ant 1.9.8
Changes that could break older environments:
-------------------------------------------
+ * // exhibited undefined
+ behavior when both the dir and file attribute have been used on the
+ same instance. This will now cause the build to fail.
+ Bugzilla Report 59402
+
Fixed bugs:
-----------
diff --git a/manual/Types/fileset.html b/manual/Types/fileset.html
index 9a7c7d716..3d901723a 100644
--- a/manual/Types/fileset.html
+++ b/manual/Types/fileset.html
@@ -50,7 +50,7 @@ equivalent to an <and>
selector container.
dir |
the root of the directory tree of this FileSet. |
- Either dir or file must be specified |
+ Exactly one of dir or file must be specified |
file |
diff --git a/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java b/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java
index bc8c03195..c93173b34 100644
--- a/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java
@@ -382,7 +382,6 @@ public abstract class AbstractJarSignerTask extends Task {
FileSet sourceJar = new FileSet();
sourceJar.setProject(getProject());
sourceJar.setFile(jar);
- sourceJar.setDir(jar.getParentFile());
sources.add(sourceJar);
}
return sources;
diff --git a/src/main/org/apache/tools/ant/types/AbstractFileSet.java b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
index 8f274a09e..e3b8aa8ef 100644
--- a/src/main/org/apache/tools/ant/types/AbstractFileSet.java
+++ b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
@@ -67,6 +67,7 @@ public abstract class AbstractFileSet extends DataType
private List selectors = new ArrayList();
private File dir;
+ private boolean fileAttributeUsed;
private boolean useDefaultExcludes = true;
private boolean caseSensitive = true;
private boolean followSymlinks = true;
@@ -131,6 +132,9 @@ public abstract class AbstractFileSet extends DataType
if (isReference()) {
throw tooManyAttributes();
}
+ if (fileAttributeUsed && !getDir().equals(dir)) {
+ throw dirAndFileAreMutuallyExclusive();
+ }
this.dir = dir;
directoryScanner = null;
}
@@ -228,7 +232,11 @@ public abstract class AbstractFileSet extends DataType
if (isReference()) {
throw tooManyAttributes();
}
+ if (getDir() != null) {
+ throw dirAndFileAreMutuallyExclusive();
+ }
setDir(file.getParentFile());
+ fileAttributeUsed = true;
createInclude().setName(file.getName());
}
@@ -919,4 +927,8 @@ public abstract class AbstractFileSet extends DataType
setChecked(true);
}
}
+
+ private BuildException dirAndFileAreMutuallyExclusive() {
+ return new BuildException("you can only specify one of the dir and file attributes");
+ }
}
diff --git a/src/tests/antunit/types/fileset-test.xml b/src/tests/antunit/types/fileset-test.xml
index 9580a1cec..ea39dec8b 100644
--- a/src/tests/antunit/types/fileset-test.xml
+++ b/src/tests/antunit/types/fileset-test.xml
@@ -64,4 +64,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+