Author: bodewig
Date: Tue Aug 17 19:16:19 2010
New Revision: 986457

URL: http://svn.apache.org/viewvc?rev=986457&view=rev
Log:
support casesensitive in linecontainsregexp and casesensitive, multiline and 
singleline in containsregexp.  PR 49764

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/Types/filterchain.html
    ant/core/trunk/docs/manual/Types/selectors.html
    ant/core/trunk/src/main/org/apache/tools/ant/filters/LineContainsRegExp.java
    
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java

Modified: ant/core/trunk/WHATSNEW
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=986457&r1=986456&r2=986457&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Aug 17 19:16:19 2010
@@ -169,6 +169,13 @@ Other changes:
  * <copy tofile=""> now also works for non-filesystem resources.
    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 
 ===================================
 

Modified: ant/core/trunk/docs/manual/Types/filterchain.html
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/Types/filterchain.html?rev=986457&r1=986456&r2=986457&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/Types/filterchain.html (original)
+++ ant/core/trunk/docs/manual/Types/filterchain.html Tue Aug 17 19:16:19 2010
@@ -414,6 +414,12 @@ regular expression matching strings.
       <i>non-</i>matching lines only. <b>Since Ant 1.7</b></td>
     <td vAlign=top align="center">No</td>
   </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>
 
 See <a href="regexp.html">Regexp Type</a> for the description of the nested 
element regexp and of

Modified: ant/core/trunk/docs/manual/Types/selectors.html
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/Types/selectors.html?rev=986457&r1=986456&r2=986457&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/Types/selectors.html (original)
+++ ant/core/trunk/docs/manual/Types/selectors.html Tue Aug 17 19:16:19 2010
@@ -557,6 +557,28 @@
         match true in every file</td>
         <td valign="top" align="center">Yes</td>
       </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>
 
     <p>Here is an example of how to use the regular expression Selector:</p>

Modified: 
ant/core/trunk/src/main/org/apache/tools/ant/filters/LineContainsRegExp.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/filters/LineContainsRegExp.java?rev=986457&r1=986456&r2=986457&view=diff
==============================================================================
--- 
ant/core/trunk/src/main/org/apache/tools/ant/filters/LineContainsRegExp.java 
(original)
+++ 
ant/core/trunk/src/main/org/apache/tools/ant/filters/LineContainsRegExp.java 
Tue Aug 17 19:16:19 2010
@@ -24,6 +24,7 @@ import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.Parameter;
 import org.apache.tools.ant.types.RegularExpression;
 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
@@ -49,9 +50,12 @@ public final class LineContainsRegExp
     /** Parameter name for the regular expression to filter on. */
     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";
 
+    /** Parameter name for the casesensitive attribute. */
+    private static final String CS_KEY = "casesensitive";
+
     /** Vector that holds the expressions that input lines must contain. */
     private Vector regexps = new Vector();
 
@@ -63,6 +67,7 @@ public final class LineContainsRegExp
     private String line = null;
 
     private boolean negate = false;
+    private int regexpOptions = Regexp.MATCH_DEFAULT;
 
     /**
      * Constructor for "dummy" instances.
@@ -118,7 +123,7 @@ public final class LineContainsRegExp
                     RegularExpression regexp
                         = (RegularExpression) regexps.elementAt(i);
                     Regexp re = regexp.getRegexp(getProject());
-                    matches = re.matches(line);
+                    matches = re.matches(line, regexpOptions);
                 }
                 if (matches ^ isNegated()) {
                     break;
@@ -182,6 +187,10 @@ public final class LineContainsRegExp
         LineContainsRegExp newFilter = new LineContainsRegExp(rdr);
         newFilter.setRegexps(getRegexps());
         newFilter.setNegate(isNegated());
+        newFilter
+            .setCaseSensitive(!RegexpUtil.hasFlag(regexpOptions,
+                                                  
Regexp.MATCH_CASE_INSENSITIVE)
+                              );
         return newFilter;
     }
 
@@ -194,6 +203,14 @@ public final class LineContainsRegExp
     }
 
     /**
+     * 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.
      * @return boolean negation flag.
      */
@@ -215,6 +232,8 @@ public final class LineContainsRegExp
                     regexps.addElement(regexp);
                 } else if (NEGATE_KEY.equals(params[i].getType())) {
                     setNegate(Project.toBoolean(params[i].getValue()));
+                } else if (CS_KEY.equals(params[i].getType())) {
+                    setCaseSensitive(Project.toBoolean(params[i].getValue()));
                 }
             }
         }

Modified: 
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java?rev=986457&r1=986456&r2=986457&view=diff
==============================================================================
--- 
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
 (original)
+++ 
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
 Tue Aug 17 19:16:19 2010
@@ -24,12 +24,14 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 
 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.RegularExpression;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.types.resources.selectors.ResourceSelector;
 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.
@@ -42,8 +44,17 @@ public class ContainsRegexpSelector exte
     private String userProvidedExpression = null;
     private RegularExpression myRegExp = null;
     private Regexp myExpression = null;
+    private boolean caseSensitive = true;
+    private boolean multiLine = false;
+    private boolean singleLine = false;
     /** Key to used for parameterized custom selector */
     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.
@@ -72,6 +83,34 @@ public class ContainsRegexpSelector exte
     }
 
     /**
+     * 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.
      * It translates each parameter into the appropriate setXXX() call.
      *
@@ -84,6 +123,13 @@ public class ContainsRegexpSelector exte
                 String paramname = parameters[i].getName();
                 if (EXPRESSION_KEY.equalsIgnoreCase(paramname)) {
                     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 {
                     setError("Invalid parameter " + paramname);
                 }
@@ -148,7 +194,10 @@ public class ContainsRegexpSelector exte
 
             while (teststr != null) {
 
-                if (myExpression.matches(teststr)) {
+                if (myExpression.matches(teststr,
+                                         RegexpUtil.asOptions(caseSensitive,
+                                                              multiLine,
+                                                              singleLine))) {
                     return true;
                 }
                 teststr = in.readLine();


Reply via email to