how to build a property from several other properties?

Jan Matèrne

Use <propertycopy> of Ant-Contrib:


<?xml version="1.0" encoding="ISO-8859-1"?>


<project default="displayprop">

    <!-- contains the propertycopy -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" />

    <target name="displayprop">
        <!-- set defaults (if no -D settings exist) -->
        <property name="domain"     value="localhost" />
        <property name="deployment" value="test"      />

        <!-- some test values -->
        <property name="myapp.localhost.test.acl.enforcement" value="on"/>
        <property name="myapp.localhost.prod.acl.enforcement" value="off"/>
        <property name="myapp.internet.test.acl.enforcement"  value="off"/>
        <property name="myapp.internet.prod.acl.enforcement"  value="on"/>

        <!-- derive the new value -->
        <propertycopy name="acl.enforcement.value"
                      from="myapp.${domain}.${deployment}.acl.enforcement"
        />

        <echo>
            Settings:
            ---------------
            domain       ${domain}
            deployment   ${deployment}
            enforcement  ${acl.enforcement.value}
        </echo>
    </target>

</project>
Output:
C:	emp>ant
displayprop:
     [echo]
     [echo]             Settings:
     [echo]             ---------------
     [echo]             domain       localhost
     [echo]             deployment   test
     [echo]             enforcement  on
     [echo]

C:	emp>ant -Ddomain=internet
displayprop:
     [echo]
     [echo]             Settings:
     [echo]             ---------------
     [echo]             domain       internet
     [echo]             deployment   test
     [echo]             enforcement  off
     [echo]
Ant-Contrib: Homepage, CVS-Source, CVS-Manual, Binary
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact