From 9e79f648a4ddc280e7b87248a8690b9e8f6de311 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 14 May 2003 12:40:18 +0000 Subject: [PATCH] Make support nested s. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274575 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 +- docs/manual/OptionalTasks/echoproperties.html | 32 +++++++++++++--- .../taskdefs/optional/echoproperties.xml | 8 ++++ .../ant/taskdefs/optional/EchoProperties.java | 37 +++++++++++++------ .../taskdefs/optional/EchoPropertiesTest.java | 10 ++++- 5 files changed, 70 insertions(+), 21 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 8bc95e87a..292c8eabc 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -306,8 +306,8 @@ Other changes: defaultexcludes task. Bugzilla Report 12700. * There is a new data type that can be used to collect - properties. It is supported by , , , - and . + properties. It is supported by , , , , + and . * can now control the encoding of the output as well and optionally add new-line characters at the end of files that get concatenated but diff --git a/docs/manual/OptionalTasks/echoproperties.html b/docs/manual/OptionalTasks/echoproperties.html index 40a52fee7..05c52a83d 100644 --- a/docs/manual/OptionalTasks/echoproperties.html +++ b/docs/manual/OptionalTasks/echoproperties.html @@ -9,12 +9,14 @@

echoproperties

Description

-

Displays all the current properties in the project. The output can be -sent to a file if desired. You can also specify a subset of properties -to save by naming a prefix: only properties starting with this -prefix will be saved. This task can be used as a somewhat contrived -means of returning data from an <ant> invocation, -but is really for debugging build files.

+ +

Displays all the current properties (or a subset of them specified +by a nested <propertyset>) in the project. The +output can be sent to a file if desired. This task can be used as a +somewhat contrived means of returning data from an +<ant> invocation, but is really for debugging build +files.

+

Parameters

@@ -59,6 +61,16 @@ but is really for debugging build files.

No
+ +

Parameters specified as nested elements

+ +

propertyset

+ +

You can specify subsets of properties to be echoed with propertysets.

+ +

since Ant 1.6.

+

Examples

   <echoproperties/>
@@ -79,6 +91,14 @@ allow the build to continue.

<echoproperties prefix="java."/>

List all properties beginning with "java."

+
+  <echoproperties>
+    <propertyset>
+      <propertyref prefix="java."/>
+    </propertyset>
+  </echoproperties>
+
+

List all properties beginning with "java."


Copyright © 2002-2003 Apache Software Foundation. All rights diff --git a/src/etc/testcases/taskdefs/optional/echoproperties.xml b/src/etc/testcases/taskdefs/optional/echoproperties.xml index b3e39dc1c..265c4f5d9 100644 --- a/src/etc/testcases/taskdefs/optional/echoproperties.xml +++ b/src/etc/testcases/taskdefs/optional/echoproperties.xml @@ -64,6 +64,14 @@ + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java b/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java index 6143d7445..f9243eb27 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -65,12 +65,14 @@ import java.io.Writer; import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; +import java.util.Vector; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.EnumeratedAttribute; +import org.apache.tools.ant.types.PropertySet; import org.apache.tools.ant.util.CollectionUtils; import org.apache.tools.ant.util.DOMElementWriter; import org.w3c.dom.Document; @@ -153,11 +155,7 @@ public class EchoProperties extends Task { */ private boolean failonerror = true; - /** - * Prefix string controls which properties to save. - */ - private String prefix = null; - + private Vector propertySets = new Vector(); private String format = "text"; @@ -207,9 +205,20 @@ public class EchoProperties extends Task { *@param prefix The new prefix value */ public void setPrefix(String prefix) { - this.prefix = prefix; + PropertySet ps = new PropertySet(); + ps.setProject(getProject()); + ps.appendPrefix(prefix); + addPropertyset(ps); } + /** + * A set of properties to write. + * + * @since Ant 1.6 + */ + public void addPropertyset(PropertySet ps) { + propertySets.addElement(ps); + } public void setFormat(FormatAttribute ea) { format = ea.getValue(); @@ -234,10 +243,10 @@ public class EchoProperties extends Task { /* load properties from file if specified, otherwise use Ant's properties */ - if(inFile == null) { + if (inFile == null && propertySets.size() == 0) { // add ant properties CollectionUtils.putAll(allProps, getProject().getProperties()); - } else { + } else if (inFile != null) { if (inFile.exists() && inFile.isDirectory()) { String message = "srcfile is a directory!"; if (failonerror) { @@ -291,6 +300,12 @@ public class EchoProperties extends Task { } } + Enumeration enum = propertySets.elements(); + while (enum.hasMoreElements()) { + PropertySet ps = (PropertySet) enum.nextElement(); + CollectionUtils.putAll(allProps, ps.getProperties()); + } + OutputStream os = null; try { if (destfile == null) { @@ -355,9 +370,7 @@ public class EchoProperties extends Task { while (enum.hasMoreElements()) { String name = enum.nextElement().toString(); String value = allProps.get(name).toString(); - if (prefix == null || name.indexOf(prefix) == 0) { - props.put(name, value); - } + props.put(name, value); } if ("text".equals(format)) { diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java index 9943bdcbc..a33e94748 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -188,6 +188,14 @@ public class EchoPropertiesTest extends BuildFileTest { props.getProperty("b.set")); } + public void testEchoPrefixAsPropertyset() throws Exception { + executeTarget( "testEchoPrefixAsPropertyset" ); + Properties props=loadPropFile(PREFIX_OUTFILE); + assertEquals("prefix didn't include 'a.set' property","true",props.getProperty("a.set")); + assertNull("prefix failed to filter out property 'b.set'", + props.getProperty("b.set")); + } + protected Properties loadPropFile(String relativeFilename) throws IOException { File f = createRelativeFile( relativeFilename );