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 2002/05/10 13:33:54 UTC

cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs AntTest.java

bodewig     02/05/10 04:33:54

  Modified:    .        Tag: ANT_15_BRANCH WHATSNEW
               docs/manual/CoreTasks Tag: ANT_15_BRANCH ant.html
               src/etc/testcases/taskdefs Tag: ANT_15_BRANCH ant.xml
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
                        Ant.java Property.java
               src/testcases/org/apache/tools/ant/taskdefs Tag:
                        ANT_15_BRANCH AntTest.java
  Log:
  Make refid attribute of <property>s that are nested into <ant> work.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.263.2.9 +3 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.263.2.8
  retrieving revision 1.263.2.9
  diff -u -r1.263.2.8 -r1.263.2.9
  --- WHATSNEW	10 May 2002 06:41:46 -0000	1.263.2.8
  +++ WHATSNEW	10 May 2002 11:33:54 -0000	1.263.2.9
  @@ -28,6 +28,9 @@
   longer try this, but you may run into problems with the length of the
   command line now.
   
  +* the refid attribute for <property>s nested into <ant> or <param>s
  +nested into <antcall> didn't work.
  +
   Other changes:
   --------------
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.14.2.2  +4 -3      jakarta-ant/docs/manual/CoreTasks/ant.html
  
  Index: ant.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/ant.html,v
  retrieving revision 1.14.2.1
  retrieving revision 1.14.2.2
  diff -u -r1.14.2.1 -r1.14.2.2
  --- ant.html	3 May 2002 09:40:28 -0000	1.14.2.1
  +++ ant.html	10 May 2002 11:33:54 -0000	1.14.2.2
  @@ -87,9 +87,10 @@
     </tr>
   </table>
   
  -<h3>Parameters specified as nested elements</h3>
  -<h4>property</h4>
  -<p>See the description of the <a href="property.html">property task</a>.</p>
  +<h3>Parameters specified as nested elements</h3> <h4>property</h4>
  +<p>See the description of the <a href="property.html">property
  +task</a>.  Note that the <code>refid</code> attribute points to a
  +reference in the calling project, not in the new one.</p>
   
   <h4><a name="reference">reference</a></h4>
   <p>Used to chose references that shall be copied into the new project,
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.6.2.1   +10 -0     jakarta-ant/src/etc/testcases/taskdefs/ant.xml
  
  Index: ant.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/ant.xml,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- ant.xml	3 Apr 2002 08:15:30 -0000	1.6
  +++ ant.xml	10 May 2002 11:33:54 -0000	1.6.2.1
  @@ -2,6 +2,10 @@
   
   <project name="ant-test" basedir="." default="test1">
   
  +  <path id="inheritable">
  +    <pathelement path="${java.class.path}" />
  +  </path>
  +
     <target name="cleanup">
       <delete file="test1.log" />
       <delete file="test2.log" />
  @@ -82,5 +86,11 @@
            inheritall="false" dir="ant" />
       <ant antfile="ant.xml" target="dummy" output="test4.log" 
            dir="ant" />
  +  </target>
  +
  +  <target name="testRefid">
  +    <ant antfile="ant/references.xml" inheritRefs="false" target="dummy">
  +      <property name="testprop" refid="inheritable" />
  +    </ant>
     </target>
   </project>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.56.2.2  +1 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.56.2.1
  retrieving revision 1.56.2.2
  diff -u -r1.56.2.1 -r1.56.2.2
  --- Ant.java	10 May 2002 10:16:38 -0000	1.56.2.1
  +++ Ant.java	10 May 2002 11:33:54 -0000	1.56.2.2
  @@ -527,7 +527,7 @@
           if (newProject == null) {
               reinit();
           }
  -        Property p = new Property(true);
  +        Property p = new Property(true, getProject());
           p.setProject(newProject);
           p.setTaskName("property");
           properties.addElement(p);
  
  
  
  1.48.2.2  +21 -5     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java
  
  Index: Property.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
  retrieving revision 1.48.2.1
  retrieving revision 1.48.2.2
  diff -u -r1.48.2.1 -r1.48.2.2
  --- Property.java	10 May 2002 10:16:39 -0000	1.48.2.1
  +++ Property.java	10 May 2002 11:33:54 -0000	1.48.2.2
  @@ -88,18 +88,27 @@
       protected String env;
       protected Reference ref;
       protected String prefix;
  +    private Project fallback;
   
       protected boolean userProperty; // set read-only properties
   
       public Property() {
  -        super();
  +        this(false);
       }
   
       /**
        * @since Ant 1.5
        */
       protected Property(boolean userProperty) {
  +        this(userProperty, null);
  +    }
  +
  +    /**
  +     * @since Ant 1.5
  +     */
  +    protected Property(boolean userProperty, Project fallback) {
           this.userProperty = userProperty;
  +        this.fallback = fallback;
       }
   
       public void setName(String name) {
  @@ -250,10 +259,17 @@
           }
   
           if ((name != null) && (ref != null)) {
  -            Object obj = ref.getReferencedObject(getProject());
  -            if (obj != null) {
  -                addProperty(name, obj.toString());
  -            }
  +            try {
  +                addProperty(name, 
  +                            ref.getReferencedObject(getProject()).toString());
  +            } catch (BuildException be) {
  +                if (fallback != null) {
  +                    addProperty(name, 
  +                                ref.getReferencedObject(fallback).toString());
  +                } else {
  +                    throw be;
  +                }
  +            }                
           }
       }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.11.2.1  +54 -8     jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java
  
  Index: AntTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java,v
  retrieving revision 1.11
  retrieving revision 1.11.2.1
  diff -u -r1.11 -r1.11.2.1
  --- AntTest.java	22 Apr 2002 13:43:52 -0000	1.11
  +++ AntTest.java	10 May 2002 11:33:54 -0000	1.11.2.1
  @@ -68,7 +68,7 @@
   /**
    * @author Nico Seessle <ni...@seessle.de> 
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
  - * @version $Revision: 1.11 $
  + * @version $Revision: 1.11.2.1 $
    */
   public class AntTest extends BuildFileTest { 
       
  @@ -161,6 +161,7 @@
           if (ae != null) {
               throw ae;
           }
  +        project.removeBuildListener(bc);
       }
   
       public void testReferenceInheritance() {
  @@ -252,6 +253,20 @@
           getProject().removeBuildListener(ic);
       }
   
  +    public void testRefId() {
  +        PropertyChecker pc = 
  +            new PropertyChecker("testprop",
  +                                new String[] {null, 
  +                                              Path.systemClasspath.toString()});
  +        project.addBuildListener(pc);
  +        executeTarget("testRefid");
  +        AssertionFailedError ae = pc.getError();
  +        if (ae != null) {
  +            throw ae;
  +        }
  +        project.removeBuildListener(pc);
  +    }
  +
       private class BasedirChecker implements BuildListener {
           private String[] expectedBasedirs;
           private int calls = 0;
  @@ -271,13 +286,8 @@
           public void targetStarted(BuildEvent event) {
               if (error == null) {
                   try {
  -                    if (calls == expectedBasedirs.length) {
  -                        assertEquals("cleanup",
  -                                     event.getTarget().getName());
  -                    } else {
  -                        assertEquals(expectedBasedirs[calls++],
  -                                     event.getProject().getBaseDir().getAbsolutePath());
  -                    }
  +                    assertEquals(expectedBasedirs[calls++],
  +                                 event.getProject().getBaseDir().getAbsolutePath());
                   } catch (AssertionFailedError e) {
                       error = e;
                   }
  @@ -403,5 +413,41 @@
           }
   
       }
  +
  +    private class PropertyChecker implements BuildListener {
  +        private String[] expectedValues;
  +        private String key;
  +        private int calls = 0;
  +        private AssertionFailedError error;
  +
  +        PropertyChecker(String key, String[] values) {
  +            this.key = key;
  +            this.expectedValues = values;
  +        }
  +
  +        public void buildStarted(BuildEvent event) {}
  +        public void buildFinished(BuildEvent event) {}
  +        public void targetFinished(BuildEvent event){}
  +        public void taskStarted(BuildEvent event) {}
  +        public void taskFinished(BuildEvent event) {}
  +        public void messageLogged(BuildEvent event) {}
  +
  +        public void targetStarted(BuildEvent event) {
  +            if (error == null) {
  +                try {
  +                    assertEquals(expectedValues[calls++],
  +                                 event.getProject().getProperty(key));
  +                } catch (AssertionFailedError e) {
  +                    error = e;
  +                }
  +            }
  +        }
  +
  +        AssertionFailedError getError() {
  +            return error;
  +        }
  +
  +    }
  +
   
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>