<?xml version="1.0"?>
<!--

    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

    Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.

    The contents of this file are subject to the terms of either the GNU
    General Public License Version 2 only ("GPL") or the Common Development
    and Distribution License("CDDL") (collectively, the "License").  You
    may not use this file except in compliance with the License.  You can
    obtain a copy of the License at
    https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
    or packager/legal/LICENSE.txt.  See the License for the specific
    language governing permissions and limitations under the License.

    When distributing the software, include this License Header Notice in each
    file and include the License file at packager/legal/LICENSE.txt.

    GPL Classpath Exception:
    Oracle designates this particular file as subject to the "Classpath"
    exception as provided by Oracle in the GPL Version 2 section of the License
    file that accompanied this code.

    Modifications:
    If applicable, add the following below the License Header, with the fields
    enclosed by brackets [] replaced by your own identifying information:
    "Portions Copyright [year] [name of copyright owner]"

    Contributor(s):
    If you wish your version of this file to be governed by only the CDDL or
    only the GPL Version 2, indicate your decision by adding "[Contributor]
    elects to include this software in this distribution under the [CDDL or GPL
    Version 2] license."  If you don't indicate a single choice of license, a
    recipient has the option to distribute your version of this file under
    either the CDDL, the GPL Version 2 or to extend the choice of license to
    its licensees as provided above.  However, if you add GPL Version 2 code
    and therefore, elected the GPL Version 2 license, then the option applies
    only if the new code is made subject to such option by the copyright
    holder.

-->

<project name="XJC Servlet" default="deploy" basedir="../..">

    <!-- import build properties -->
    <property file="${basedir}/build.properties" />

    <property name="servlet.root" value="${jaxb.root}/tools/servlet"/>
    <property name="commons.root" value="${servlet.root}/../webapp-commons" />
<!--
  deploy.home          The name of the directory into which the
                       deployment hierarchy will be created, and into
                       which the build directory will be copied.
                       Defaults to "${catalina.home}/webapps/${app.name}".
