| @@ -7,6 +7,9 @@ Fixed bugs: | |||||
| * Fixed NullPointerException in ChainedMapper | * Fixed NullPointerException in ChainedMapper | ||||
| Bugzilla Report 62086 | Bugzilla Report 62086 | ||||
| * Fixed NullPointerException when a mappedresource is used in pathconvert | |||||
| Bugzilla Report 62076 | |||||
| Changes from Ant 1.10.1 TO Ant 1.10.2 | Changes from Ant 1.10.1 TO Ant 1.10.2 | ||||
| ===================================== | ===================================== | ||||
| @@ -17,6 +17,8 @@ | |||||
| --> | --> | ||||
| <project name="pathconvert"> | <project name="pathconvert"> | ||||
| <import file="../buildfiletest-base.xml"/> | |||||
| <path id="testpath"> | <path id="testpath"> | ||||
| <pathelement path="${ant.file}" /> | <pathelement path="${ant.file}" /> | ||||
| </path> | </path> | ||||
| @@ -39,4 +41,20 @@ | |||||
| <pathconvert property="result" refid="testpath" /> | <pathconvert property="result" refid="testpath" /> | ||||
| </target> | </target> | ||||
| <target name="test-nonmatching-mapper" description="test for bug fix bz-62076"> | |||||
| <mkdir dir="${output}/mapper-source-dir"/> | |||||
| <!-- create 2 files, one of which will be matched/included by the globmapper | |||||
| later in this target --> | |||||
| <touch file="${output}/mapper-source-dir/file1.txt"/> | |||||
| <touch file="${output}/mapper-source-dir/file2.log"/> | |||||
| <pathconvert property="pc"> | |||||
| <mappedresources> | |||||
| <fileset dir="${output}/mapper-source-dir"/> | |||||
| <!-- we intentionally exclude one of the files --> | |||||
| <globmapper from="*.log" to="*.txt"/> | |||||
| </mappedresources> | |||||
| </pathconvert> | |||||
| </target> | |||||
| </project> | </project> | ||||
| @@ -50,6 +50,14 @@ public class IdentityMapper implements FileNameMapper { | |||||
| */ | */ | ||||
| @Override | @Override | ||||
| public String[] mapFileName(String sourceFileName) { | public String[] mapFileName(String sourceFileName) { | ||||
| return new String[] { sourceFileName }; | |||||
| if (sourceFileName == null) { | |||||
| // The FileNameMapper#mapFileName contract states that: | |||||
| // "if the given rule doesn't apply to the source file, | |||||
| // implementation must return null" | |||||
| // we consider a null source file name as non-matching and | |||||
| // hence return null | |||||
| return null; | |||||
| } | |||||
| return new String[] {sourceFileName}; | |||||
| } | } | ||||
| } | } | ||||
| @@ -57,6 +57,17 @@ public class PathConvertTest { | |||||
| buildRule.executeTarget("testnotargetos"); | buildRule.executeTarget("testnotargetos"); | ||||
| } | } | ||||
| /** | |||||
| * Tests that if a {@code mappedresource}, that excludes certain resources, is used in a {@code pathconvert}, | |||||
| * then it doesn't lead to a {@link NullPointerException}. | |||||
| * | |||||
| * @see <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=62076">bz-62076</a> for more details | |||||
| */ | |||||
| @Test | |||||
| public void testNonMatchingMapper() { | |||||
| buildRule.executeTarget("test-nonmatching-mapper"); | |||||
| } | |||||
| private void test(String target) { | private void test(String target) { | ||||
| buildRule.executeTarget(target); | buildRule.executeTarget(target); | ||||
| assertEquals("test#" + BUILD_FILENAME, buildRule.getProject().getProperty("result")); | assertEquals("test#" + BUILD_FILENAME, buildRule.getProject().getProperty("result")); | ||||