ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cyril Sagan" <Cyril.Sa...@sas.com>
Subject workaround: fileset dir attribute is non-existent directory?
Date Thu, 02 Oct 2003 22:50:16 GMT

HELP!  Is this a bug or a feature?

Background
----------
   I'm trying to build a general fileset from a user-supplied property
plus a pattern which I supply.  The problem occurs when the user
supplied directory does not exist.  For some projects this is okay, so
it is not the user's fault, I need a smarter build.xml which will work
across all proejcts.

Something as simple as this:
    <fileset dir="${user.dir}" includes="**/*.jar" />

... will work, but only works if user.dir exists!

What is the right workaround for when the dir attribute of <fileset>
points to a non-existent directory???  (FYI: I searched the ant-user
archives, this has not been this discussed since July 2001.)

The only thing I can think of is testing existence with <available>
then embedding the <fileset> is an conditonally executed target.  Is
there a better way??  I hope so, but I can't find a solution.  I tried
the following, and think its a bug...


Workaround?
-----------
In my attempt to work around the non-existent directory problem, I
tried:
    <fileset dir=".">
        <filename name="${user.dir}/*.jar" />
    </fileset>

This "works" in so far as it does not crash Ant, but it doesn't point
to the "right" fileset in all cases either since users specify the jar
directory using relative paths.  Here's where I stumbled on what I
THINK IS A BUG:
    The *name* attribute can be a file or directory,
    but NOT if it starts with '..'.

So, is this a bug or feature??  My enclosed sample illustrates two
variations attempting to construct the right path.  I use two
different dir attributes, one starting with "dot dot".  However, both
resolve to same jar directory.

See below <filename name="../*.jar"/> is NOT interpreted properly...

** First the build script:

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="pathtest" default="run" basedir=".">

<target name="init">
    <echo>Ant version: ${ant.version}</echo>
</target>


<target name="run" depends="init">
    <!-- Attempt to work around non-existent dir attribute     -->
    <!-- in fileset, it does not crash ant, but doesn't return -->
    <!-- the correct path either...  Seems that '..' in the    -->
    <!-- name attribute of fileset causes problems.            -->

    <!-- project layout:                                       -->
    <!--   "root" is /tmp/ant                                  -->
    <!--             /tmp/ant/Source/Java (build here!)        -->
    <!--             /tmp/ant/lib/jars                         -->

    <path id="jar.path1">
        <fileset dir="/tmp/ant">
            <filename name="lib/jars/*.jar" />
        </fileset>
    </path>
    <property name="path.string1" refid="jar.path1" /> 
    <echo>Using project path: ${path.string1}</echo>


    <path id="jar.path2">
        <fileset dir="/tmp/ant/Source/Java">
            <filename name="../../lib/jars/*.jar" />
        </fileset>
    </path>
    <property name="path.string2" refid="jar.path2" /> 
    <echo>Using 'dot dot' path: ${path.string2}</echo>
</target>

</project>


** Run log:

$ ant -f bug.xml
Buildfile: bug.xml

init:
     [echo] Ant version: Apache Ant version 1.5.1 compiled on October 2 2002

run:
     [echo] Using project path: /tmp/ant/lib/jars/a.jar:/tmp/ant/lib/jars/b.jar
     [echo] Using 'dot dot' path: 

BUILD SUCCESSFUL
Total time: 1 second

$ rm -rf ../../lib/jars

$ ant -f bug.xml	(at least it doesnt crash ant!)
Buildfile: bug.xml

init:
     [echo] Ant version: Apache Ant version 1.5.1 compiled on October 2 2002

run:
     [echo] Using project path: 
     [echo] Using 'dot dot' path: 

BUILD SUCCESSFUL
Total time: 1 second
$ 


Thanks for any suggestions!!

--Cyril

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


Mime
View raw message