Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional property in Ant properties' file

Tags:

ant

build.xml

Is it possible to set a property value in Ant property files (as opposed to build.xml) in a conditional way? For example, if apache.root property is set - the my_property will be ${apache.root}/myapp, /var/www/myapp otherwise. If not, what would be the common practice - reusable build.xml files?

like image 468
BreakPhreak Avatar asked Nov 25 '12 17:11

BreakPhreak


2 Answers

Use the condition task:

<project name="demo" default="run">

    <condition property="my_property" value="${apache.root}/myapp" else="/var/www/myapp">
        <isset property="apache.root"/>
    </condition>

    <target name="run">
        <echo message="my_property=${my_property}"/>
    </target>

</project>
like image 114
Mark O'Connor Avatar answered Sep 17 '22 14:09

Mark O'Connor


You can include different property files based on environments or the conditional variables. For example

    <echo>Building ${ant.project.name} on OS: ${os.name}-${os.arch}</echo>
<property file="build-${os.name}.properties" />

this would include a file named 'build-Windows 7.properties' or 'build-Linux.properties' depending on where the build is being run. Of course the property directive looks in the current directory as well as home directory. So the property file could be a part of the build source or in the home directory of the build account.

You can use the condition tag to generate part of the name of the property file as well to select

like image 35
M The Developer Avatar answered Sep 16 '22 14:09

M The Developer