<?xml version="1.0"?>

<!-- =============================================================== -->
<!-- Ant own build file                                              -->
<!-- =============================================================== -->

<project name="iReport" default="compile" basedir=".">
  <description>Builds, tests, and runs the project iReport.</description>

  <property name="build.compiler" value="modern"/>
  <property name="build.sysclasspath" value="ignore"/>

  <property name="name" value="iReport"/>
  <property name="version" value="0.5.1"/>

  <property name="src" value="${basedir}/src"/>
  <property name="lib" value="${basedir}/lib"/>
  <property name="target" value="${basedir}/target" />
  <property name="classes" value="${basedir}/classes"/>
  <property name="javadocs" value="${target}/javadocs"/>
  <property name="dist" value="${target}/dist"/>

  <property name="fonts" value="${basedir}/fonts"/>

  <property name="packages" value="org.*, it.*"/>

  <!-- ============================================================= -->
  <!-- Classpath with libraries needed to compile this application   -->
  <!-- ============================================================= -->
  <path id="compile.classpath">
    <fileset dir="${lib}">
      <include name="**/*.jar"/>
      <include name="**/*.zip"/>
    </fileset>
  </path>

  <!-- ============================================================= -->
  <!-- Prepares the project                                          -->
  <!-- ============================================================= -->
  <target name="prepare">
    <defaultexcludes echo="false" add="**/*.nbattrs"/>
  
    <mkdir dir="${classes}"/>
    <mkdir dir="${lib}"/>
    <mkdir dir="${dist}"/>

    <!-- Copy all images to the classes directory -->
    <copy todir="${classes}">
      <fileset dir="${src}">
        <include name="**/*.jpg"/>
        <include name="**/*.gif"/>
        <include name="**/*.dtd"/>
        <include name="**/*.jav"/>
        <include name="**/*.png"/>
        <include name="it/**/*.jrxml"/>
        <include name="it/**/*.jasper"/>
      </fileset>
    </copy>

  </target>

  <!-- ============================================================= -->
  <!-- Compiles the source code                                      -->
  <!-- ============================================================= -->
  <target name="compile" depends="prepare">

    <javac srcdir="${src}"
           destdir="${classes}"
           debug="on"
	   excludes="**/bak/**"
           optimize="on">
      <classpath refid="compile.classpath"/>
    </javac>

    <!-- copy over the language and other properties files. -->      
    <copy todir="${classes}">
      <fileset dir="${src}">
        <include name="**/*.properties"/>
      </fileset>
    </copy>
    
    
  </target>

  <!-- ============================================================= -->
  <!-- Clean up all files that are generated.                        -->
  <!-- ============================================================= -->
  <target name="clean">
    <delete quiet="true" dir="${classes}"/>
    <delete dir="${dist}" />
    <delete file="${target}/${name}-${version}.jar"/>
    <delete file="${target}/${name}-utils-${version}.jar"/>
  </target>

  <!-- ============================================================= -->
  <!-- Clean and then compile the project                            -->
  <!-- ============================================================= -->
  <target name="rebuild">
    <antcall target="clean"/>
    <antcall target="compile"/>
  </target>

  <!-- ============================================================= -->
  <!-- Create the jar file                                           -->
  <!-- ============================================================= -->
  <target name="jar" depends="compile">
    <jar jarfile="${target}/${name}-${version}.jar">
      <fileset dir="${classes}"/>
    </jar>
    <jar jarfile="${target}/${name}-utils-${version}.jar">
      <fileset dir="${classes}">
        <include name="it/businesslogic/ireport/util/Misc.class"/>
        <include name="it/businesslogic/ireport/IReportScriptlet.class"/>
        <include name="it/businesslogic/ireport/util/ReportUtils.class"/>
        <include name="it/businesslogic/ireport/chart/ChartFactory.class"/>
        <include name="it/businesslogic/ireport/chart/DefaultChartFactory.class"/>
        <include name="it/businesslogic/ireport/barcode/BcImage.class"/>
      </fileset>
      <fileset dir=".">
        <include name="utils_license.txt"/>
      </fileset>
    </jar>
  </target>

  <!-- ============================================================= -->
  <!-- Create the dist_bin_zip                                               -->
  <!-- ============================================================= -->
  <target name="dist_bin_zip" depends="jar">
    <!-- Full includes a bunch of JDBC drivers so, the user has nothing todo -->
    <!-- It just works out of the box                                        -->
    <zip destfile="${dist}/iReport-${version}.zip">
      <zipfileset dir="lib" includes="*.jar" excludes="**/no_ireport_*" prefix="iReport-${version}/lib"/>
      <zipfileset dir="lib" includes="*.txt" prefix="iReport-${version}/lib"/>
      <!--<zipfileset dir="db_drivers" prefix="iReport_${version}/lib"/>-->
      <zipfileset dir="${target}" includes="${name}-${version}.jar" fullpath="iReport-${version}/lib/${name}.jar"/>
      <!--<zipfileset dir="etc" prefix="iReport-${version}/"/>-->
      <zipfileset dir="docs" prefix="iReport-${version}/docs"/>
      <zipfileset dir="fonts" prefix="iReport-${version}/fonts"/>
      <zipfileset dir="plugins" prefix="iReport-${version}/plugins"/>
      <zipfileset dir="templates" prefix="iReport-${version}/templates"/>
      <zipfileset dir="bin" prefix="iReport-${version}/bin"/>
      <zipfileset dir="." includes="Changelog.txt" fullpath="iReport-${version}/Changelog.txt"/>
      <zipfileset dir="." includes="iReport.bat" fullpath="iReport-${version}/iReport.bat"/>
      <zipfileset dir="." includes="iReport.sh" fullpath="iReport-${version}/iReport.sh"/>
      <zipfileset dir="." includes="license.txt" fullpath="iReport-${version}/license.txt"/>
      <zipfileset dir="." includes="relnotes${version}.html" fullpath="iReport-${version}/relnotes${version}.html"/>
    </zip>  
  </target>
      
  <!-- ============================================================= -->
  <!-- Create the dist_src_zip                                               -->
  <!-- ============================================================= -->
  <target name="dist_src_zip">
    <!-- Full includes a bunch of JDBC drivers so, the user has nothing todo -->
    <!-- It just works out of the box                                        -->
    <zip destfile="${dist}/iReport-${version}-src.zip">
      <zipfileset dir="src" excludes="**/*.class" prefix="iReport-${version}-src/src"/>      
      <zipfileset dir="lib" includes="*.jar" excludes="**/no_ireport*.jar" prefix="iReport-${version}-src/lib"/>
      <zipfileset dir="lib" includes="*.txt" prefix="iReport-${version}-src/lib"/>
      <!--<zipfileset dir="db_drivers" prefix="iReport_${version}/lib"/>-->
      <!--<zipfileset dir="${target}" includes="${name}.jar" fullpath="iReport-${version}/lib/${name}.jar"/>-->
      <!--<zipfileset dir="etc" prefix="iReport-${version}/"/>-->
      <zipfileset dir="plugins" prefix="iReport-${version}-src/plugins"/>
      <zipfileset dir="docs" prefix="iReport-${version}-src/docs"/>
      <zipfileset dir="fonts" prefix="iReport-${version}-src/fonts"/>
      <zipfileset dir="templates" prefix="iReport-${version}-src/templates"/>
      <zipfileset dir="bin" prefix="iReport-${version}-src/bin"/>
      <zipfileset dir="." includes="iReport.bat" fullpath="iReport-${version}-src/iReport.bat"/>
      <zipfileset dir="." includes="iReport.sh" fullpath="iReport-${version}-src/iReport.sh"/>
      <zipfileset dir="." includes="Changelog.txt" fullpath="iReport-${version}-src/Changelog.txt"/>
      <zipfileset dir="." includes="build.xml" fullpath="iReport-${version}-src/build.xml"/>      
      <zipfileset dir="." includes="license.txt" fullpath="iReport-${version}-src/license.txt"/>
      <zipfileset dir="." includes="relnotes${version}.html" fullpath="iReport-${version}-src/relnotes${version}.html"/>
      <zipfileset dir="nbproject" includes="build-impl.xml" prefix="iReport-${version}-src/nbproject"/>
    </zip>  
  </target>

  <!-- ============================================================= -->
  <!-- Create the dist_bin_zip                                               -->
  <!-- ============================================================= -->
  <target name="dist_bin_tar" depends="jar">
    <!-- Full includes a bunch of JDBC drivers so, the user has nothing todo -->
    <!-- It just works out of the box                                        -->
    <tar destfile="${dist}/iReport-${version}.tar">
      <tarfileset dir="lib" includes="*.jar" excludes="**/no_ireport_*" prefix="iReport-${version}/lib"/>
      <tarfileset dir="lib" includes="*.txt" prefix="iReport-${version}/lib"/>
      <!--<zipfileset dir="db_drivers" prefix="iReport_${version}/lib"/>-->
      <tarfileset dir="${target}" includes="${name}-${version}.jar" fullpath="iReport-${version}/lib/${name}.jar"/>
      <!--<zipfileset dir="etc" prefix="iReport-${version}/"/>-->
      <tarfileset dir="docs" prefix="iReport-${version}/docs"/>
      <tarfileset dir="fonts" prefix="iReport-${version}/fonts"/>
      <tarfileset dir="plugins" prefix="iReport-${version}/plugins"/>
      <tarfileset dir="templates" prefix="iReport-${version}/templates"/>
      <tarfileset dir="bin" excludes="startup.sh" prefix="iReport-${version}/bin"/>
      <tarfileset dir="bin"  prefix="iReport-${version}/bin/" mode="755" >
            <include name="startup.sh"/>
      </tarfileset>      
      <tarfileset dir="." includes="Changelog.txt" fullpath="iReport-${version}/Changelog.txt"/>
      <tarfileset dir="." includes="relnotes${version}.html" fullpath="iReport-${version}/relnotes${version}.html"/>
      <tarfileset dir="." includes="iReport.bat" fullpath="iReport-${version}/iReport.bat"/>
      <tarfileset dir="."  prefix="iReport-${version}/" mode="755" >
            <include name="iReport.sh"/>
      </tarfileset>            
      <tarfileset dir="." includes="license.txt" fullpath="iReport-${version}/license.txt"/>
    </tar>
    <gzip src="${dist}/iReport-${version}.tar" destfile="${dist}/iReport-${version}.tar.gz"/>
    <delete file="${dist}/iReport-${version}.tar"/>      
  </target>
  
  <!-- ============================================================= -->
  <!-- Create the dist                                               -->
  <!-- ============================================================= -->
  <target name="dist" depends="dist_bin_zip, dist_bin_tar, dist_src_zip">
    <!-- Full includes a bunch of JDBC drivers so, the user has nothing todo -->
    <!-- It just works out of the box                                        -->
    
                
  </target>
   
  <!-- ============================================================= -->
  <!-- Execute iReport2                                   	     -->
  <!-- ============================================================= -->
  <target name="iReport" depends="compile">
    <java classname="it.businesslogic.ireport.gui.MainFrame" fork="true">
    <sysproperty key="ireport.home" value="."/> 
		<classpath>
			<pathelement location="./"/>
			<pathelement location="${fonts}"/>
			<pathelement location="${classes}"/>
			<fileset dir="${lib}">
				<include name="**/*.jar"/>
				<include name="**/*.zip"/>
			</fileset>
		</classpath>
     </java>
  </target>
  
  <!-- ============================================================= -->
  <!-- Execute iReport2 from jar                               	     -->
  <!-- ============================================================= -->
  <target name="start_jar" depends="jar">
    <java classname="it.businesslogic.ireport.gui.MainFrame" fork="true">
		<classpath>
			<pathelement location="./"/>
			<pathelement location="${fonts}"/>
			<fileset dir="${lib}">
				<include name="**/*.jar"/>
			</fileset>
                        <fileset dir="${target}">
                                <include name="${name}-${version}.jar"/>
                        </fileset>
		</classpath>
     </java>
  </target>

  <!-- ============================================================= -->
  <!-- Creates the API documentation                                 -->
  <!-- ============================================================= -->
  <target name="javadocs" depends="compile">
    <mkdir dir="${javadocs}"/>
    <javadoc packagenames="${packages}"
             sourcepath="${src}"
             destdir="${javadocs}"
             author="true"
             version="true"
             windowtitle="iReport API"
             doctitle="iReport"
             use="true"
             bottom="Copyright &#169; 2003 by Giulio Toffoli. All Rights Reserved."
    />
  </target>
  
<!--
  <taskdef resource="checkstyletask.properties"  classpath="${lib}/checkstyle-all-4.0-beta2.jar"/>
  <target name="checkstyle">
  <checkstyle config="docs/sun_checks.xml">
  <fileset dir="src2/" includes="**/*.java"/>

  <property key="checkstyle.cache.file" file="target/cachefile"/>
  </checkstyle>
  </target>
-->


  <!-- ============================================================= -->
  <!-- Creates the API documentation                                 -->
  <!-- ============================================================= -->
  <target name="cvs_logs">
    <cvs cvsRoot=":pserver:gt78@cvs.sourceforge.net:/cvsroot/ireport"
       package="ireport2"
       command="log"
  />
  </target>

</project>
