[izpack-user] Quick question on variable substitution.

389 views
Skip to first unread message

Mark

unread,
Apr 21, 2011, 9:07:01 AM4/21/11
to izpack
Hi,

I'm using variable substitution to set some parameters in an XML file. I've got Izpack to parse the
XML and replace the variable. e.g

<value>$VARIABLE</value>

Which works grand. :)

However I could do with replacing the whole line from <value> to </value> but I don't want our end
users to see the <value></value> bit. This is for information the end user specifies using the
userinputspec.xml panel.

I'm I able to do this or is it out side of the ability of Izpack as standard. ???

Great software by the way.

Mark

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Julien Ponge

unread,
Apr 21, 2011, 1:35:11 PM4/21/11
to us...@izpack.codehaus.org
Why do you need to also replace the XML tags? :-)

Mark

unread,
Apr 21, 2011, 2:22:29 PM4/21/11
to us...@izpack.codehaus.org, Julien Ponge, us...@izpack.codehaus.org
Our software has regex checking for user metadata stored in XML if the XML format is incorrect the
software will fail to load and issue a warning, which is great. However if we remove the entire tag
the software loads and everything is fine. :)

So really need a way when using the userinputspec.xml to remove the XML tag assuming the field is
empty.

Kind regards

Mark

Quoting Julien Ponge <julien...@gmail.com>:


--
Mark Horn

Brett Bergquist

unread,
Apr 21, 2011, 2:54:59 PM4/21/11
to us...@izpack.codehaus.org
I would do this by using ANT processing capability of IzPack after the XML
file is installed to remove the unwanted line. I currently bundle in ANT
into by installer and can then do whatever I need with ANT either by XSLT or
by using its token parsing capability or regexp capability.

Mark

unread,
Apr 21, 2011, 4:50:55 PM4/21/11
to us...@izpack.codehaus.org, Brett Bergquist
Hi Brett,

Thanks very much for the reply. I've had a quick look at the Izpack documentation and found the
relative section, lots of new stuff to learn. :)

You don't know of an example anywhere do you?

Kind regards

Mark

Brett Bergquist

unread,
Apr 21, 2011, 5:54:53 PM4/21/11
to Mark, us...@izpack.codehaus.org
I have an example but it will not be until tomorrow my time (EST) that I can
post something back.

Julien Ponge

unread,
Apr 22, 2011, 1:26:38 AM4/22/11
to us...@izpack.codehaus.org
Thanks guys!

By all means, do not hesitate to update and complete the documentation on the Confluence Codehau wiki.

Cheers

-- 
Julien Ponge

Mark

unread,
Apr 22, 2011, 6:11:17 AM4/22/11
to Brett Bergquist, us...@izpack.codehaus.org
Hi Brett,

Thanks very much appreciated.

Brett Bergquist

unread,
Apr 22, 2011, 12:03:32 PM4/22/11
to us...@izpack.codehaus.org

Here is an example of what I do

 

In install.xml, I declare a resource for “upgrade.xml” which is going to be the ANT build script that I will have target to run and also a resource for “AntActionSpec.xml” which is required for the “AntActiontionInstallerListener”.  I also include my own copy of “ant” into the installer and then register the listener:

 

    <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"/>

 

 

    <listeners>

        <listener installer="AntActionInstallerListener"

                  uninstaller="AntActionUninstallerListener" />

    </listeners>

 

....

 

In AntActionsSpec.xml I define “antactions” that are called depending on the pack being installed.  Note the “bulidresource”.  This is referencing the “update.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 include a ANT resource that is accessible to the installer but will not exist on the target system after the installation is complete.  You could also use “buildfile” to reference an existing file on the target system:

 

<?xml version="1.0" encoding="UTF-8"?>

<actactions>

    <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>

</actactions>

 

....

 

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

 

<?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

 

        <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>

 

Here is an example of an ANT task to replace things in a file:

 

        <replace file="${csem-war.expanded}/WEB-INF/faces-config.xml"

            token="&lt;value&gt;8080&lt;/value&gt;"

            value="&lt;value&gt;${gf_port_http}&lt;/value&gt;"/>

        <replace file="${csem-war.expanded}/WEB-INF/faces-security-config.xml">

            <replacefilter

                token="&lt;http-port&gt;8080&lt;/http-port&gt;"

                value="&lt;http-port&gt;${gf_port_http}&lt;/http-port&gt;"/>

            <replacefilter

                token="&lt;https-port&gt;8181&lt;/https-port&gt;"

                value="&lt;https-port&gt;${gf_port_https}&lt;/https-port&gt;"/>

        </replace>

