<!--
   Glazed Lists
   Copyright 2003 publicobject.com, O'Dell Engineering Ltd.
-->

<project name="glazedlists" default="jar" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">

    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       BUILD ADMINISTRATION
       Create build directories and set up necessary paths.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

    <property name="java.target.version" value="1.5"/>
    <property name="java.target.version.fileFriendlyName" value="java15"/>

	<!-- Version number for the next planned release -->
    <property name="next.release.version" value="1.9.2"/>
    
	<!-- Maven coordinates -->
	<!-- version number, use suffix '-SNAPSHOT' for development build -->
	<!--
    <property name="version" value="${next.release.version}-SNAPSHOT"/>
    -->
	<property name="version" value="1.9.1"/>
    <property name="artifactId" value="glazedlists_${java.target.version.fileFriendlyName}" />
	<property name="groupId" value="net.java.dev.glazedlists" />

	<!-- filter for maven pom.xml -->
	<filter token="glazedlists.version" value="${version}"/>
	<filter token="glazedlists.artifactId" value="${artifactId}"/>
	
    <!-- defined maven snapshots and staging repository id and url -->
    <property name="maven-snapshots-repository-id" value="jvnet-nexus-snapshots" />
    <property name="maven-snapshots-repository-url" value="https://maven.java.net/content/repositories/snapshots/" />
    <property name="maven-staging-repository-id" value="jvnet-nexus-staging" />
    <property name="maven-staging-repository-url" value="https://maven.java.net/service/local/staging/deploy/maven2/" />

    <property environment="env"/>
    <tstamp prefix="datestamp">
        <format property="dateAndTime" pattern="yyyy-MM-dd H:mm"/>
    </tstamp>

	<!-- Default name for distribution zip file -->
	<property name="dist.file" value="${artifactId}-${version}-dist.zip"/>

	<!-- name for jar file -->
	<property name="jar.file" value="${artifactId}-${version}.jar"/>

	<!-- name for source jar file -->
    <property name="source.jar.file" value="${artifactId}-${version}-sources.jar"/>

	<!-- name for javadoc jar file -->
    <property name="javadoc.jar.file" value="${artifactId}-${version}-javadoc.jar"/>

	<!-- base output directory for build artefacts -->
	<property name="target.dir" value="target"/>

	<!-- output directory for compiled classes -->
	<property name="classes.dir" value="${target.dir}/classes"/>

	<!-- output directory for compiled test classes -->
	<property name="testclasses.dir" value="${target.dir}/test-classes"/>

	<!-- output directory for japex reports -->
	<property name="reports.dir" value="${target.dir}/reports"/>

	<!-- output directory for javadocs -->
	<property name="docs.dir" value="${target.dir}/docs"/>

	<!-- title for javadocs -->
    <property name="doctitle" value="Glazed Lists ${version}"/>

	<!-- output directory for demo jar contents -->
	<property name="issuesbrowserjar.dir" value="${target.dir}/issuesbrowserjar"/>
	<property name="xmlbrowser.dir" value="${target.dir}/xmlbrowserjar"/>
	
	<!-- deploy directory -->
	<property name="deploy.dir" value="${target.dir}/deploy"/>
	
	<patternset id="test.files">
		<include name="**/*.xml"/>
	</patternset>

	<!-- base url for downloads --> 
	<property name="download.tools.url" value="http://java.net/projects/glazedlists/downloads/download/tools"/>
	<property name="download.lib.url" value="http://java.net/projects/glazedlists/downloads/download/lib"/>
	
	<!-- determine the platform swt jar file name and download path from java.net -->
    <property name="swt.jar.path" value="${download.lib.url}/swt/3.7.1"/>

	<condition property="swt.jar.file" value="org.eclipse.swt.win32.win32.x86.jar">
		<and>
			<os family="windows"/>
			<not>
				<contains string="${os.arch}" substring="64"/>
			</not>
		</and>
	</condition>

	<condition property="swt.jar.file" value="org.eclipse.swt.win32.win32.x86_64.jar">
		<and>
			<os family="windows"/>
			<contains string="${os.arch}" substring="64"/>
		</and>
	</condition>

	<condition property="swt.jar.file" value="org.eclipse.swt.cocoa.macosx.jar">
		<and>
			<os family="mac"/>
			<not>
				<contains string="${os.arch}" substring="64"/>
			</not>
		</and>
	</condition>

	<condition property="swt.jar.file" value="org.eclipse.swt.cocoa.macosx.x86_64.jar">
		<and>
			<os family="mac"/>
			<contains string="${os.arch}" substring="64"/>
		</and>
	</condition>

	<condition property="swt.jar.file" value="org.eclipse.swt.gtk.linux.x86.jar">
		<and>
			<os name="Linux"/>
			<not>
				<contains string="${os.arch}" substring="64"/>
			</not>
		</and>
	</condition>

	<condition property="swt.jar.file" value="org.eclipse.swt.gtk.linux.x86_64.jar">
		<and>
			<os name="Linux"/>
			<contains string="${os.arch}" substring="64"/>
		</and>
	</condition>
	
	<!-- use windows files as default if nothing matches -->
	<property name="swt.jar.file" value="org.eclipse.swt.win32.win32.x86.jar"/>
	
	<target name="clean"
		description="Clean up generated files, forcing them to be rebuilt.">
		<!-- Delete target directory with all generated build artifacts -->
		<delete dir="${target.dir}"/>

		<delete>
			<fileset dir="${basedir}" defaultexcludes="no">
                <!-- Delete temporary files from JEdit -->
				<include name="**/*~"/>
			</fileset>
		</delete>
	</target>


	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	   JAVADOC
	   Construct a browsable API.
	 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

	<target name="docs"
		description="Scan the source code to generate the Javadoc API.">
		<!-- document all the source -->
        <mkdir dir="${docs.dir}"/>
		<javadoc
			destdir="${docs.dir}/api" author="true" use="true" windowtitle="Glazed Lists" source="${java.target.version}">
			<packageset dir="source"><exclude name="**/impl/**"/><exclude name="**/migrationkit/**"/></packageset>
			<packageset dir="extensions/calculation/source"><exclude name="**/impl/**"/></packageset>
			<packageset dir="extensions/swt/source"><exclude name="**/impl/**"/><exclude name="**/migrationkit/**"/></packageset>
			<packageset dir="extensions/ktable/source"><exclude name="**/impl/**"/></packageset>
			<packageset dir="extensions/jgoodiesforms/source"><exclude name="**/impl/**"/></packageset>
			<packageset dir="extensions/nachocalendar/source"><exclude name="**/impl/**"/></packageset>
			<packageset dir="extensions/jfreechart/source"><exclude name="**/impl/**"/></packageset>
			<packageset dir="extensions/swinglabs/source"><exclude name="**/impl/**"/></packageset>
			<packageset dir="extensions/hibernate/source"><exclude name="**/impl/**"/></packageset>			
			<packageset dir="extensions/treetable/source"><exclude name="**/impl/**"/></packageset>			
            <classpath><fileset dir="extensions/" includes="**/lib/*.jar"/></classpath>
            <link href="http://download.oracle.com/javase/1.5.0/docs/api/"/>
            <link href="http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/overview-summary.html"/>
            <link href="http://www.jdocs.com/formlayout/1.0.4/api/" packagelistloc="extensions/jgoodiesforms/lib"/>
            <link href="http://nachocalendar.sourceforge.net/doc/"/>
            <link href="http://www.jfree.org/jfreechart/api/javadoc/"/>
            <link href="http://download.java.net/javadesktop/swinglabs/releases/0.8/docs/api/"/>
			<link href="http://docs.jboss.org/hibernate/core/3.6/javadocs/"/>
            <doctitle><![CDATA[<h1>${doctitle}</h1>]]></doctitle>
			<bottom><![CDATA[<a href="http://www.glazedlists.com" target="_top">Glazed Lists</a>, Copyright &#169; 2003 publicobject.com, O'Dell Engineering.<br>Documentation build by ${user.name} at ${datestamp.dateAndTime}]]></bottom>
		</javadoc>
	</target>


	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	   JAR
	   Construct the .jar file for use in a library.
	 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- update property values depending on version (snapshot or release)-->
	<target name="update-version-properties" depends="check-snapshot-version, update-snapshot-properties, update-release-properties">
		<echo message="implementation.version=${implementation.version}"/>
		<echo message="bundle.version=${bundle.version}"/>
	</target>

	<!-- checks if current version is SNAPSHOT -->
	<target name="check-snapshot-version" depends="check-version">
        <condition property="isSnapshot">
            <matches string="${version}" pattern="-SNAPSHOT$"/>
        </condition>
    </target>

	<!-- ensures that version property is set -->
	<target name="check-version" description="Checks version property">
        <fail unless="version" message="To build or deploy a release the property 'version' must be defined."/>
    </target>

	<!-- update property values depending on snapshot version -->
	<target name="update-snapshot-properties" if="isSnapshot">
	    <!-- implementation version for jar file -->
	    <property name="implementation.version" value="${next.release.version}.alpha${datestamp.DSTAMP}"/>	    
	    <!-- OSGI Bundle version for jar file --> 
	    <property name="bundle.version" value="${implementation.version}"/>
	</target>
	
	<!-- update property values depending on release version -->
    <target name="update-release-properties" unless="isSnapshot">
        <!-- implementation version for jar file -->
        <property name="implementation.version" value="${version}"/>        
        <!-- OSGI Bundle version for jar file --> 
        <property name="bundle.version" value="${implementation.version}"/>
    </target>
	
    <target name="jar" depends="compileall,update-version-properties"
        description="Creates glazedlists jar file (which is also a valid OSGi bundle) containing all UI libraries.">

        <mkdir dir="tools"/>
        <!--download the BND library for creating entries in the manifest.mf file which make it a compliant OSGi bundle. See http://www.osgi.org/ -->
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.tools.url}/bnd/bnd.jar"/>
            <arg value="tools/bnd.jar"/>
        </java>

        <!-- prepare the bnd task which generates OSGi bundle JARs -->
        <taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="tools/bnd.jar"/>

        <!-- create a normal jar file -->
        <jar destfile="${target.dir}/${jar.file}" update="true" index="true">
            <fileset dir="${classes.dir}">
                <exclude name="com/publicobject/**"/> <!-- IssuesBrowser -->
            	<exclude name="com"/>
            </fileset>
            <fileset dir=".">
                <include name="resources/**"/>
            </fileset>
        </jar>

        <!-- use the BND tool to generate an OSGi jar from scratch, using the original JAR file as input -->
        <bnd classpath="${target.dir}/${jar.file}" output="${target.dir}/${jar.file}.osgi" exceptions="true" files="glazedlists.bnd"/>

        <!-- delete the original jar file -->
        <delete file="${target.dir}/${jar.file}"/>

        <!-- rename the OSGi Bundle to the orignal jar file's name -->
        <move file="${target.dir}/${jar.file}.osgi" toFile="${target.dir}/${jar.file}"/>
    </target>

    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       SOURCEJAR
       Construct the .jar file with all sources of the library.
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<target name="sourcejar"
        description="Creates glazedlists source jar file containing all sources.">
		
        <mkdir dir="${target.dir}/sources"/>
	    <!--copy source files to temp directory -->
		<copy todir="${target.dir}/sources">
		    <fileset dir="${basedir}">
		        <include name="source/**"/>
		        <include name="extensions/**/source/**"/>
		    </fileset>
		    <regexpmapper from=".*source/(.*)" to="\1" handledirsep="true"/>
		</copy>

        <!-- create a jar file with the resources and copied sources -->
        <jar destfile="${target.dir}/${source.jar.file}">
            <fileset dir="${target.dir}/sources">
            	<include name="**/*.java" />
            </fileset>
            <fileset dir="${basedir}">
                <include name="resources/**"/>
            </fileset>
        </jar>
		<delete dir="${target.dir}/sources"/>
    </target>

    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       JAVADOCJAR
       Construct the .jar file with all javadoc for the library.
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <target name="javadocjar" depends="docs"
        description="Create a .jar file containing the javadoc.">
        <jar destfile="${target.dir}/${javadoc.jar.file}" basedir="${docs.dir}/api"/>
    </target>
	
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	   COMPILE
	 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

	<target name="compile" depends="swing"
		description="Compile the default components of the source.">
	</target>

	<target name="compileall" depends="core,migrationkit,swing,io,calculation,swt,ktable,issuesbrowser,swinglabs,hibernate,icu4j"
		description="Compile all components of the source.">
	</target>

	<target name="core">
        <mkdir dir="${classes.dir}"/>
		<javac destdir="${classes.dir}" srcdir="source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <!-- swing -->
            <exclude name="**/swing/**"/>
            <!-- io -->
            <exclude name="**/ctp/**"/>
            <exclude name="**/io/**"/>
            <exclude name="**/nio/**"/>
            <exclude name="**/pmap/**"/>
            <exclude name="**/rbp/**"/>
		</javac>
	</target>

    <target name="migrationkit" depends="core">
        <javac destdir="${classes.dir}" srcdir="source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <include name="**/migrationkit/**"/>
        </javac>
    </target>

	<target name="swing" depends="core">
		<javac destdir="${classes.dir}" srcdir="source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
			<include name="**/swing/**"/>
			<exclude name="**/migrationkit/**"/>
		</javac>
	</target>

	<target name="io" depends="core">
		<javac destdir="${classes.dir}" srcdir="source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
			<include name="**/ctp/**"/>
			<include name="**/io/**"/>
			<include name="**/nio/**"/>
			<include name="**/pmap/**"/>
			<include name="**/rbp/**"/>
		</javac>
	</target>


    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       EXTENSIONS
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

    <target name="calculation" depends="swing">
        <mkdir dir="extensions/calculation/lib"/>
        <javac destdir="${classes.dir}" srcdir="extensions/calculation/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/calculation/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="swt" depends="core,calculation">
        <mkdir dir="extensions/swt/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${swt.jar.path}/${swt.jar.file}"/>
            <arg value="extensions/swt/lib/${swt.jar.file}"/>
        </java>
        <javac destdir="${classes.dir}" srcdir="extensions/swt/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/swt/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="ktable" depends="core,swt,issuesbrowser">
        <mkdir dir="extensions/ktable/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/ktable/2.1.2/ktable.jar"/>
            <arg value="extensions/ktable/lib/ktable.jar"/>
        </java>
        <javac destdir="${classes.dir}" srcdir="extensions/ktable/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/ktable/lib/" includes="*.jar"/>
                <fileset dir="extensions/swt/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="jgoodiesforms" depends="swing">
        <mkdir dir="extensions/jgoodiesforms/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/forms/1.0.5/forms.jar"/>
            <arg value="extensions/jgoodiesforms/lib/forms.jar"/>
        </java>
        <javac destdir="${classes.dir}" srcdir="extensions/jgoodiesforms/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/jgoodiesforms/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="swinglabs" depends="swing, issuesbrowser">
        <!-- the swinglabs .jar is Java 1.5+ only, so we do not bother to run
             this code through our Java 1.5 to Java 1.4 source code translator -->
        <mkdir dir="extensions/swinglabs/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>        	
            <arg value="${download.lib.url}/swinglabs/1.0.0/swingx.jar"/>
            <arg value="extensions/swinglabs/lib/swingx.jar"/>
        </java>
        <javac destdir="${classes.dir}" srcdir="extensions/swinglabs/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/swinglabs/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="icu4j" depends="swing">
        <mkdir dir="extensions/icu4j/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/icu4j/3.6/icu4j.jar"/>
            <arg value="extensions/icu4j/lib/icu4j.jar"/>
        </java>
        <javac destdir="${classes.dir}" srcdir="extensions/icu4j/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/icu4j/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="nachocalendar" depends="swing">
        <mkdir dir="extensions/nachocalendar/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/nachocalendar/0.23/nachocalendar.jar"/>
            <arg value="extensions/nachocalendar/lib/nachocalendar.jar"/>
        </java>
        <javac destdir="${classes.dir}" srcdir="extensions/nachocalendar/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/nachocalendar/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="treetable" depends="swing">
        <javac destdir="${classes.dir}" srcdir="extensions/treetable/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off"/>
    </target>

    <target name="jfreechart" depends="swing,calculation">
        <mkdir dir="extensions/jfreechart/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/jfreechart/1.0.0/jcommon.jar"/>
            <arg value="extensions/jfreechart/lib/jcommon.jar"/>
        </java>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/jfreechart/1.0.0/jfreechart.jar"/>
            <arg value="extensions/jfreechart/lib/jfreechart.jar"/>
        </java>
        <javac destdir="${classes.dir}" srcdir="extensions/jfreechart/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/jfreechart/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

	<target name="hibernate" depends="core">
        <mkdir dir="extensions/hibernate/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/hibernate/3.6.8.Final/hibernate.jar"/>
            <arg value="extensions/hibernate/lib/hibernate.jar"/>
        </java>		
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/hibernate/3.6.8.Final/hibernate-libs.jar"/>
            <arg value="extensions/hibernate/lib/hibernate-libs.jar"/>
        </java>				
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/hsqldb/2.2.6/hsqldb-jdk5.jar"/>
            <arg value="extensions/hibernate/lib/hsqldb-jdk5.jar"/>
        </java>				
        <javac destdir="${classes.dir}" srcdir="extensions/hibernate/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/hibernate/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="japex" depends="compile">
        <!-- download dependencies for japex -->
        <mkdir dir="extensions/japex/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/japex/1.0.18/activation.jar"/>
            <arg value="extensions/japex/lib/activation.jar"/>
        </java>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/japex/1.0.18/japex-all.jar"/>
            <arg value="extensions/japex/lib/japex-all.jar"/>
        </java>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/japex/1.0.18/mail.jar"/>
            <arg value="extensions/japex/lib/mail.jar"/>
        </java>
        <!-- compile the Japex performance tests -->
        <javac destdir="${classes.dir}" srcdir="extensions/japex/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/japex/lib/" includes="*.jar"/>
            </classpath>
        </javac>
        <!-- execute the Japex performance tests -->
    	<!--
        <property name="config" value="extensions/japex/ListEventAssembler-JapexConfig.xml"/>
        <property name="config" value="extensions/japex/ListEventPublisher-JapexConfig.xml"/>
        <property name="config" value="extensions/japex/SortedList-JapexConfig.xml"/>
        -->
        <property name="config" value="extensions/japex/ThreadProxy-JapexConfig.xml"/>
        <java dir="." fork="true" classname="com.sun.japex.Japex">
            <classpath>
                <fileset dir="extensions/japex/lib/" includes="*.jar"/>
            </classpath>
        	<sysproperty key="japex.reportsDirectory" value="${reports.dir}"/>
            <arg line="${config}/"/>
        </java>
    </target>

    <target name="issuesbrowser" depends="core,swing,swt,jfreechart,jgoodiesforms,nachocalendar,treetable">
        <mkdir dir="extensions/issuesbrowser/lib"/>
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/httpclient/0.3.3/http.jar"/>
            <arg value="extensions/issuesbrowser/lib/http.jar"/>
        </java>
        <javac destdir="${classes.dir}" srcdir="extensions/issuesbrowser/source" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <fileset dir="extensions/swt/lib/" includes="*.jar"/>
                <fileset dir="extensions/jfreechart/lib/" includes="*.jar"/>
                <fileset dir="extensions/jgoodiesforms/lib/" includes="*.jar"/>
                <fileset dir="extensions/nachocalendar/lib/" includes="*.jar"/>
                <fileset dir="extensions/issuesbrowser/lib/" includes="*.jar"/>
            </classpath>
        </javac>
    </target>

    <!-- check if the user already has BCEL in their ANT \lib directory (which is required to execute the "demojar" target -->
    <available classname="org.apache.bcel.Constants" property="bcel.present"/>

    <target name="downloadBCEL" unless="bcel.present">
        <!-- explain the BCEL requirement -->
        <echo>To build the demojar, Glazed Lists requires the Byte Code Engineering Library (BCEL) to be available in the \lib directory of your ANT installation. The Glazed Lists build system will now automatically attempt to download the BCEL into ${ant.home}\lib on your behalf.</echo>

        <!-- wait for the user to read the message before continuing -->
        <input>Press Return to begin the download...</input>

        <!-- download bcel.jar to the ant \lib directory -->
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.lib.url}/bcel/5.2/bcel.jar"/>
            <arg value="${ant.home}/lib/bcel.jar"/>
        </java>

        <!-- recheck if bcel.jar is now in the ANT \lib directory -->
        <available classname="org.apache.bcel.Constants" property="bcel.present"/>

        <!-- check if bcel.jar was downloaded successfully and display the instructions to rerun the ANT command. -->
        <fail message="BCEL has been successfully downloaded. Please re-execute the ANT task and it will now proceed normally.">
            <condition>
                <available file="${ant.home}/lib/bcel.jar"/>
            </condition>
        </fail>

        <!-- otherwise bcel.jar could not be downloaded so fail with instructions on how to resolve the problem manually -->
        <fail message="The BCEL could not be downloaded. You must manually download it from here: http://jakarta.apache.org/site/downloads/downloads_bcel.cgi and place it in your ANT installation here: ${ant.home}\lib"/>
    </target>

    <target name="issuesbrowserjar" depends="clean,issuesbrowser,downloadBCEL"
        description="Create a .jar file with the Issues Browser demo application.">

        <!-- make a temporary folder for assembling the demojar -->
        <mkdir dir="${issuesbrowserjar.dir}"/>

        <!-- copy the classes into the demojar folder -->
        <copy todir="${issuesbrowserjar.dir}">
            <fileset dir="${classes.dir}"/>
        </copy>

        <!-- unjar the third-party classes into the demojar folder -->
        <unjar src="extensions/jfreechart/lib/jcommon.jar" dest="${issuesbrowserjar.dir}"/>
        <unjar src="extensions/jfreechart/lib/jfreechart.jar" dest="${issuesbrowserjar.dir}"/>
        <unjar src="extensions/jgoodiesforms/lib/forms.jar" dest="${issuesbrowserjar.dir}"/>
        <unjar src="extensions/nachocalendar/lib/nachocalendar.jar" dest="${issuesbrowserjar.dir}"/>
        <unjar src="extensions/issuesbrowser/lib/http.jar" dest="${issuesbrowserjar.dir}"/>

        <!-- create a *minimal* set of classes required to execute the swing demo -->
        <classfileset id="issuesBrowserClasses" dir="${issuesbrowserjar.dir}" rootclass="com.publicobject.issuesbrowser.swing.IssuesBrowser"/>

        <!-- create the actual demo jar -->
        <jar destfile="${target.dir}/glazedlists-demo.jar" update="true" index="true">
            <fileset refid="issuesBrowserClasses"/>
            <fileset dir="${issuesbrowserjar.dir}">
                <include name="**/LocalizationBundle*.properties"/>
                <include name="org/jfree/chart/resources/JFreeChartResources.class"/>
                <include name="org/jfree/resources/JCommonResources.class"/>
                <include name="net/sf/nachocalendar/language*.properties"/>
            </fileset>
            <fileset dir=".">
                <include name="resources/**"/>
            </fileset>
            <fileset dir="extensions/issuesbrowser">
                <include name="resources/**"/>
            </fileset>
            <manifest>
                <attribute name="Main-Class" value="com.publicobject.issuesbrowser.swing.IssuesBrowser"/>
            </manifest>
        </jar>
	</target>

    <target name="xmlbrowserjar" depends="clean,issuesbrowser,downloadBCEL"
        description="Create a .jar file with the Xml Browser demo application.">

        <!-- make a temporary folder for assembling the demojar -->
        <mkdir dir="${xmlbrowser.dir}"/>

        <!-- copy the classes into the xmlbrowser folder -->
        <copy todir="${xmlbrowser.dir}">
            <fileset dir="${classes.dir}"/>
        </copy>

        <!-- xmlToEventList a *minimal* set of classes required to execute the swing demo -->
        <classfileset id="xmlBrowserClasses" dir="${xmlbrowser.dir}" rootclass="com.publicobject.xmlbrowser.XmlBrowser"/>

        <!-- xmlToEventList the actual demo jar -->
        <jar destfile="${target.dir}/xmlbrowser.jar" update="true" index="true">
            <fileset refid="xmlBrowserClasses"/>
            <fileset dir=".">
                <include name="resources/**"/>
                <include name="pom.xml"/>
            </fileset>
            <manifest>
                <attribute name="Main-Class" value="com.publicobject.xmlbrowser.XmlBrowser"/>
            </manifest>
        </jar>
	</target>

	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	   REDISTRIBUTING THE SOURCE
	   Package the entire Glazed Lists source tree in a .zip file.
	 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

	<target name="dist" depends="clean"
		description="Create a .zip file of the source for backup or distribution.">
		<mkdir dir="${target.dir}"/>
		<zip destfile="${target.dir}/${dist.file}" basedir=".">
			<exclude name="${target.dir}/**"/>
			<exclude name="tools/**"/>
			<exclude name="extensions/**/lib/**"/>
			<exclude name="www/**"/>
			<exclude name="*.iml"/> <!-- Intellij IDEA Module File -->
			<exclude name="*.ipr"/> <!-- Intellij IDEA Project File -->
			<exclude name="*.iws"/> <!-- Intellij IDEA Workspace File -->
			<exclude name="*.tfpt"/> <!-- Performance Test Data (mozillabugs.tfpt, mp3collection.tfpt) -->
			<exclude name=".project"/> <!-- Eclipse project file -->
			<exclude name=".classpath"/> <!-- Eclipse project classpath -->
			<exclude name=".settings/**"/>	<!-- Eclipse project settings -->
		</zip>
	</target>

    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       TEST
       Compile unit tests and run them using JUnit.
       This task depends on JUnit, available free at http://www.junit.org
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

    <target name="test" depends="compiletests"
            description="Compile unit tests and run them using JUnit.">
           <!-- Execute JUnit tests -->
            <junit printsummary="true" showoutput="false" fork="true"
                    errorProperty="test.failed" failureProperty="test.failed">
                    <assertions>
                    	<enable/>
                    </assertions>
                    <classpath>
                        <pathelement location="${classes.dir}"/>
                        <pathelement location="${testclasses.dir}"/>
                        <fileset dir="extensions" includes="**/*.jar"/>
                        <fileset file="${ant.home}/lib/junit.jar"/>
                    	<pathelement location="extensions/hibernate/etc"/>
                    </classpath>
                    <formatter type="brief" usefile="false"/>
                    <batchtest>
                    	<fileset dir="${testclasses.dir}" includes="**/**Test.class"/>
                    </batchtest>
            </junit>
            <fail message="Tests failed. Check test output." if="test.failed"/>
    </target>

    <target name="compiletests" depends="compileall">
        <!-- Verify that JUnit is available on the classpath -->
		<available classname="junit.framework.TestCase" property="junit.present"/>
		<fail unless="junit.present" message="To run this task, install junit.jar and optional.jar into ${ant.home}/lib/ JUnit is available free at http://www.junit.org"/>
		<mkdir dir="${testclasses.dir}"/>
	    <javac destdir="${testclasses.dir}" srcdir="test" debug="on" source="${java.target.version}" target="${java.target.version}" deprecation="off">
            <classpath>
                <pathelement location="${classes.dir}"/>
                <fileset dir="extensions" includes="**/*.jar"/>
                <fileset file="${ant.home}/lib/junit.jar"/>
            </classpath>
        </javac>

		<!-- Copy over the mapping files -->
		<copy todir="${testclasses.dir}">
			<fileset dir="test">
				<patternset refid="test.files"/>
			</fileset>
		</copy>
    </target>
	
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       BUILD
       Build a source distribution, binary jar, source jar and javadoc jar ready for deployment 
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<target name="build" depends="dist,jar,sourcejar,javadocjar,compiletests"
		  description="builds a source distribution, binary jar, source jar and javadoc jar ready for deployment">
		   <echo message="${line.separator}Release build completed. Please upload with: 'ant deploy'"/>
	</target>
	
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       DEPLOY
       Deploy an already built snapshot or release to the corresponding java.net maven repository
       if the version property ends with '-SNAPSHOT' a snapshot is published, otherwise a release is staged 
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <target name="deploy" depends="deploy-snapshot, stage-release" 
    	description="deploys an already built snapshot or release to the corresponding java.net maven repository"/>
    	
	<!-- deploy a snapshot/latest build with binary, source and javadoc jar to the corresponding java.net snapshot maven repository -->
	<!-- project version should have a proper value (ending with '-SNAPSHOT') -->
    <target name="deploy-snapshot" depends="deploy-init, check-deploy-artifacts" if="isSnapshot">
        <echo message="deploying latest build ${version} to Maven SNAPSHOT repository ${maven-snapshots-repository-url}"/>
        <artifact:mvn pom="${deploy.dir}/pom.xml">
            <arg value="org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy-file" />
            <arg value="-Durl=${maven-snapshots-repository-url}" />
            <arg value="-DrepositoryId=${maven-snapshots-repository-id}" />
            <arg value="-DpomFile=pom.xml" />
            <arg value="-Dfile=${jar.file}" />
            <arg value="-Dsources=${source.jar.file}" />
            <arg value="-Djavadoc=${javadoc.jar.file}" />
        </artifact:mvn>
        <echo message="${line.separator}Snapshot deployment completed."/>    	
    </target>

	<!-- deploy a release with a source distribution, binary, source and javadoc jar to the corresponding java.net staging maven repository -->
    <!-- project version should have a proper value (no SNAPSHOT) -->
    <target name="stage-release" depends="deploy-init, check-deploy-artifacts" unless="isSnapshot">
        <echo message="deploying release version to Maven STAGING repository ${maven-staging-repository-url}"/>     
        <!-- sign and deploy the main artifact -->
        <artifact:mvn pom="${deploy.dir}/pom.xml">
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=pom.xml" />
            <arg value="-Dfile=${jar.file}" />
            <arg value="-Pgpg" />
        </artifact:mvn>

        <!-- sign and deploy the sources artifact -->
        <artifact:mvn pom="${deploy.dir}/pom.xml">
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=pom.xml" />
            <arg value="-Dfile=${source.jar.file}" />
            <arg value="-Dclassifier=sources" />
            <arg value="-Pgpg" />
        </artifact:mvn>
        <!-- sign and deploy the javadoc artifact -->
        <artifact:mvn pom="${deploy.dir}/pom.xml">
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=pom.xml" />
            <arg value="-Dfile=${javadoc.jar.file}" />
            <arg value="-Dclassifier=javadoc" />
            <arg value="-Pgpg" />
        </artifact:mvn>
        <!-- sign and deploy the dist artifact -->
        <artifact:mvn pom="${deploy.dir}/pom.xml">
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=pom.xml" />
            <arg value="-Dfile=${dist.file}" />
            <arg value="-Dclassifier=dist" />
        	<arg value="-Dpackaging=zip" />
            <arg value="-Pgpg" />
        </artifact:mvn>
        <echo message="${line.separator}Release staging completed. Please test, close and release the staging repo at 'maven.java.net'"/>
        <echo message="Remember to increase the value for build properties 'next.release.version' and 'version'"/>
    </target>
	
	<!-- initializes deploy directory with the needed artifacts -->
    <target name="deploy-init" depends="download-mavenanttasks, check-snapshot-version">
    	<echo message="Preparing artifacts for deployment..."/>
        <mkdir dir="${deploy.dir}" />
        <copy file="pom.xml" todir="${deploy.dir}" filtering="true" failonerror="true"/>
        <copy file="${target.dir}/${jar.file}" tofile="${deploy.dir}/${jar.file}" failonerror="true"/>
        <copy file="${target.dir}/${source.jar.file}" tofile="${deploy.dir}/${source.jar.file}" failonerror="true"/>
        <copy file="${target.dir}/${javadoc.jar.file}" tofile="${deploy.dir}/${javadoc.jar.file}" failonerror="true"/>
    	<copy file="${target.dir}/${dist.file}" tofile="${deploy.dir}/${dist.file}" failonerror="true"/>
    </target>

	<!-- download Maven ANT tasks for deployment -->
    <target name="download-mavenanttasks">
        <mkdir dir="tools"/>
        <!--download the Maven ANT tasks needed for deploying to maven repositories -->
        <java classname="ca.odell.glazedlists.impl.HttpClient">
            <classpath path="${classes.dir}"/>
            <arg value="${download.tools.url}/mavenanttasks/maven-ant-tasks.jar"/>
            <arg value="tools/maven-ant-tasks.jar"/>
        </java>
        <!-- check if download was successfull -->
        <fail message="Maven ANT tasks could not be downloaded. Please check your settings to ensure internet access.">
            <condition>
                <not>
                    <available file="tools/maven-ant-tasks.jar"/>
                </not>
            </condition>
        </fail>
        <path id="maven-ant-tasks.classpath" path="tools/maven-ant-tasks.jar" />
        <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant"
                   classpathref="maven-ant-tasks.classpath" />
    </target>

    <!-- checks if all needed artifacts are available -->
    <target name="check-deploy-artifacts">
        <fail message="Files for deployment are missing, build a release first with 'ant build'.">
            <condition>
                <or>
                    <not>
                        <available file="${deploy.dir}/${jar.file}" property="jar.file.present"/>
                    </not>
                    <not>
                        <available file="${deploy.dir}/${source.jar.file}" property="sources.jar.file.present"/>
                    </not>
                    <not>
                        <available file="${deploy.dir}/${javadoc.jar.file}" property="javadoc.jar.file.present"/>
                    </not>
                    <not>
                        <available file="${deploy.dir}/${dist.file}" property="dist.jar.file.present"/>
                    </not>
                    <not>
                        <available file="${deploy.dir}/pom.xml" property="pom.file.present"/>
                    </not>
                </or>
            </condition>
        </fail>
    </target>

	<!-- deletes the deploy dir with all contents -->
    <target name="deploy-clean" description="clean up deploy directory">
        <delete dir="${deploy.dir}" />
    </target>
	
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       M4
       Run the m4 preprocessor to generate source code, see
       Unix: http://www.gnu.org/software/m4/
       Windows; http://gnuwin32.sourceforge.net/packages/m4.htm
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <target name="m4">
        <!-- generate the four color tree -->
        <mapper id="bcii_to_fourcolorintermediate" type="glob"
           from="source/ca/odell/glazedlists/impl/adt/barcode2/Bcii*.java"
           to="source/ca/odell/glazedlists/impl/adt/barcode2/FourColor*.java_intermediate"/>
        <apply executable="m4" parallel="false">
            <arg line="--prefix-builtins"/>
            <arg line="-DVAR_COLOUR_COUNT=4"/>
            <arg line="-DVAR_WIDE_NODES=true"/>
            <arg line="-DVAR_TYPE_COUNT=1"/>
            <srcfile/>
            <fileset dir="${basedir}" includes="source/ca/odell/glazedlists/impl/adt/barcode2/Bcii*.java"/>
            <mapper refid="bcii_to_fourcolorintermediate"/>
            <redirector><outputmapper refid="bcii_to_fourcolorintermediate"/></redirector>
        </apply>

        <mapper id="fourcolorintermediate_to_fourcolor" type="glob"
           from="source/ca/odell/glazedlists/impl/adt/barcode2/FourColor*.java_intermediate"
           to="source/ca/odell/glazedlists/impl/adt/barcode2/FourColor*.java"/>
        <apply executable="m4" parallel="false">
            <arg line="--prefix-builtins"/>
            <arg line="-DBciiTree=FourColorTree"/>
            <arg line="-DBciiNode=FourColorNode"/>
            <arg line="-DBciiTreeAsList=FourColorTreeAsList"/>
            <arg line="-DBciiTreeIterator=FourColorTreeIterator"/>
            <arg line="-DCOMMAPLACEHOLDER=,"/>
            <srcfile/>
            <fileset dir="${basedir}" includes="source/ca/odell/glazedlists/impl/adt/barcode2/FourColor*.java_intermediate"/>
            <mapper refid="fourcolorintermediate_to_fourcolor"/>
            <redirector><outputmapper refid="fourcolorintermediate_to_fourcolor"/></redirector>
        </apply>

        <!-- generate the four color two value tree -->
        <mapper id="bcii_to_fourcolortwovalueintermediate" type="glob"
           from="source/ca/odell/glazedlists/impl/adt/barcode2/Bcii*.java"
           to="source/ca/odell/glazedlists/impl/adt/barcode2/FourColorTwoValue*.java_intermediate"/>
        <apply executable="m4" parallel="false">
            <arg line="--prefix-builtins"/>
            <arg line="-DVAR_COLOUR_COUNT=4"/>
            <arg line="-DVAR_WIDE_NODES=true"/>
            <arg line="-DVAR_TYPE_COUNT=2"/>
            <srcfile/>
            <fileset dir="${basedir}" includes="source/ca/odell/glazedlists/impl/adt/barcode2/Bcii*.java"/>
            <mapper refid="bcii_to_fourcolortwovalueintermediate"/>
            <redirector><outputmapper refid="bcii_to_fourcolortwovalueintermediate"/></redirector>
        </apply>

        <mapper id="fourcolortwovalueintermediate_to_fourcolortwovalue" type="glob"
           from="source/ca/odell/glazedlists/impl/adt/barcode2/FourColorTwoValue*.java_intermediate"
           to="source/ca/odell/glazedlists/impl/adt/barcode2/FourColorTwoValue*.java"/>
        <apply executable="m4" parallel="false">
            <arg line="--prefix-builtins"/>
            <arg line="-DBciiTree=FourColorTwoValueTree"/>
            <arg line="-DBciiNode=FourColorTwoValueNode"/>
            <arg line="-DBciiTreeAsList=FourColorTwoValueTreeAsList"/>
            <arg line="-DBciiTreeIterator=FourColorTwoValueTreeIterator"/>
            <arg line="-DCOMMAPLACEHOLDER=,"/>
            <srcfile/>
            <fileset dir="${basedir}" includes="source/ca/odell/glazedlists/impl/adt/barcode2/FourColor*.java_intermediate"/>
            <mapper refid="fourcolortwovalueintermediate_to_fourcolortwovalue"/>
            <redirector><outputmapper refid="fourcolortwovalueintermediate_to_fourcolortwovalue"/></redirector>
        </apply>

        <!-- generate the simple tree -->
        <mapper id="bcii_to_simpleintermediate" type="glob"
           from="source/ca/odell/glazedlists/impl/adt/barcode2/Bcii*.java"
           to="source/ca/odell/glazedlists/impl/adt/barcode2/Simple*.java_intermediate"/>
        <apply executable="m4" parallel="false">
            <arg line="--prefix-builtins"/>
            <arg line="-DVAR_COLOUR_COUNT=1"/>
            <arg line="-DVAR_WIDE_NODES=false"/>
            <arg line="-DVAR_TYPE_COUNT=1"/>
            <srcfile/>
            <fileset dir="${basedir}" includes="source/ca/odell/glazedlists/impl/adt/barcode2/Bcii*.java"/>
            <mapper refid="bcii_to_simpleintermediate"/>
            <redirector><outputmapper refid="bcii_to_simpleintermediate"/></redirector>
        </apply>

        <mapper id="simpleintermediate_to_simple" type="glob"
           from="source/ca/odell/glazedlists/impl/adt/barcode2/Simple*.java_intermediate"
           to="source/ca/odell/glazedlists/impl/adt/barcode2/Simple*.java"/>
        <apply executable="m4" parallel="false">
            <arg line="--prefix-builtins"/>
            <arg line="-DBciiTree=SimpleTree"/>
            <arg line="-DBciiNode=SimpleNode"/>
            <arg line="-DBciiTreeAsList=SimpleTreeAsList"/>
            <arg line="-DBciiTreeIterator=SimpleTreeIterator"/>
            <arg line="-DCOMMAPLACEHOLDER=,"/>
            <srcfile/>
            <fileset dir="${basedir}" includes="source/ca/odell/glazedlists/impl/adt/barcode2/Simple*.java_intermediate"/>
            <mapper refid="simpleintermediate_to_simple"/>
            <redirector><outputmapper refid="simpleintermediate_to_simple"/></redirector>
        </apply>

        <!-- Delete intermediate files -->
        <delete>
            <fileset dir="${basedir}" defaultexcludes="no">
                <include name="source/ca/odell/glazedlists/impl/adt/barcode2/*.java_intermediate"/>
            </fileset>
        </delete>
    </target>

</project>