We need you!

Icon

The IzPack documentation needs work, and you are invited to edit it!

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

More detailed examples can be downloaded from http://jira.codehaus.org/secure/attachment/39246/sample.tar.gz and http://jira.codehaus.org/secure/attachment/39379/sample2.tar.gz

Additional Ant Actions examples. 

In install.xml, I declare a resource AntInstall.xml which is going to be the ANT build script so that I will have target to run and also a resource for AntActionsSpec.xml which is required for the AntActionInstallerListener.  I also include a copy of ant in the installer and then register the listener.

In AntActionsSpec.xml I define antactions that are called depending on the pack being installed.  Note the buildresource.  This is referencing the AntInstall.xml resource that I included in install.xml.  Using a buildresource extracts the resource to a temporary file and then references that temporary file.  This allows you to install an ANT resource that is accessible ti the installer but will not exist in the target system after the installation is complete.  You could use buildfile to reference an existing file on the target system.

The AntInstall.xml contains the actual ANT targets that can be invoked during installation.  Since ANT was bundled with installer, all the core ANT tasks are available.

Example 1

Code Block
borderStyledashed
titleInstall.xml
   <resources>
        <res id="AntInstall.xml" src="installer/AntInstall.xml"/>
        <res id="AntActionsSpec.xml" src="installer/AntActionsSpec.xml"/>
    </resources>

    <jar src="installer/ant.jar" stage="stage" />
    <jar src="installer/ant-launcher.jar" stage="stage"/>

    <listeners>
    <listener installer="AntActionInstallerListener"/>
    </listeners>
Code Block
borderStyledashed
titleAntActionsSpec.xml
<?xml	version="1.0" encoding="UTF-8"?>

<antactions>

    <pack name="Framework">

        <antcall
        order="afterpack"
        buildresource="AntInstall.xml"
        quiet="yes">

            <property name="frameworks.country" value="$frameCountry"/>
            <property name="Frameworks-Metadata"/>

        </antcall>
    </pack>

</antactions>
Code Block
borderStyledashed
titleAntInstall.xml
<?xml	version="1.0" encoding="UTF-8"?>

<project name="Metadata">

    <target name="Frameworks">

        <replace file="/Contents/Resources/Java/imports/frameworks.xml">

            <replacefilter token="&lt;Country&gt;GB&lt;/Country&gt;" value="&lt;Country&gt;${frameworks.country}&lt;/Country&gt;"/>

        </replace>

    </target>

</project>

A longer more complicated example.

Code Block
borderStyledashed
titleInstall.xml
<resources>
	<res id="upgrade.xml" src="resources/upgrade/upgrade.xml"/>
	<res id="AntActionsSpec.xml" src="install/main/actions/ant/AntActionsSpec.xml"/>
</resources>
<jar src="install/main/jars/ant/ant.jar" stage="both"/>
<jar src="install/main/jars/ant/ant-launcher.jar" stage="both"/>
<listeners>
	<listener installer="AntActionInstallerListener"
		uninstaller="AntActionUninstallerListener" />
