Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix examples for filters on dynamic variables from windows registry

...

Dynamic variables behave like "normal" static variables defined by the <variable> tag, except that they are evaluated on each panel change . They are maintained as normal variables in an installation process, but in comparison to them dynamic variables have been enhanced by many more facilities. You can set dynamic variables and have additional features.

Dynamic variables, like other variables can be used within ${ and } for substitution.

Dynamic variables can get their values from the following sources on the target computer:

  • plain values
  • environment variables
  • system properties
  • INI files
  • option/property files (key-value pairs)
  • XML files (using XPath-like queries)
  • INI/option/XML files from within an ZIP or JAR file
  • Windows registry
  • output of a command execution

and filter them optionally They can be filtered using regular expressions. A particular dynamic variable can be evaluated based on a certain condition.

Other variables and dynamic variables can be used within ${ and } to be replaced in the assignment expressions below.

Common attributes to Attributes common to all types of dynamic variables are:

  • name
    The name of the dynamic variable used to refer to it from panels, in variable substitution and so on. Since dynamic variables are saved like a normal variable (as $INSTALL_PATH), they can be accessed like any other variable from within an IzPack installer.
  • checkonce:= "true" | "false" (optional, defaults to "false")
    Mark the dynamic variable to be evaluated just once, either when the installation starts or as soon as an optional condition gets true. This makes it behave like a normal variable, although with enhanced capabilities to gather a value.
    Values gathered by a dynamic variable definition with checkonce="true" can be overridden, if there is another dynamic variable with the same key (and different conditions ) defined, which gets evaluate to  true ) found later.
  • ignorefailure:= "true" | "false" (optional, defaults to "falsetrue")
    Might be used to allow the installation to continue or abort if an error occurred during gathering the value for a certain dynamic variable.
  • condition (optional)
    The assignment of a dynamic variable itself can be made dependent on a certain condition, using the condition attribute, which refers to the ID of condition defined in the installer description elsewhere.

 

Note

Although dynamic variables almost completely integrate with static IzPack variables, which means they are mapped to a normal IzPack variable, be aware of using them as direct variables in user input fields. Even on using checkonce="true" they always refresh to the previous value matching the original dynamic variable definition of the according dynamic variable and override the "normal" IzPack variable after leaving a panel. Thus, user input field variables which are also defined as dynamic variable will not have the user input as effective value, but the value they had when entering the panel.

Lifecycle of Dynamic Variables

Each dynamic variable is mapped to an Izpack variable by its unique name.

It is possible to define a dynamic variable more times based on different conditions:

Code Block
languagexml
titleExample
<dynamicvariables>
  <variable name="thechoice" value="choice1" condition="cond1">
  <variable name="thechoice" value="choice2" condition="cond2">
</dynamicvariables>

A dynamic variable becomes a "normal" IzPack variable with a static key-value pair if it has set the attribute checkonce="true" and an optional condition for its evaluation becomes true. After this, it is represented with a static value as an IzPack variable. It can be overridden if there is another dynamic variable definition for the same key, which evaluates later for example based on another condition.

A dynamic variable is unset at installation time as static IzPack variable as soon as it cannot be evaluated any longer from any of the definitions for the same key. It is reinitialized with a value as soon as at least one dynamic variable definition can be evaluated in some later phase, again.

Types of Dynamic Variable Assignments

Plain Values

The easiest way to assign a value to a dynamic variable is a plain value.

Using a plain dynamic variable assignment is recognized by using the attribute value in the variable definition.

Specific attributes:

  • value
    The plain value to be assigned to the dynamic variable.

Example:

...

titleAssigning a plain value to a dynamic variable
langxml

...

  • unset:= "true" | "false" (optional, defaults to "true")
    By defaut, if none of the conditions of a dynamic variable of one and the same name isn't met, a dynamic variable is unset for cleanup purposes.
    Setting unset false prevents unsetting a variable if the complex condition above is not met and leaves the variable value unchanged for that definition.


Note

