diff --git a/WHATSNEW b/WHATSNEW index cfc2004b3..a6070463a 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -24,6 +24,9 @@ Other changes: * 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 ============================================= diff --git a/docs/manual/OptionalTasks/echoproperties.html b/docs/manual/OptionalTasks/echoproperties.html index b79fbd74a..00d2981c3 100644 --- a/docs/manual/OptionalTasks/echoproperties.html +++ b/docs/manual/OptionalTasks/echoproperties.html @@ -58,9 +58,15 @@ files.
text
or xml
.
@@ -84,7 +89,11 @@ files.
You can specify subsets of properties to be echoed with propertysets.
+href="../CoreTypes/propertyset.html">propertysets. Using +propertysets gives more control on which properties will be +picked up. The attributes prefix and regex are just +shorcuts that use propertysets internally. +since Ant 1.6.
@@ -115,7 +124,20 @@ allow the build to continue. </propertyset> </echoproperties> -List all properties beginning with "java."
+This again lists all properties beginning with "java." using a nested +</propertyset> which is an equivalent but longer way.
+++ <echoproperties regex=".*ant.*"/> +
Lists all properties that contain "ant" in their names. +The equivalent snippet with </propertyset> is:
+diff --git a/src/etc/testcases/taskdefs/optional/echoproperties.xml b/src/etc/testcases/taskdefs/optional/echoproperties.xml index 9458b5224..921bfd067 100644 --- a/src/etc/testcases/taskdefs/optional/echoproperties.xml +++ b/src/etc/testcases/taskdefs/optional/echoproperties.xml @@ -94,6 +94,18 @@ ++ <echoproperties> + <propertyset> + <propertyref regex=".*ant.*"/> + </propertyset> + </echoproperties> +
+ * 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 null, + * then all properties will be recorded.
* - * For example, if the property is set as: + * For example, if the attribute is set as: *
<echoproperties prefix="ant." />* then the property "ant.home" will be recorded, but "ant-example" * will not. * - *@param 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); @@ -183,6 +191,31 @@ public class EchoProperties extends Task { } } + /** + * 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 null, then all + * properties will be recorded.
+ * + * For example, if the attribute is set as: + *
<echoproperties prefix=".*ant.*" />+ * 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 @@ -209,6 +242,7 @@ public class EchoProperties extends Task { /** * @see EnumeratedAttribute#getValues() + * @return accepted values */ public String[] getValues() { return formats; @@ -221,6 +255,10 @@ public class EchoProperties extends Task { *@exception 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(); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java index ed66e13b5..9bc433a88 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java @@ -161,6 +161,22 @@ public class EchoPropertiesTest extends BuildFileTest { 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);