<?xml version="1.0"?>
<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements.  See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership.  The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied.  See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->
<project name="web" default="dist">

    <property name="root.base.dir" value="../.."/>

    <!-- "extend" parent build definition -->
    <import file="../../build.xml"/>

    <property name="module.name" value="web"/>
    <property name="module.base.dir" value="${root.base.dir}/samples/web"/>
    <property name="dist.jar.name" value="${project.name}-${module.name}.jar"/>
    <property name="dist.jar" value="${root.dist.dir}/${dist.jar.name}"/>

    <!-- Module properties -->
    <property name="dist.war.name" value="${project.name}-${module.name}.war"/>
    <property name="dist.war" value="${root.base.dir}/build/${dist.war.name}"/>

    <property name="dist.dir" value="${build.dir}/dist"/>

    <!-- Deployment properties for development -->
    <property name="deploy.dir" value="${env.CATALINA_HOME}/webapps"/>

    <path id="compile.path">
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>

    <!-- ===================================================================
  -  clean - clean all build remnants from this submodule
  - ==================================================================== -->
    <target name="clean" description="Cleans the samples webapp build">
        <echo message="cleaning ${module.name} module"/>
        <delete file="${dist.war}"/>
        <delete dir="${build.dir}"/>
    </target>

    <!-- ===================================================================
 -  compile - compile Java source files
 -  =================================================================== -->
    <target name="compile" description="Compiles the sample webapp classes">

        <!-- <mkdir dir="${classes.dir}"/>
    <mkdir dir="${classes.dir}/META-INF"/>

    <javac destdir="${classes.dir}"
              debug="${compile.debug}"
              deprecation="${compile.deprecation}"
              optimize="${compile.optimize}"
              failonerror="true"
              classpathref="all.libs">
     <src path="${src.dir}"/>
           <classpath location="${root.dist.dir}/jsecurity.jar"/>
       </javac> -->

    </target>

    <target name="jar" depends="compile" description="Creates a jar of the sample webapp classes">

        <!-- <mkdir dir="${dist.dir}"/>

       <jar jarfile="${dist.jar}">
           <fileset dir="${classes.dir}">
               <include name="**/*.class"/>
           </fileset>
           <fileset dir="${etc.dir}">
               <include name="*.xml"/>
               <include name="*.gif"/>
               <include name="*.jpg"/>
               <include name="*.properties"/>
           </fileset>
           <manifest>
               <attribute name="Implementation-Title" value="${project.name}-${module.name}"/>
               <attribute name="Implementation-Version" value="${version}"/>
               <attribute name="${project.name}-Version" value="${version}"/>
           </manifest>
       </jar> -->
    </target>

    <!-- ===================================================================
 -  dist - create distribution war (which will be used for deployment)
 -  =================================================================== -->
    <target name="dist" description="Creates the samples webapp .war">
        <war warfile="${dist.war}" webxml="../web/WEB-INF/web.xml">
            <lib dir="${root.dist.dir}" includes="jsecurity.jar"/>
            <lib dir="${lib.dir}/samples" includes="jstl.jar"/>
            <lib dir="${lib.dir}/samples" includes="standard.jar"/>
            <lib dir="${lib.dir}/samples" includes="log4j.jar"/>
            <lib dir="${lib.dir}/samples" includes="commons-*.jar"/>
            <lib dir="${lib.dir}/samples" includes="ehcache.jar"/>
            <lib dir="${lib.dir}/samples" includes="backport-util-concurrent.jar"/>
            <fileset dir="${module.base.dir}" includes="**" excludes="**/web.xml, **/build.xml"/>
            <!-- <lib dir="${dist.dir}" includes="*.jar"/> -->
        </war>
    </target>

    <target name="quick-deploy" description="Blindly deploys the samples webapp .war to Tomcat">
        <echo>Deploying application to Tomcat...</echo>
        <unzip src="${dist.war}" dest="${env.CATALINA_HOME}/webapps/${project.name}-${module.name}"/>
        <touch file="${env.CATALINA_HOME}/webapps/${project.name}-${module.name}/WEB-INF/web.xml"/>
    </target>

    <target name="deploy" depends="dist,quick-deploy" description="Creates and deploys the samples webapp .war to Tomcat"/>

</project>
