I believe I have stumbled across a bug in ant (1.3 + 1.4.1). Assume the
following build file in ~/TEST:
<project name="tester" default="zot" basedir=".">
<target name="zot">
<ant dir="${basedir}/zotdir" target="jar"/>
</target>
</project>
and the following build file in ~/TEST/zotdir:
<project name="anothername" default="jar" basedir="..">
<target name="jar">
<echo message="${basedir}"/>
</target>
</project>
If in the ~/TEST directory I call "ant", I would have expected the echo to
have printed ~/TEST, but it prints ~/TEST/zotdir, regardless of the setting
of basedir in ~/TEST/zotdir/build.xml.
However, if I do:
cd ~/TEST/zotdir
ant
then the echo message prints out the correct result.
I have attached a patch which fixes the problem.
The main change is in ProjectHelper, where the basedir of a project can only
be overwritten if it is a user property (set on the command line) rather than
just a property. This is where the bug was, since in the execute method for
the Ant class, newProject.setBaseDir(dir) is called, which sets the basedir
property to the directory that the build file is located in.
The following line:
newProject.setUserProperty("basedir" , dir.getAbsolutePath());
was removed, since the basedir property is already set as a side effect of
the previous line, and as far as I can tell, it should be a system property,
not a user property.
I have only just started to look at the ant sources, so I may have made a
bad assumption somewhere...
Any comments?
Cheers,
David
diff -r -u
/home/sits/ORIG/jakarta-ant-1.4.1/src/main/org/apache/tools/ant/ProjectHelper.java
./src/main/org/apache/tools/ant/ProjectHelper.java
---
/home/sits/ORIG/jakarta-ant-1.4.1/src/main/org/apache/tools/ant/ProjectHelper.java
Thu Oct 11 23:58:29 2001
+++ ./src/main/org/apache/tools/ant/ProjectHelper.java Sat Oct 20 01:17:35 2001
@@ -316,8 +316,8 @@
if (id != null) project.addReference(id, project);
- if (project.getProperty("basedir") != null) {
- project.setBasedir(project.getProperty("basedir"));
+ if (project.getUserProperty("basedir") != null) {
+ project.setBasedir(project.getUserProperty("basedir"));
} else {
if (baseDir == null) {
project.setBasedir(buildFileParent.getAbsolutePath());
diff -r -u
/home/sits/ORIG/jakarta-ant-1.4.1/src/main/org/apache/tools/ant/taskdefs/Ant.java
./src/main/org/apache/tools/ant/taskdefs/Ant.java
---
/home/sits/ORIG/jakarta-ant-1.4.1/src/main/org/apache/tools/ant/taskdefs/Ant.java
Thu Oct 11 23:58:29 2001
+++ ./src/main/org/apache/tools/ant/taskdefs/Ant.java Sat Oct 20 01:20:00 2001
@@ -231,7 +231,6 @@
initializeProject();
newProject.setBaseDir(dir);
- newProject.setUserProperty("basedir" , dir.getAbsolutePath());
// Override with local-defined properties
Enumeration e = properties.elements();