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

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

<!--
  This file contains all the jar download targets to build Velocity.
  Its tasks are referenced from the build.xml file and should not be
  called directly.

  This is here so that the main build file is not cluttered any further.
-->

<project name="VelocityTools - Example Apps" basedir=".">
  
  <target name="build-examples"
          description="Build WAR files for all VelocityTools example applications">
    <property name="target" value="war"/>
    <antcall target="simple-example" />
    <antcall target="showcase-example" />
    <antcall target="struts-example" />
  </target>

  <target name="clean-examples"
          description="Build WAR files for all VelocityTools example applications">
    <property name="target" value="clean"/>
    <antcall target="simple-example" />
    <antcall target="showcase-example" />
    <antcall target="struts-example" />
  </target>

  <target name="simple-example">
    <property name="name" value="simple" />
    <property name="base" value="${examples.home}/${name}" />
    <property name="lib" value="${base}/WEB-INF/lib"/>
    <antcall target="example-${target}"/>
  </target>
  <target name="simple-dependencies">
    <copy todir="${lib}" file="${dist.dir}/${view.id}.jar"/>
    <copy todir="${lib}" file="${commons-beanutils.jar}"/>
    <copy todir="${lib}" file="${commons-collections.jar}"/>
    <copy todir="${lib}" file="${commons-digester.jar}"/>
    <copy todir="${lib}" file="${commons-lang.jar}"/>
    <copy todir="${lib}" file="${commons-logging.jar}"/>
    <copy todir="${lib}" file="${oro.jar}"/>
    <copy todir="${lib}" file="${velocity.jar}"/>
  </target>

  <target name="showcase-example">
    <property name="name" value="showcase" />
    <property name="base" value="${examples.home}/${name}" />
    <property name="lib" value="${base}/WEB-INF/lib"/>
    <antcall target="example-${target}"/>
  </target>
  <target name="showcase-dependencies" depends="simple-dependencies">
    <copy todir="${lib}" file="${dom4j.jar}"/>
    <copy todir="${lib}" file="${jaxen.jar}"/>
    <copy todir="${lib}" file="${servlet.jar}"/>
  </target>

  <target name="struts-example">
    <property name="name" value="struts" />
    <property name="base" value="${examples.home}/${name}" />
    <property name="lib" value="${base}/WEB-INF/lib"/>
    <antcall target="example-${target}"/>
  </target>
  <target name="struts-dependencies">
    <copy todir="${lib}" file="${dist.dir}/${struts.id}.jar"/>
    <copy todir="${lib}" file="${commons-beanutils.jar}"/>
    <copy todir="${lib}" file="${commons-chain.jar}"/>
    <copy todir="${lib}" file="${commons-collections.jar}"/>
    <copy todir="${lib}" file="${commons-digester.jar}"/>
    <copy todir="${lib}" file="${commons-lang.jar}"/>
    <copy todir="${lib}" file="${commons-logging.jar}"/>
    <copy todir="${lib}" file="${commons-validator.jar}"/>
    <copy todir="${lib}" file="${servlet.jar}"/>
    <copy todir="${lib}" file="${sslext.jar}"/>
    <copy todir="${lib}" file="${struts-core.jar}"/>
    <copy todir="${lib}" file="${struts-taglib.jar}"/>
    <copy todir="${lib}" file="${struts-tiles.jar}"/>
    <copy todir="${lib}" file="${oro.jar}"/>
    <copy todir="${lib}" file="${velocity.jar}"/>
  </target>

  <target name="example-compile">
    <!-- run the dependencies target -->
    <mkdir dir="${lib}"/>
    <antcall target="${name}-dependencies"/>

    <!-- compile the classes -->
    <mkdir dir="${base}/WEB-INF/classes"/>
    <javac srcdir="${base}/WEB-INF/src"
           includes="*/**"
           debug="${compile.debug}"
           optimize="${compile.optimize}"
           source="${compile.source}"
           target="${compile.target}"
           deprecation="${compile.deprecation}"
           encoding="${compile.encoding}"
           destdir="${base}/WEB-INF/classes">
       <classpath>
        <fileset dir="${lib}">
          <include name="*.jar"/>
        </fileset>
      </classpath>
    </javac>

    <!-- copy non-java resources -->
    <copy todir="${base}/WEB-INF/classes">
      <fileset dir="${base}/WEB-INF/src" excludes="**/*.java"/>
    </copy>
  </target>

  <target name="example-war" depends="example-compile">
    <jar jarfile="${examples.home}/${name}.war"
         basedir="${base}"
         excludes="**/MANIFEST.MF,**/servletapi-${jar.servletapi.version}.jar"/>
    <echo>                                                  </echo>
    <echo>  A WAR file (Web ARchive) was created for you at </echo>
    <echo>                                                  </echo>
    <echo>      ${examples.home}/${name}.war                </echo>
    <echo>                                                  </echo>
    <echo>  To use it with Tomcat, copy the ${name}.war file</echo>
    <echo>  to the webapps directory in the Tomcat tree     </echo>
    <echo>  (assuming a standard Tomcat installation)  and  </echo>
    <echo>  then restart Tomcat.  To access the page        </echo>
    <echo>  point your browser to                           </echo>
    <echo>                                                  </echo>
    <echo>     http://localhost:8080/${name}/index.vm       </echo>
    <echo>                                                  </echo>
    <echo>  If you have any questions, don't hesitate to    </echo>
    <echo>  ask on the Velocity user list.                  </echo>
  </target>

  <target name="example-clean">
    <delete file="${examples.home}/${name}.war"/>
    <delete dir="${lib}" />
    <delete dir="${base}/WEB-INF/classes"/>
  </target>

</project>