As dynamic variables almost completely integrate with static IzPack variables, which means they are mapped to a normal IzPack variable, they can be used as direct variables in user input fields. Take care to have stable evaluation conditions after the user entered a value or use checkonce="true" for this purpose to not override the user value after leaving the panel.

Types of Dynamic Variable Assignments

Plain Values

The easiest way to assign a value to a dynamic variable is a plain value.

Using a plain dynamic variable assignment is recognized by using the attribute value in the variable definition.

Specific attributes:

  • value
    The plain value to be assigned to the dynamic variable.

Example:

Code Block
langxml
titleAssigning a plain value to a dynamic variable
<dynamicvariables>
    <variable name="previous.version" value="4.3.3"/>
</dynamicvariable>

The above example is functionally equivalent to

Code Block
langxml
<variables>
    <variable name="previous.version" value="4.3.3"/>
</variable>

since there are no replacements used which might be refreshed on a panel change.

Plain Values as Embedded Text

In another addition to normal variables, the value of a variable can be also defined using a nested value element embedding plain text

Example:

To comment out something in a xml file if a certain pack with the ID "mycoolfeature" is not activated, you might alternate between one and the same variable name, which gets assigned different values in different conditions.

Code Block
xml
xml
<dynamicvariables>

    <variable name="XML_Comment_Start" condition="\!izpack.selected.mycoolfeature">
        <value><\!\[CDATA[<!--]\]></value>
    </variable>
    <variable name="XML_Comment_End" condition="\!izpack.selected.mycoolfeature">
        <value><\!\[CDATA[-->]\]></value>
    </variable>

    <variable name="previous.versionXML_Comment_Start" value="" condition="4izpack.3selected.3mycoolfeature" />
</dynamicvariable>

The above example is functionally equivalent to

Code Block
langxml
<variables>
    <variable name="previous.versionXML_Comment_End" value="4.3.3"/>" condition="izpack.selected.mycoolfeature" />

</variable>

since there are no replacements used which might be refreshed on a panel change.

Plain Values as Embedded Text

In another addition to normal variables, the value of a variable can be also defined using a nested value element embedding plain text

Example:

...

dynamicvariables>

The condition "izpack.selected.mycoolfeature" is generated automatically when a pack with the ID "mycoolfeature" is not activated, you might alternate between one and the same variable name, which gets assigned different values in different conditions.

...

<dynamicvariables>

    <variable name="XML_Comment_Start" condition="\!izpack.selected.mycoolfeature">
        <value><\!\[CDATA[<!--]\]></value>
    </variable>
    <variable name="XML_Comment_End" condition="\!izpack.selected.mycoolfeature">
        <value><\!\[CDATA[-->]\]></value>
    </variable>

    <variable name="XML_Comment_Start" value="" condition="izpack.selected.mycoolfeature" />
    <variable name="XML_Comment_End" value="" condition="izpack.selected.mycoolfeature" />

</dynamicvariables>

The condition "izpack.selected.mycoolfeature" is generated automatically when a pack with the ID "mycoolfeature" was specified. You could now use ${XML_Comment_Start} and ${XML_Comment_End} in a file which should be parsed.

Values from Environment Variables

Using a  dynamic variable assignment from an environment variable is recognized by using the attribute environment in the variable definition.

was specified. You could now use ${XML_Comment_Start} and ${XML_Comment_End} in a file which should be parsed.

For example, there might be an input file test.xml installed to ${INSTALL_PATH}:

Code Block
languagexml
<?xml version="1.0"?>
<test>
	<a></a>
	${XmlCommentStart}<b></b>${XmlCommentEnd}
</test>

parsed like this in install.xml:

Code Block
languagexml
<parsable targetfile="$INSTALL_PATH/test.xml" encoding="UTF-8"/>

If the pack mycoolfeature would be enabled during the installation, the file would look like this at the end:

Code Block
languagexml
<?xml version="1.0"?>
<test>
	<a></a>
	<b></b>
</test>

otherwise the <b></b> element would be commented out:

