Dimitris Mouchritsas wrote:
jan.mate...@rzf.fin-nrw.de wrote:
I'm giving Ant 1.8.0 a try on a new project. I'd like to ask if there
have been any changes for loading property files (break the build if they're not found)

should not.
But using <property file/> the specified property file doesnt have to
exist - since a long time...


and if ant can report on the properties missing.
Are there any related ant-contrib tasks?

<fail> with <isset> condition.


<macrodef name="requireFile">
    <attribute name="file"/>
    <sequential>
        <fail message="@{file} does not exist.">
            <condition>
                <not><available file="@{file}"/></not>
            </condition>
        </fail>
    </sequential>
</macrodef>

<macrodef name="requireProperty">
    <attribute name="property"/>
    <sequential>
        <fail message="@{property} does not exist.">
            <condition>
                <not><isset property="@{property}"/></not>
            </condition>
        </fail>
    </sequential>
</macrodef>




Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Seems to work pretty well :) Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Ok, I know I didn't ask it on my first mail, but I want ant to display all the missing properties, not only the first one. So here's a little improvement I did:
Macro:
    <macrodef name="requireProperty">
        <attribute name="property"/>
        <attribute name="example" default="" />
        <sequential>
            <if>
                <not><isset property="@{property}" /></not>
                <then>
                    <property name="missing.property" value="true" />
<echo>"@{property} is missing. Example: @{example}"</echo>
                </then>
            </if>
        </sequential>
    </macrodef>

Then create a target e.g. check-properties and have init target depend on it:

<target name="check-properties" description="Check required project properties">
        <requireFile file="dev_build.properties" />
        <!-- Section: Ivy Properties -->
        <requireProperty property="ivy.nexus.host"
            example="127.0.0.1" />
        <requireProperty property="ivy.maven.repo"

example="http://${ivy.nexus.host}:8081/nexus/context/repositories/central"; /> <fail if="missing.property" message="There are missing properties. Please see above" />
    </target>

Regards

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to