set lots of parameters from properties file

Comments

2 comments

  • Avatar
    wojciechka

    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.

  • Avatar
    juanjo

    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>
    

Please sign in to leave a comment.