Code Block
languagexml
<?xml version="1.0"?>
<test>
	<a></a>
	<!--<b></b>-->
</test>


Info

In the <parsable> tag don't use the type="xml" for this example, because it would replace the characters '<' and '>' in your comment XML elements by '&lt;' and '&gt;' in the resulting output.

Values from Environment Variables

Using a  dynamic variable assignment from an environment variable is recognized by using the attribute environment in the variable definition.

Specific attributes:

  • environment
    The name of the environment variable to get the assignment value from.
Code Block
langxml
titleAssigning the value of an environment variable to a dynamic variablelangxml
<dynamicvariables>
    <variable name="search.path" environment="PATH"/>
</dynamicvariables>

The above example is functionally equivalent to

Code Block
langxml
<variables><dynamicvariables>
    <variable name="search.path" value="${ENV[PATH]}"/>
</variable>dynamicvariable>

since there are no replacements used which might be refreshed on a panel change and the environment variable PATH won't change during the runtime of an installation process.

Values from Property/Option Files

Dynamic variables can be also assigned from a value in configuration files with key-value pairs, as property files.

Using a  dynamic variable assignment from a certain option or property of an option or property file is recognized by using the attribute file in the variable definition along with the attribute type set to "options" (or left out).

Specific attributes:

...

Note

There is one import difference:

  • a variable defined with the environment-attribute is resolved instantly while reading the <dynamicvariables> section. So it can be used as a parameter for subsequent file-attributes in the variable definitions for example.
  • a variable defined with the value="${ENV[PATH]}" attribute will be resolved later, so subsequent usage within <dynamicvariables> will fail.

Values from System Properties

Using a  dynamic variable assignment from an system property is recognized by using the value ${SYSTEM[property]} in the variable definition. For example the following definition will give you the java.io.tmpdir:

Code Block
langxml
<dynamicvariables>
    <variable name="tmpdir" value="${SYSTEM[java.io.tmpdir]}"/>
</dynamicvariable>

Values from Property/Option Files

Dynamic variables can be also assigned from a value in configuration files with key-value pairs, as property files.

Using a  dynamic variable assignment from a certain option or property of an option or property file is recognized by using the attribute file in the variable definition along with the attribute type set to "options" (default if omitted).

Specific attributes:

  • file
    The property/option file path to read from.
  • type := "options" | "ini" | "xml" (optional, defaults to "options")
    The file type, must be "options" to read options or properties.
  • key
    The option or property key to read the value for.
  • escape := "true" | "false" (optional: defaults to "true")
    Whether to apply escape sequences escaped by backslashes, like defined for Java properties files.
    Set "false" especially if you want to read values with backslashes where backslashes are not assumed to introduce escape sequences, like Windows paths.

The attribute type="options" is to be used to make this file parsed as an option file. Separators between the key and value might be for instance '=', ':' including their escaped variants '\=', '\:', where leading and trailing whitespaces are trimmed off.

Example:

Code Block
langxml
titleAssigning a dynamic variable from properties/option files
langxml
<dynamicvariables>

    <variable name="option.1" checkonce="true"
              file="${INSTALL_PATH}/../old_installation/test.properties" type="options"
              key="first.setting"/>

    <variable name="option.2" checkonce="true"
              file="${INSTALL_PATH}/../old_installation/test.conf"
type="options"
                key="work.dir"/>

</dynamicvariables>

...

  • file
    The INI file path to read from.
  • type := "options" | "ini" | "xml" (optional, defaults to "options")
    The file type, must be "ini" to read INI keys.
  • section
    The INI section to lookup the entry in.
  • key
    The INI entry key to read the value for.
  • escape := "true" | "false" (optional: defaults to "true")
    Whether to apply escape sequences escaped by backslashes, like defined for Java properties files.
    Set "false" especially if you want to read values with backslashes where backslashes are not assumed to introduce escape sequences, like Windows paths.

Example:

