Could not find any match !

Ant Contribution -

Set default value for property


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Sets a default value in case a value has not been provided yet.     -->
<!--                                                                     -->
<!-- @param property   The property which must have a value afterwards.  -->
<!-- @param value      The value which will be set when the              -->
<!--                   property currently doesn't contain anything.      -->
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="set-default">
    <attribute name="property"/>
    <attribute name="value"/>
    <sequential>
        <if>
            <or>
                <!-- is empty -->
                <equals arg1="" arg2="${@{property}}"/>
                <!-- has not been set -->
                <equals arg1="$${@{property}}" arg2="${@{property}}"/>
            <or>
            <then>
                <var name="@{property}" value="@{value}"/>
            </then>
        </if>
    </sequential>
</macrodef>

Require a property


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- This macro verifies that a specific property has been set    -->
<!-- and causes a failure if this is not the case.                -->
<!--                                                              -->
<!-- @param property   The property which has to be tested.       -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="require-property">
    <attribute name="property"/>
    <sequential>
        <set-default property="@{property}" value=""/>
        <if>
            <equals arg1="" arg2="${@{property}}"/>
            <then>
                <fail message="the property '@{property}' has not been set !"/>
            </then>
        </if>
    </sequential>
</macrodef>

Append/Prepend to a list


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Appends a value to a list.                                              -->
<!--                                                                         -->
<!-- @param property    The name of the variable used to contain a list.     -->
<!-- @param value       The value which has to be added.                     -->
<!-- @param delimiter   The delimiter which has to be used. (Default: ',')   -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="append">
    <attribute name="property"/>
    <attribute name="value"/>
    <attribute name="delimiter" default=","/>
    <sequential>
        <if>
            <equals arg1="${@{property}}" arg2=""/>
            <then>
                <var name="@{property}" value="@{value}"/>
            </then>
            <else>
                <var name="@{property}" value="${@{property}}@{delimiter}@{value}"/>
            </else>
        </if>
    </sequential>
</macrodef>

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Prepends a value to a list.                                             -->
<!--                                                                         -->
<!-- @param property    The name of the variable used to contain a list.     -->
<!-- @param value       The value which has to be prepended.                 -->
<!-- @param delimiter   The delimiter which has to be used. (Default: ',')   -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="prepend">
    <attribute name="property"/>
    <attribute name="value"/>
    <attribute name="delimiter" default=","/>
    <sequential>
        <if>
            <equals arg1="${@{property}}" arg2=""/>
            <then>
                <var name="@{property}" value="@{value}"/>
            </then>
            <else>
                <var name="@{property}" value="@{value}@{delimiter}${@{property}}"/>
            </else>
        </if>
    </sequential>
</macrodef>

Iterate a properties file


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Allows to traverse a file containing properties.            -->
<!--                                                             -->
<!-- @param file             The file that has to be traversed.  -->
<!-- @param prefix           The prefix to be used for the       -->
<!--                         properties. (Default: 'prop.')      -->
<!-- @param handleproperty   The sequence that will be invoked   -->
<!--                         with the properties.                -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="iterate-properties">
    <attribute name="file"/>
    <attribute name="prefix" default="prop."/>
    <element name="handleproperty"/>
    <sequential>
        <loadfile srcfile="@{file}" property="ip_content">
            <filterchain>
                <striplinecomments>
                    <comment value="#"/>
                </striplinecomments>
                <fixcrlf/>
                <deletecharacters chars="\t "/>
            </filterchain>
        </;loadfile>
        <for 
            param="singleline" 
            list="${ip_content}" 
            trim="yes" 
            delimiter="${line.separator}"
        >
            <sequential>
                <propertyregex 
                    regexp="^([^=]+)=(.+)$" 
                    input="@{singleline}" 
                    property="@{prefix}key" 
                    select="\1"
                />
                <propertyregex 
                    regexp="^([^=]+)=(.+)$" 
                    input="@{singleline}" 
                    property="@{prefix}value" 
                    select="\2"
                />
                <handleproperty/>
                <var unset="true" name="@{prefix}key"/>
                <var unset="true" name="@{prefix}value"/>
            </sequential>
        </for>
        <var unset="true" name="ip_content"/>
    </sequential>
</macrodef>