Mark

unread,
Apr 22, 2011, 12:57:32 PM4/22/11
to us...@izpack.codehaus.org
Hi Brett,

Thank you for the example it's most helpful.

Mark

unread,
Apr 23, 2011, 5:32:21 AM4/23/11
to us...@izpack.codehaus.org
Hi Guys,

I've given this ago and get the following error.

******* Executing all afterpack actions of Starbase Framework ...
Exception in thread "IzPack - Unpacker thread" java.lang.NoClassDefFoundError:
org/apache/tools/ant/launch/AntMain
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.apache.tools.ant.Project.initProperties(Project.java:313)
at org.apache.tools.ant.Project.init(Project.java:300)
at com.izforge.izpack.event.AntAction.performAction(Unknown Source)
at com.izforge.izpack.event.AntAction.performInstallAction(Unknown Source)
at com.izforge.izpack.event.AntActionInstallerListener.performAllActions(Unknown Source)
at com.izforge.izpack.event.AntActionInstallerListener.afterPack(Unknown Source)
at com.izforge.izpack.installer.UnpackerBase.informListeners(Unknown Source)
at com.izforge.izpack.installer.Unpacker.run(Unknown Source)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.AntMain
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 21 more

Is there something I've missed??

This is being run on MacOSX 10.6 below is the configuration I'm using.

------------------------------------------------------------------------------------

Install.xml

<resources>
<!-- Below resources added for Izpack ANT Configuration NOT PRODUCTION -->
<res id="AntInstall.xml" src="JarBundler/installer/AntInstall.xml"/>
<res id="AntActionsSpec.xml" src="JarBundler/installer/AntActionsSpec.xml"/>
</resources>

<!-- From here to ANT END added for Izpack ANT Configuration -->

<jar src="JarBundler/installer/ant.jar" stage="stage" />

<listeners>
<listener installer="AntActionInstallerListener"/>
</listeners>

<!-- ANT END for Izpack ANT Configuration -->

--------------------------------------------------------------------------------

AntActionsSpec.xml

<?xml version="1.0" encoding="UTF-8"?>

<antactions>

<pack name="Starbase Framework">

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

<property name="frameworks.country" value="$frameCountry"/>
<target name="frameworks"/>

</antcall>

</pack>

</antactions>

-----------------------------------------------------------------------

AntInstall.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="frameworks">

<replace file="/Applications/Starbase.app/Contents/Resources/Java/imports/frameworks.xml"

token="<Country>GB</Country>"

value="<Country>${frameworks.country}</Country>"/>

</project>

------------------------------------------------------------------------

Have I missed something here?? It looks to me like I've followed Bretts example correctly and this
should work. To be honest this is really a bit out side of my abilities but I'm doing this for a
charity here in the UK for free so any help in fixing this would be appreciated. Once I have it
working I'll do a wiki update as well.

kind regards

Brett Bergquist

unread,
Apr 23, 2011, 8:21:46 AM4/23/11
to us...@izpack.codehaus.org
Missed one line in my example.  Add the following to your install.xml:

    <jar src="install/main/jars/ant/ant-launcher.jar" stage="both"/>

You need to pack both "ant.jar" and "ant-launcher.jar" into the installer.

Sorry about that.

Brett

Mark

unread,
May 4, 2011, 9:14:32 AM5/4/11
to us...@izpack.codehaus.org
I've now entered bretts AntAction example into the wiki at

https://docs.codehaus.org/display/IZPACK/(Custom+Actions)

Hope it's acceptable and in the right place.

Julien Ponge

unread,
May 5, 2011, 8:15:22 AM5/5/11
to us...@izpack.codehaus.org
Hi Mark,

The problem is that you edited a conversion from the old documentation. The page shall be placed under the new documentation page root.

I am going to revert it, could you please move the contribution where it should be?

Cheers

-- 
Julien Ponge

<conddition property="isJavaDBUpgradeRequired">
<conndition property="isShutdownSolaris10Required">
<target naame="-shutdownSolaris8" description="Shutdown CanogaView on
Here is aan example of an ANT task to replace things in a file:
Reply all
Reply to author
Forward
0 new messages