Browse Source

Add testcases for the inheritall/dir attribute combinations and their

results on the new project's basedir - clarify documentation.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269838 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
32da696de4
4 changed files with 175 additions and 1 deletions
  1. +37
    -0
      docs/manual/CoreTasks/ant.html
  2. +22
    -0
      src/etc/testcases/taskdefs/ant.xml
  3. +16
    -0
      src/etc/testcases/taskdefs/ant/ant.xml
  4. +100
    -1
      src/testcases/org/apache/tools/ant/taskdefs/AntTest.java

+ 37
- 0
docs/manual/CoreTasks/ant.html View File

@@ -67,6 +67,43 @@ setting of <i>inheritAll</i>. This allows you to parameterize your subprojects.
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>
</tr> </tr>
</table> </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> <h3>Examples</h3>
<pre> <pre>
&lt;ant antfile=&quot;subproject/subbuild.xml&quot; dir=&quot;subproject&quot; target=&quot;compile&quot;/&gt; &lt;ant antfile=&quot;subproject/subbuild.xml&quot; dir=&quot;subproject&quot; target=&quot;compile&quot;/&gt;


+ 22
- 0
src/etc/testcases/taskdefs/ant.xml View File

@@ -31,4 +31,26 @@
<target name="dummy"> <target name="dummy">
</target> </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> </project>

+ 16
- 0
src/etc/testcases/taskdefs/ant/ant.xml View File

@@ -0,0 +1,16 @@
<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>

+ 100
- 1
src/testcases/org/apache/tools/ant/taskdefs/AntTest.java View File

@@ -54,17 +54,29 @@


package org.apache.tools.ant.taskdefs; 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 <nico@seessle.de> * @author Nico Seessle <nico@seessle.de>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @version $Revision$
*/ */
public class AntTest extends TaskdefsTest { 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) { public AntTest(String name) {
super(name); super(name);
} }
public void setUp() { public void setUp() {
configureProject("src/etc/testcases/taskdefs/ant.xml");
configureProject(TASKDEFS_DIR + "/ant.xml");
} }
public void test1() { public void test1() {
@@ -92,4 +104,91 @@ public class AntTest extends TaskdefsTest {
public void test6() { public void test6() {
executeTarget("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;
}

}

} }

Loading…
Cancel
Save