简体   繁体   中英

Access platform.properties variables from nbi ant script

is it possible to access from the ant script of the nbi (installer project) to variables defined in the platform.properties file, like the nbjdk.active which is setted when in a project the Java platform is changed?

The goal is from the ant script select one of the packaged jre (32 or 64) in function of this variable.

Thanks in advance.

Edit: this is the build script fragment from when I try to access this variables:

<target name="-generate-bundles">
    <for-each property="platform" list="${target.platforms}" separator=" ">

        <condition property="bundle.extention.${platform}" value="exe">
             <contains string="${platform}" substring="windows"/>
        </condition>
        <condition property="bundle.extention.${platform}" value="sh">
             <or>
                 <contains string="${platform}" substring="linux"/>
                 <contains string="${platform}" substring="solaris"/>
             </or>
        </condition>
        <condition property="bundle.extention.${platform}" value="zip">
             <contains string="${platform}" substring="macosx"/>
        </condition>

        <set property="bundle.extention" source="bundle.extention.${platform}"/>

        <create-bundle root="${output.dir}/registry-temp" 
                   platform="${platform}" 
                   target="${bundles.release.dir}/${bundle.files.prefix}-${platform}.${bundle.extention}">
            <component uid="${main.product.uid}" version="1.0.0.0.0"/>


            <!-- HERE I WANT TO CHECK THE VARIABLE AND SELECT ONE OF THE PACKED JRE -->
            <!--<property name="nbi.bundled.jvm.file" value="D:\packed\jre1.8.0_65_32bits\jre.exe"/>-->
            <property name="nbi.bundled.jvm.file" value="D:\packed\jre1.8.0_25_64bits\jre.exe"/>

        </create-bundle>

        <echo>************************</echo>
        <echo>********* OS: ${platform}</echo>
        <echo>********* Arch: ${os.arch}</echo>
        <echo>********* JDK in NB: ${jdk.home}</echo> 
        <echo>********* JDK in platform.properties: HERE I TRY TO ACCESS VARIABLE</echo> 
        <echo>************************</echo>


        <if property="bundle.extention" value="zip">
            <antcall target="zip-to-tgz">
                <param name="input.file"  value="${bundles.release.dir}/${bundle.files.prefix}-${platform}.zip"/>
                <param name="output.file" value="${bundles.release.dir}/${bundle.files.prefix}-${platform}.tgz"/>
            </antcall>
        <delete file="${bundles.release.dir}/${bundle.files.prefix}-${platform}.zip"/>
        </if>
    </for-each>
    <echo>Installer(s) for [${target.platforms}] are available at ${bundles.release.dir}</echo>
</target>

and this is the variable in platform.properties file:

nbjdk.active=JDK_1.8.0_65-32bits

Here is the property file contents which are going to be accessed in the build script:

Below build script example shows how to access property abc which is from test.properties file.

All you need is to load the property file before accessing it as shown in the script using, of course, change the property file path as per your environment.

<property file="D:/Temp/test.properties"/>

Then use ${abc} whereever its value is needed as shown in the echo task below.

test.properties contents

abc=123
def=234

build.xml

<project name="imported" basedir="." default="test">  
  <property file="D:/Temp/test.properties"/>
  <target name="test" description="check if the property can be retrieved from file">
    <echo message="Property abc's value from file is ${abc}"/>
  </target>
</project>

Output

test:
     [echo] Property abc's value from file is 123

BUILD SUCCESSFUL
Total time: 0 seconds
[Finished in 4.7s]

Hope this is helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM