You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dimitris Mouchritsas <di...@eurodyn.com> on 2008/07/21 16:59:26 UTC
Re: AW: Checking for build.properties and properties upon initialization
Gilbert Rebhan wrote:
> Dimitris Mouchritsas schrieb:
>> What I'd like to accomplish is checking if build.properties 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 build.properties 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 =
> http://antxtras.sourceforge.net/AntXtras/docs/howto/fix_chk_properties.html
>
>
> Regards, Gilbert
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
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 build.properties">
<condition property="required.properties.set">
<not>
<or>
<matches string="${log4j.lib.dir}"
pattern="^\$\{.*\}$" />
<matches string="${log4j.jar}"
pattern="^\$\{.*\}$" />
<matches string="${commons.io.lib.dir}"
pattern="^\$\{.*\}$" />
<matches string="${commons.io.jar}"
pattern="^\$\{.*\}$" />
<matches string="${junit.lib.dir}"
pattern="^\$\{.*\}$" />
<matches string="${junit.jar}"
pattern="^\$\{.*\}$" />
<matches string="${jdbc.lib.dir}"
pattern="^\$\{.*\}$" />
<matches string="${jdbc.jar}"
pattern="^\$\{.*\}$" />
</or>
</not>
</condition>
<fail unless="required.properties.set">
One of the required propeties is missing. Please check the
following
list and see which one. Then please add it to build.properties
log4j.lib.dir = ${log4j.lib.dir}
log4j.jar = ${log4j.jar}
commons.io.lib.dir = ${commons.io.lib.dir}
commons.io.jar = ${commons.io.jar}
junit.lib.dir = ${junit.lib.dir}
junit.jar = ${junit.jar}
jdbc.lib.dir = ${jdbc.lib.dir}
jdbc.jar = ${jdbc.jar}
</fail>
</target>
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?
Regards
Dimitris
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: AW: Checking for build.properties and properties upon initialization
Posted by Dimitris Mouchritsas <di...@eurodyn.com>.
Dominique Devienne wrote:
> On Mon, Jul 21, 2008 at 9:59 AM, Dimitris Mouchritsas
> <dimitris.mouchritsas@eurodyn.com
>
>> What do you think?
>>
>
> Why not simply
>
> <fail unless="log4j.lib.dir">Property log4j.lib.dir must be set</fail>
> <fail unless="log4j.jar">Property log4j.jar must be set</fail>
> etc...
>
> And wrap this into a macro allowing to call as as <assert-property-set
> name="log4j.lib.dir" />?
>
> Only difference is that you can't easily all the properties not set at
> once, but one at a time. Looks a bit simpler to me though. --DD
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
Well, from the little thought I gave to the problem, to me it seems
better to have all the properties
shown at once. I know it's fast since it's executed right at the start
of the project but I prefer this
to run, find missing, declare, run, find missing, declare, run, .... you
get the idea.
It's just a personal preference I guess. I haven't thought of the
multiple fail unless like that though.
That looks good as well.
Dimitris
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: AW: Checking for build.properties and properties upon initialization
Posted by Dominique Devienne <dd...@gmail.com>.
On Mon, Jul 21, 2008 at 9:59 AM, Dimitris Mouchritsas
<dimitris.mouchritsas@eurodyn.com
> What do you think?
Why not simply
<fail unless="log4j.lib.dir">Property log4j.lib.dir must be set</fail>
<fail unless="log4j.jar">Property log4j.jar must be set</fail>
etc...
And wrap this into a macro allowing to call as as <assert-property-set
name="log4j.lib.dir" />?
Only difference is that you can't easily all the properties not set at
once, but one at a time. Looks a bit simpler to me though. --DD
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org