git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@684721 13f79535-47bb-0310-9956-ffa450edef68master
@@ -221,7 +221,7 @@ leading directory information stripped off. Both <code>to</code> and | |||
<!-- --> | |||
<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 @@ that don't match the <code>from</code> pattern will be ignored.</p> | |||
<!-- --> | |||
<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 @@ 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 <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 @@ with <code><uptodate></code> and <code><junit></code> output.</p> | |||
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"> | |||
@@ -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"); | |||
} | |||
} | |||
/** | |||
@@ -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"); | |||
} | |||
} | |||
/** | |||