ant.regexp.regexpimpl as a normal project property PR: 15390 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275722 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -333,19 +333,8 @@ Convenience method: | |||||
| Filter which includes only those lines that contain the user-specified | Filter which includes only those lines that contain the user-specified | ||||
| regular expression matching strings. | regular expression matching strings. | ||||
| <TABLE cellSpacing=0 cellPadding=2 border=1> | |||||
| <TR> | |||||
| <TD vAlign=top><B>Parameter Type</B></TD> | |||||
| <TD vAlign=top><B>Parameter Value</B></TD> | |||||
| <TD vAlign=top align="center"><B>Required</B></TD> | |||||
| </TR> | |||||
| <TR> | |||||
| <TD vAlign=top>regexp</TD> | |||||
| <TD vAlign=top align="center">Pattern of the substring to be searched for.</TD> | |||||
| <TD vAlign=top align="center">Yes</TD> | |||||
| </TR> | |||||
| </TABLE> | |||||
| <P> | |||||
| See <a href="../CoreTypes/regexp.html">Regexp Type</a> for the description of the nested element regexp and of | |||||
| the choice of regular expression implementation. | |||||
| <H4>Example:</H4> | <H4>Example:</H4> | ||||
| This will fetch all those lines that contain the pattern <code>foo</code> | This will fetch all those lines that contain the pattern <code>foo</code> | ||||
| @@ -1112,10 +1101,12 @@ Include only lines that contain "foo"; | |||||
| </PRE></BLOCKQUOTE> | </PRE></BLOCKQUOTE> | ||||
| <p><b><em><a name="replaceregex">ReplaceRegex</a></em></b></p> | <p><b><em><a name="replaceregex">ReplaceRegex</a></em></b></p> | ||||
| This string filter replaces regular expressions. See | |||||
| <a href="../OptionalTasks/replaceregexp.html">ReplaceRegexp</a> | |||||
| for an explanation on regular expressions. | |||||
| This string filter replaces regular expressions. | |||||
| This filter may be used directly within a filterchain. | This filter may be used directly within a filterchain. | ||||
| <p> | |||||
| See <a href="../CoreTypes/regexp.html#implementation">Regexp Type</a> | |||||
| concerning the choice of the implementation. | |||||
| </p> | |||||
| <TABLE cellSpacing=0 cellPadding=2 border=1> | <TABLE cellSpacing=0 cellPadding=2 border=1> | ||||
| <TR> | <TR> | ||||
| @@ -1143,7 +1134,6 @@ for an explanation of regex flags.</TD> | |||||
| <TD vAlign=top align="center">No</TD> | <TD vAlign=top align="center">No</TD> | ||||
| </TR> | </TR> | ||||
| </TABLE> | </TABLE> | ||||
| <H4>Examples:</H4> | <H4>Examples:</H4> | ||||
| Replace all occurances of "hello" with "world", ignoring case. | Replace all occurances of "hello" with "world", ignoring case. | ||||
| @@ -1158,11 +1148,12 @@ Replace all occurances of "hello" with "world", ignoring case. | |||||
| <p><b><em><a name="containsregex">ContainsRegex</a></em></b></p> | <p><b><em><a name="containsregex">ContainsRegex</a></em></b></p> | ||||
| This filters strings that match regular expressions. | This filters strings that match regular expressions. | ||||
| The filter may optionally replace the matched regular expression. | The filter may optionally replace the matched regular expression. | ||||
| See | |||||
| <a href="../OptionalTasks/replaceregexp.html">ReplaceRegexp</a> | |||||
| for an explanation on regular expressions. | |||||
| This filter may be used directly within a filterchain. | This filter may be used directly within a filterchain. | ||||
| <p> | |||||
| See | |||||
| <a href="../CoreTypes/regexp.html#implementation">Regexp Type</a> | |||||
| concerning the choice of regular expression implementation. | |||||
| </p> | |||||
| <TABLE cellSpacing=0 cellPadding=2 border=1> | <TABLE cellSpacing=0 cellPadding=2 border=1> | ||||
| <TR> | <TR> | ||||
| <TD vAlign=top><B>Attribute</B></TD> | <TD vAlign=top><B>Attribute</B></TD> | ||||
| @@ -0,0 +1,98 @@ | |||||
| <html> | |||||
| <head> | |||||
| <meta http-equiv="Content-Language" content="en-us"> | |||||
| <title>Regexp Type</title> | |||||
| </head> | |||||
| <body> | |||||
| <h2><a name="regexp">Regexp</a></h2> | |||||
| <p> | |||||
| Regexp represents a regular expression. | |||||
| <h3>Parameters</h3> | |||||
| <table border="1" cellpadding="2" cellspacing="0"> | |||||
| <tr> | |||||
| <td valign="top"><b>Attribute</b></td> | |||||
| <td valign="top"><b>Description</b></td> | |||||
| <td align="center" valign="top"><b>Required</b></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">pattern</td> | |||||
| <td valign="top">regular expression pattern</td> | |||||
| <td valign="top" align="center">Yes</td> | |||||
| </tr> | |||||
| </table> | |||||
| <h3>Examples</h3> | |||||
| <blockquote><pre> | |||||
| <regexp id="myregexp" pattern="alpha(.+)beta"/><br /> | |||||
| </pre></blockquote> | |||||
| <p> | |||||
| Defines a regular expression for later use with id myregexp. | |||||
| </p> | |||||
| <blockquote><pre> | |||||
| <regexp refid="myregexp"/><br /> | |||||
| </pre></blockquote> | |||||
| <p> | |||||
| Use the regular expression with id myregexp. | |||||
| </p> | |||||
| <a name="implementation"/> | |||||
| <h3>Choice of regular expression implementation</h3> | |||||
| <p> | |||||
| Ant comes with | |||||
| wrappers for | |||||
| <a href="http://java.sun.com/j2se/1.4/docs/api/java/util/regex/package-summary.html" target="_top">the java.util.regex package of JDK 1.4</a>, | |||||
| <a href="http://jakarta.apache.org/regexp/" target="_top">jakarta-regexp</a> | |||||
| and <a href="http://jakarta.apache.org/oro/" target="_top">jakarta-ORO</a>, | |||||
| See <a href="../install.html#librarydependencies">installation dependencies</a> | |||||
| concerning the supporting libraries.</p> | |||||
| <p> | |||||
| The property <code>ant.regexp.regexpimpl</code> governs which regular expression implementation will be chosen. | |||||
| Possible values for this property are : | |||||
| <ul> | |||||
| <li> | |||||
| org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp | |||||
| </li> | |||||
| <li> | |||||
| org.apache.tools.ant.util.regexp.JakartaOroRegexp | |||||
| </li> | |||||
| <li> | |||||
| org.apache.tools.ant.util.regexp.JakartaRegexpRegexp | |||||
| </li> | |||||
| </ul> | |||||
| It can also be another implementation of the interface <code>org.apache.tools.ant.util.regexp.Regexp</code>. | |||||
| If <code>ant.regexp.regexpimpl</code> is not defined, ant checks in the order Jdk14Regexp, JakartaOroRegexp, | |||||
| JakartaRegexp for the availability of the corresponding library. The first of these 3 which is found will be used.</p> | |||||
| <p> | |||||
| There are cross-platform issues for matches related to line terminator. | |||||
| For example if you use $ to anchor your regular expression on the end of a line | |||||
| the results might be very different depending on both your platform and the regular | |||||
| expression library you use. It is 'highly recommended' that you test your pattern on | |||||
| both Unix and Windows platforms before you rely on it. | |||||
| <ul> | |||||
| <li>Jakarta Oro defines a line terminator as '\n' and is consistent with Perl.</li> | |||||
| <li>Jakarta RegExp uses a system-dependant line terminator.</li> | |||||
| <li>JDK 1.4 uses '\n', '\r\n', '\u0085', '\u2028', '\u2029' as a default | |||||
| but is configured in the wrapper to use only '\n' (UNIX_LINE)</li> | |||||
| </ul> | |||||
| <em>We <b>strongly</b> recommend that you use Jakarta Oro.</em> | |||||
| </p> | |||||
| <h3>Usage</h3> | |||||
| The following tasks and types use the Regexp type : | |||||
| <ul> | |||||
| <li><a href="CoreTasks/replaceregexp.html">ReplaceRegExp task</a></li> | |||||
| <li><a href="filterchain.html#linecontainsregexp">LineContainsRegexp filter</a></li> | |||||
| </ul> | |||||
| <p> | |||||
| These string filters also use the mechanism of regexp to choose a regular expression implementation : | |||||
| </p> | |||||
| <ul> | |||||
| <li><a href="filterchain.html#containsregex">ContainsRegex string filter</a></li> | |||||
| <li><a href="filterchain.html#replaceregex">ReplaceRegex string filter</a></li> | |||||
| </ul> | |||||
| <hr> | |||||
| <p align="center">Copyright © 2003 Apache Software Foundation. | |||||
| All rights Reserved.</p> | |||||
| </body> | |||||
| </html> | |||||
| @@ -19,7 +19,8 @@ have been regenerated by this task.</p> | |||||
| <p>Similar to <a href="../CoreTypes/mapper.html#regexp-mapper">regexp | <p>Similar to <a href="../CoreTypes/mapper.html#regexp-mapper">regexp | ||||
| type mappers</a> this task needs a supporting regular expression | type mappers</a> this task needs a supporting regular expression | ||||
| library and an implementation of | library and an implementation of | ||||
| <code>org.apache.tools.ant.util.regexp.Regexp</code>. See details <a href="#implementation">below</a>. </p> | |||||
| <code>org.apache.tools.ant.util.regexp.Regexp</code>. | |||||
| See details in the documentation of the <a href=../CoreTypes/regexp.html#implementation">Regexp Type</a>. </p> | |||||
| <h3>Parameters</h3> | <h3>Parameters</h3> | ||||
| <table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
| @@ -79,51 +80,11 @@ library and an implementation of | |||||
| <p>replaces occurrences of the property name "OldProperty" | <p>replaces occurrences of the property name "OldProperty" | ||||
| with "NewProperty" in a properties file, preserving the existing | with "NewProperty" in a properties file, preserving the existing | ||||
| value, in the file <code>${src}/build.properties</code></p> | value, in the file <code>${src}/build.properties</code></p> | ||||
| <a name="implementation"/> | |||||
| <h3>Choice of regular expression implementation</h3> | |||||
| <p> | |||||
| Ant comes with | |||||
| wrappers for | |||||
| <a href="http://java.sun.com/j2se/1.4/docs/api/java/util/regex/package-summary.html" target="_top">the java.util.regex package of JDK 1.4</a>, | |||||
| <a href="http://jakarta.apache.org/regexp/" target="_top">jakarta-regexp</a> | |||||
| and <a href="http://jakarta.apache.org/oro/" target="_top">jakarta-ORO</a>, | |||||
| See <a href="../install.html#librarydependencies">installation dependencies</a> | |||||
| concerning the supporting libraries.</p> | |||||
| <p> | |||||
| The system property <code>ant.regexp.regexpimpl</code> governs which regular expression implementation will be chosen. | |||||
| Possible values for this property are : | |||||
| <ul> | |||||
| <li> | |||||
| org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp | |||||
| </li> | |||||
| <li> | |||||
| org.apache.tools.ant.util.regexp.JakartaOroRegexp | |||||
| </li> | |||||
| <li> | |||||
| org.apache.tools.ant.util.regexp.JakartaRegexpRegexp | |||||
| </li> | |||||
| </ul> | |||||
| It can also be another implementation of the interface <code>org.apache.tools.ant.util.regexp.Regexp</code>. | |||||
| If <code>ant.regexp.regexpimpl</code> is not defined, ant checks in the order Jdk14Regexp, JakartaOroRegexp, | |||||
| JakartaRegexp for the availability of the corresponding library. The first of these 3 which is found will be used.</p> | |||||
| <p> | |||||
| There are cross-platform issues for matches related to line terminator. | |||||
| For example if you use $ to anchor your regular expression on the end of a line | |||||
| the results might be very different depending on both your platform and the regular | |||||
| expression library you use. It is 'highly recommended' that you test your pattern on | |||||
| both Unix and Windows platforms before you rely on it. | |||||
| <ul> | |||||
| <li>Jakarta Oro defines a line terminator as '\n' and is consistent with Perl.</li> | |||||
| <li>Jakarta RegExp uses a system-dependant line terminator.</li> | |||||
| <li>JDK 1.4 uses '\n', '\r\n', '\u0085', '\u2028', '\u2029' as a default | |||||
| but is configured in the wrapper to use only '\n' (UNIX_LINE)</li> | |||||
| </ul> | |||||
| <em>We <b>strongly</b> recommend that you use Jakarta Oro.</em> | |||||
| </p> | |||||
| <h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
| <p>This task supports a nested <a href="../CoreTypes/fileset.html">FileSet</a> | <p>This task supports a nested <a href="../CoreTypes/fileset.html">FileSet</a> | ||||
| element.</p> | element.</p> | ||||
| <p>This task supports a nested <i>Regexp</i> element to specify | |||||
| <p>This task supports a nested <i><a href="../CoreTypes/regexp.html">Regexp</a></i> element to specify | |||||
| the regular expression. You can use this element to refer to a previously | the regular expression. You can use this element to refer to a previously | ||||
| defined regular expression datatype instance.</p> | defined regular expression datatype instance.</p> | ||||
| <blockquote> | <blockquote> | ||||
| @@ -27,6 +27,7 @@ | |||||
| <a href="using.html#path">Path-like Structures</a><br> | <a href="using.html#path">Path-like Structures</a><br> | ||||
| <a href="CoreTypes/permissions.html">Permissions</a><br> | <a href="CoreTypes/permissions.html">Permissions</a><br> | ||||
| <a href="CoreTypes/propertyset.html">PropertySet</a><br> | <a href="CoreTypes/propertyset.html">PropertySet</a><br> | ||||
| <a href="CoreTypes/regexp.html">Regexp</a><br> | |||||
| <a href="CoreTypes/selectors.html">Selectors</a><br> | <a href="CoreTypes/selectors.html">Selectors</a><br> | ||||
| <a href="CoreTypes/xmlcatalog.html">XMLCatalog</a><br> | <a href="CoreTypes/xmlcatalog.html">XMLCatalog</a><br> | ||||
| <a href="CoreTypes/zipfileset.html">ZipFileSet</a><br> | <a href="CoreTypes/zipfileset.html">ZipFileSet</a><br> | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
| * | * | ||||
| * Copyright (c) 2001-2002 The Apache Software Foundation. All rights | |||||
| * Copyright (c) 2001-2003 The Apache Software Foundation. All rights | |||||
| * reserved. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
| @@ -99,42 +99,81 @@ import org.apache.tools.ant.util.regexp.RegexpFactory; | |||||
| public class RegularExpression extends DataType { | public class RegularExpression extends DataType { | ||||
| /** Name of this data type */ | /** Name of this data type */ | ||||
| public static final String DATA_TYPE_NAME = "regexp"; | public static final String DATA_TYPE_NAME = "regexp"; | ||||
| private boolean alreadyInit = false; | |||||
| // The regular expression factory | // The regular expression factory | ||||
| private static final RegexpFactory factory = new RegexpFactory(); | |||||
| private static final RegexpFactory FACTORY = new RegexpFactory(); | |||||
| private Regexp regexp; | |||||
| private Regexp regexp = null; | |||||
| // temporary variable | |||||
| private String myPattern; | |||||
| private boolean setPatternPending = false; | |||||
| /** | |||||
| * default constructor | |||||
| */ | |||||
| public RegularExpression() { | public RegularExpression() { | ||||
| this.regexp = factory.newRegexp(); | |||||
| } | } | ||||
| private void init(Project p) { | |||||
| if (!alreadyInit) { | |||||
| this.regexp = FACTORY.newRegexp(p); | |||||
| alreadyInit = true; | |||||
| } | |||||
| } | |||||
| private void setPattern() { | |||||
| if (setPatternPending) { | |||||
| regexp.setPattern(myPattern); | |||||
| setPatternPending = false; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * sets the regular expression pattern | |||||
| * @param pattern regular expression pattern | |||||
| */ | |||||
| public void setPattern(String pattern) { | public void setPattern(String pattern) { | ||||
| this.regexp.setPattern(pattern); | |||||
| if (regexp == null) { | |||||
| myPattern = pattern; | |||||
| setPatternPending = true; | |||||
| } else { | |||||
| regexp.setPattern(pattern); | |||||
| } | |||||
| } | } | ||||
| /*** | /*** | ||||
| * Gets the pattern string for this RegularExpression in the | * Gets the pattern string for this RegularExpression in the | ||||
| * given project. | * given project. | ||||
| * @param p project | |||||
| * @return pattern | |||||
| */ | */ | ||||
| public String getPattern(Project p) { | public String getPattern(Project p) { | ||||
| init(p); | |||||
| if (isReference()) { | if (isReference()) { | ||||
| return getRef(p).getPattern(p); | return getRef(p).getPattern(p); | ||||
| } | } | ||||
| setPattern(); | |||||
| return regexp.getPattern(); | return regexp.getPattern(); | ||||
| } | } | ||||
| /** | |||||
| * provides a reference to the Regexp contained in this | |||||
| * @param p project | |||||
| * @return Regexp instance associated with this RegularExpression instance | |||||
| */ | |||||
| public Regexp getRegexp(Project p) { | public Regexp getRegexp(Project p) { | ||||
| init(p); | |||||
| if (isReference()) { | if (isReference()) { | ||||
| return getRef(p).getRegexp(p); | return getRef(p).getRegexp(p); | ||||
| } | } | ||||
| setPattern(); | |||||
| return this.regexp; | return this.regexp; | ||||
| } | } | ||||
| /*** | /*** | ||||
| * Get the RegularExpression this reference refers to in | * Get the RegularExpression this reference refers to in | ||||
| * the given project. Check for circular references too | * the given project. Check for circular references too | ||||
| * @param p project | |||||
| * @return resolved RegularExpression instance | |||||
| */ | */ | ||||
| public RegularExpression getRef(Project p) { | public RegularExpression getRef(Project p) { | ||||
| if (!isChecked()) { | if (!isChecked()) { | ||||
| @@ -147,7 +186,7 @@ public class RegularExpression extends DataType { | |||||
| Object o = getRefid().getReferencedObject(p); | Object o = getRefid().getReferencedObject(p); | ||||
| if (!(o instanceof RegularExpression)) { | if (!(o instanceof RegularExpression)) { | ||||
| String msg = getRefid().getRefId() + " doesn\'t denote a " | String msg = getRefid().getRefId() + " doesn\'t denote a " | ||||
| + DATA_TYPE_NAME; | |||||
| + DATA_TYPE_NAME; | |||||
| throw new BuildException(msg); | throw new BuildException(msg); | ||||
| } else { | } else { | ||||
| return (RegularExpression) o; | return (RegularExpression) o; | ||||