</listeners>
Code Block
borderStyledashed
titleAntActionsSpec.xml
<?xml version="1.0" encoding="UTF-8"?>
<antactions>
	<pack name="GlassFish">
		<antcall order="beforepack" buildresource="upgrade.xml" quiet="yes">
			<property name="install.dir" value="$INSTALL_PATH"/>
			<property name="install.type" value="$INSTALL_TYPE"/>
			<property name="upgrade.version" value="$UPGRADE_VERSION"/>
			<target name="beforeGlassfishUpgrade"/>
		</antcall>
		<antcall order="afterpack" buildresource="upgrade.xml" quiet="yes">
			<property name="install.dir" value="$INSTALL_PATH"/>
			<property name="install.type" value="$INSTALL_TYPE"/>
			<property name="upgrade.version" value="$UPGRADE_VERSION"/>
			<target name="afterGlassfishUpgrade"/>
		 </antcall>
	</pack>
	<pack name="JavaDB">
		<antcall order="beforepack" buildresource="upgrade.xml" quiet="yes">
			<property name="install.dir" value="$INSTALL_PATH"/>
			<property name="install.type" value="$INSTALL_TYPE"/>
			<property name="upgrade.version" value="$UPGRADE_VERSION"/>
			<target name="beforeJavaDBUpgrade"/>
		</antcall>
	</pack>
	<pack name="App">
		<antcall order="beforepack" buildresource="upgrade.xml" quiet="yes">
			<property name="install.dir" value="$INSTALL_PATH"/>
			<property name="install.type" value="$INSTALL_TYPE"/>
			<property name="upgrade.version" value="$UPGRADE_VERSION"/>
			<target name="beforeAppUpgrade"/>
		</antcall>
		<antcall order="afterpack" buildresource="upgrade.xml" quiet="yes">
			<property name="install.dir" value="$INSTALL_PATH"/>
			<property name="install.type" value="$INSTALL_TYPE"/>
			<property name="upgrade.version" value="$UPGRADE_VERSION"/>
			<target name="afterAppUpgrade"/>
		</antcall>
		<antcall order="afterpacks" uninstall_order="beforedeletion" messageid="Remove CanogaView EMS Server"
			buildfile="$INSTALL_PATH/app/pkg/core/build.xml"	quiet="yes">
			<target name="fix-files"/>
			<uninstall_target name="uninstall-service"/>
		</antcall>
	</pack>
