Author: bodewig
Date: Mon Aug 11 04:40:31 2008
New Revision: 684721
URL: http://svn.apache.org/viewvc?rev=684721&view=rev
Log:
explicitly guard against nul values, mark to and from attributes as required.
PR 44790.
Modified:
ant/core/trunk/docs/manual/CoreTypes/mapper.html
ant/core/trunk/src/main/org/apache/tools/ant/util/GlobPatternMapper.java
ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
Modified: ant/core/trunk/docs/manual/CoreTypes/mapper.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/mapper.html?rev=684721&r1=684720&r2=684721&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/mapper.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/mapper.html Mon Aug 11 04:40:31 2008
@@ -221,7 +221,7 @@
<!-- -->
<h4><a name="glob-mapper">glob</a></h4>
-<p>Both <code>to</code> and <code>from</code> define patterns that may
+<p>Both <code>to</code> and <code>from</code> are required and define patterns
that may
contain at most one <code>*</code>. For each source file that matches
the <code>from</code> pattern, a target file name will be constructed
from the <code>to</code> pattern by substituting the <code>*</code> in
@@ -350,7 +350,7 @@
<!-- -->
<h4><a name="regexp-mapper">regexp</a></h4>
-<p>Both <code>to</code> and <code>from</code> define regular
+<p>Both <code>to</code> and <code>from</code> are required and define regular
expressions. If the source file name matches the <code>from</code>
pattern, the target file name will be constructed from the
<code>to</code> pattern, using <code>\0</code> to <code>\9</code> as
@@ -571,6 +571,7 @@
directory separators found in the matched source pattern with dots in the
target
pattern placeholder. This mapper is particularly useful in combination
with <code><uptodate></code> and <code><junit></code> output.</p>
+<p>The to and from attributes are both required.</p>
<b>Example:</b>
<blockquote><pre>
<mapper type="package" from="*Test.java" to="TEST-*Test.xml"/>
@@ -602,6 +603,7 @@
test cases. The mapper shares the sample syntax
as the <a href="#glob-mapper">glob mapper</a>.
</p>
+<p>The to and from attributes are both required.</p>
<b>Example:</b>
<blockquote><pre>
<mapper type="unpackage" from="TEST-*Test.xml"
to="${test.src.dir}/*Test.java">
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/GlobPatternMapper.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/GlobPatternMapper.java?rev=684721&r1=684720&r2=684721&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/GlobPatternMapper.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/GlobPatternMapper.java
Mon Aug 11 04:40:31 2008
@@ -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 @@
* @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 @@
}
prefixLength = fromPrefix.length();
postfixLength = fromPostfix.length();
+ } else {
+ throw new BuildException("this mapper requires a 'from'
attribute");
+ }
}
/**
@@ -112,6 +118,7 @@
* @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 @@
toPrefix = to.substring(0, index);
toPostfix = to.substring(index + 1);
}
+ } else {
+ throw new BuildException("this mapper requires a 'to' attribute");
+ }
}
/**
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java?rev=684721&r1=684720&r2=684721&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
Mon Aug 11 04:40:31 2008
@@ -80,6 +80,7 @@
* @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 @@
throw new BuildException("Cannot load regular expression matcher",
e);
}
+ } else {
+ throw new BuildException("this mapper requires a 'from'
attribute");
+ }
}
/**
@@ -96,7 +100,11 @@
* @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");
+ }
}
/**