Author: bodewig
Date: Wed Oct 29 10:39:27 2008
New Revision: 708948
URL: http://svn.apache.org/viewvc?rev=708948&view=rev
Log:
deal with resources without name in <copy>. PR 39960.
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java
ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java
ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=708948&r1=708947&r2=708948&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Oct 29 10:39:27 2008
@@ -282,6 +282,10 @@
original error is now logged to System.err.
Bugzilla Report 25086.
+ * <copy> failed with a NullPointerException when copying a resource
+ without a name. It will now fail with a meaningful error message.
+ Bugzilla Report 39960.
+
Other changes:
--------------
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java?rev=708948&r1=708947&r2=708948&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java Wed Oct 29
10:39:27 2008
@@ -757,6 +757,13 @@
}
for (int i = 0; i < toCopy.length; i++) {
String[] mappedFiles = mapper.mapFileName(toCopy[i].getName());
+ for (int j = 0; j < mappedFiles.length; j++) {
+ if (mappedFiles[j] == null) {
+ throw new BuildException("Can't copy a resource without a"
+ + " name if the mapper doesn't"
+ + " provide one.");
+ }
+ }
if (!enableMultipleMappings) {
map.put(toCopy[i],
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java?rev=708948&r1=708947&r2=708948&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java Wed
Oct 29 10:39:27 2008
@@ -155,6 +155,11 @@
Project.MSG_VERBOSE);
continue;
}
+ for (int i = 0; i < targetnames.length; i++) {
+ if (targetnames[i] == null) {
+ targetnames[i] = "(no name)";
+ }
+ }
Union targetColl = new Union();
for (int i = 0; i < targetnames.length; i++) {
targetColl.add(targets.getResource(
Modified: ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml?rev=708948&r1=708947&r2=708948&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml Wed Oct 29 10:39:27
2008
@@ -42,4 +42,62 @@
<au:assertFileExists file="${output}/file.txt"/>
</target>
+ <target name="-setupNullByteStreamResource">
+ <mkdir dir="${input}"/>
+ <echo file="${input}/NullByteStreamResource.java"><![CDATA[
+import org.apache.tools.ant.types.Resource;
+import java.io.*;
+public class NullByteStreamResource extends Resource {
+ private long length = 1024;
+
+ public boolean isExists() {
+ return true;
+ }
+
+ public long getLastModified() {
+ return UNKNOWN_DATETIME;
+ }
+
+ public void setLength(long length) {
+ this.length = length;
+ }
+
+ public InputStream getInputStream() {
+ return new InputStream() {
+ int readSoFar = 0;
+
+ public int read() {
+ return readSoFar++ > length ? -1 : 0;
+ }
+ };
+ }
+}
+]]></echo>
+ <mkdir dir="${output}"/>
+ <javac srcdir="${input}" destdir="${output}"/>
+ <typedef name="nullstream" classname="NullByteStreamResource">
+ <classpath>
+ <pathelement location="${output}"/>
+ </classpath>
+ </typedef>
+ </target>
+
+ <target name="testResourceWithoutName"
+ depends="-setupNullByteStreamResource">
+ <au:expectfailure>
+ <copy todir="${output}">
+ <nullstream/>
+ </copy>
+ </au:expectfailure>
+ </target>
+
+ <target name="testResourceWithoutNameWithMergeMapper"
+ depends="-setupNullByteStreamResource">
+ <copy todir="${output}">
+ <nullstream/>
+ <mergemapper to="foo"/>
+ </copy>
+ <au:assertFileExists file="${output}/foo"/>
+ </target>
+
</project>