I was a bit confused with the behavior of dirname when the file property was that of an unset parameter. QUESTION: Is this a bug of feature?
Here's my full example: $ cd /tmp/Ant_Mystery $ ant -version Apache Ant version 1.6.5 compiled on June 2 2005 $ cat build.xml <?xml version="1.0"?> <project name="Ant_Mystery"> <!-- Illustrate some mysteries with <dirname> task --> <dirname property="foobar.dir" file="${foobar}" /> <property name="foobar.fullpath" location="${foobar.dir}"/> <echo> foobar = ${foobar} foobar.dir = ${foobar.dir} foobar.fullpath = ${foobar.fullpath} </echo> </project> $ ant Buildfile: build.xml [echo] [echo] foobar = ${foobar} [echo] foobar.dir = /tmp/Ant_Mystery [echo] foobar.fullpath = /tmp/Ant_Mystery [echo] BUILD SUCCESSFUL Total time: 1 second I wouldn't expect the foobar.dir property to be set since the file attribute comes from an unset property. From the ant source code, I think I see why this is happening: from main/org/apache/tools/ant/taskdefs/Dirname.java: public void setFile(File file) { this.file = file; } // The method executing the task public void execute() throws BuildException { ... if (file == null) { throw new BuildException("file attribute required", getLocation()); } else { String value = file.getParent(); getProject().setNewProperty(property, value); } } I suspect that the new File object gets constructed before calling setFile, so in my example ${foobar}.getParent() is equivalent to the current directory. Seems like the right behavior would be to fail someway if the path named by dirname's file attribute didn't exist. Anyone else agree? Second question: I thought foobar.dir would be a relative path and <property location=...> would be the absolute path, but they're both the same. What am I missing?? I'd appreciate hearing other comments. Thanks. --Cyril --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]