You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Nolan Ring <No...@Sun.Com> on 2002/08/27 19:35:29 UTC

any way include a fileset in a classpath conditionally?

Hi,

The following is the classpath for my javac task.  The problem I'm having is
that the nightlyBuildDir directory, which is defined in a global.properties
file, may or may not exist.  If it does exist, I want its contents to be
included in the classpath; if it doesn't exist I want it to be skipped.
Right now, if ${nightlyBuildDir} doesn't exist my build fails.

Is there some way to conditionally set include fileset based on whether or
not ${nightlyBuildDir} exists?  I thought, at first, that <available> might
work, but don't want to run the entire target conditionally - just set this
piece of the classpath. 

        <classpath>
            <pathelement path="${classpath}"/>
            <pathelement path="${classesDir}"/>
            <fileset dir="${distDir}">
                <include name="**/*.jar"/>
                <include name="**/*.zip"/>
                <exclude name="${jarName}"/>
            </fileset>
            <fileset dir="${nightlyBuildDir}">
                <include name="**/*.jar" />
                <include name="**/*.zip" />
                <exclude name="${jarName}" />
            </fileset>
            <fileset dir="${libDir}">
                <include name="**/*.jar"/>
            </fileset>
         </classpath>

Thanks much.

Nolan Ring

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: any way include a fileset in a classpath conditionally?

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Filesets cannot be conditional, but include/exclude elements have 
if/unless attributes in exactly the same manner as target if/unless.

	Erik


Nolan Ring wrote:
> Hi,
> 
> The following is the classpath for my javac task.  The problem I'm having is
> that the nightlyBuildDir directory, which is defined in a global.properties
> file, may or may not exist.  If it does exist, I want its contents to be
> included in the classpath; if it doesn't exist I want it to be skipped.
> Right now, if ${nightlyBuildDir} doesn't exist my build fails.
> 
> Is there some way to conditionally set include fileset based on whether or
> not ${nightlyBuildDir} exists?  I thought, at first, that <available> might
> work, but don't want to run the entire target conditionally - just set this
> piece of the classpath. 
> 
>         <classpath>
>             <pathelement path="${classpath}"/>
>             <pathelement path="${classesDir}"/>
>             <fileset dir="${distDir}">
>                 <include name="**/*.jar"/>
>                 <include name="**/*.zip"/>
>                 <exclude name="${jarName}"/>
>             </fileset>
>             <fileset dir="${nightlyBuildDir}">
>                 <include name="**/*.jar" />
>                 <include name="**/*.zip" />
>                 <exclude name="${jarName}" />
>             </fileset>
>             <fileset dir="${libDir}">
>                 <include name="**/*.jar"/>
>             </fileset>
>          </classpath>
> 
> Thanks much.
> 
> Nolan Ring
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: any way include a fileset in a classpath conditionally?

Posted by Matt Benson <gu...@yahoo.com>.
I have gotten around this by using nested dirsets. 
The trick is to point the dirset to some higher-level
directory that you expect will exist, and include
subdirectories that match the directory that might
exist.  If it does not, the dirset will be empty, no
harm done.  I'm not sure how best to make this
approach work if you are using an absolute path,
however.

-Matt

--- Nolan Ring <No...@Sun.Com> wrote:
> 
> Hi,
> 
> The following is the classpath for my javac task. 
> The problem I'm having is
> that the nightlyBuildDir directory, which is defined
> in a global.properties
> file, may or may not exist.  If it does exist, I
> want its contents to be
> included in the classpath; if it doesn't exist I
> want it to be skipped.
> Right now, if ${nightlyBuildDir} doesn't exist my
> build fails.
> 
> Is there some way to conditionally set include
> fileset based on whether or
> not ${nightlyBuildDir} exists?  I thought, at first,
> that <available> might
> work, but don't want to run the entire target
> conditionally - just set this
> piece of the classpath. 
> 
>         <classpath>
>             <pathelement path="${classpath}"/>
>             <pathelement path="${classesDir}"/>
>             <fileset dir="${distDir}">
>                 <include name="**/*.jar"/>
>                 <include name="**/*.zip"/>
>                 <exclude name="${jarName}"/>
>             </fileset>
>             <fileset dir="${nightlyBuildDir}">
>                 <include name="**/*.jar" />
>                 <include name="**/*.zip" />
>                 <exclude name="${jarName}" />
>             </fileset>
>             <fileset dir="${libDir}">
>                 <include name="**/*.jar"/>
>             </fileset>
>          </classpath>
> 
> Thanks much.
> 
> Nolan Ring
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: any way include a fileset in a classpath conditionally?

