How to acess property within a property in ant

2019-04-14 05:56发布

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.

标签: ant
3条回答
女痞
2楼-- · 2019-04-14 06:19

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}"

${myproperty} - This will give you value of ${propA${propB}}

查看更多
你好瞎i
3楼-- · 2019-04-14 06:28
<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

查看更多
在下西门庆
4楼-- · 2019-04-14 06:38

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.

查看更多
登录 后发表回答