<?xml version="1.0" encoding="utf-8"?>
<project name="main" default="usage" basedir=".">
<!--
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# $Id$
# 
# Copyright 2006 University of Dundee. All rights reserved.
# Use is subject to license terms supplied in LICENSE.txt
# 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Written by:  Josh Moore <josh.moore@gmx.de>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  DOCUMENTATION:
  =================================================

  To use this script you need only have downloaded
  the source code (either from subversion or as
  distribution). The build system can be used by 
  calling:

    java omero <arguments>

  from within the OMERO_HOME directory (this is 
  what you checked out of subversion and where this
  file is located).

-->

	<import file="components/antlib/resources/global.xml"/>

	<target name="help" depends="usage"/>
	<target name="usage"
		description="Usage information">
		<concat>
			<filelist dir="${import.dir}" files="usage-ant.txt"/>
		</concat>
	</target>

	<!-- Multiproject:
	  The idea for these targets is taken from maven2 and is
	  supported by the antlib/resources/lifecycle.xml ant script.
	  Unlike most other targets which can be called from anywhere,
	  these targets can only be called from the top-level because
	  they mask the lifecycle.xml target definitions.
	 -->
	<target name="multiproject" depends="compatibility,init"/>

	<target name="multi" depends="multiproject"
		description="Convenience target. Iterates over all components calling the $${defaultTarget} method (default=${defaultTarget}">
		<iterate target="${defaultTarget}"/>
	</target>

	<target name="prepare" depends="multiproject"
		description="Lifecycle target: calls 'prepare' on all components">
		<iterate target="prepare"/>
	</target>

	<target name="generate" depends="multiproject"
		description="Lifecycle target: calls 'generate' on all components">
		<iterate target="generate"/>
	</target>

	<target name="compile" depends="multiproject"
		description="Lifecycle target: calls 'compile' on all components">
		<iterate target="compile"/>
	</target>

	<target name="test" depends="multiproject"
		description="Lifecycle target: calls 'test' on all components">
		<iterate target="test"/>
	</target>

	<target name="package" depends="multiproject"
		description="Lifecycle target: calls 'package' on all components">
		<iterate target="package"/>
	</target>

	<target name="install" depends="multiproject"
		description="Lifecycle target: calls 'install' on all components">
		<iterate target="install"/>
	</target>

	<target name="integration" depends="multiproject"
		description="Lifecycle target: calls 'integration' on all components">
		<iterate target="integration"/>
	</target>

	<target name="dist">
		<mkdir dir="${dist.dir}"/>
		<echo>javadoc needs to copy images</echo>

		<!-- 
			etc/
			========================================================
			Copies example property files to the ${dist.dir}
			for use by the user to configure the install.
		-->
		<copy todir="${dist.dir}/etc" overwrite="true">
			<fileset dir="${omero.home}/etc">
				<exclude name="local.properties"/>
			</fileset>
		</copy>
		<concat destfile="${dist.dir}/etc/omero.properties" append="true">
 			<filelist dir="${app.comp}" files="product.properties"/>
 		</concat>

		<!-- 
			Copies ...
		-->
		<copy todir="${dist.dir}">
			<fileset dir="${omero.home}">
				<include name="omero.class"/>
				<include name="components/antlib/**"/>
				<include name="lib/tools/**"/>
				<include name="lib/repository/ant/**"/>
				<include name="lib/repository/xml-apis/**"/>
				<include name="lib/repository/xerces/**"/>
				<include name="lib/repository/omero/postgresql/**"/>
				<!-- For testing purposes -->
				<include name="lib/repository/groovy/**"/>
				<include name="lib/repository/testng/**"/>
				<!-- deploy -->
				<include name="components/common/build.xml"/>
				<!-- reload-db -->
				<include name="components/server/build.xml"/>
				<!-- usermgmt -->
				<include name="components/client/build.xml"/>
			</fileset>
		</copy>
		<copy todir="${dist.dir}">
			<fileset dir="${app.comp}/${target.rel}">
				<include name="*.ear"/>
			</fileset>
		</copy>

		<!-- 
			SQL to createdb.
		-->
		<copy todir="${dist.dir}/sql">
			<fileset dir="${common.comp}/${generated.rel}/resources" includes="*.sql"/>
                </copy>
		<!-- 
			Copy new build.xml to ${dist.dir}
		-->
                <copy
                        file="${import.dir}/omero.xml"
                        tofile="${dist.dir}/build.xml"
                        overwrite="true"
                />
		<copy todir="${dist.dir}/client">
			<fileset dir="${common.comp}/${target.rel}" includes="*.jar"/>
			<fileset dir="${client.comp}/${target.rel}" includes="*.jar"/>
			<fileset dir="${import.comp}/${target.rel}" includes="*.jar"/>
			<fileset dir="${server.comp}/${target.rel}" includes="*.jar"/>
			<fileset dir="${lib.dir}/repository">
				<include name="omero/jboss*/**/*.jar"/>
				<include name="org/springframework/spring/**/*.jar"/>
				<include name="commons-logging/commons-logging/**/*.jar"/>
				<include name="log4j/**/*.jar"/>
				<include name="omero/omejava/**/*.jar"/>
			</fileset>
			<flattenmapper/>
		</copy>

	</target>

	<target name="zip">
		<zip destfile="omero-${omero.version}.zip">
			<zipfileset dir="${dist.dir}" prefix="omero-${omero.version}"/>
		</zip>
	</target>

	<target name="clean" depends="multiproject"
		description="Lifecycle target: calls 'clean' on all components">
		<delete dir="${dist.dir}"/>
		<iterate target="clean"/>
	</target>

</project>
