Take a look at the <available> task. This can verify that a directory
or file exist.. You can also use the <condition> task and verify that
a property is set via the <isset> subtask.

<condition property="deploy.dir.set">
    <isset property="deploy.dir"/>
</condition>

<fail unless="deploy.dir.set"
   message="Property &quot;$${deploy.dir}&quot; is not set"/>

<available property="deploy.dir.exists"
    file="${deploy.dir}"
    type="dir"/>

<fail unless="deploy.directory.exists"
    message="Directory &quot;${deploy.dir}&quot; doesn't exist"/>

They can also be combined:


<condition property="everything.is.okay">
   <and>
       <isset property="deploy.dir"/>
       <available file="${deploy.dir}" type="dir"/>
   </and>
</condition>

<fail unless="everything.is.okay"
   message="You really messed up!"/>

On Thu, Jan 15, 2009 at 1:00 PM, Kent Larsson <[email protected]> wrote:
> Hi,
>
> I have two files for my new build setup, one is build.xml and the other is
> build.properties. The latter one is used to override default values for some
> properties as well as providing values for properties which vary between
> computers.
>
> Their contents are:
>
> $    cat build.properties
> # Override properties for build.xml for which the default values does not
> work
> # on your machine.
> deploy.dir=/home/someuser/webapps
>
> $    cat build.xml
> <?xml version="1.0"?>
> <project xmlns:ivy="antlib:org.apache.ivy.ant" name="webcollab">
>        <property file="build.properties"/>
>        <property environment="env"/>
>
>        <!-- Sets default values to properties that are not overridden in
>             build.properties -->
>        <property name="deploy.dir" value="${CATALINA_HOME}/webapps"/>
>
>        <!-- HERE I WANT SOME VALIDATION LOGIC -->
>
> </project>
>
> At the comment about validation logic I would like to verify that deploy.dir
> is
> an existing directory. And if it is not I would like to echo "deploy.dir is
> not an
> existing directory" and fail.
>
> In the case of a property pointing to a file I would like to: a) validate
> that the file
> exist, or b) validate that the path to the file exists (in case the property
> value
> is set to a file which is about to be created by my build script).
>
> How do you validate your properties? There might become a lot of properties,
> what's the cleanest way?
>
> Best regards, Kent
>



-- 
--
David Weintraub
[email protected]

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to