<?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/multiproject.xml"/>
	<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>

<!-- 	===============================================
		BUILD
	==================================================  -->
	<target name="fullbuild" depends="check-system,clean,build,reload-db"
		description="Extensive build which checks and cleans the build environment, builds, and setups the database"/>

	<target name="build" depends="dsl,model,install"
		description="A simple build that will install all artifacts to ${omero.repo.local}"/>

	<target name="build-client" depends="check-system,model">
		<antRun component="common"><target name="install"/></antRun>
		<antRun component="client"><target name="install"/></antRun>
	</target>

	<target name="build-server" depends="check-system,model">
		<antRun component="common"><target name="install"/></antRun>
		<antRun component="romio"><target name="install"/></antRun>
		<antRun component="rendering"><target name="install"/></antRun>
		<antRun component="server"><target name="install"/></antRun>
	</target>

	<target name="deploy" depends="check-system,build-server">
		<antRun component="app">
			<target name="package"/>
			<target name="deploy-ear-jboss"/>
		</antRun>
	</target>

	<target name="fulldeploy" depends="check-system,build-server,deploy"/>



	<!-- Special Components -->
	<property name="defaultTarget" value="install"/>

	<target name="dsl" depends="check-system" unless="generate.skip">
		<antRun component="dsl">
			<target name="${defaultTarget}"/>
		</antRun>
	</target>

	<target name="model" depends="check-system,dsl" unless="generate.skip">
		<antRun component="common">
			<target name="clean"/>
			<target name="install"/>
		</antRun>
	</target>

	<target name="reload-db">
		<antRun component="server">
			<target name="reload-db"/>
		</antRun>
	</target>

	<target name="addgroup">
		<antRun component="client">
			<target name="addgroup"/>
		</antRun>
	</target>

	<target name="adduser">
		<antRun component="client">
			<target name="adduser"/>
		</antRun>
	</target>

	<target name="dist">
		<mkdir dir="${dist.dir}"/>
		<iterate target="dist"/>

		<!-- 
			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="sql/**"/>
				<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 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="${blitz.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"/>
				<include name="omero/ice/**/*.jar"/>
				<include name="omero/client/**/*.jar"/>
			</fileset>
			<flattenmapper/>
		</copy>

	</target>

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

	<target name="tar">
		<tar destfile="${product.name}-${product.version}.tar.bz2" compress="bzip2">
			<zipfileset dir="${dist.dir}" prefix="${product.name}-${product.version}"/>
		</tar>
	</target>

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

	<target name="withtools"
		description="Calls build and dist on the tools component, copying over dist/">
		<antRun component="tools">
			<target name="build"/>
			<target name="dist"/>
		</antRun>
	</target>

	<target name="cleantools"
		description="Calls cleans on the tools component and removes tools/target">
		<antRun component="tools">
			<target name="clean"/>
		</antRun>
	</target>

</project>
