antoine 2003/12/01 14:03:26 Modified: src/main/org/apache/tools/ant/types RegularExpression.java docs/manual conceptstypeslist.html docs/manual/CoreTypes filterchain.html docs/manual/OptionalTasks replaceregexp.html Added: docs/manual/CoreTypes regexp.html Log: Make the choice of regular expression implementation possible with ant.regexp.regexpimpl as a normal project property PR: 15390 Revision Changes Path 1.16 +46 -7 ant/src/main/org/apache/tools/ant/types/RegularExpression.java Index: RegularExpression.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/RegularExpression.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- RegularExpression.java 19 Jul 2003 08:11:07 -0000 1.15 +++ RegularExpression.java 1 Dec 2003 22:03:25 -0000 1.16 @@ -1,7 +1,7 @@ /* * 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. * * Redistribution and use in source and binary forms, with or without @@ -99,42 +99,81 @@ public class RegularExpression extends DataType { /** Name of this data type */ public static final String DATA_TYPE_NAME = "regexp"; + private boolean alreadyInit = false; // 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() { - 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) { - this.regexp.setPattern(pattern); + if (regexp == null) { + myPattern = pattern; + setPatternPending = true; + } else { + regexp.setPattern(pattern); + } } /*** * Gets the pattern string for this RegularExpression in the * given project. + * @param p project + * @return pattern */ public String getPattern(Project p) { + init(p); if (isReference()) { return getRef(p).getPattern(p); } - + setPattern(); 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) { + init(p); if (isReference()) { return getRef(p).getRegexp(p); } + setPattern(); return this.regexp; } /*** * Get the RegularExpression this reference refers to in * the given project. Check for circular references too + * @param p project + * @return resolved RegularExpression instance */ public RegularExpression getRef(Project p) { if (!isChecked()) { @@ -147,7 +186,7 @@ Object o = getRefid().getReferencedObject(p); if (!(o instanceof RegularExpression)) { String msg = getRefid().getRefId() + " doesn\'t denote a " - + DATA_TYPE_NAME; + + DATA_TYPE_NAME; throw new BuildException(msg); } else { return (RegularExpression) o; 1.14 +1 -0 ant/docs/manual/conceptstypeslist.html Index: conceptstypeslist.html =================================================================== RCS file: /home/cvs/ant/docs/manual/conceptstypeslist.html,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- conceptstypeslist.html 1 Sep 2003 14:22:04 -0000 1.13 +++ conceptstypeslist.html 1 Dec 2003 22:03:25 -0000 1.14 @@ -27,6 +27,7 @@ <a href="using.html#path">Path-like Structures</a><br> <a href="CoreTypes/permissions.html">Permissions</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/xmlcatalog.html">XMLCatalog</a><br> <a href="CoreTypes/zipfileset.html">ZipFileSet</a><br> 1.15 +12 -21 ant/docs/manual/CoreTypes/filterchain.html Index: filterchain.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTypes/filterchain.html,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- filterchain.html 12 Nov 2003 09:35:31 -0000 1.14 +++ filterchain.html 1 Dec 2003 22:03:25 -0000 1.15 @@ -333,19 +333,8 @@ Filter which includes only those lines that contain the user-specified 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> This will fetch all those lines that contain the pattern <code>foo</code> @@ -1112,10 +1101,12 @@ </PRE></BLOCKQUOTE> <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. +<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> <TR> @@ -1143,7 +1134,6 @@ <TD vAlign=top align="center">No</TD> </TR> </TABLE> - <H4>Examples:</H4> Replace all occurances of "hello" with "world", ignoring case. @@ -1158,11 +1148,12 @@ <p><b><em><a name="containsregex">ContainsRegex</a></em></b></p> This filters strings that match regular expressions. 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. - +<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> <TR> <TD vAlign=top><B>Attribute</B></TD> 1.1 ant/docs/manual/CoreTypes/regexp.html Index: regexp.html =================================================================== <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> 1.18 +4 -43 ant/docs/manual/OptionalTasks/replaceregexp.html Index: replaceregexp.html =================================================================== RCS file: /home/cvs/ant/docs/manual/OptionalTasks/replaceregexp.html,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- replaceregexp.html 24 Nov 2003 21:56:53 -0000 1.17 +++ replaceregexp.html 1 Dec 2003 22:03:25 -0000 1.18 @@ -19,7 +19,8 @@ <p>Similar to <a href="../CoreTypes/mapper.html#regexp-mapper">regexp type mappers</a> this task needs a supporting regular expression 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> <table border="1" cellpadding="2" cellspacing="0"> @@ -79,51 +80,11 @@ <p>replaces occurrences of the property name "OldProperty" with "NewProperty" in a properties file, preserving the existing 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> <p>This task supports a nested <a href="../CoreTypes/fileset.html">FileSet</a> 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 defined regular expression datatype instance.</p> <blockquote>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]