AntActionInstallerListener and AntActionUninstallerListener
IzPack provides support to execute Ant tasks during installation and uninstallation.
For example:
<resources> ... <res id="AntActionsSpec.xml" src="myInstallSpecs/MyAntActionsSpec.xml" /> ... </resources> <jar src="jar/ant.jar" stage="both"/> <jar src="jar/ant-launcher.jar" stage="both"/> <jar src="jar/customtasks.jar" stage="both"/> <listeners> <listener classname="AntActionInstallerListener" stage="install" /> <listener classname="AntActionUninstallerListener" stage="uninstall" /> </listeners>
In the above:
- the AntActionsSpec.xml resource determines the Ant tasks to be executed. The base path of
src
is the installation project path. - the <jar/> element specifies jar dependencies required to execute the Ant tasks. At a minimum, this must include the ant jar and ant-launcher.jar.
- the <listeners> element is used to hook execution of the Ant tasks into the installer and uninstaller
Note that an "extended" ant use needs more than one jar, for example often xercesImpl.jar
. If an obscure "class not found" exception is raised during testing, check first for missing jar files.
The stage
attribute of the jar element determines when a jar is required. If an ant uninstaller custom action is used, the uninstaller also needs the jar files. If stage
is "both" or "uninstall", the contents of the referenced jar file will be packed into the uninstaller.
Note that not the jar file itself, but the contents of it are required. This implies, that the paths of the contained files are unique and the information in meta-inf/Manifest.mf
will be lost. The jars are merged into the installer during compile. So the attribute src is used during compile time, not installation time. The jar files are not needed during installation anymore.
The AntActionSpec XML Structure
An ant action is defined in the resource with the id "AntActionsSpec.xml". In IzPack 5.0 (as of 5.0.0-beta-11), an XML-Schema is provided, which may be declared as follows:
<izpack:antactions version="5.0" xmlns:izpack="http://izpack.org/schema/antactions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://izpack.org/schema/antactions http://izpack.org/schema/5.0/izpack-antactions-5.0.xsd"> <!-- .... --> </izpack:antactions>
Prior to processing the packs a substitution is performed using all defined IzPack
variables on the spec file. This is a common way of loading spec files into custom actions.
For more information see method com.izforge.izpack.util.SpecHelper.readSpec
. If you want to substitute a value in the file, simply add a variable via installData.setVariable in a custom panel before InstallPanel
. The given variable name (id) should be written into the xml file in the common variable notation.
The following outlines the sections available in the AntActionsSpec.xml:
antactions
The top level XML section is called <antactions>
. The antactions element may contain zero or more pack elements described below:
pack
The pack element is used to tie the action(s) to be performed to the packs selected in the installation. The pack element may have the following attribute:
Name | Description |
---|---|
name | The name of the pack that this pack element maps to. This should correspond to the name of a pack defined in install.xml |
The pack element must contain 1 or more antcall elements.
antcall
The antcall
element has the following attributes:
Name | Required | Description | Allowed Values |
---|---|---|---|
| yes | Determine at what point of installation the antcalls defined by element |
|
| no | Determine at what point of uninstallation the antcalls defined by element |
|
| no | Whether to log just warnings and errors, be quiet otherwise. | yes or no, default: no |
| no | Whether to log verbose information. | yes or no, default: no |
loglevel | no | Straight Ant log priority level mapping to the according log levels in Ant projects. | error, warning, info, verbose, debug |
| no | Path to the file where logging should be performed. Note: The logfile should be not marked for uninstallation otherwise it will be deleted too. | Any valid file path (TODO: should verify format) |
logfile_append | no | Whether to append to an existing log file (true) or create a new one / overwrite existing one (false). | true | false (default: false) |
| yes, if buildresource not specified | Path to the file which contains the antcall. This is the file you normally use as | Any valid file path (TODO: should verify format) |
| yes, if buildfile not specified | The value is the id of the resource which contains the antcall. This resource will be extracted out into a temporary file and the path to this file will be passed as if | A resource id. |
dir | no | The working directory for executing the Ant build in buildfile or buildresource . If set, it explicitly overrides the basedir set there and serves as base directory for relative path names accessed during the Ant build. | Any valid directory path |
| no | If it is defined, the message will be displayed in the InstallPanel whilst performing the ant call. | A string ID which refers to |
condition | no | Execute this action only if the condition is fulfilled. | A valid condition string. |
severity | no | The severity of an Ant action:
since: 5.0 RC5 |
|
In addition to the possible attributes there are some elements may be defined within an antcall element. All elements can be defined zero or more times in an <antcall>
. Although all elements are optional, no ANT tasks will be performed unless a <target>
element is specified. Do not confuse the following: "required"s are related to the attributes of the elements, not to the elements themselfs.
property
Defines a property to be used with all targets and uninstall_targets which are defined for this antcall. The following attributes may be defined:
Name | Required | Description | Allowed Values |
---|---|---|---|
name | yes | The name of the property to set. | Any string value |
value | yes | The value to set for the property. | Any string value |
propertyfile
Defines properties to be used, read from a property file which are defined for this antcall. The following attributes may be defined:
Name | Required | Description | Allowed Values |
---|---|---|---|
path | yes | The path to the properties file. | A valid file path. |
One way to fill specific data into it is to create a new file in a custom panel and fill it with values given by input fields. The file path can be set at installation time, if there is a variable in AntActionSpec.xml and an IzPack variable was defined before InstallPanel. That file can be only created with deleteOnExit, if no <uninstall_target>
was defined in this <antcall>
. This implies, that other <antcall>s can have a <uninstall_target>
.Â
target
Ant buildfile target to perform with this action at installation time.Â
Note: Multiple targets to execute for the action may be specified by using multiple target elements.
Name | Required | Description | Allowed Values |
---|---|---|---|
name | yes | Name of the target to execute in the Ant buildfile | Any valid Ant target defined in the build file. |
uninstall_target
Ant buildfile target to perform with this action at uninstallation time.
Note: Multiple targets to execute for the action may be specified by using multiple target elements.
Name | Required | Description | Allowed Values |
---|---|---|---|
name | yes | Name of the target to execute in the Ant buildfile | Any valid Ant target defined in the build file. |