Load a specific property from a file


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Fetches a property value from a file. If the property could        -->
<!-- not be found the value will be empty.                              -->
<!--                                                                    -->
<!-- @param file        The file which contains all properties.         -->
<!-- @param key         The key of the desired value.                   -->
<!-- @param property    The property which has to be set to the value.  -->
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="get-property">
    <attribute name="file"/>
    <attribute name="key"/>
    <attribute name="property"/>
    <sequential>
        <loadfile srcfile="@{file}" property="gp_content">
            <filterchain>
                <linecontainsregexp>
                    <regexp pattern="^(@{key})"/>
                </linecontainsregexp>
                <tailfilter lines="1"/>
                <deletecharacters chars="\t \r\n"/>
            </filterchain>
        </;loadfile>
        <propertyregex 
            property="@{property}" 
            input="${gp_content}" 
            regexp="^([^=]+)=(.*)" 
            select="\2"
        />
        <if>
            <equals arg1="${@{property}}" arg2="$${@{property}}"/>
            <then>
                <var name="@{property}" value=""/>
            </then>
        </if>
        <var unset="true" name="gp_content"/>
    </sequential>
</macrodef>

Shortcut to set a property depending on a condition


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Short if-then-else construction which can be used if a      -->
<!-- property needs to be set depending on a specific condition. -->
<!--                                                             -->
<!-- @param property    The property which will be set.          -->
<!-- @param condition   The condition used to determine          -->
<!--                    which value has to be set.               -->
<!-- @param then        The value if the condition is true.      -->
<!-- @param else        The value if the condition is false.     -->
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="short-if">
    <attribute name="property"/>
    <attribute name="condition"/>
    <attribute name="then"/>
    <attribute name="else"/>
    <sequential>
        <if>
            <istrue value="@{condition}"/>
            <then>
                <var name="@{property}" value="@{then}"/>
            </then>
            <else>
                <var name="@{property}" value="@{else}"/>
            </else>
        </if>
    </sequential>
</macrodef>

Store filenames of a dir into a property


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Lists filenames that do match a specified pattern.                  -->
<!--                                                                     -->
<!-- @param dir         The directory which content shall be listed.     -->
<!-- @param property    The property used to be set to the listed names. -->
<!-- @param pattern     The pattern used to select the files.            -->
<!--                    (Default: '*')                                   -->
<!-- @param delimiter   The delimiter which has to be used.              -->
<!--                    (Default: ',')                                   -->
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="list-filenames">
    <attribute name="dir"/>
    <attribute name="property"/>
    <attribute name="pattern" default="*"/>
    <attribute name="delimiter" default=","/>
    <sequential>
        <var name="lf_result" value=""/>
        <for param="file">
            <fileset dir="@{dir}" includes="@{pattern}"/>
            <sequential>
                <basename file="@{file}" property="lf_name"/>
                <append 
                    property="lf_result" 
                    value="${lf_name}" 
                    delimiter="@{delimiter}"
                />
                <var unset="true" name="lf_name"/>
            </sequential>
        </for>
        <var name="@{property}" value="${lf_result}"/>
        <var unset="true" name="lf_result"/>
    </sequential>
</macrodef>

Delete a file only if it’s existing


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Deletes a file only in case it does exist. -->
<!--                                            -->
<!-- @param file    The file to be deleted.     -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="delete-file">
    <attribute name="file"/>
    <sequential>
        <if>
            <available file="@{file}"/>
            <then>
                <if>
                    <available file="@{file}" type="file"/>
                    <then>
                        <delete file="@{file}" failonerror="true"/>
                    </then>
                    <else>
                        <fail message="'@{file}' is not a file"/>
                    </else>
                </if>
            </then>
        </if>
    </sequential>
</macrodef>

Remove an element from a list


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Removes a value from a list. The list itself will be altered.          -->
<!--                                                                        -->
<!-- @param property    The name of the variable used to contain a list.    -->
<!-- @param value       The value which has to be removed.                  -->
<!-- @param delimiter   The delimiter which has to be used. (Default: ',')  -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<macrodef name="remove-list-element">
    <attribute name="property"/>
    <attribute name="value"/>
    <attribute name="delimiter" default=","/>
    <sequential>
        <if>
            <not><equals arg1="${@{property}}" arg2=""/></not>
            <then>
                <var name="rle_result" value=""/>
                <for param="entry" list="${@{property}}" delimiter="@{delimiter}">
                    <sequential>
                        <if>
                            <not><equals arg1="@{value}" arg2="@{entry}"/></not>
                            <then>
                                <append 
                                    property="rle_result" 
                                    value="@{entry}" 
                                    delimiter="@{delimiter}"
                                />
                            </then>
                        </if>
                    </sequential>
                </for>
                <var name="@{property}" value="${rle_result}"/>
                <var unset="true" name="rle_result"/>
            </then>
        </if>
    </sequential>
</macrodef>