ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gath" <gat...@bltbd.com>
Subject Re: Don't how ant interacts with directories
Date Wed, 08 Dec 2004 22:28:43 GMT
A couple things.

- Use the "location" attribute for the <property> task so it will do path
resolution and path character conversion for you.

- Review the docs for <dirname>, it drops the last path element, which is
why your "pwd" variable was set one level up.  I don't think this is what
you want.  For this same reason, you don't want to use <dirname> to echo
the other properties as well, they will be one level up to.

Try the new build.xml file below.  It's probably closer to what you want.

Brian

<?xml version="1.0" encoding="UTF-8"?>
<project name="CaseLaw_Dockets" default="showdirs" basedir=".">
   <description>
      Experiment to try to figure out how ant handles directories.
   </description>

   <!-- user.dir is a default property defined by ant -->
   <property name="source.dir"   location="${user.dir}/../source" />
   <property name="build.dir"    location="${user.dir}" />
   <property name="classes.dir"  location="${build.dir}/classes" />
   <property name="lib.dir"      location="${build.dir}/lib" />

   <target name="showdirs" >
      <echo>base        = ${basedir}</echo>
      <dirname property="pwd" file="." />
      <echo>pwd         = ${pwd}</echo>
      <echo>user.dir    = ${user.dir}</echo>
      <echo>source.dir  = ${source.dir}</echo>
      <echo>build.dir   = ${build.dir}</echo>
      <echo>classes.dir = ${classes.dir}</echo>
      <echo>lib.dir     = ${lib.dir}</echo>
      <echo/>
   </target>
</project>





<quote who="Holliday, Donald B. (LNG-CSP)">
> I am having difficulty getting ant 1.5.1 to look in the correct
> directories
> for source and put classes and jars in the right place.
>
>
>
> I work in a large IT shop and this is the latest version of ant that we
> have, so please don't tell me to upgrade to 1.6.2.  I would take months.
> I
> suspect this is not an ant defect, but user ignorance.  If its ignorance,
> what am I doing wrong?
>
>
>
> To find out what is going wrong I wrote a build file to show me what ant
> thought the directories were.  The output makes no sense to me.  The build
> file was:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <project name="CaseLaw_Dockets" default="showdirs" basedir=".">
>
>             <description>
>
>                         Experiment to try to figure out how ant handles
> directories.
>
>             </description>
>
>             <property name="source.dir" value="${user.dir}../source" />
>
>             <!-- user.dir is a default property defined by ant -->
>
>             <property name="build.dir"  value="${user.dir}" />
>
>             <property name="classes.dir"  value="${build.dir}/classes" />
>
>             <property name="lib.dir"  value="${build.dir}/lib" />
>
>
>
> <target name="showdirs" >
>
>                         <dirname property="base" file="$basedir}" />
>
>                         <echo>base = ${base}</echo>
>
>
>
>                         <dirname property="pwd" file="." />
>
>                         <echo>pwd = ${pwd}</echo>
>
>
>
>                         <echo>user.dir = ${user.dir}</echo>
>
>
>
>                         <dirname property="sourceDir"
> file="${source.dir}"/>
>
>                         <echo>source.dir = ${sourceDir}</echo>
>
>
>
>                         <dirname property="buildDir" file="${build.dir}"/>
>
>                         <echo>build.dir = ${buildDir}</echo>
>
>
>
>                         <dirname property="classesDir"
> file="${classes.dir}"/>
>
>                         <echo>classes.dir = ${classesDir}</echo>
>
>
>
>                         <dirname property="libDir" file="${lib.dir}"/>
>
>                         <echo>lib.dir = ${libDir}</echo>
>
>                         <echo/>
>
>             </target>
>
> </project>
>
>
>
> I set up a test directory structure as follows:
>
> D:\Local\AntExps\directoryExp
>
> build
>
> directoryExp.xml
>
> source
>
> com
>
> hello
>
> HelloWorld.java
>
>
>
>
>
>
>
> I ran ant using this build file as follows and got the output as shown
> (meaning the current working directory was
> D:\Local\AntExps\directoryExp\build when I ran ant).  I used the standard
> ant.bat that comes with the 1.5.1 distribution.
>
> D:\Local\AntExps\directoryExp\build>\apache\ant\bin\ant -verbose -f
> directoryExp.xml
>
> Apache Ant version 1.5.1 compiled on October 2 2002
>
> Buildfile: directoryExp.xml
>
> Detected Java version: 1.4 in: C:\j2sdk1.4.2_02\jre
>
> Detected OS: Windows XP
>
> parsing buildfile directoryExp.xml with URI =
> file:D:/Local/AntExps/directoryExp/build/directoryExp.xml
>
> Project base dir set to: D:\Local\AntExps\directoryExp\build
>
> Build sequence for target `showdirs' is [showdirs]
>
> Complete build sequence is [showdirs]
>
>
>
> showdirs:
>
>      [echo] base = D:\Local\AntExps\directoryExp\build
>
>      [echo] pwd = D:\Local\AntExps\directoryExp
>
>      [echo] user.dir = D:\Local\AntExps\directoryExp\build
>
>      [echo] source.dir = D:\Local\AntExps\directoryExp\build..
>
>      [echo] build.dir = D:\Local\AntExps\directoryExp
>
>      [echo] classes.dir = D:\Local\AntExps\directoryExp\build
>
>      [echo] lib.dir = D:\Local\AntExps\directoryExp\build
>
>
>
>
>
> BUILD SUCCESSFUL
>
> Total time: 0 seconds
>
>
>
> Here's my problem with this output
>
> 1.	The value of the "basedir" attribute of <project> was
> D:\Local\AntExps\directoryExp\build.  The value of ${user.dir} was
> D:\Local\AntExps\directoryExp\build.  So how can the value of ${pwd} be
> D:\Local\AntExps\directoryExp which is one level up from the directory
> where
> I ran ant?
> 2.	${source.dir} was supposed to be ${user.dir}../source, which should
> have evaluated to D:\Local\AntExps\directoryExp\source, but instead it
> evaluated to D:\Local\AntExps\directoryExp\build.. (note the two trailing
> dots).  Why?
> 3.	${build.dir} was supposed to be the same as ${user.dir} and evaluate
> to D:\Local\AntExps\directoryExp\build, but instead evaluated to
> D:\Local\AntExps\directoryExp which is one level up from ${user.dir} in
> the
> directory hierarchy.  How can this happen?
> 4.	${lib.dir} was supposed to evaluate to
> D:\Local\AntExps\directoryExp\build\lib, but instead evaluated to
> D:\Local\AntExps\directoryExp\build, why?
>
>
>
> None of this makes any sense to me.  Can anyone explain what is going on?
>
>
>
> Thanks,
>
>
>
> Donald Holliday
>
> (719) 481-7501 V
>
> (800) 743-7393 x 7501 V
>
> Donald.Holliday@LexisNexis.com <mailto:Donald.Holliday@LexisNexis.com>
>
>
>
> The Eight Fallacies of Distributed Computing
>
> By Peter Deutsch
>
> Essentially everyone, when they first build a distributed application,
> makes
> the following eight assumptions. All prove to be false in the long run and
> all cause big trouble and painful learning experiences.
>
> 1. The network is reliable
>
> 2. Latency is zero
>
> 3. Bandwidth is infinite
>
> 4. The network is secure
>
> 5. Topology doesn't change
>
> 6. There is one administrator
>
> 7. Transport cost is zero
>
> 8. The network is homogeneous
>
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message