ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dimitris Mouchritsas <>
Subject Re: AW: Checking for and properties upon initialization
Date Mon, 21 Jul 2008 14:59:26 GMT
Gilbert Rebhan wrote:
> Dimitris Mouchritsas schrieb:
>> What I'd like to accomplish is checking if exists 
>> (which loadproperties ensures) and
>> then check to see if a set of properties is set. If a property is 
>> missing I'd like to display a message with
>> the name of the property missing.
>> What are your thoughts?
> ?!
> as you've already said, <loadfile .. /> assures
> that the exists, otherwise your build will
> fail
> the echo if ${someproperty} is missing you will get with
> something like =
> <target name="foobar" unless="someproperty">
>   <echo>WARNING => $${someproperty} not set !!</echo>
> <target>
> if you need more reaction, you have to use <condition>
> or <assert> from antcontrib
> btw, if you need to do more complicated stuff with properties
> you should have a look on AntXtras, they have assert, fixturechecks,
> one example that would suit to your needs =
> Regards, Gilbert
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:
I know it took a long time (had other priorities at work) but I think I 
came up with a more elegant solution, without
needing antcontrib. Ok, the buildfile does not tell you exactly which 
property is not set, but you get a list to see
which one is missing.

    <target name="required-properties"
            description="Check required properties from">

        <condition property="">
                    <matches string="${log4j.lib.dir}"      
pattern="^\$\{.*\}$" />
                    <matches string="${log4j.jar}"          
pattern="^\$\{.*\}$" />
                    <matches string="${}" 
pattern="^\$\{.*\}$" />
                    <matches string="${}"     
pattern="^\$\{.*\}$" />
                    <matches string="${junit.lib.dir}"      
pattern="^\$\{.*\}$" />
                    <matches string="${junit.jar}"          
pattern="^\$\{.*\}$" />
                    <matches string="${jdbc.lib.dir}"       
pattern="^\$\{.*\}$" />
                    <matches string="${jdbc.jar}"           
pattern="^\$\{.*\}$" />

        <fail unless="">
            One of the required propeties is missing. Please check the 
            list and see which one. Then please add it to

            log4j.lib.dir       = ${log4j.lib.dir}
            log4j.jar           = ${log4j.jar}
    = ${}
        = ${}
            junit.lib.dir       = ${junit.lib.dir}
            junit.jar           = ${junit.jar}
            jdbc.lib.dir        = ${jdbc.lib.dir}
            jdbc.jar            = ${jdbc.jar}

and of course the "init" target depends on required-properties. Also 
this does not work if the property value is ${something}
but I don't think I'll ever use such a value. What do you think?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message