<!-- ===================== TheOpenStack build file to be used during DEVELOPMENT =========================== -->
<!-- Expected usage: Before starting development (Clean build): 'Ant -buildfile build_dev.xml build'        
     This command will use the build_dev.xml file as build file,
     and execute the build' target defined in this file.  
 -->
<!-- This file also provides two more targets:
      1. compile - just to compile changed java files.
      2. buildPages - copies the JSP and HTML pages etc. to the right directories. This is intended to be executed 
      after adding or modifying  any JSP s during build.
 -->
<project name="rtpdemo" default="help" basedir=".">

<!-- ===================== Property Definitions =========================== -->

    <!-- 
         All properties should be defined in this section.
	 Any host-specific properties should be defined 
	 in the build.properties file.For e.g. we have defined tomcat home in that file.
    -->

<!-- The name of the file where host specific properties are stored -->
  <property file="build.properties" />

<!-- Directory where the source code is note: based dir is defined at the top of this file -->

  <property name="src.home"          value="${basedir}/src"/>

<!-- Directory where the jar files are stored  -->

  <property name="lib.home"          value="${basedir}/lib"/>

<!-- Directory where the classes are stored  -->

  <property name="classes.home"          value="${basedir}/classes"/>

<!-- Directory where the JSP pages and HTML files are stored  -->

  <property name="view.home"          value="${src.home}/com/theopenstack/rtpdemo/view/"/>

<!-- Directory where we will store the build files temporarily during build  -->

  <property name="build.home"        value="${basedir}/build"/>

<!-- This is the most important directory. During development mode TomCat will look for all classes, config files and jar files under this.   -->

 <property name="build.web"        value="${basedir}/WEB-INF"/>



<!-- ==================== Compilation Classpath =========================== -->

    <!-- 
         This section creates the classpath for compilation.
    -->

  <path id="compile.classpath">

    <!-- The class files for this application -->
    <pathelement location="${classes.home}"/>

    <!-- The lib files for this application -->
    <fileset dir="${lib.home}">
      <include name="*.jar"/>
      <include name="*.zip"/>
    </fileset>

    <!-- All files/jars that Tomcat makes available -->
    <fileset dir="${tomcat.home}/lib">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${tomcat.home}/common/lib">
      <include name="*.jar"/>
    </fileset>
    <pathelement location="${tomcat.home}/classes"/>
    <pathelement location="${tomcat.home}/common/classes"/>

  </path>


<!-- ==================== Build Targets ========================= -->


<!-- ==================== "help" Target =================================== -->

    <!--
         This is the default ant target executed if no target is specified.
         Look at the top of this file the default is specified as 'help'.
    -->

 <target name="help" >
   <echo message="Please specify a target. [usage: ant &lt;targetname&gt;]" />
   <echo message="Here is a list of targets supported  by the current build file: "/>
   <echo message="  compile.......Compiles java files" />
   <echo message="  build.........use during startup or for a clean build.Creates directories and compiles after cleanup"/>
   <echo message="  buildPages........use any time you add or change a JSP, HTML or image" />
 </target>

<!-- ==================== "clean-all" Target ============================== -->
    
    <!--
          This target should clean up the directory structure. Note it also deletes the JSP and HTML files
          from the base directory. In development mode we will be storing all JSP s directly under the basedir.
          The build process first removes any old files there and copies the HTML and JSP s from the view home.
          That is why we have provided a buildPages target bellow.
    -->

 <target name="cleanAll" >
    <delete dir="${build.home}"/>
    <delete dir="${classes.home}"/>

    <!-- can't delete JSP / HTML if Tomcat is running -->
    <delete dir="${basedir}/*.jsp" failonerror="false"/>
    <delete dir="${basedir}/*.html" failonerror="false"/>  
    <delete dir="${basedir}/images" failonerror="false"/>  

 </target>

<!-- ==================== "prepare" Target ================================ -->
 
    <!--
          This target is executed prior to any of the later targets
	  to make sure the directories exist. It only creates them 
	  if they need to be created....
	
	  Note - this depends on cleanAll so when you type Ant prepare, it will first run cleanAll and
        then prepare. The same flow is followed inthis file till the final build target. After that there are two extra 
        targets needed specifically during development.  
    -->

  <target name="prepare" depends="cleanAll">

    <echo message="Tomcat Home  = ${tomcat.home}" />

    <mkdir  dir="${classes.home}"/>

    <mkdir dir="${build.home}"/>
    <mkdir dir="${build.home}/classes" />
    <mkdir dir="${build.home}/lib" />

  </target>


<!-- ==================== "compileAll" Target ================================ -->

    <!-- 
          This only compiles java files that are newer
	  than their corresponding .class files. 
     -->

  <target name="compileAll" depends="prepare"  >
    <javac srcdir="${src.home}" destdir="${classes.home}"  debug="yes" >
        <classpath refid="compile.classpath"/>
    </javac>
   
  </target>

<!-- ==================== "build" Target ================================== -->

    <!-- 
          Clean , create directories , compile and copy required files.
    -->

  <target name="build" depends="compileAll">

  
   <!-- Copy all the webapp content (jsp's, html and images etc. -->

    <copy    todir="${basedir}">
      <fileset dir="${view.home}/pages"/>
    </copy>

    <!-- Copy all the config content (XMLs, tld  etc. -->

	<copy    todir="${build.web}">
      <fileset dir="${view.home}/config"/>
    </copy>
    
	<!--  copy the properties files such as messages etc. -->

    <copy    todir="${build.web}/classes">
      <fileset dir="${src.home}">
         <include name="**/*.properties" />
         <include name="**/*.prop" />
      </fileset>
    </copy>
    
    <!--  copy all the Java class files -->

    <copy    todir="${build.web}/classes">
      <fileset dir="${classes.home}"/>
    </copy>

    <!-- Now, copy all the jar files we need -->

    <copy    todir="${build.web}/lib">
      <fileset dir="${lib.home}" />
    </copy>

    

  </target>

<!-- ==================== "compile" Target to be used to compile  java files during development======================= -->

    <!-- 
          Same as compileAll but there is no dependency 
	    hence will not clean and re create directories.
     -->

  <target name="compile" >
    <javac srcdir="${src.home}" destdir="${build.web}/classes"  debug="yes" >
        <classpath refid="compile.classpath"/>
    </javac>
    
  </target>

<!-- ==================== "buildPages" Target ================================== -->



<target name="buildPages" >
  <!-- Copy all the webapp content (jsp's, html and images etc. -->
    <copy    todir="${basedir}">
      <fileset dir="${view.home}/pages"/>
    </copy>

<!-- Copy all the config content (XMLs, tld  etc. -->

    <copy    todir="${build.web}">
      <fileset dir="${view.home}/config"/>
    </copy>
    
    <copy    todir="${build.web}/classes">
      <fileset dir="${src.home}">
         <include name="**/*.properties" />
         <include name="**/*.prop" />
      </fileset>
    </copy>
</target>



</project>
