<?xml version="1.0" encoding="iso-8859-1"?>
<!--

    Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.

    This program and the accompanying materials are made available under the
    terms of the Eclipse Public License v. 2.0, which is available at
    http://www.eclipse.org/legal/epl-2.0.

    This Source Code may also be made available under the following Secondary
    Licenses when the conditions for such availability set forth in the
    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
    version 2 with the GNU Classpath Exception, which is available at
    https://www.gnu.org/software/classpath/license.html.

    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0

-->

<!-- This file is used by the package-appclient script -->

<project name="package-appclient" default="all" basedir=".">

    <property name="install.home" value="${basedir}/.."/>
    <property name="appclientjar" value="${user.dir}/appclient.jar"/>

    <!-- package-appclient script should override the following properties -->
    <property name="mq.home" value="${install.home}/imq"/>
    <property name="domain.dir" value="${install.home}/domains"/>

    <target name="all">

        <echo message="Creating ${appclientjar} ... "/>

        <condition property="windows">
            <os family="windows" />
        </condition>
        <condition property="unix">
            <os family="unix" />
        </condition>

        <delete file="${appclientjar}" quiet="true"/>
        <tempfile destdir="${java.io.tmpdir}" prefix="pkgac" property="tmp.dir"/>
        <!--
            There is a small but non-zero chance that a concurrent user could have
            created the same temp file.  If the file exists abort the task.
        -->
        <available file="${tmp.dir}" property="tmp.dir.exists"/>
        <fail if="tmp.dir.exists">Temporary directory ${tmp.dir} already exists - aborting.  Please try again.</fail>

        <delete dir="${tmp.dir}" quiet="true"/>
        <mkdir dir="${tmp.dir}"/>

        <antcall target="do.copy"/>

        <zip destfile="${appclientjar}">
            <zipfileset dir="${install.home}"
                        prefix="appclient">
                <include name="lib/dtds/*.dtd"/>
                <include name="lib/schemas/*"/>
                <include name="lib/appclient/client.policy"/>
                <include name="lib/appclient/appclientlogin.conf"/>
                <include name="lib/appclient/wss-client-config-2.0.xml"/>
                <include name="lib/endorsed/*.jar"/>

                <include name="lib/*.jar"/>
                <include name="lib/install/applications/jmsra/imqjmsra.jar"/>
                <exclude name="lib/appserv-assemblytool.jar"/>
                <exclude name="lib/appserv-jstl.jar"/>
                <exclude name="lib/appserv-tags.jar"/>
                <exclude name="lib/commons-launcher.jar"/>
                <exclude name="lib/deployhelp.jar"/>
                <exclude name="lib/j2ee-svc.jar"/>
                <exclude name="lib/jhall.jar"/>
                <exclude name="lib/sun-appserv-ant.jar"/>
            </zipfileset>
            <zipfileset dir="${tmp.dir}"
                        prefix="appclient"
                        filemode="755">
                <include name="bin/appclient"/>
            </zipfileset>
            <zipfileset dir="${tmp.dir}"
                        prefix="appclient">
                <include name="config/asenv.conf"/>
                <include name="config/asenv.bat"/>
                <include name="bin/appclient.bat"/>
            </zipfileset>

            <zipfileset dir="${install.home}/lib/install/applications/jmsra"
                            prefix="appclient/imq/lib">
                <include name="imq.jar"/>
                <include name="imqadmin.jar"/>
                <include name="imqutil.jar"/>
            </zipfileset>

            <zipfileset dir="${mq.home}"
                        prefix="appclient/imq">
                <include name="lib/fscontext.jar"/>
            </zipfileset>
            <zipfileset dir="${domain.dir}/domain1"
                        prefix="appclient">
                <include name="config/sun-acc.xml"/>
            </zipfileset>
            <zipfileset dir="${install.home}/lib/install/templates"
                        prefix="appclient/config">
                <include name="sun-acc.xml.template"/>
            </zipfileset>
        </zip>

        <delete dir="${tmp.dir}" quiet="true"/>

        <echo message="File created: ${appclientjar}"/>
    </target>

    <target name="do.copy" depends="do.copy.windows, do.copy.unix"/>

    <target name="do.copy.windows" if="windows">
        <!-- token-replace asenv.bat and appclient.bat -->
        <copy file="${install.home}/lib/install/templates/asenv.bat.template"
              tofile="${tmp.dir}/config/asenv.bat"/>
        <copy file="${install.home}/lib/install/templates/appclient.bat.template"
              tofile="${tmp.dir}/bin/appclient.bat"/>
        <replace token="%CONFIG_HOME%"
                 value="..\config"
                 file="${tmp.dir}/bin/appclient.bat"/>
        <replace file="${tmp.dir}/config/asenv.bat">
            <replacefilter token="%ANT_HOME%" value=""/>
            <replacefilter token="%ANT_LIB%" value=""/>
            <replacefilter token="%PERL_HOME%" value=""/>
            <replacefilter token="%POINTBASE_HOME%" value=""/>
            <replacefilter token="%WEBSERVICES_LIB%" value=""/>
            <replacefilter token="%NSS_HOME%" value=""/>
            <replacefilter token="%NSS_BIN_HOME%" value=""/>
            <replacefilter token="%IMQ_LIB%" value="..\imq\lib"/>
            <replacefilter token="%IMQ_BIN%" value="..\imq\bin"/>
            <replacefilter token="%CONFIG_HOME%" value="..\config"/>
            <replacefilter token="%INSTALL_HOME%" value=".."/>
            <replacefilter token="%JAVA_HOME%" value="${java.home}\.."/>
            <replacefilter token="%JHELP_HOME%" value=""/>
            <replacefilter token="%ICU_LIB%" value=""/>
            <replacefilter token="%LOCALE%" value=""/>
            <replacefilter token="%DEF_DOMAINS_PATH%" value=""/>
            <replacefilter token="%ACC_CONFIG%" value="..\config\sun-acc.xml"/>
        </replace>
    </target>

    <target name="do.copy.unix" if="unix">
        <!-- token-replace asenv.conf and appclient -->
        <copy file="${install.home}/lib/install/templates/asenv.conf.template"
              tofile="${tmp.dir}/config/asenv.conf"/>
        <copy file="${install.home}/lib/install/templates/appclient.template"
              tofile="${tmp.dir}/bin/appclient"/>
        <replace token="%CONFIG_HOME%"
                 value="../config"
                 file="${tmp.dir}/bin/appclient"/>
        <replace file="${tmp.dir}/config/asenv.conf">
            <replacefilter token="%ANT_HOME%" value=""/>
            <replacefilter token="%ANT_LIB%" value=""/>
            <replacefilter token="%PERL_HOME%" value=""/>
            <replacefilter token="%POINTBASE_HOME%" value=""/>
            <replacefilter token="%WEBSERVICES_LIB%" value=""/>
            <replacefilter token="%NSS_HOME%" value=""/>
            <replacefilter token="%NSS_BIN_HOME%" value=""/>
            <replacefilter token="%IMQ_LIB%" value="${mq.home}/lib"/>
            <replacefilter token="%IMQ_BIN%" value=""/>
            <replacefilter token="%CONFIG_HOME%" value="../config"/>
            <replacefilter token="%INSTALL_HOME%" value=".."/>
            <replacefilter token="%JAVA_HOME%" value="${java.home}/.."/>
            <replacefilter token="%JHELP_HOME%" value=""/>
            <replacefilter token="%ICU_LIB%" value=""/>
            <replacefilter token="%LOCALE%" value=""/>
            <replacefilter token="%DEF_DOMAINS_PATH%" value=""/>
            <replacefilter token="%ACC_CONFIG%" value="../config/sun-acc.xml"/>
        </replace>
    </target>

</project>
