git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@986457 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -169,6 +169,13 @@ Other changes: | |||||
| * <copy tofile=""> now also works for non-filesystem resources. | * <copy tofile=""> now also works for non-filesystem resources. | ||||
| Bugzilla Report 49756. | Bugzilla Report 49756. | ||||
| * The <linecontainsregexp> filter now supports a casesensitive | |||||
| attribute. | |||||
| * The <containsregexp> selector now supports casesensitive, multiline | |||||
| and singleline attributes. | |||||
| Bugzilla Report 49764. | |||||
| Changes from Ant 1.8.0 TO Ant 1.8.1 | Changes from Ant 1.8.0 TO Ant 1.8.1 | ||||
| =================================== | =================================== | ||||
| @@ -414,6 +414,12 @@ regular expression matching strings. | |||||
| <i>non-</i>matching lines only. <b>Since Ant 1.7</b></td> | <i>non-</i>matching lines only. <b>Since Ant 1.7</b></td> | ||||
| <td vAlign=top align="center">No</td> | <td vAlign=top align="center">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td vAlign=top>casesensitive</td> | |||||
| <td vAlign=top align="center">Perform a case sensitive | |||||
| match. Default is true. <b>Since Ant 1.8.2</b></td> | |||||
| <td vAlign=top align="center">No</td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| See <a href="regexp.html">Regexp Type</a> for the description of the nested element regexp and of | See <a href="regexp.html">Regexp Type</a> for the description of the nested element regexp and of | ||||
| @@ -557,6 +557,28 @@ | |||||
| match true in every file</td> | match true in every file</td> | ||||
| <td valign="top" align="center">Yes</td> | <td valign="top" align="center">Yes</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">casesensitive</td> | |||||
| <td valign="top">Perform a case sensitive match. Default is | |||||
| true. <em>since Ant 1.8.2</em></td> | |||||
| <td valign="top" align="center">No</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">multiline</td> | |||||
| <td valign="top"> | |||||
| Perform a multi line match. | |||||
| Default is false. <em>since Ant 1.8.2</em></td> | |||||
| <td valign="top" align="center">No</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">singleline</td> | |||||
| <td valign="top"> | |||||
| This allows '.' to match new lines. | |||||
| SingleLine is not to be confused with multiline, SingleLine is a perl | |||||
| regex term, it corresponds to dotall in java regex. | |||||
| Default is false. <em>since Ant 1.8.2</em></td> | |||||
| <td valign="top" align="center">No</td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| <p>Here is an example of how to use the regular expression Selector:</p> | <p>Here is an example of how to use the regular expression Selector:</p> | ||||
| @@ -24,6 +24,7 @@ import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.types.Parameter; | import org.apache.tools.ant.types.Parameter; | ||||
| import org.apache.tools.ant.types.RegularExpression; | import org.apache.tools.ant.types.RegularExpression; | ||||
| import org.apache.tools.ant.util.regexp.Regexp; | import org.apache.tools.ant.util.regexp.Regexp; | ||||
| import org.apache.tools.ant.util.regexp.RegexpUtil; | |||||
| /** | /** | ||||
| * Filter which includes only those lines that contain the user-specified | * Filter which includes only those lines that contain the user-specified | ||||
| @@ -49,9 +50,12 @@ public final class LineContainsRegExp | |||||
| /** Parameter name for the regular expression to filter on. */ | /** Parameter name for the regular expression to filter on. */ | ||||
| private static final String REGEXP_KEY = "regexp"; | private static final String REGEXP_KEY = "regexp"; | ||||
| /** Parameter name for the words to filter on. */ | |||||
| /** Parameter name for the negate attribute. */ | |||||
| private static final String NEGATE_KEY = "negate"; | private static final String NEGATE_KEY = "negate"; | ||||
| /** Parameter name for the casesensitive attribute. */ | |||||
| private static final String CS_KEY = "casesensitive"; | |||||
| /** Vector that holds the expressions that input lines must contain. */ | /** Vector that holds the expressions that input lines must contain. */ | ||||
| private Vector regexps = new Vector(); | private Vector regexps = new Vector(); | ||||
| @@ -63,6 +67,7 @@ public final class LineContainsRegExp | |||||
| private String line = null; | private String line = null; | ||||
| private boolean negate = false; | private boolean negate = false; | ||||
| private int regexpOptions = Regexp.MATCH_DEFAULT; | |||||
| /** | /** | ||||
| * Constructor for "dummy" instances. | * Constructor for "dummy" instances. | ||||
| @@ -118,7 +123,7 @@ public final class LineContainsRegExp | |||||
| RegularExpression regexp | RegularExpression regexp | ||||
| = (RegularExpression) regexps.elementAt(i); | = (RegularExpression) regexps.elementAt(i); | ||||
| Regexp re = regexp.getRegexp(getProject()); | Regexp re = regexp.getRegexp(getProject()); | ||||
| matches = re.matches(line); | |||||
| matches = re.matches(line, regexpOptions); | |||||
| } | } | ||||
| if (matches ^ isNegated()) { | if (matches ^ isNegated()) { | ||||
| break; | break; | ||||
| @@ -182,6 +187,10 @@ public final class LineContainsRegExp | |||||
| LineContainsRegExp newFilter = new LineContainsRegExp(rdr); | LineContainsRegExp newFilter = new LineContainsRegExp(rdr); | ||||
| newFilter.setRegexps(getRegexps()); | newFilter.setRegexps(getRegexps()); | ||||
| newFilter.setNegate(isNegated()); | newFilter.setNegate(isNegated()); | ||||
| newFilter | |||||
| .setCaseSensitive(!RegexpUtil.hasFlag(regexpOptions, | |||||
| Regexp.MATCH_CASE_INSENSITIVE) | |||||
| ); | |||||
| return newFilter; | return newFilter; | ||||
| } | } | ||||
| @@ -193,6 +202,14 @@ public final class LineContainsRegExp | |||||
| negate = b; | negate = b; | ||||
| } | } | ||||
| /** | |||||
| * Whether to match casesensitevly. | |||||
| * @since Ant 1.8.2 | |||||
| */ | |||||
| public void setCaseSensitive(boolean b) { | |||||
| regexpOptions = RegexpUtil.asOptions(b); | |||||
| } | |||||
| /** | /** | ||||
| * Find out whether we have been negated. | * Find out whether we have been negated. | ||||
| * @return boolean negation flag. | * @return boolean negation flag. | ||||
| @@ -215,6 +232,8 @@ public final class LineContainsRegExp | |||||
| regexps.addElement(regexp); | regexps.addElement(regexp); | ||||
| } else if (NEGATE_KEY.equals(params[i].getType())) { | } else if (NEGATE_KEY.equals(params[i].getType())) { | ||||
| setNegate(Project.toBoolean(params[i].getValue())); | setNegate(Project.toBoolean(params[i].getValue())); | ||||
| } else if (CS_KEY.equals(params[i].getType())) { | |||||
| setCaseSensitive(Project.toBoolean(params[i].getValue())); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -24,12 +24,14 @@ import java.io.IOException; | |||||
| import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.types.Parameter; | import org.apache.tools.ant.types.Parameter; | ||||
| import org.apache.tools.ant.types.RegularExpression; | import org.apache.tools.ant.types.RegularExpression; | ||||
| import org.apache.tools.ant.types.Resource; | import org.apache.tools.ant.types.Resource; | ||||
| import org.apache.tools.ant.types.resources.FileResource; | import org.apache.tools.ant.types.resources.FileResource; | ||||
| import org.apache.tools.ant.types.resources.selectors.ResourceSelector; | import org.apache.tools.ant.types.resources.selectors.ResourceSelector; | ||||
| import org.apache.tools.ant.util.regexp.Regexp; | import org.apache.tools.ant.util.regexp.Regexp; | ||||
| import org.apache.tools.ant.util.regexp.RegexpUtil; | |||||
| /** | /** | ||||
| * Selector that filters files based on a regular expression. | * Selector that filters files based on a regular expression. | ||||
| @@ -42,8 +44,17 @@ public class ContainsRegexpSelector extends BaseExtendSelector | |||||
| private String userProvidedExpression = null; | private String userProvidedExpression = null; | ||||
| private RegularExpression myRegExp = null; | private RegularExpression myRegExp = null; | ||||
| private Regexp myExpression = null; | private Regexp myExpression = null; | ||||
| private boolean caseSensitive = true; | |||||
| private boolean multiLine = false; | |||||
| private boolean singleLine = false; | |||||
| /** Key to used for parameterized custom selector */ | /** Key to used for parameterized custom selector */ | ||||
| public static final String EXPRESSION_KEY = "expression"; | public static final String EXPRESSION_KEY = "expression"; | ||||
| /** Parameter name for the casesensitive attribute. */ | |||||
| private static final String CS_KEY = "casesensitive"; | |||||
| /** Parameter name for the multiline attribute. */ | |||||
| private static final String ML_KEY = "multiline"; | |||||
| /** Parameter name for the singleline attribute. */ | |||||
| private static final String SL_KEY = "singleline"; | |||||
| /** | /** | ||||
| * Creates a new <code>ContainsRegexpSelector</code> instance. | * Creates a new <code>ContainsRegexpSelector</code> instance. | ||||
| @@ -71,6 +82,34 @@ public class ContainsRegexpSelector extends BaseExtendSelector | |||||
| this.userProvidedExpression = theexpression; | this.userProvidedExpression = theexpression; | ||||
| } | } | ||||
| /** | |||||
| * Whether to ignore case or not. | |||||
| * @param b if false, ignore case. | |||||
| * @since Ant 1.8.2 | |||||
| */ | |||||
| public void setCaseSensitive(boolean b) { | |||||
| caseSensitive = b; | |||||
| } | |||||
| /** | |||||
| * Whether to match should be multiline. | |||||
| * @param b the value to set. | |||||
| * @since Ant 1.8.2 | |||||
| */ | |||||
| public void setMultiLine(boolean b) { | |||||
| multiLine = b; | |||||
| } | |||||
| /** | |||||
| * Whether to treat input as singleline ('.' matches newline). | |||||
| * Corresponsds to java.util.regex.Pattern.DOTALL. | |||||
| * @param b the value to set. | |||||
| * @since Ant 1.8.2 | |||||
| */ | |||||
| public void setSingleLine(boolean b) { | |||||
| singleLine = b; | |||||
| } | |||||
| /** | /** | ||||
| * When using this as a custom selector, this method will be called. | * When using this as a custom selector, this method will be called. | ||||
| * It translates each parameter into the appropriate setXXX() call. | * It translates each parameter into the appropriate setXXX() call. | ||||
| @@ -84,6 +123,13 @@ public class ContainsRegexpSelector extends BaseExtendSelector | |||||
| String paramname = parameters[i].getName(); | String paramname = parameters[i].getName(); | ||||
| if (EXPRESSION_KEY.equalsIgnoreCase(paramname)) { | if (EXPRESSION_KEY.equalsIgnoreCase(paramname)) { | ||||
| setExpression(parameters[i].getValue()); | setExpression(parameters[i].getValue()); | ||||
| } else if (CS_KEY.equalsIgnoreCase(paramname)) { | |||||
| setCaseSensitive(Project | |||||
| .toBoolean(parameters[i].getValue())); | |||||
| } else if (ML_KEY.equalsIgnoreCase(paramname)) { | |||||
| setMultiLine(Project.toBoolean(parameters[i].getValue())); | |||||
| } else if (SL_KEY.equalsIgnoreCase(paramname)) { | |||||
| setSingleLine(Project.toBoolean(parameters[i].getValue())); | |||||
| } else { | } else { | ||||
| setError("Invalid parameter " + paramname); | setError("Invalid parameter " + paramname); | ||||
| } | } | ||||
| @@ -148,7 +194,10 @@ public class ContainsRegexpSelector extends BaseExtendSelector | |||||
| while (teststr != null) { | while (teststr != null) { | ||||
| if (myExpression.matches(teststr)) { | |||||
| if (myExpression.matches(teststr, | |||||
| RegexpUtil.asOptions(caseSensitive, | |||||
| multiLine, | |||||
| singleLine))) { | |||||
| return true; | return true; | ||||
| } | } | ||||
| teststr = in.readLine(); | teststr = in.readLine(); | ||||