Author: antoine Date: Wed Oct 25 18:39:57 2006 New Revision: 467828 URL: http://svn.apache.org/viewvc?view=rev&rev=467828 Log: add regex attribute to echoproperties task. Bugzilla 40019.
Modified: ant/core/trunk/WHATSNEW ant/core/trunk/docs/manual/OptionalTasks/echoproperties.html ant/core/trunk/src/etc/testcases/taskdefs/optional/echoproperties.xml ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=467828&r1=467827&r2=467828 ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Wed Oct 25 18:39:57 2006 @@ -24,6 +24,9 @@ * removed dependence on sun.misc.UUEncoder for UUMailer. +* added regex attribute to the echoproperties task. + Bugzilla 40019. + Changes from Ant 1.7.0Beta2 to Ant 1.7.0Beta3 ============================================= Modified: ant/core/trunk/docs/manual/OptionalTasks/echoproperties.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/OptionalTasks/echoproperties.html?view=diff&rev=467828&r1=467827&r2=467828 ============================================================================== --- ant/core/trunk/docs/manual/OptionalTasks/echoproperties.html (original) +++ ant/core/trunk/docs/manual/OptionalTasks/echoproperties.html Wed Oct 25 18:39:57 2006 @@ -58,9 +58,15 @@ </td> <td valign="top" align="center">No</td> </tr> - - - + <tr> + <td valign="top">regex</td> + <td valign="top"> + a regular expression which is used to filter the + properties + only those properties whose names match it will be echoed. + </td> + <td valign="top" align="center">No</td> + </tr> <tr> <td valign="top">failonerror</td> <td valign="top">By default, the "failonerror" attribute is enabled. @@ -70,7 +76,6 @@ statement, and the build will continue without failure from this task.</td> <td valign="top" align="center">No</td> </tr> - <tr> <td valign="top">format</td> <td valign="top">One of <code>text</code> or <code>xml</code>. @@ -84,7 +89,11 @@ <h4>propertyset</h4> <p>You can specify subsets of properties to be echoed with <a -href="../CoreTypes/propertyset.html">propertyset</a>s.</p> +href="../CoreTypes/propertyset.html">propertyset</a>s. Using +<tt>propertyset</tt>s gives more control on which properties will be +picked up. The attributes <tt>prefix</tt> and <tt>regex</tt> are just +shorcuts that use <tt>propertyset</tt>s internally. +</p> <p><em>since Ant 1.6</em>.</p> @@ -115,7 +124,20 @@ </propertyset> </echoproperties> </pre></blockquote> -<p>List all properties beginning with "java."</p> +<p>This again lists all properties beginning with "java." using a nested +<tt></propertyset></tt> which is an equivalent but longer way.</p> +<blockquote><pre> + <echoproperties regex=".*ant.*"/> +</pre></blockquote> +<p>Lists all properties that contain "ant" in their names. +The equivalent snippet with <tt></propertyset></tt> is:</p> +<blockquote><pre> + <echoproperties> + <propertyset> + <propertyref regex=".*ant.*"/> + </propertyset> + </echoproperties> +</pre></blockquote> Modified: ant/core/trunk/src/etc/testcases/taskdefs/optional/echoproperties.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/optional/echoproperties.xml?view=diff&rev=467828&r1=467827&r2=467828 ============================================================================== --- ant/core/trunk/src/etc/testcases/taskdefs/optional/echoproperties.xml (original) +++ ant/core/trunk/src/etc/testcases/taskdefs/optional/echoproperties.xml Wed Oct 25 18:39:57 2006 @@ -94,6 +94,18 @@ </echoproperties> </target> + <target name="testWithPrefixAndRegex" depends="setup"> + <echoproperties prefix="ant." regex=".*ant.*"/> + </target> + + <target name="testWithEmptyPrefixAndRegex" depends="setup"> + <echoproperties prefix="" regex=""/> + </target> + + <target name="testWithRegex" depends="setup"> + <echoproperties regex=".*ant.*"/> + </target> + <target name="cleanup"> <delete file="test.properties" failonerror="no" /> <delete file="test-prefix.properties" failonerror="no" /> Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java?view=diff&rev=467828&r1=467827&r2=467828 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java Wed Oct 25 18:39:57 2006 @@ -129,6 +129,13 @@ private String format = "text"; + private String prefix; + + /** + * @since Ant 1.7 + */ + private String regex; + /** * Sets the input file. * @@ -163,19 +170,20 @@ /** * If the prefix is set, then only properties which start with this - * prefix string will be recorded. If this is never set, or it is set - * to an empty string or <tt>null</tt>, then all properties will be - * recorded. <P> + * prefix string will be recorded. If regex is not set and if this + * is never set, or it is set to an empty string or <tt>null</tt>, + * then all properties will be recorded. <P> * - * For example, if the property is set as: + * For example, if the attribute is set as: * <PRE><echoproperties prefix="ant." /></PRE> * then the property "ant.home" will be recorded, but "ant-example" * will not. * - [EMAIL PROTECTED] prefix The new prefix value + * @param prefix The new prefix value */ public void setPrefix(String prefix) { if (prefix != null && prefix.length() != 0) { + this.prefix = prefix; PropertySet ps = new PropertySet(); ps.setProject(getProject()); ps.appendPrefix(prefix); @@ -184,6 +192,31 @@ } /** + * If the regex is set, then only properties whose names match it + * will be recorded. If prefix is not set and if this is never set, + * or it is set to an empty string or <tt>null</tt>, then all + * properties will be recorded.<P> + * + * For example, if the attribute is set as: + * <PRE><echoproperties prefix=".*ant.*" /></PRE> + * then the properties "ant.home" and "user.variant" will be recorded, + * but "ant-example" will not. + * + * @param regex The new regex value + * + * @since Ant 1.7 + */ + public void setRegex(String regex) { + if (regex != null && regex.length() != 0) { + this.regex = regex; + PropertySet ps = new PropertySet(); + ps.setProject(getProject()); + ps.appendRegex(regex); + addPropertyset(ps); + } + } + + /** * A set of properties to write. * @param ps the property set to write * @since Ant 1.6 @@ -209,6 +242,7 @@ /** * @see EnumeratedAttribute#getValues() + * @return accepted values */ public String[] getValues() { return formats; @@ -221,6 +255,10 @@ [EMAIL PROTECTED] BuildException trouble, probably file IO */ public void execute() throws BuildException { + if (prefix != null && regex != null) { + throw new BuildException("Please specify either prefix" + + " or regex, but not both", getLocation()); + } //copy the properties file Hashtable allProps = new Hashtable(); Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java?view=diff&rev=467828&r1=467827&r2=467828 ============================================================================== --- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java (original) +++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java Wed Oct 25 18:39:57 2006 @@ -161,6 +161,22 @@ testEchoPrefixVarious("testEchoPrefixAsDoublyNegatedPropertyset"); } + public void testWithPrefixAndRegex() throws Exception { + expectSpecificBuildException("testWithPrefixAndRegex", + "The target must fail with prefix and regex attributes set", + "Please specify either prefix or regex, but not both"); + } + + public void testWithEmptyPrefixAndRegex() throws Exception { + expectLogContaining("testEchoWithEmptyPrefixToLog", "test.property="+TEST_VALUE); + } + + public void testWithRegex() throws Exception { + executeTarget("testWithRegex"); + assertDebuglogContaining("ant.home="); + assertDebuglogContaining("user.variant="); + } + private void testEchoPrefixVarious(String target) throws Exception { executeTarget(target); Properties props = loadPropFile(PREFIX_OUTFILE); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]