Browse Source

deal with resources without name in <copy>. PR 39960.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@708948 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
7f3406304a
4 changed files with 74 additions and 0 deletions
  1. +4
    -0
      WHATSNEW
  2. +7
    -0
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  3. +5
    -0
      src/main/org/apache/tools/ant/util/ResourceUtils.java
  4. +58
    -0
      src/tests/antunit/taskdefs/copy-test.xml

+ 4
- 0
WHATSNEW View File

@@ -282,6 +282,10 @@ Fixed bugs:
original error is now logged to System.err. original error is now logged to System.err.
Bugzilla Report 25086. 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: Other changes:
-------------- --------------




+ 7
- 0
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -757,6 +757,13 @@ public class Copy extends Task {
} }
for (int i = 0; i < toCopy.length; i++) { for (int i = 0; i < toCopy.length; i++) {
String[] mappedFiles = mapper.mapFileName(toCopy[i].getName()); 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) { if (!enableMultipleMappings) {
map.put(toCopy[i], map.put(toCopy[i],


+ 5
- 0
src/main/org/apache/tools/ant/util/ResourceUtils.java View File

@@ -155,6 +155,11 @@ public class ResourceUtils {
Project.MSG_VERBOSE); Project.MSG_VERBOSE);
continue; continue;
} }
for (int i = 0; i < targetnames.length; i++) {
if (targetnames[i] == null) {
targetnames[i] = "(no name)";
}
}
Union targetColl = new Union(); Union targetColl = new Union();
for (int i = 0; i < targetnames.length; i++) { for (int i = 0; i < targetnames.length; i++) {
targetColl.add(targets.getResource( targetColl.add(targets.getResource(


+ 58
- 0
src/tests/antunit/taskdefs/copy-test.xml View File

@@ -42,4 +42,62 @@
<au:assertFileExists file="${output}/file.txt"/> <au:assertFileExists file="${output}/file.txt"/>
</target> </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> </project>

Loading…
Cancel
Save