Code Block
lang
langxml
titleAssigning a dynamic variable from an INI file valuexml
<dynamicvariables>
    <variable name="ini.1" checkonce="true"
              file="C:/Program Files/freesshd/FreeSSHDService.ini" type="ini"
              section="SSH server" key="SSHCMD"/>
</dynamicvariables>

...

  • file
    The XML file path to read from.
  • type := "options" | "ini" | "xml" (optional, defaults to "options")
    The file type, must be "xml" to assume read a XML file.
  • key
    The XPath path to the entry to read the value for.
    Note: Currently, the XPath language revision depends on the JRE version the installer runs on. JRE 6/7 support XPath 1.0.

Example:

Code Block
langxml
titleDynamic variable assignment from XML file contents
langxml
<dynamicvariables>

    <variable name="XMLReadTest.1" checkonce="true" ignorefailure="false"
              file="${INSTALL_PATH}/../old_installation/test.xml" type="xml"
              key="/installations/installation[path='/usr/local']/title[@lang='en']/text()"/>

    <variable name="XMLReadTest.2" checkonce="true" ignorefailure="false"
              file="${INSTALL_PATH}/../old_installation/test.xml" type="xml"
              key="//title[@lang='en']/text()"/>

</dynamicvariables>

...

  • jarfile
    The jar file path to read from.
  • zipfile
    The zip file path to read from.
  • type := "options" | "ini" | "xml" (optional, defaults to "options")
    The archived file's type.
  • section
    The INI section to lookup the entry in, is evaluated only if type = "ini".
  • key
    The XPath, INI, option or property entry key to read the value for.
  • escape := "true" | "false" (optional: defaults to "true")
    Whether to apply escape sequences escaped by backslashes, like defined for Java properties files.
    Set "false" especially if you want to read values with backslashes where backslashes are not assumed to introduce escape sequences, like Windows paths.

Example:

Code Block
langxml
titleAssigning a dynamic variable from an configuration entry in a JAR/ZIP file
langxml
<dynamicvariables>

    <variable name="previous.version" jarfile="${INSTALL_PATH}/${INSTALL_SUBPATH}/libs/config.jar"
              entry="release.properties" type="options"
              key="release.version"
              checkonce="false" ignorefailure="true">
    </variable>

    <variable name="other.stuff" zipfile="${INSTALL_PATH}/${INSTALL_SUBPATH}/libs/misc.zip"
              entry="app.ini" type="ini"
              section="Global Settings" key="AUTOSTART"
              checkonce="true" ignorefailure="true">
    </variable>

</dynamicvariables>

...

  • regkey
    The registry entry root key to find the registry value to read from.
  • regvalue
    The registry value to read from, which is in Microsoft terms equivalent to a key in ordinary INI files.

Example:

Code Block
langxml
titleAssigning a dynamic variable value from the Windows registry
langxml
<dynamicvariables>
    <variable name="RegistryReadTest" checkonce="true"
              regkey="HKLMHKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
              regvalue="Path"/>
</dynamicvariables>

...

  • executable
    Absolute or relative path to the command to be launched. If the "dir" attribute is used, than relative paths are computed against the mentioned directory. The characters '.' and '..' inside the command path are resolved to a canonical path according to the operating system.
  • type := "process" | "shell" (optional, defaults to "process")
    "process" - launch the command directly without an underlying shell invocation
    "shell" - launch the command over the system shell, assuming it to be a shell script
  • dir (optional)
    Absolute or relative path to a work directory, from where the command should be launched. The characters '.' and '..' inside the directory path are resolved to a canonical path according to the operating system.
  • stderr := "true" | "false" (optional, defaults to "false")
    Whether the standard error output of the command should be used instead of the standard output.
    This can be useful for some commands which deliver certain information only as error, for instance 'java -version'..

Example 1:

Code Block
lang
langxml
titleAssigning a dynamic variable value from the output of a command executionxml
<dynamicvariables>

    <variable name="hostname" checkonce="true"
              executable="hostname"
              type="process"/>

    <variable name="result.value" checkonce="true"
              executable="${INSTALL_PATH}/bin/init.sh"
              type="shell"/>

