From 3f609f9775af802508e9d11307aec587cd9ff521 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig Both Both Both Both The to and from attributes are both required.to
and
glob
-to
and from
define patterns that may
+to
and from
are required and define patterns that may
contain at most one *
. For each source file that matches
the from
pattern, a target file name will be constructed
from the to
pattern by substituting the *
in
@@ -350,7 +350,7 @@ that don't match the from
pattern will be ignored.regexp
-to
and from
define regular
+to
and from
are required and define regular
expressions. If the source file name matches the from
pattern, the target file name will be constructed from the
to
pattern, using \0
to \9
as
@@ -571,6 +571,7 @@ the package mapper replaces
directory separators found in the matched source pattern with dots in the target
pattern placeholder. This mapper is particularly useful in combination
with <uptodate>
and <junit>
output.
<mapper type="package" from="*Test.java" to="TEST-*Test.xml"/>
@@ -602,6 +603,7 @@ with
<uptodate>
and <junit>
output.
The to and from attributes are both required.
Example:<mapper type="unpackage" from="TEST-*Test.xml" to="${test.src.dir}/*Test.java"> diff --git a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java index 24f4fede4..9aabf969b 100644 --- a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java +++ b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java @@ -18,6 +18,8 @@ package org.apache.tools.ant.util; +import org.apache.tools.ant.BuildException; + /** * Implementation of FileNameMapper that does simple wildcard pattern * replacements. @@ -95,6 +97,7 @@ public class GlobPatternMapper implements FileNameMapper { * @param from a string */ public void setFrom(String from) { + if (from != null) { int index = from.lastIndexOf("*"); if (index == -1) { fromPrefix = from; @@ -105,6 +108,9 @@ public class GlobPatternMapper implements FileNameMapper { } prefixLength = fromPrefix.length(); postfixLength = fromPostfix.length(); + } else { + throw new BuildException("this mapper requires a 'from' attribute"); + } } /** @@ -112,6 +118,7 @@ public class GlobPatternMapper implements FileNameMapper { * @param to a string */ public void setTo(String to) { + if (to != null) { int index = to.lastIndexOf("*"); if (index == -1) { toPrefix = to; @@ -120,6 +127,9 @@ public class GlobPatternMapper implements FileNameMapper { toPrefix = to.substring(0, index); toPostfix = to.substring(index + 1); } + } else { + throw new BuildException("this mapper requires a 'to' attribute"); + } } /** diff --git a/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java b/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java index 51ad6e652..2971daaed 100644 --- a/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java +++ b/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java @@ -80,6 +80,7 @@ public class RegexpPatternMapper implements FileNameMapper { * @throws BuildException on error. */ public void setFrom(String from) throws BuildException { + if (from != null) { try { reg.setPattern(from); } catch (NoClassDefFoundError e) { @@ -88,6 +89,9 @@ public class RegexpPatternMapper implements FileNameMapper { throw new BuildException("Cannot load regular expression matcher", e); } + } else { + throw new BuildException("this mapper requires a 'from' attribute"); + } } /** @@ -96,7 +100,11 @@ public class RegexpPatternMapper implements FileNameMapper { * @throws BuildException on error. */ public void setTo(String to) { + if (to != null) { this.to = to.toCharArray(); + } else { + throw new BuildException("this mapper requires a 'to' attribute"); + } } /**