</antactions>
Code Block
borderStyledashed
titleupgrade.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="upgrade">
 
	<target name="init" depends="-setupConditions,-shutdown"/>
 	<target name="beforeGlassfishUpgrade" description="Pre-upgrade glassfish processiong" depends="init" if="isGlassfishUpgradeRequired">
		<antcall target="-backupGlassfishFiles"/>
	</target>
	<target name="beforeJavaDBUpgrade" description="Pre-upgrade JavaDB processiong" depends="init" if="isJavaDBUpgradeRequired">
		<delete dir="${install.dir}/glassfish/javadb" quiet="true" includeemptydirs="true"/>
	</target>
 	<target name="beforeAppUpgrade" description="Pre-upgrade app processiong" depends="init" if="isUpgrade">
		<antcall target="-backupAppFiles"/>
	</target>
	<target name="afterGlassfishUpgrade" description="Post-upgrade glassfish processing" depends="init" if="isGlassfishUpgradeRequired">
		<antcall target="-restoreGlassfishFiles"/>
		<antcall target="-removeBackupGlassfishFiles"/>
	</target>

	<target name="afterAppUpgrade" description="Post-upgrade app processing" depends="init" if="isUpgrade">
		<antcall target="-restoreAppFiles"/>
		<antcall target="-removeBackupAppFiles"/>
	</target>

	<target name="-setupConditions">
		<fail message="property install.dir must be set" unless="install.dir"/>
		<fail message="property install.type must be set" unless="install.type"/>
		<condition property="isWin32">
			<os family="winnt"/>
		</condition>
		<condition property="isSolaris8">
			 <os family="unix" name="SunOS" arch="sparc" version="5.8"/>
		</condition>
		<condition property="isSolaris10">
			<os family="unix" name="SunOS" version="5.10"/>
		</condition>
		<condition property="isUpgrade">
			<equals arg1="${install.type}" arg2="upgrade" trim="true"/>
		</condition>
		<condition property="isGlassfishUpgradeRequired">
			<and>
				<isset property="isUpgrade"/>
				<equals arg1="${upgrade.version}" arg2="2.0" trim="true"/>
			</and>
		</condition>
		<condition property="isJavaDBUpgradeRequired">
			<and>
				<isset property="isUpgrade"/>
			<or>
				<equals arg1="${upgrade.version}" arg2="2.0" trim="true"/>
				<equals arg1="${upgrade.version}" arg2="2.1" trim="true"/>
			</or>
			 </and>
		</condition>
		<condition property="isShutdownRequired">
			<or>
				<isset property="isGlassfishUpgradeRequired"/>
				<isset property="isJavaDBUpgradeRequired"/>
			</or>
		</condition>
		<condition property="isShutdownWin32Required">
			<and>
				<isset property="isShutdownRequired"/>
				<isset property="isWin32"/>
			</and>
		</condition>
		<condition property="isShutdownSolaris8Required">
			 <and>
				<isset property="isShutdownRequired"/>
				<isset property="isSolaris8"/>
			</and>
		</condition>
		<condition property="isShutdownSolaris10Required">
			<and>
				<isset property="isShutdownRequired"/>
				<isset property="isSolaris10"/>
			</and>
		</condition>
	</target>
 
	<target name="-shutdown" description="Shutdown CanogaView" depends="-shutdownWin32, -shutdownSolaris8, -shutdownSolaris10">
	</target>
	<target name="-backupGlassfishFiles" description="Make a backup of needed glassfish files" depends="init">
		<move file="${install.dir}/glassfish" tofile="${install.dir}/glassfish.old"/>
	</target>
	<target name="-backupAppFiles" description="Make a backup of needed app files" depends="init">
		<move file="${install.dir}/app/pkg/dependencies.xml" tofile="${install.dir}/app/pkg/dependencies.xml.bak"/>
	 </target>
	<target name="-restoreGlassfishFiles" description="Restore backup glassfish files" depends="init">
		<copy todir="${install.dir}/glassfish/databases" overwrite="true" includeEmptyDirs="true">
			<fileset dir="${install.dir}/glassfish.old/databases"/>
		</copy>
	</target>

	<target name="-restoreAppFiles" description="Restore backup app files" depends="init">
		<copy file="${install.dir}/app/pkg/dependencies.xml.bak" tofile="${install.dir}/app/pkg/dependencies.xml" overwrite="true"/>
	</target>
	<target name="-removeBackupGlassfishFiles" description="Restore backup files" depends="init">
		<delete dir="${install.dir}/glassfish.old"/>
	</target>
	<target name="-removeBackupAppFiles" description="Restore backup files" depends="init">
		<delete file="${install.dir}/app/pkg/dependencies.xml.bak"/>
	</target>
	<target name="-shutdownWin32" description="Shutdown CanogaView on Windows installation" depends="-setupConditions" if="isShutdownWin32Required">
		<exec executable="cmd">
			<arg value="/c"/>
			<arg value="${install.dir}\app\scripts\win32\csemstop.bat"/>
		</exec>
	</target>
	<target name="-shutdownSolaris8" description="Shutdown CanogaView on Solaris 8 installation" depends="-setupConditions" if="isShutdownSolaris8Required">
		<exec executable="/bin/sh">
			<arg value="/etc/init.d/canogaview"/>
			<arg value="stop"/>
		</exec>
	</target>
	<target name="-shutdownSolaris10" description="Shutdown CanogaView on Solaris 10 installation" depends="-setupConditions" if="isShutdownSolaris10Required">
		<exec executable="/usr/sbin/svcadm">
			<arg value="disable"/>
			<arg value="-s"/>
			<arg value="canogaview"/>
		</exec>
		<exec executable="/usr/sbin/svcadm">
			<arg value="disable"/>
			<arg value="-s"/>
			<arg value="csemdb"/>
		</exec>
	</target>
</project>

Here is an example of ANT task to replace tokens in a file while copying.

Code Block
borderStyledashed
titleANT task to replace tokens
<copy file="pkg_9161_1200_patch.xml" tofile="../pkg9161/patches/1_1/1200/patch.xml" failonerror="true" overwrite="true">
		<filterset begintoken="$" endtoken="/">
			<filter token="PKG9161_INSTALL_PATH" value="${pkg9161_install_path}/"/>
			</filterset>
	</copy>