</dynamicvariables>

Example 2:

Code Block
langxml
titleAssigning a dynamic variable value from the output of a command execution
langxml
<dynamicvariables>

    <variable name="previous.java.version" checkonce="true"
              dir="${INSTALL_PATH}"
              executable="jre/bin/java" stderr="true"
              type="process" ignorefailure="true"
              condition="haveInstallPath+isUpgrade">
      <arg>-version</arg>
      <filters>
        <regex regexp="java version[^\d]+([\d\._]+)" select="\1"/>
      </filters>
    </variable>

</dynamicvariables>

...

Multiple nested filters can be used. In this case, the order of defining them is the order they will be executed at installation timeThe filters will be applied in the order in which they are defined.

Filters are evaluated on each panel change, regardless whether <dynamicvariable checkonce="true"/>, because there can change several variables that might changed are also resolved in a filter attributes.

Filters are embedded in the nested filters element like this:

Code Block
languagehtml/xml
titleDynamic Variable Filter Element Definition
<dynamicvariable<dynamicvariables>
...>   <variable ... <!-- other nested arguments might go here -->
      <filters>
         <filter1 .../>
         <filter2 .../>
         ... <!-- more filters might go here -->
      </filters>
   </variable>
</dynamicvariable>

...


Regular Expression Filter

After straight evaluation, each dynamic variable's value can be filtered using a Java regular expression. This is done by the nested regex element.

...

  • regexp
    The Java regular expression to be used for selecting from the variable value or for replacing certain parts of the variable value. For more information see the Java Platform SE 6 API and other documents describing the according regular expression syntax more in detail.
  • select (one of both, select or replace must be given)
    Selection expression according to regexp, used to select certain groups from the expression defined in regexp and possibly combine them with several text around.
  • replace (one of both, select or replace must be given)
    Replacement expression according to regexp, used to replace the regular expression defined in regexp and possibly combine them with several text around.
  • defaultValue defaultvalue (optional)
    The default value to be used if the expression defined in regexp does not match the enclosing variable value at all.
  • casesensitive (optional, defaults to "true")
    Whether the regular expression matching should consider the case of alphabetic letters or not for matching.
  • global (optional, defaults to "false")
    Whether the replacement operation should be performed on the entire variable value, rather than just the first occurance. This has effect only on using together with replace.

Example:

Code Block
langxml
titleFiltering dynamic variable assignments using regular expressions
langxml
<dynamicvariables>

	<!--
   <variable name="previous.version" jarfile="${INSTALL_PATH}/${INSTALL_SUBPATH}/libs/config.jar"
              entry="release.properties" type="options"
              key="release.version"
 Read the property value of release.version in the resource release.properties from the root of the config.jar file.
	  Filter just the version string from the result, if there is one, otherwise return 'none'.
      -->
    <variable name="previous.version" jarfile="${INSTALL_PATH}/${INSTALL_SUBPATH}/libs/config.jar"
             checkonce="false" ignorefailureentry="truerelease.properties" conditiontype="upgradecheckoptions">
      <filters>         <regex regexp="key="release.version"
              checkonce="false" ignorefailure="true" condition="upgradecheck">
      <filters>
        <regex regexp="([0-9]+(\.[0-9]+){2})" select="\1" defaultvalue="none"/>
      </filters>
    </variable>

	<!--
    <variable name="RegExTest.Select.Windows" checkonce="true"
              regkey="HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
   Read the value of the Windows system environment variable %PATH% directly from the Windows registry (can done smarter by ${SYSTEM[PATH]}).
      Filter just the first  regvalue="Path">
      <filters>
        <regex regexp="([^;]*)(.*)"single path (if there are more separated by the ';' character). If there was a valid value, otherwise return '(unmatched)'.
      -->
    <variable    select="\1name="RegExTest.Select.Windows" checkonce="true"
               defaultValue="(unmatched)regkey="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
               casesensitiveregvalue="falsePath"/>
      </filters><filters>
    </variable>    <regex  <variable nameregexp="RegExTest.ReplaceFirst.Windows" checkonce="true"([^;]*)(.*)"
               regkeyselect="HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"\1"
               regvaluedefaultvalue="Path(unmatched)">
      <filters>         <regex regexpcasesensitive="([^;]*)"false"/>
      </filters>
    </variable>

	<!--
 replace="+++ \1 +++"   Read the value of the Windows system environment variable %PATH% directly from  defaultValue="(unmatched)"
     the Windows registry (can done smarter by ${SYSTEM[PATH]}).
      Filter just the casesensitive="false"first single path (if there are more separated by the ';' character).
	  Prepend and append three plus signs  global="false"/>
      </filters>to the resulting value, if there was a valid value, otherwise return '(unmatched)'.
     </variable> -->
    <variable name="RegExTest.ReplaceAllReplaceFirst.Windows" checkonce="true"
              regkey="HKLMHKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
              regvalue="Path">
      <filters>
        <regex regexp="([^;]*)"
               replace="+++ \1 +++"
               defaultValue="(unmatched)
               replace="+++ \1 +++"
               defaultvalue="(unmatched)"
               casesensitive="false"
               global="false"/>
      </filters>
    </variable>

