diff --git a/WHATSNEW b/WHATSNEW index 342095898..d91c47676 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -10,6 +10,11 @@ Changes that could break older environments: * The task has been removed since apt itself has been removed with Java8. + * // 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 bc3d02ef9..92d5ace9c 100644 --- a/src/main/org/apache/tools/ant/types/AbstractFileSet.java +++ b/src/main/org/apache/tools/ant/types/AbstractFileSet.java @@ -70,6 +70,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; @@ -134,6 +135,9 @@ public abstract class AbstractFileSet extends DataType if (isReference()) { throw tooManyAttributes(); } + if (fileAttributeUsed && !getDir().equals(dir)) { + throw dirAndFileAreMutuallyExclusive(); + } this.dir = dir; directoryScanner = null; } @@ -231,7 +235,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()); } @@ -943,4 +951,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 @@ + + + + + + + + + + + + + + + + + +