-->
    <!-- this property needs to be defined externally -->
    <!--property name="catalina.home" value="${servlet.root}/catalina"/-->
    <property name="deploy.home"   value="${catalina.home}/webapps/xjc"/>

    <!-- determine the behavior of the servlet -->
    <property name="mode" value="jwsdp" /><!-- or "standalone" -->

    <!-- when deployed to JWSDP1.0_01, we can't have Xerces in our classpath. -->
    <property name="exclusion.lib" value="xercesImpl.jar" />


    <!-- libraries that are referenced when compiling Java source files -->
    <path id="javac.classpath">
      <pathelement path="${codemodel.classes}" />
      <pathelement path="${runtime.classes}" />
      <pathelement path="${xjc.classes}" />
      <pathelement path="${commons.root}/jaxb-webapp-commons.jar"/>
      <fileset dir="${jaxb.libs.redist}" includes="*.jar"/>
      <fileset dir="${jaxb.libs.rebundle}" includes="**/*.jar"/>
      <fileset dir="${jaxb.libs.util}" includes="*.jar"/>
    </path>





  <target name="all" depends="clean,compile"
   description="Clean build and dist, then compile"/>



  <target name="clean">
    <delete dir="${servlet.root}/build"/>
    <delete dir="${servlet.root}/boxed.jar"/>
    <delete dir="${deploy.home}"/>
  </target>


  <target name="compile">
    <ant target="jar" antfile="${commons.root}/build.xml" />


    <!-- Compile Java classes as necessary -->
    <mkdir    dir="${servlet.root}/build/classes"/>
    <javac srcdir="${servlet.root}/src" destdir="${servlet.root}/build/classes"
           debug="${compile.debug}" optimize="${compile.optimize}"
    	   source="1.5" target="1.5"
           deprecation="${compile.deprecation}" >
      <classpath refid="javac.classpath"/>
    </javac>

    <!-- Copy associated resource files -->
    <copy  todir="${servlet.root}/build/classes">
      <fileset dir="${servlet.root}/src" includes="**/*.properties"/>
    </copy>

    <!-- make boxed jar file -->
    <jar destfile="${servlet.root}/boxed.jar">
      <fileset dir="${servlet.root}/build/classes" includes="**/boxed/**/*" />
    </jar>

    <!-- make setting file -->
    <echo file="${servlet.root}/build/classes/com/sun/tools/xjc/servlet/Mode.properties">mode=${mode}</echo>
  </target>



  <target name="war" description="build a war file from jaxb-ri/dist" depends="compile">
    <delete file="${servlet.root}/xjc.war" />
    <war destfile="${servlet.root}/xjc.war" webxml="${servlet.root}/web.xml">
      <classes dir="${servlet.root}/build/classes"/>
      <classes dir="${servlet.root}/src" includes="**/package-list" />

      <lib dir="${jaxb.root}/dist/lib" includes="*.jar" excludes="${exclusion.lib}" />
      <lib dir="${jaxb.libs.util}" includes="mailapi.jar, smtp.jar, gsc.jar, antlr.jar"/>
      <lib dir="${servlet.root}" includes="boxed.jar"/>
      <lib dir="${commons.root}" includes="jaxb-webapp-commons.jar"/>

      <webinf dir="${servlet.root}" includes="taglib.tld"/>

      <!-- static contents -->
      <fileset dir="${servlet.root}/web"/>
    </war>
  </target>


  <target name="war-jwsdp" description="build a war file for JWSDP" depends="compile">
    <delete file="${servlet.root}/xjc.war" />
    <war destfile="${servlet.root}/xjc.war" webxml="${servlet.root}/web.xml">
      <classes dir="${servlet.root}/build/classes"/>
      <classes dir="${servlet.root}/src" includes="**/package-list" />

      <lib dir="${jaxb.libs.util}" includes="mailapi.jar, smtp.jar, gsc.jar, antlr.jar"/>
      <lib dir="${servlet.root}" includes="boxed.jar"/>
      <lib dir="${commons.root}" includes="jaxb-webapp-commons.jar"/>

      <webinf dir="${servlet.root}" includes="taglib.tld"/>

      <!-- static contents -->
      <fileset dir="${servlet.root}/web"/>
    </war>
  </target>


  <!-- make sure the deployment directory is available -->
  <target name="init-prepare">
    <available property="deploy.dir.available" file="${catalina.home}"/>
  </target>
  <target name="init" depends="init-prepare" unless="deploy.dir.available">
    <fail>
      Directory ${catalina.home} doesn't exist. Set the property
      catalina.home before launching ant.

      e.g.,  ant -Dcatalina.home=xxxxx
    </fail>
  </target>



  <target name="deploy" depends="init,compile"
   description="Deploy application to servlet container">


    <!-- Copy the contents of the build directory -->
    <mkdir     dir="${deploy.home}/WEB-INF/classes"/>
    <copy    todir="${deploy.home}/WEB-INF/classes">
      <fileset dir="${servlet.root}/build/classes"/>
      <fileset dir="${servlet.root}/src" includes="**/package-list" />
    </copy>

    <!-- Copy external dependencies as required -->
    <mkdir  dir="${deploy.home}/WEB-INF/lib"/>
    <copy todir="${deploy.home}/WEB-INF/lib">
      <fileset dir="${jaxb.root}/dist/lib" includes="*.jar" excludes="${exclusion.lib}"/>
      <fileset dir="${jaxb.libs.util}" includes="mailapi.jar, smtp.jar, gsc.jar, antlr.jar"/>
      <fileset dir="${commons.root}" includes="jaxb-webapp-commons.jar"/>
      <fileset dir="${servlet.root}" includes="boxed.jar"/>
    </copy>

    <copy todir="${deploy.home}/WEB-INF">
      <fileset dir="${servlet.root}" includes="web.xml, taglib.tld" />
    </copy>

    <!-- Copy static content -->
    <copy todir="${deploy.home}">
      <fileset dir="${servlet.root}/web"/>
    </copy>
  </target>



  <target name="reload" depends="init,deploy" description="Deploy and reload Tomcat">
    <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
      <classpath path="${catalina.home}/server/lib/catalina-ant.jar" />
    </taskdef>
    <reload url="http://localhost:8080/manager" username="tomcat" password="tomcat" path="/xjc" />
  </target>

</project>
