ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs AntTest.java
Date Mon, 12 May 2003 12:57:06 GMT
bodewig     2003/05/12 05:57:05

  Modified:    src/etc/testcases/taskdefs ant.xml
               src/main/org/apache/tools/ant/taskdefs Ant.java
                        CallTarget.java SubAnt.java
               src/testcases/org/apache/tools/ant/taskdefs AntTest.java
  Log:
  Add nested <propertyset>s to <ant>, <antcall> and <subant>.
  
  Revision  Changes    Path
  1.10      +19 -0     ant/src/etc/testcases/taskdefs/ant.xml
  
  Index: ant.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/ant.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ant.xml	16 Jul 2002 13:06:45 -0000	1.9
  +++ ant.xml	12 May 2003 12:57:04 -0000	1.10
  @@ -143,4 +143,23 @@
       <property name="test" value="5" />
       <echo message="The value of test is ${test}" />
     </target>
  +
  +  <target name="test-propertyset">
  +    <property name="test1" value="1"/>
  +    <property name="test2" value="2"/>
  +    <propertyset id="set">
  +      <propertyref name="test1"/>
  +      <mapper type="glob" from="*" to="*.x"/>
  +    </propertyset>
  +    <ant antfile="ant.xml" target="echo-for-propertyset-test" 
  +         inheritall="false">
  +      <propertyset refid="set"/>
  +    </ant>
  +  </target>
  +
  +  <target name="echo-for-propertyset-test">
  +    <echo>test1 is ${test1}</echo>
  +    <echo>test2 is ${test2}</echo>
  +    <echo>test1.x is ${test1.x}</echo>
  +  </target>
   </project>
  
  
  
  1.77      +44 -16    ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- Ant.java	3 Apr 2003 14:44:02 -0000	1.76
  +++ Ant.java	12 May 2003 12:57:04 -0000	1.77
  @@ -69,6 +69,7 @@
   import org.apache.tools.ant.ProjectComponent;
   import org.apache.tools.ant.ProjectHelper;
   import org.apache.tools.ant.Task;
  +import org.apache.tools.ant.types.PropertySet;
   import org.apache.tools.ant.util.FileUtils;
   
   /**
  @@ -129,6 +130,9 @@
       /** The stream to which output is to be written. */
       private PrintStream out = null;
   
  +    /** the sets of properties to pass to the new project */
  +    private Vector propertySets = new Vector();
  +
       /**
        * If true, pass all properties to the new Ant project.
        * Defaults to true.
  @@ -264,23 +268,13 @@
   
           } else {
               // set all properties from calling project
  +            addAlmostAll(getProject().getProperties());
  +        }
   
  -            Hashtable props = getProject().getProperties();
  -            e = props.keys();
  -            while (e.hasMoreElements()) {
  -                String arg = e.nextElement().toString();
  -                if ("basedir".equals(arg) || "ant.file".equals(arg)) {
  -                    // basedir and ant.file get special treatment in execute()
  -                    continue;
  -                }
  -
  -                String value = props.get(arg).toString();
  -                // don't re-set user properties, avoid the warning message
  -                if (newProject.getProperty(arg) == null){
  -                    // no user property
  -                    newProject.setNewProperty(arg, value);
  -                }
  -            }
  +        e = propertySets.elements();
  +        while (e.hasMoreElements()) {
  +            PropertySet ps = (PropertySet) e.nextElement();
  +            addAlmostAll(ps.getProperties());
           }
       }
   
  @@ -551,6 +545,31 @@
       }
   
       /**
  +     * Copies all properties from the given table to the new project -
  +     * ommiting those that have already been set in the new project as
  +     * well as properties named basedir or ant.file.
  +     *
  +     * @since Ant 1.6
  +     */
  +    private void addAlmostAll(Hashtable props) {
  +        Enumeration e = props.keys();
  +        while (e.hasMoreElements()) {
  +            String key = e.nextElement().toString();
  +            if ("basedir".equals(key) || "ant.file".equals(key)) {
  +                // basedir and ant.file get special treatment in execute()
  +                continue;
  +            }
  +
  +            String value = props.get(key).toString();
  +            // don't re-set user properties, avoid the warning message
  +            if (newProject.getProperty(key) == null){
  +                // no user property
  +                newProject.setNewProperty(key, value);
  +            }
  +        }
  +    }
  +
  +    /**
        * The directory to use as a base directory for the new Ant project.
        * Defaults to the current project's basedir, unless inheritall
        * has been set to false, in which case it doesn't have a default
  @@ -615,6 +634,15 @@
        */
       public void addReference(Reference r) {
           references.addElement(r);
  +    }
  +
  +    /**
  +     * Set of properties to pass to the new project.
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void addPropertyset(PropertySet ps) {
  +        propertySets.addElement(ps);
       }
   
       /**
  
  
  
  1.33      +12 -0     ant/src/main/org/apache/tools/ant/taskdefs/CallTarget.java
  
  Index: CallTarget.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/CallTarget.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- CallTarget.java	7 Mar 2003 11:23:00 -0000	1.32
  +++ CallTarget.java	12 May 2003 12:57:04 -0000	1.33
  @@ -167,6 +167,18 @@
       }
   
       /**
  +     * Set of properties to pass to the new project.
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void addPropertyset(org.apache.tools.ant.types.PropertySet ps) {
  +        if (callee == null) {
  +            init();
  +        }
  +        callee.addPropertyset(ps);
  +    }
  +
  +    /**
        * Target to execute, required.
        */
       public void setTarget(String target) {
  
  
  
  1.2       +14 -0     ant/src/main/org/apache/tools/ant/taskdefs/SubAnt.java
  
  Index: SubAnt.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/SubAnt.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SubAnt.java	14 Mar 2003 00:42:04 -0000	1.1
  +++ SubAnt.java	12 May 2003 12:57:04 -0000	1.2
  @@ -68,6 +68,7 @@
   import org.apache.tools.ant.types.DirSet;
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.FileList;
  +import org.apache.tools.ant.types.PropertySet;
   import org.apache.tools.ant.types.Reference;
   
   import org.apache.tools.ant.taskdefs.Ant;
  @@ -97,6 +98,7 @@
   
       private Vector properties = new Vector();
       private Vector references = new Vector();
  +    private Vector propertySets = new Vector();
   
       /**
        * Runs the various sub-builds.
  @@ -239,6 +241,14 @@
       }
   
       /**
  +     * Corresponds to <code>&lt;ant&gt;</code>'s
  +     * nested <code>&lt;propertyset&gt;</code> element.
  +     */
  +    public void addPropertyset(PropertySet ps) {
  +        propertySets.addElement(ps);
  +    }
  +
  +    /**
        * Adds a directory set to the implicit build path.
        * <p>
        * <em>Note that the directories will be added to the build path
  @@ -343,6 +353,10 @@
           ant.setInheritAll(inheritAll);
           for (Enumeration i = properties.elements(); i.hasMoreElements();) {
               copyProperty(ant.createProperty(), (Property) i.nextElement());
  +        }
  +        
  +        for (Enumeration i = propertySets.elements(); i.hasMoreElements();) {
  +            ant.addPropertyset((PropertySet) i.nextElement());
           }
           
           ant.setInheritRefs(inheritRefs);
  
  
  
  1.17      +9 -2      ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java
  
  Index: AntTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AntTest.java	7 Mar 2003 11:23:11 -0000	1.16
  +++ AntTest.java	12 May 2003 12:57:05 -0000	1.17
  @@ -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
  @@ -293,6 +293,13 @@
       public void testOverrideWinsNoInheritAll() {
           expectLogContaining("test-property-override-no-inheritall-start",
                               "The value of test is 4");
  +    }
  +
  +    public void testPropertySet() {
  +        executeTarget("test-propertyset");
  +        assertTrue(getLog().indexOf("test1 is ${test1}") > -1);
  +        assertTrue(getLog().indexOf("test2 is ${test2}") > -1);
  +        assertTrue(getLog().indexOf("test1.x is 1") > -1);
       }
   
       private class BasedirChecker implements BuildListener {
  
  
  

Mime
View raw message