Browse Source

must not set file and dir in <fileset>

https://bz.apache.org/bugzilla/show_bug.cgi?id=59402
master
Stefan Bodewig 9 years ago
parent
commit
de5b4058b9
5 changed files with 36 additions and 2 deletions
  1. +5
    -0
      WHATSNEW
  2. +1
    -1
      manual/Types/fileset.html
  3. +0
    -1
      src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java
  4. +12
    -0
      src/main/org/apache/tools/ant/types/AbstractFileSet.java
  5. +18
    -0
      src/tests/antunit/types/fileset-test.xml

+ 5
- 0
WHATSNEW View File

@@ -4,6 +4,11 @@ Changes from Ant 1.9.7 TO Ant 1.9.8
Changes that could break older environments:
-------------------------------------------

* <fileset>/<zipfileset>/<tarfileset> 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:
-----------



+ 1
- 1
manual/Types/fileset.html View File

@@ -50,7 +50,7 @@ equivalent to an <code>&lt;and&gt;</code> selector container.</p>
<tr>
<td valign="top">dir</td>
<td valign="top">the root of the directory tree of this FileSet.</td>
<td valign="middle" align="center" rowspan="2">Either dir or file must be specified</td>
<td valign="middle" align="center" rowspan="2">Exactly one of dir or file must be specified</td>
</tr>
<tr>
<td valign="top">file</td>


+ 0
- 1
src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java View File

@@ -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;


+ 12
- 0
src/main/org/apache/tools/ant/types/AbstractFileSet.java View File

@@ -67,6 +67,7 @@ public abstract class AbstractFileSet extends DataType
private List<FileSelector> selectors = new ArrayList<FileSelector>();

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");
}
}

+ 18
- 0
src/tests/antunit/types/fileset-test.xml View File

@@ -64,4 +64,22 @@
<au:assertLogContains text="fileset-test.xml"/>
</target>

<target name="test-fileset-dir-and-file-exception">
<mkdir dir="${output}"/>
<au:expectfailure expectedmessage="you can only specify one of the dir and file attributes">
<copy todir="${output}">
<fileset dir="foo" file="bar" />
</copy>
</au:expectfailure>
</target>

<target name="test-fileset-file-and-dir-exception">
<mkdir dir="${output}"/>
<au:expectfailure expectedmessage="you can only specify one of the dir and file attributes">
<copy todir="${output}">
<fileset file="bar" dir="foo"/>
</copy>
</au:expectfailure>
</target>

</project>

Loading…
Cancel
Save