You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2003/05/14 14:40:19 UTC

cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional EchoProperties.java

bodewig     2003/05/14 05:40:18

  Modified:    .        WHATSNEW
               docs/manual/OptionalTasks echoproperties.html
               src/etc/testcases/taskdefs/optional echoproperties.xml
               src/testcases/org/apache/tools/ant/taskdefs/optional
                        EchoPropertiesTest.java
               src/main/org/apache/tools/ant/taskdefs/optional
                        EchoProperties.java
  Log:
  Make <echoproperties> support nested <propertyset>s.
  
  Revision  Changes    Path
  1.417     +2 -2      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.416
  retrieving revision 1.417
  diff -u -r1.416 -r1.417
  --- WHATSNEW	13 May 2003 14:36:56 -0000	1.416
  +++ WHATSNEW	14 May 2003 12:40:17 -0000	1.417
  @@ -306,8 +306,8 @@
     defaultexcludes task.  Bugzilla Report 12700.
   
   * There is a new data type <propertyset> that can be used to collect
  -  properties.  It is supported by <ant>, <antcall>, <subant>, <java>
  -  and <junit>.
  +  properties.  It is supported by <ant>, <antcall>, <subant>, <java>,
  +  <echoproperties> and <junit>.
   
   * <concat> 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
  
  
  
  1.4       +26 -6     ant/docs/manual/OptionalTasks/echoproperties.html
  
  Index: echoproperties.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/OptionalTasks/echoproperties.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- echoproperties.html	14 May 2003 12:28:54 -0000	1.3
  +++ echoproperties.html	14 May 2003 12:40:18 -0000	1.4
  @@ -9,12 +9,14 @@
   
   <h2><a name="echoproperties">echoproperties</a></h2>
   <h3>Description</h3>
  -<p>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 <tt>&lt;ant&gt;</tt> invocation,
  -but is really for debugging build files.</p>
  +
  +<p>Displays all the current properties (or a subset of them specified
  +by a nested <code>&lt;propertyset&gt;</code>) 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
  +<tt>&lt;ant&gt;</tt> invocation, but is really for debugging build
  +files.</p>
  +
   <h3>Parameters</h3>
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
  @@ -59,6 +61,16 @@
       <td valign="top" align="center">No</td>
     </tr>
   </table>
  +
  +<h3>Parameters specified as nested elements</h3>
  +
  +<h4>propertyset</h4>
  +
  +<p>You can specify subsets of properties to be echoed with <a
  +href="../CoreTypes/propertyset.html">propertyset</a>s.</p>
  +
  +<p><em>since Ant 1.6</em>.</p>
  +
   <h3>Examples</h3>
   <blockquote><pre>
     &lt;echoproperties/&gt;
  @@ -77,6 +89,14 @@
   allow the build to continue.</p>
   <blockquote><pre>
     &lt;echoproperties prefix="java."/&gt;
  +</pre></blockquote>
  +<p>List all properties beginning with "java."</p>
  +<blockquote><pre>
  +  &lt;echoproperties&gt;
  +    &lt;propertyset&gt;
  +      &lt;propertyref prefix="java."/&gt;
  +    &lt;/propertyset&gt;
  +  &lt;/echoproperties&gt;
   </pre></blockquote>
   <p>List all properties beginning with "java."</p>
   
  
  
  
  1.3       +8 -0      ant/src/etc/testcases/taskdefs/optional/echoproperties.xml
  
  Index: echoproperties.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/optional/echoproperties.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- echoproperties.xml	29 May 2002 15:24:38 -0000	1.2
  +++ echoproperties.xml	14 May 2003 12:40:18 -0000	1.3
  @@ -64,6 +64,14 @@
       <echoproperties destfile="test-prefix.properties" prefix="a." />
     </target>
   
  +  <target name="testEchoPrefixAsPropertyset" depends="setup">
  +    <echoproperties destfile="test-prefix.properties">
  +      <propertyset>
  +        <propertyref prefix="a."/>
  +      </propertyset>
  +    </echoproperties>
  +  </target>
  +
     <target name="cleanup">
       <delete file="test.properties" failonerror="no" />
       <delete file="test-prefix.properties" failonerror="no" />
  
  
  
  1.6       +9 -1      ant/src/testcases/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
  
  Index: EchoPropertiesTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EchoPropertiesTest.java	10 Feb 2003 14:14:51 -0000	1.5
  +++ EchoPropertiesTest.java	14 May 2003 12:40:18 -0000	1.6
  @@ -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
  @@ -183,6 +183,14 @@
           executeTarget( "testEchoPrefix" );
           Properties props=loadPropFile(PREFIX_OUTFILE);
   //        props.list(System.out);
  +        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"));
  +    }
  +
  +    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"));
  
  
  
  1.17      +25 -12    ant/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java
  
  Index: EchoProperties.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- EchoProperties.java	10 Feb 2003 14:13:45 -0000	1.16
  +++ EchoProperties.java	14 May 2003 12:40:18 -0000	1.17
  @@ -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.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 @@
        */
       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 @@
        *@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 @@
   
           /* 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 @@
               }
           }
   
  +        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 @@
           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)) {