<!--
tagnetic.org: Tools for tag parsing and rich web experiences.
Copyright (C) 2004-2005 tagnetic.org

This file is part of Tagneto, a developer tool for making rich web experiences.

Tagneto is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

Tagneto is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser Public License for more details.

You should have received a copy of the GNU Lesser Public License
along with Tagneto; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Also available at: http://www.gnu.org/licenses/lgpl.html
-->
<project name="Tagneto" default="dist" basedir=".">
	<description>
	    Build file for building the Tagneto.
	</description>
 
  <import file="../tagneticcore/build.xml" />
  
	<!-- set global properties for this build -->
	<property name="tagneto.basedir" location="${ant.file.Tagneto}/.."/>
	<property name="tagneto.src" location="${tagneto.basedir}/src"/>
	<property name="tagneto.src.java" location="${tagneto.src}/java"/>
  <property name="tagneto.src.js" location="${tagneto.src}/js"/>
	<property name="tagneto.src.test" location="${tagneto.src}/test"/>
	<property name="tagneto.build" location="${tagneto.basedir}/build"/>
  <property name="tagneto.deliverables"  location="${tagneto.basedir}/../deliverables"/>

	<target name="init">
    <antcall target="TagneticCore.init" inheritall="true" inheritrefs="true"/>
		<!-- Create the time stamp -->
		<tstamp/>
		<!-- Create the build directory structure used by compile -->
		<mkdir dir="${tagneto.build}"/>
	</target>
	
	<target name="compile" depends="init" description="compile the source " >
    <antcall target="TagneticCore.compile" inheritall="true" inheritrefs="true"/>

    <!-- Compile the java code from ${src} into ${build} -->
		<javac srcdir="${tagneto.src.java}" destdir="${tagneto.build}" debug="true">
      <classpath>
        <pathelement path="${tcore.classpath}"/> 
        <pathelement location="${tcore.build}"/> 
      </classpath>   
		</javac>
	</target>
	
	<target name="dist" description="generate the distribution" >
	
    <input
        message="Please enter build number:"
        addproperty="tagnetic.buildnumber"
      />

    <!-- Package up the source code for distribution -->
    <antcall target="package_source" inheritall="true" inheritrefs="true"/>     
   
    <!-- Copy the README.txt file -->  
    <copy todir="${tcore.dist}">
      <fileset dir="${tagneto.basedir}">
        <include name="README.txt"/>
      </fileset>
    </copy>

    <!-- Copy the source into the website area, so we can use it to refer to examples.
         Don't include the lib files though, since that will bloat the download. -->
    <copy todir="../website/dist/how/srcsample/tagneticcore">
      <fileset dir="../tagneticcore" defaultexcludes="yes">
        <include name="src/xsd/**"/>
      </fileset>
    </copy>
    <copy todir="../website/dist/how/srcsample/tagneto">
      <fileset dir="../tagneto" defaultexcludes="yes">
        <include name="build.xml"/>
        <include name="src/config/**"/>
        <include name="src/js/**"/>
        <include name="src/test/**"/>
      </fileset>  
    </copy>
    <copy todir="../website/dist/how/srcsample/website">
      <fileset dir="../website" defaultexcludes="yes">
        <include name="WebsiteConfig.xml"/>
        <include name="src/**"/>
      </fileset>
    </copy>

    <!-- Compile the codd and make the base distribution --> 
    <antcall target="compile" inheritall="true" inheritrefs="true"/>
	  <antcall target="dist_jars" inheritall="true" inheritrefs="true"/>
	  
		<jar jarfile="${tcore.dist.lib}/tagneto-${tagnetic.buildnumber}.jar" basedir="${tagneto.build}"/>
	 
    <antcall target="dist_other" inheritall="true" inheritrefs="true"/>
	  
    <!-- Copy over batch files/shell scripts -->  
    <copy todir="${tcore.dist}/bin">
      <fileset dir="${tagneto.basedir}/resource/bin"/>
    </copy>

    <!-- Make the shell scripts executable -->
    <chmod file="${tcore.dist}/bin/tcore" perm="ugo+rx"/>
    <chmod file="${tcore.dist}/bin/tagneto" perm="ugo+rx"/>
    
    <mkdir dir="${tcore.dist}/config"/>
    <copy todir="${tcore.dist}/config">
      <fileset dir="${tagneto.src}/config">
        <include name="**/*.xml"/>
      </fileset>
    </copy>
    
    <antcall target="tagdoc" inheritall="true" inheritrefs="true"/>
    <antcall target="schemadoc" inheritall="true" inheritrefs="true"/>
    <antcall target="websitedoc" inheritall="true" inheritrefs="true"/>
        
    <!-- Copy the XSD file to the website dist folder -->
    <copy todir="../website/dist/how/reference/tagneticconfig">
      <fileset dir="${tcore.src.xsd}">
        <include name="TagneticConfig.xsd"/>
      </fileset>
    </copy>

    <!-- Copy the JS files to the distribution -->
    <mkdir dir="${tcore.dist}/js"/>
    <copy todir="${tcore.dist}/js">
      <fileset dir="${tagneto.src.js}">
        <include name="*.js"/>
        <include name="*.xml"/>
      </fileset>
    </copy>
  
    <!-- Copy the JS files to the website dist folder -->
    <copy todir="../website/dist/how/reference/js">
      <fileset dir="${tagneto.src.js}">
        <include name="*.js"/>
        <include name="*.xml"/>
      </fileset>
    </copy>
    
    <move todir="../website/dist/how/reference/js" includeemptydirs="false">
      <fileset dir="../website/dist/how/reference/js">
        <exclude name="**/*.txt"/>
      </fileset>
      <mapper type="glob" from="*.js" to="*.js.txt"/>
    </move>
    
    <!-- Generate Javadoc -->   
    <javadoc destdir="../website/dist/how/reference/javadoc" author="true" version="true" use="true" windowtitle="Tagneto Javadoc">
      <fileset dir="src/java" defaultexcludes="yes">
        <include name="org/**"/>
      </fileset>
      <fileset dir="../tagneticcore/src/java" defaultexcludes="yes">
        <exclude name="**/*.ser"/>
        <exclude name="**/*.properties"/>
        <include name="org/**"/>
      </fileset>
      <doctitle><![CDATA[<h1>Tagneto Javadoc</h1>]]></doctitle>
      <bottom><![CDATA[<i>Copyright &#169; 2005 tagnetic.org. All Rights Reserved.</i>]]></bottom>
     </javadoc>
 
    <!-- Copy the webapps stuff to the server dist area -->
    <mkdir dir="${tcore.dist}/server"/>
    <copy todir="${tcore.dist}/server">
      <fileset dir="../webapps/data/dist">
      </fileset>
    </copy>
    
    <!-- Package up the build. --> 
    <antcall target="package_deliverable" inheritall="true" inheritrefs="true"/>
   
   <!-- Package up the website -->
    <tar tarfile="../deliverables/website.tar" basedir="../website/dist"/>
    <gzip zipfile="../deliverables/website.tar.gz" src="../deliverables/website.tar"/>
	</target>
	
  
  <target name="package_source" description="Packages up the source files into distributable binaries.">
    <property name="tagneto.srcpackagedir"  location="${tagneto.deliverables}/src/tagneto-${tagnetic.buildnumber}-src"/> 
    <property name="tagneto.deliver.src.basename"  value="${tagneto.deliverables}/tagneto-${tagnetic.buildnumber}-src"/> 
    <mkdir dir="${tagneto.srcpackagedir}"/>
  
    <copy todir="${tagneto.srcpackagedir}">
      <fileset dir="..">
        <exclude name="deliverables/**"/>
      </fileset>
    </copy>
    
    <zip destfile="${tagneto.deliver.src.basename}.zip">
      <fileset dir="${tagneto.srcpackagedir}/.."/>
    </zip>
   
    <tar tarfile="${tagneto.deliver.src.basename}.tar" basedir="${tagneto.srcpackagedir}/..">
      <tarfileset dir="${tagneto.srcpackagedir}/.." mode="755">
        <include name="${tagneto.srcpackagedir}/bin/tagneticcore"/>
        <include name="${tagneto.srcpackagedir}/bin/tagneto"/>
      </tarfileset>
      <tarfileset dir="${tagneto.srcpackagedir}/..">
        <include name="${tagneto.srcpackagedir}/**"/>
        <exclude name="${tagneto.srcpackagedir}/bin/tagneticcore"/>
        <exclude name="${tagneto.srcpackagedir}/bin/tagneto"/>
      </tarfileset>
    </tar>
    
    <gzip zipfile="${tagneto.deliver.src.basename}.tar.gz" src="${tagneto.deliver.src.basename}.tar"/>
    
    <delete dir="${tagneto.srcpackagedir}"/> 
    <delete file="${tagneto.deliver.src.basename}.tar"/> 
  </target>
  
  <target name="package_deliverable" depends="init" description="package up the distribution for delivery">
    <mkdir dir="${tagneto.deliverables}"/>

    <property name="tagneto.packagedir"  location="${tagneto.deliverables}/package/tagneto-${tagnetic.buildnumber}"/> 
    <property name="tagneto.deliver.basename"  value="${tagneto.deliverables}/tagneto-${tagnetic.buildnumber}"/> 
    <mkdir dir="${tagneto.packagedir}"/>

    <copy todir="${tagneto.packagedir}">
      <fileset dir="${tcore.dist}"/>
    </copy>

    <copy todir="${tagneto.packagedir}/docs">
      <fileset dir="../website/dist"/>
    </copy>

    <zip destfile="${tagneto.deliver.basename}.zip">
      <fileset dir="${tagneto.packagedir}/.."/>
    </zip>
   
    <tar tarfile="${tagneto.deliver.basename}.tar" basedir="${tagneto.packagedir}/.."/>
    <gzip zipfile="${tagneto.deliver.basename}.tar.gz" src="${tagneto.deliver.basename}.tar"/>
    
    <delete dir="${tagneto.packagedir}"/> 
    <delete file="${tagneto.deliver.basename}.tar"/> 
  </target> 

  <target name="clean" description="clean up" >
    <delete dir="${tagneto.build}"/>
    <delete dir="../website/dist"/>
    <delete dir="../website/disttemp"/>
    <delete dir="../website/build"/>
    <delete dir="${tagneto.deliverables}"/>
   <antcall target="TagneticCore.clean" inheritall="true" inheritrefs="true"/>
  </target>
 
  <target name="tagdoc" description="Generates documentation for the tags.">
    <path id="tagneto.doc.classpath">
      <pathelement path="${classpath}"/>
      <fileset dir="${tcore.dist.lib}">
        <include name="**/*.jar"/>
      </fileset>
    </path>
    <taskdef name="tctransform" classname="org.tagnetic.core.ant.TagneticCoreTask">
      <classpath refid="tagneto.doc.classpath"/>
    </taskdef>
    <tctransform>
      <fileset dir="./src/config/tagdoc">
        <filename name="TagDocConfig.xml"/>
      </fileset>
      <fileset dir="${tcore.dist.config}">
        <filename name="Master.xml"/>
      </fileset>
    </tctransform>
  </target>
  
  <target name="schemadoc" description="Generates documentation for the XML Schema.">
    <path id="tagneto.doc.classpath">
      <pathelement path="${classpath}"/>
      <fileset dir="${tcore.dist.lib}">
        <include name="**/*.jar"/>
      </fileset>
    </path>
    <taskdef name="tctransform" classname="org.tagnetic.core.ant.TagneticCoreTask">
      <classpath refid="tagneto.doc.classpath"/>
    </taskdef>
    <tctransform>
      <fileset dir="../tagneticcore/src/xsd/tagdoc">
        <filename name="SchemaConfig.xml"/>
      </fileset>
      <fileset dir="${tcore.dist.config}">
        <filename name="Master.xml"/>
      </fileset>
    </tctransform>
  </target>
  
  <target name="websitedoc" description="Generates web site documentation.">
    <path id="tagneto.doc.classpath">
      <pathelement path="${classpath}"/>
      <fileset dir="${tcore.dist.lib}">
        <include name="**/*.jar"/>
      </fileset>
    </path>
    <taskdef name="tctransform" classname="org.tagnetic.core.ant.TagneticCoreTask">
      <classpath refid="tagneto.doc.classpath"/>
    </taskdef>
    <tctransform>
      <fileset dir="../website/">
        <filename name="WebsiteConfig.xml"/>
      </fileset>
      <fileset dir="${tcore.dist.config}">
        <filename name="Master.xml"/>
      </fileset>
    </tctransform>
  </target>
</project>