You could do this validation in your build file.
For example, the following build file defines a macrodef validate-file-property
which validates that a specified property is defined and that it exists as a file or dir in the file system.
<project default="init">
<property file="test.properties"/>
<target name="init">
<validate-file-property property="program.files" type="dir"/>
<validate-file-property property="mydata.root" type="dir"/>
<validate-file-property property="foo"/>
</target>
<macrodef name="validate-file-property">
<attribute name="property"/>
<attribute name="type" default="file"/>
<sequential>
<fail unless="@{property}" message="The property '@{property}' is undefinded."/>
<available file="${@{property}}" property="@{property}.exists" type="@{type}"/>
<fail unless="@{property}.exists" message="The @{type} '@{property}' with value '${@{property}}' does not exist."/>
</sequential>
</macrodef>
</project>
You need to decide when to validate the properties, and you need to validate them explicitly - as shown in the init
target in this example.
BTW, if you used a standardized pattern to name properties which refer to files or directories - e.g. my.special.file
, my.build.dir
- then you could use a shell script to discover all relevant properties and write all your validate-file-property
elements . Something like this:
awk -F= '/\.(file|dir)/{ printf "<validate-file-property property=\"%s\" type=\"%s\"/>\n", $1, gensub(/.*\.(file|dir)/, "\\1", "g", $1) }' *.properties
You could paste the output into your build file.