bodewig     01/10/30 00:42:14

  Modified:    docs/manual/CoreTasks ant.html
               src/etc/testcases/taskdefs ant.xml
               src/testcases/org/apache/tools/ant/taskdefs AntTest.java
  Added:       src/etc/testcases/taskdefs/ant ant.xml
  Log:
  Add testcases for the inheritall/dir attribute combinations and their
  results on the new project's basedir - clarify documentation.
  
  Revision  Changes    Path
  1.6       +37 -0     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ant.html  2001/10/29 09:38:48     1.5
  +++ ant.html  2001/10/30 08:42:13     1.6
  @@ -67,6 +67,43 @@
       <td align="center" valign="top">No</td>
     </tr>
   </table>
  +
  +<h4>Basedir of the new project</h4>
  +
  +<p>The basedir value of the new project is affected by the two
  +attributes dir and inheritall, see the following table for
  +details:</p>
  +
  +<table border="1" cellpadding="2" cellspacing="0">
  +  <tr>
  +    <td valign="top"><b>dir attribute</b></td>
  +    <td valign="top"><b>inheritAll attribute</b></td>
  +    <td valign="top"><b>new project's basedir</b></td>
  +  </tr>
  +  <tr>
  +    <td valign="top">value provided</td>
  +    <td valign="top">true</td>
  +    <td valign="top">value of dir attribute</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">value provided</td>
  +    <td valign="top">false</td>
  +    <td valign="top">value of dir attribute</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">omitted</td>
  +    <td valign="top">true</td>
  +    <td valign="top">basedir of calling project (the one whose build
  +        file contains the &lt;ant&gt; task).</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">omitted</td>
  +    <td valign="top">false</td>
  +    <td valign="top">basedir attribute of the &lt;project&gt; element
  +        of the new project</td>
  +  </tr>
  +</table>
  +
   <h3>Examples</h3>
   <pre>
     &lt;ant antfile=&quot;subproject/subbuild.xml&quot; 
dir=&quot;subproject&quot; target=&quot;compile&quot;/&gt;
  
  
  
  1.3       +22 -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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ant.xml   2000/12/18 15:43:50     1.2
  +++ ant.xml   2001/10/30 08:42:13     1.3
  @@ -31,4 +31,26 @@
     <target name="dummy">
     </target>
   
  +  <target name="inheritBasedir">
  +    <ant antfile="ant/ant.xml" target="dummy" inheritAll="true" />
  +  </target>
  +
  +  <target name="doNotInheritBasedir">
  +    <ant antfile="ant/ant.xml" target="dummy" inheritAll="false" />
  +  </target>
  +
  +  <target name="explicitBasedir1">
  +    <ant antfile="taskdefs/ant/ant.xml" target="dummy" inheritAll="true" 
  +         dir=".." />
  +  </target>
  +
  +  <target name="explicitBasedir2">
  +    <ant antfile="taskdefs/ant/ant.xml" target="dummy" inheritAll="false" 
  +         dir=".." />
  +  </target>
  +
  +  <target name="tripleCall">
  +    <ant antfile="ant/ant.xml" target="callback" inheritAll="false" />
  +  </target>
  +
   </project>
  
  
  
  1.1                  jakarta-ant/src/etc/testcases/taskdefs/ant/ant.xml
  
  Index: ant.xml
  ===================================================================
  <project name="test" default="def" basedir=".">
  
    <target name="def">
      <fail>This build file should only be run from within the testcase</fail>
    </target>
  
    <target name="dummy">
      <echo message="${basedir}" />
    </target>
  
    <target name="callback">
      <ant antfile="../ant.xml" target="dummy" inheritAll="false" />
    </target>
  
  
  </project>
  
  
  1.3       +100 -1    
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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AntTest.java      2001/01/03 14:18:48     1.2
  +++ AntTest.java      2001/10/30 08:42:14     1.3
  @@ -54,17 +54,29 @@
   
   package org.apache.tools.ant.taskdefs;
   
  +import java.io.File;
  +
  +import junit.framework.AssertionFailedError;
  +
  +import org.apache.tools.ant.BuildEvent;
  +import org.apache.tools.ant.BuildListener;
  +
   /**
    * @author Nico Seessle <[EMAIL PROTECTED]> 
  + * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a> 
  + * @version $Revision: 1.3 $
    */
   public class AntTest extends TaskdefsTest { 
       
  +    private static final String TESTCASES_DIR = "src/etc/testcases";
  +    private static final String TASKDEFS_DIR = TESTCASES_DIR + "/taskdefs";
  +
       public AntTest(String name) { 
           super(name);
       }    
       
       public void setUp() { 
  -        configureProject("src/etc/testcases/taskdefs/ant.xml");
  +        configureProject(TASKDEFS_DIR + "/ant.xml");
       }
       
       public void test1() { 
  @@ -92,4 +104,91 @@
       public void test6() { 
           executeTarget("test6");
       }
  +
  +    public void testExplicitBasedir1() {
  +        File dir1 = getProjectDir();
  +        File dir2 = new File(TESTCASES_DIR);
  +        testBaseDirs("explicitBasedir1", 
  +                     new String[] {dir1.getAbsolutePath(), 
  +                                   dir2.getAbsolutePath()
  +                     });
  +    }
  +
  +    public void testExplicitBasedir2() {
  +        File dir1 = getProjectDir();
  +        File dir2 = new File(TESTCASES_DIR);
  +        testBaseDirs("explicitBasedir2",
  +                     new String[] {dir1.getAbsolutePath(), 
  +                                   dir2.getAbsolutePath()
  +                     });
  +    }
  +
  +    public void testInheritBasedir() {
  +        String basedir = getProjectDir().getAbsolutePath();
  +        testBaseDirs("inheritBasedir", new String[] {basedir, basedir});
  +    }
  +
  +    public void testDoNotInheritBasedir() {
  +        File dir1 = getProjectDir();
  +        File dir2 = new File(TASKDEFS_DIR+"/ant");
  +        String basedir = getProjectDir().getAbsolutePath();
  +        testBaseDirs("doNotInheritBasedir",
  +                     new String[] {dir1.getAbsolutePath(), 
  +                                   dir2.getAbsolutePath()
  +                     });
  +    }
  +
  +    public void testBasedirTripleCall() {
  +        File dir1 = getProjectDir();
  +        File dir2 = new File(TASKDEFS_DIR+"/ant");
  +        testBaseDirs("tripleCall", 
  +                     new String[] {dir1.getAbsolutePath(), 
  +                                   dir2.getAbsolutePath(),
  +                                   dir1.getAbsolutePath()
  +                     });
  +    }
  +
  +    protected void testBaseDirs(String target, String[] dirs) {
  +        BasedirChecker bc = new BasedirChecker(dirs);
  +        project.addBuildListener(bc);
  +        executeTarget(target);
  +        AssertionFailedError ae = bc.getError();
  +        if (ae != null) {
  +            throw ae;
  +        }
  +    }
  +
  +    private class BasedirChecker implements BuildListener {
  +        private String[] expectedBasedirs;
  +        private int calls = 0;
  +        private AssertionFailedError error;
  +
  +        BasedirChecker(String[] dirs) {
  +            expectedBasedirs = dirs;
  +        }
  +
  +        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(expectedBasedirs[calls++],
  +                                 
event.getProject().getBaseDir().getAbsolutePath());
  +                } catch (AssertionFailedError e) {
  +                    error = e;
  +                }
  +            }
  +        }
  +
  +        AssertionFailedError getError() {
  +            return error;
  +        }
  +
  +    }
  +
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to