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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]