Reputation: 249
Hi all please give a look to this code
in my properties file i have win-x86.pc-shared-location=E:\Ant_Scripts
Now below i am trying to call PrintInstallerName_build
from my build.xml,while as PrintInstallerName_build
is in test.xml. In build.xml file,${platform.id} has value=win-x86
in the calling target and in called target param1 also has value=win-x86
<target name="PrintInstallerName" >
<echo>PlatForm.Id====>${platform.id}</echo>
<ant antfile="test.xml" target="PrintInstallerName_build">
<property name="param1" value="${platform.id}"/>
</ant>
<target name="PrintInstallerName_build" >
<echo>${param1.pc-shared-location}</echo><!--${param1.pc-shared-location}-->
<echo>${param1}.pc-shared-location}</echo><!--win-x86.pc-shared-location-->
<echo>${win-x86.pc-shared-location}</echo><!--E:\\Ant_Scripts-->
</target>
as you can see only the last statement gives correct output but it is hardcoded,i want to use param1 and the output should be E:\\Ant_Scripts
i tried to use $ and @ but none works,may be i am doing wrong somewhere can someone help please,i am struck and tomorrow is its DOD.
Upvotes: 3
Views: 4394
Reputation: 31
You can use <propertycopy>
to make it happen.
Consider that you need to have the property value of ${propA${propB}}
Use ant tag of propertycopy
as follows:
<propertycopy property="myproperty" from="PropA.${PropB}"/>
<echo >${myproperty}</echo>
This will echo the value of ${propA${propB}}
Upvotes: 3
Reputation: 249
<target name="PrintInstallerName_process" >
<echo>${param1}</echo><!--win-x86-->
<macrodef name="testing">
<attribute name="v" default="NOT SET"/>
<element name="some-tasks" optional="yes"/>
<sequential>
<echo>Source Dir of ${param1}: ${@{v}}</echo><!-- Dir of Win-x86:E:\Ant_Scripts-->
<some-tasks/>
</sequential>
</macrodef>
<testing v="${param1}.pc-shared-location">
<some-tasks>
</some-tasks>
</testing>
</target>
this is the way it works and for me it works fine anyways @sudocode
your tip took me there so thank you very much
Upvotes: 1
Reputation: 16235
See Nesting of Braces in the Properties page of the Ant Manual.
In its default configuration Ant will not try to balance braces in property expansions, it will only consume the text up to the first closing brace when creating a property name. I.e. when expanding something like ${a${b}} it will be translated into two parts:
the expansion of property a${b - likely nothing useful. the literal text } resulting from the second closing brace
This means you can't use easily expand properties whose names are given by properties, but there are some workarounds for older versions of Ant. With Ant 1.8.0 and the the props Antlib you can configure Ant to use the NestedPropertyExpander defined there if you need such a feature.
Upvotes: 5