</dynamicvariables>

Location Filter

After straight evaluation, each dynamic variable value can be filtered to be canonicalized like a filename. This is done by the nested location element. Operating system-specific path conventions are considered when assembling the result.

This means especially the file separator will be converted to that of the target operating system. On Windows, an absolute path is assumed to start with a drive letter followed by a colon, on Unix or MacOSX by a slash.

Furthermore all path parts containing /./ are replaced by the file separator and /dir/../ by the parent directory of dir.

Attributes:

  • basedir
    The root directory relative path to be assumed when the origin value is not an absolute path. If not set, the current working directory is assumed as the base directory, instead.

Example:

Assuming all defined conditions are met, the following definition converts all ${previous.wrapper.java.home.canonical}/bin/java not being an absolute path to a canonical path of the form

${INSTALL_PATH}/${previous.wrapper.java.home.canonical}/bin/java

on Unix or

${INSTALL_PATH}\${previous.wrapper.java.home.canonical}\bin\java

on Windows.

Code Block
languagehtml/xml
titleExample of the location filter
<dynamicvariables>
   <variable name="previous.wrapper.java.command.canonical" value="${previous.wrapper.java.home.canonical}/bin/java"
               casesensitivecondition="false"haveInstallPath+isCompatibleUpgrade+haveWrapperJavaCmd+isSetCanonicalJavaHome">
      <filters>
         <location globalbasedir="true${INSTALL_PATH}"/>
      </filters>
    </variable>

</dynamicvariables>

...

Case Style Filter

After straight evaluation, each dynamic variable value can be filtered to be canonicalized like a filename. This is done by the nested location elementSometimes you need a variable value with all lowercase or all uppercase. This filter has been introduced in version 5.0.0-rc5.

Attributes:

  • basedir
    The root directory relative path to be assumed when the origin value is not an absolute path. If not set, the current working directory is assumed as the base directory, instead.

...

  • style
    How the value should be capitalized. Possible values are "lowercase" and "uppercase".

Example:

Code Block
titleExample of the location case style filter
 <variable<dynamicvariables>
   <variable name="previous.wrapper.java.command.canonicalvar1" value="${previous.wrapper.java.home.canonical}/bin/java""Some Text" >
      <filters>
         <case style="lower"/>
      </filters>
   </variable>
   condition="haveInstallPath+isCompatibleUpgrade+haveWrapperJavaCmd+isSetCanonicalJavaHome"<variable name="var2" value="${var1}" >
      <filters>
        <location <case basedirstyle="${INSTALL_PATH}upper"/>
      </filters>
   </variable>
 </dynamicvariables>

will set var1 to "some text" and var2 to "SOME TEXT".