<?xml version="1.0"?>

<project name="antville" default="usage" basedir=".">

   <!-- =================================================================== -->
   <!-- help on usage                                                       -->
   <!-- =================================================================== -->
   <target name="help" depends="usage"/>
   <target name="usage">
      <echo/>
      <echo/>
      <echo message="Antville build instructions"/>
      <echo message="-------------------------------------------------------------"/>
      <echo/>
      <echo message=" available targets are:"/>
      <echo/>
      <echo message=" all        - generates the antville and antclick packages"/>
      <echo message=" antville   - generates the antville packages"/>
      <echo message=" antclick   - generates the antclick packages"/>
      <echo message=" transfer   - copy packages to download server"/>
      <!-- echo message=" docs       - generates the API helmaDocs"/ -->
      <echo/>
      <echo message=" usage      - provides help on using the build tool (default)"/>
      <echo/>
      <echo message=" See comments inside the build.xml file for more details."/>
      <echo message="-------------------------------------------------------------"/>
      <echo/>
      <echo/>
   </target>


   <!-- =================================================================== -->
   <!-- initialize some variables                                           -->
   <!-- =================================================================== -->
   <target name="init">
      <property name="name" value="Antville"/>
      <property name="year" value="2001-${year}"/>
      <property name="version" value="1.1"/>
      <property name="project" value="antville"/>
      <property name="build.compiler" value="classic"/>

      <property name="cvs.antville.root" 
         value=":pserver:anonymous@194.232.104.95:/opt/cvs/apps"/>
      <property name="cvs.antville.tag" value="HEAD"/>
      <property name="cvs.manage.root" 
         value=":pserver:anonymous@194.232.104.95:/opt/cvs/apps"/>
      <property name="cvs.manage.tag" value="HEAD"/>
      <property name="cvs.hop.root" 
         value=":pserver:anonymous@194.232.104.95:/opt/cvs/hop"/>
      <property name="cvs.hop.tag" value="HEAD"/>

      <property name="home.dir" value=".."/>
      <property name="build.dir" value="${home.dir}/build"/>
      <property name="build.code" value="${home.dir}/code"/>
      <property name="build.static" value="${home.dir}/static"/>
      <property name="build.docs" value="${home.dir}/docs"/>

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

      <property name="package.name" value="${project}-${version}"/>
      <property name="antclick.name" value="antclick-${version}"/>

      <property name="scp.server" value="194.232.104.95"/>
      <property name="scp.path" value="/usr/local/httpd/htdocs/download/antville"/>

      <property name="debug" value="on"/>
      <property name="optimize" value="on"/>
      <property name="deprecation" value="off"/>

      <tstamp/>

      <filter token="year" value="${year}"/>
      <filter token="version" value="${version}"/>
      <filter token="date" value="${TODAY}"/>

      <cvspass cvsroot="${cvs.antville.root}" password=""/>
      <cvspass cvsroot="${cvs.hop.root}" password=""/>
   </target>


   <!-- =================================================================== -->
   <!-- generate both, the antville and antclick packages                   -->
   <!-- =================================================================== -->
   <target name="all" depends="export">
      <property name="nocleanup" value="true"/>
      <property name="noexport" value="true"/>
      <antcall target="antville"/>
      <antcall target="antclick"/>
      <antcall target="cleanup"/>
      <!-- FIXME: currently don't know about a way to call target cleanup here -->
      <delete dir="${build.work}"/>
   </target>


   <!-- =================================================================== -->
   <!-- generate the antville distribution packages                         -->
   <!-- =================================================================== -->
   <target name="antville" depends="export">
      <antcall target="package-zip">
         <param name="filename" value="${package.name}"/>
         <param name="path" value="${build.work}/apps/${project}"/>
      </antcall>
      <antcall target="package-tgz">
         <param name="filename" value="${package.name}"/>
         <param name="path" value="${build.work}/apps/${project}"/>
      </antcall>
      <antcall target="cleanup"/>
   </target>


   <!-- =================================================================== -->
   <!-- generate the antclick distribution packages                         -->
   <!-- =================================================================== -->
   <target name="antclick" depends="export">
      <copy todir="${build.work}/">
         <fileset dir="${build.extra}" 
            includes="antclick.sh antclick.bat apps.properties 
                      launcher.jar server.properties"/>
      </copy>
      <copy file="${build.extra}/db.properties" 
         todir="${build.work}/apps/${project}/code"
         overwrite="true"/>

      <cvs cvsRoot="${cvs.manage.root}" 
         command="export" 
         tag="${cvs.manage.tag}" 
         package="manage" 
         dest="${build.work}/apps"/>

      <cvs cvsRoot="${cvs.hop.root}" 
         command="export" 
         tag="${cvs.hop.tag}" 
         package="helma/lib helma/licenses helma/license.txt" 
         dest="${build.work}"/>

      <copy todir="${build.work}/lib">
         <fileset dir="${build.work}/helma/lib" includes="*.jar"/>
      </copy>
      <copy file="${build.extra}/helma.jar" todir="${build.work}/lib"/>
      <copy file="${build.extra}/mckoidb.jar" todir="${build.work}/lib/ext"/>

      <copy todir="${build.work}/licenses">
         <fileset dir="${build.work}/helma/licenses"/>
      </copy>
      <copy file="${build.work}/helma/license.txt" 
         tofile="${build.work}/licenses/helma.txt"/>
      <move file="${build.work}/apps/${project}/license.txt" 
         tofile="${build.work}/licenses/antville.txt"/>

      <delete dir="${build.work}/helma"/>

      <antcall target="package-zip">
         <param name="filename" value="${antclick.name}"/>
         <param name="path" value="${build.work}"/>
      </antcall>
      <antcall target="package-tgz">
         <param name="filename" value="${antclick.name}"/>
         <param name="path" value="${build.work}"/>
      </antcall>
      <antcall target="cleanup"/>
   </target>


   <!-- =================================================================== -->
   <!-- export the antville module from CVS                                 -->
   <!-- =================================================================== -->
   <target name="export" depends="init" unless="noexport">
      <mkdir dir="${build.work}/apps"/>
      <cvs cvsRoot="${cvs.antville.root}" 
         command="export" 
         tag="${cvs.antville.tag}" 
         package="${project}" 
         dest="${build.work}/apps"/>
      <delete dir="${build.work}/apps/antville/build/extra"/>
      <delete dir="${build.work}/apps/antville/build/lib"/>
   </target>


   <!-- =================================================================== -->
   <!-- copy packages to download server                                    -->
   <!-- =================================================================== -->
   <target name="transfer" depends="init">
   <input message="User: " addproperty="scp.user"/>
   <input message="Password: " addproperty="scp.pass"/>    
   <scp trust="yes" todir="${scp.user}:${scp.pass}@${scp.server}:${scp.path}">
      <fileset dir="${build.dist}" includes="${project}-${version}.*"/>
   </scp>      
   <scp trust="yes" todir="${scp.user}:${scp.pass}@${scp.server}:${scp.path}/antclick">
      <fileset dir="${build.dist}" includes="antclick-${version}.*"/>
   </scp>      
   </target>


   <!-- =================================================================== -->
   <!-- Packages the work directory with TAR-GZIP                           -->
   <!-- needs parameter ${filename} for final dist-file                     -->
   <!-- =================================================================== -->
   <target name="package-tgz" depends="init">
      <mkdir dir="${build.dist}" />
      <fixcrlf srcdir="${path}" eol="lf" eof="remove" 
         includes="**/*.txt, **/*.properties, **/*.hac, **/*.js, **/*.skin, **/.xml, **/.sh" />
      <tar tarfile="${build.dist}/${filename}.tar" basedir="${path}" excludes="**">
         <tarfileset prefix="${filename}" dir="${path}" mode="755">
            <include name="**/*.sh"/>
         </tarfileset>
         <tarfileset prefix="${filename}" dir="${path}">
            <include name="**"/>
            <exclude name="**/*.sh"/>
         </tarfileset>
      </tar>
      <gzip zipfile="${build.dist}/${filename}.tgz" src="${build.dist}/${filename}.tar"/>
      <delete file="${build.dist}/${filename}.tar"/>
   </target>


   <!-- =================================================================== -->
   <!-- Packages the work directory with ZIP                                -->
   <!-- needs parameter ${filename} for final dist-file                     -->
   <!-- =================================================================== -->
   <target name="package-zip" depends="init">
      <mkdir dir="${build.dist}" />
      <fixcrlf srcdir="${path}" eol="crlf" 
         includes="**/*.txt, **/*.properties, **/*.hac, **/*.js, **/*.skin, **/*.xml, **/.bat" />
      <zip zipfile="${build.dist}/${filename}.zip">
         <zipfileset dir="${path}" prefix="${filename}" includes="**" />
      </zip>
   </target>


   <!-- =================================================================== -->
   <!-- clean up the mess                                                   -->
   <!-- =================================================================== -->
   <target name="cleanup" depends="init" unless="nocleanup">
      <delete dir="${build.work}"/>
   </target>

</project>