Posted by Laurie Harper <zo...@holoweb.net>.
I have the exact same problem, and I don't think the suggested solutions
work for me... I have top level path elements such as:

    <path id="classpath.lib.runtime">
        <!-- Libraries required at run-time -->
        <fileset dir="${dir.lib.runtime}">
            <include name="**/*.jar"/>
            <include name="**/*.zip"/>
        </fileset>
    </path>

I can't put if/unless clauses on the include elements because they're not
the part that's at issue; ${dir.lib.runtime} may point anywhere and be
absolute or relative, so I can't pick a parent directory that's known to
exist, for use with a DirSet; and I can't use DD's solution, using multiple
property definitions, because I can't guarantee that the includes won't
match something they shouldn't (I can't make assumptions about the directory
structure of the project being built).

The only solution I can think of is to split the path element into a set of
targets, something like:

    <target name="set-classpath.lib.runtime"
      depends="check-classpath.lig.runtime,
               do-set-classpath.lib.runtime,
               default-classpath.lib.runtime"/>

    <target name="check-classpath.lib.runtime">
        <available type="dir" file="${dir.lib.runtime}" property="exists"/>
    </target>

    <target name="do-set-classpath.lib.runtime" if="exists">
        <path id="classpath.lib.runtime">
            <!-- Libraries required at run-time -->
            <fileset dir="${dir.lib.runtime}">
                <include name="**/*.jar"/>
                <include name="**/*.zip"/>
            </fileset>
        </path>
    </target>

    <target name="default-classpath.lib.runtime" unless="exists">
        <path id="classpath.lib.runtime"/>
    </target>

Appart from the obvious disadvantage of how verbose this is, it has the
disadvantage that build files must change to add a reference to the
set-classpath.lib.runtime task. I'm also not sure you can define an empty
path in default-classpath.lib.runtime.

Can anyone think of a way to do this that¹s robust?

L.

On 8/27/02 1:35 PM, "Nolan Ring" <No...@Sun.Com> wrote:

> 
> Hi,
> 
> The following is the classpath for my javac task.  The problem I'm having is
> that the nightlyBuildDir directory, which is defined in a global.properties
> file, may or may not exist.  If it does exist, I want its contents to be
> included in the classpath; if it doesn't exist I want it to be skipped.
> Right now, if ${nightlyBuildDir} doesn't exist my build fails.
> 
> Is there some way to conditionally set include fileset based on whether or
> not ${nightlyBuildDir} exists?  I thought, at first, that <available> might
> work, but don't want to run the entire target conditionally - just set this
> piece of the classpath.
> 
>       <classpath>
>           <pathelement path="${classpath}"/>
>           <pathelement path="${classesDir}"/>
>           <fileset dir="${distDir}">
>               <include name="**/*.jar"/>
>               <include name="**/*.zip"/>
>               <exclude name="${jarName}"/>
>           </fileset>
>           <fileset dir="${nightlyBuildDir}">
>               <include name="**/*.jar" />
>               <include name="**/*.zip" />
>               <exclude name="${jarName}" />
>           </fileset>
>           <fileset dir="${libDir}">
>               <include name="**/*.jar"/>
>           </fileset>
>        </classpath>
> 
> Thanks much.
> 
> Nolan Ring
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>