We have a bunch of parameters that we need to pass to InstallBuilder at build time (using gradle).

I can add them manually one by one using <propertiesfileget>, but this is laborious.

Is there a way to just point to a properties file and have all the parameters in the file available in the script?

asked 12 Mar '12, 15:53

wildcatz's gravatar image

wildcatz
16141417
accept rate: 0%


It is possible to use foreach to set multiple variables without repeating the <propertiesFileGet> action. For example:

<preBuildActionList>
  <foreach>
    <values>var1 var2 anothervar</values>
    <variables>variablename</variables>
    <actionList>
      <propertiesFileGet>
        <file>/path/to/properties.file</file>
        <key>${variablename}</key>
        <variable>${variablename}</variable>
      </propertiesFileGet>
    </actionList>
  </foreach>
</preBuildActionList>

You can also set a list of variables in the properties file using a pre-defined key and also use <propertiesFileGet> before the <foreach> action. This will allow managing the variables from properties file.

link

answered 12 Mar '12, 17:16

wojciechka's gravatar image

wojciechka ♦♦
7.8k61122
accept rate: 26%

There is not a built-in mechanism to load a full properties file but you could create a custom action:

    <functionDefinitionList>
         <!-- Define the action -->
         <actionDefinition>
            <name>loadPropertiesFile</name>
            <actionList>
                <readFile>
                    <name>text</name>
                    <path>${path}</path>
                </readFile>
                <while>
                    <actionList>
                        <setInstallerVariableFromRegEx>
                            <name>line</name>
                            <pattern>(^[^\\n]*).*</pattern>
                            <substitution>\\1</substitution>
                            <text>${text}</text>
                        </setInstallerVariableFromRegEx>  
                        <setInstallerVariableFromRegEx>
                            <name>text</name>
                            <pattern>^[^\\n]*\\n*(.*)</pattern>
                            <substitution>\\1</substitution>
                            <text>${text}</text>
                        </setInstallerVariableFromRegEx>
                        <continue>
                            <ruleList>
                                <regExMatch>
                                    <logic>does_not_match</logic>
                                    <pattern>^.*=.*$</pattern>
                                    <text>${line}</text>
                                </regExMatch>
                            </ruleList>
                        </continue>
                        <setInstallerVariableFromRegEx>
                            <name>var</name>
                            <pattern>^([^=]+)=.*</pattern>
                            <substitution>\\1</substitution>
                            <text>${line}</text>
                        </setInstallerVariableFromRegEx>
                        <setInstallerVariableFromRegEx>
                            <name>value</name>
                            <pattern>^[^=]+=(.*)</pattern>
                            <substitution>\\1</substitution>
                            <text>${line}</text>
                        </setInstallerVariableFromRegEx>
                        <setInstallerVariable>
                            <name>${var}</name>
                            <value>${value}</value>
                        </setInstallerVariable>
<globalVariables names="${var}"/>
                    </actionList>
                    <conditionRuleList>
                        <regExMatch>
                            <logic>matches</logic>
                            <pattern>.+=.*</pattern>
                            <text>${text}</text>
                        </regExMatch>
                    </conditionRuleList>
                </while>
            </actionList>
            <parameterList>
                <stringParameter name="path" value="" default="">
                    <description></description>
                    <explanation></explanation>
                    <allowEmptyValue>1</allowEmptyValue>
                    <width>30</width>
                </stringParameter>
            </parameterList>
        </actionDefinition>
    </functionDefinitionList>

  <preBuildActionList>
    <loadPropertiesFile>
        <path>/path/to/the/file</path>
    </loadPropertiesFile>
</preBuildActionList>
link

answered 12 Mar '12, 17:35

juanjo's gravatar image

juanjo ♦♦
5.8k413
accept rate: 23%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×47
×4

Asked: 12 Mar '12, 15:53

Seen: 2,346 times

Last updated: 12 Mar '12, 17:35