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

    Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.

    This program and the accompanying materials are made available under the
    terms of the Eclipse Distribution License v. 1.0, which is available at
    http://www.eclipse.org/org/documents/edl-v10.php.

    SPDX-License-Identifier: BSD-3-Clause

-->

<project basedir="." default="help" name="fromwsdl">

    <import file="etc/deploy-targets.xml"/>

    <path id="metro.classpath">
        <pathelement location="${java.home}/../lib/tools.jar"/>
        <fileset dir="${lib.home}">
            <include name="*.jar"/>
            <exclude name="j2ee.jar"/>
        </fileset>
    </path>

    <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">

        <classpath refid="metro.classpath"/>
    </taskdef>

    <target name="setup">
        <mkdir dir="${build.home}"/>
        <mkdir dir="${build.classes.home}"/>
        <mkdir dir="${build.war.home}"/>
    </target>

    <target name="clean">
        <delete dir="${build.home}" includeEmptyDirs="true"/>
    </target>

    <target name="build-server-wsdl" depends="setup">
        <wsimport
                debug="true"
                verbose="${verbose}"
                keep="true"
                destdir="${build.classes.home}"
                package="fromwsdl.server"
                wsdl="${basedir}/etc/AddNumbers.wsdl">
        </wsimport>
        <javac
                fork="true"
                srcdir="${basedir}/src"
                destdir="${build.classes.home}"
                includes="**/server/**,**/common/**">
            <classpath refid="metro.classpath"/>
        </javac>
    </target>

    <target name="create-war">
        <war warfile="${build.war.home}/metro-${ant.project.name}.war" webxml="etc/web.xml">
            <webinf dir="${basedir}/etc" includes="sun-jaxws.xml"/>
            <zipfileset
                    dir="${basedir}/etc"
                    includes="*.wsdl, *.xsd"
                    prefix="WEB-INF/wsdl"/>
            <classes dir="${build.classes.home}"/>
        </war>
    </target>

    <target name="generate-client" depends="setup">
        <wsimport
                debug="true"
                verbose="${verbose}"
                keep="true"
                destdir="${build.classes.home}"
                package="fromwsdl.client"
                wsdl="http://localhost:8080/metro-fromwsdl/addnumbers?wsdl">
        </wsimport>
    </target>

    <target name="client" depends="generate-client">
        <javac
                fork="true"
                srcdir="${basedir}/src"
                destdir="${build.classes.home}"
                includes="**/client/**,**/common/**">
            <classpath refid="metro.classpath"/>
        </javac>
    </target>

    <target name="run">
        <java fork="true" classname="fromwsdl.client.AddNumbersClient">
            <classpath>
                <path refid="metro.classpath"/>
                <pathelement location="${build.classes.home}"/>
                <pathelement location="${basedir}/etc"/>
            </classpath>
            <jvmarg value="-Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=${log}"/>
        </java>
    </target>

    <target name="help">
        <echo message="server:       Builds and deploy the service endpoint WAR"/>
        <echo message="client:       Builds the client"/>
        <echo message="run:          Runs the client"/>
    </target>


    <target name="server" depends="setup">

        <antcall target="clean"/>

        <antcall target="build-server-wsdl"/>

        <antcall target="create-war"/>

        <antcall target="deploy"/>
    </target>

</project>
