<?xml version="1.0"?>
<!--
	*   '$RCSfile$'
	*     Authors: Michael Daigle
	*   Copyright: 2009 Regents of the University of California and the
	*              National Center for Ecological Analysis and Synthesis
	* For Details: http://www.nceas.ucsb.edu/
	*
	*    '$Author: daigle $'
	*    '$Date: 2009-07-30 10:31:08 -0700 (Thu, 30 Jul 2009) $'
	*    '$Revision: 5009 $'
	*
	* Build file for the Ant cross-platform build system for the 
	* Workflow Scheduler Application
	* See http://jakarta.apache.org for details on Ant
	*
	* usage: ant [compile|jar|install|jdoc]
	*
	* This program is free software; you can redistribute it and/or modify
	* it under the terms of the GNU General Public License as published by
	* the Free Software Foundation; either version 2 of the License, or
	* (at your option) any later version.
	*
	* This program 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 General Public License for more details.
	*
	* You should have received a copy of the GNU General Public License
	* along with this program; if not, write to the Free Software
	* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-->
<project name="workflowscheduler" default="jar" basedir=".">
	<property environment="env" />
	<property file="build.properties" /><!-- USER SPECIFIC PROPS -->

	<target name="config">
		<property name="jsdk"
			value="${build.tomcat.dir}/common/lib/servlet-api.jar" />

		<property name="debug" value="on" />
		<!-- property name="morphosourcedir" value="../morpho" / -->
		<property name="utilitiesdir" value="../utilities" />
		<property name="installdir"
			value="${app.deploy.dir}/${workflowscheduler.context}" />

		<echo>*********** set jsdk to ${jsdk}</echo>
	</target>

	<target name="init" depends="config">
		<path id="compile.classpath">
			<pathelement location="${jsdk}" />
			<pathelement location="lib" />
			<fileset dir="lib">
				<include name="cos.jar" />
				<include name="postgresql-8.0-312.jar" />
				<include name="quartz-1.5.2.jar" />
				<include name="utilities.jar" />
				<include name="log4j-1.2.12.jar" />
			</fileset>
			<fileset dir="lib/lsid_lib">
				<include name="commons-logging-1.0.4.jar" />
				<include name="commons-discovery.jar" />
				<include name="commons-discovery-0.2.jar" />
				<include name="wsdl4j-1.5.1.jar" />
				<include name="saaj.jar" />
				<include name="axis.jar" />
				<include name="jaxrpc.jar" />
			</fileset>
			<fileset dir="lib/spatial/geoserver/WEB-INF/lib">
				<include name="commons-httpclient-2.0.jar" />
			</fileset>
			<fileset dir="../seek/projects/ecogrid/build/lib">
				<include name="org.ecoinformatics.ecogrid.AuthenticationService-stub.jar" />
				<include name="org.ecoinformatics.ecogrid.AuthorizationService-stub.jar" />
			</fileset>
		</path>

		<!-- It is less likely you'll need to make any changes from here down,
			but customization is possible -->
		<property name="name" value="workflowscheduler" />
		<property name="Name" value="workflowscheduler" />
		<property name="debugprefix" value="${Name}:" />
		<property name="release" value="${metacat.version}" />

		<filter token="docrooturl" value="./" />
		<filter token="debugprefix" value="${debugprefix}" />
		<filter token="build.context" value="${workflowscheduler.context}" />

		<property name="srcdir" value="./src" />
		<property name="lib.dir" value="./lib" />
		<property name="docdir" value="./docs" />
		<property name="testdir" value="./test" />
		<property name="build.dir" value="./workflowscheduler.build" />
		<property name="build.src" value="${build.dir}/src" />
		<property name="build.dest" value="${build.dir}/classes" />
		<property name="build.samples" value="${build.dir}/samples" />
		<property name="build.tests" value="${build.dir}/tests" />
		<property name="build.tmp" value="${build.dir}/tmp" />
		<property name="build.metacattest"
			value="${build.tests}/metacattest" />
		<property name="build.metacatnettest"
			value="${build.tests}/metacatnettest" />
		<property name="build.data" value="${build.dir}/data" />
		<property name="build.javadocs" value="${build.dir}/docs/api" />
		<property name="build.war" value="${build.dir}/war" />
		<property name="dist.dir" value="${name}.dist" />
		<property name="ver.dir" value="${dist.dir}/${name}-${release}" />
		<property name="ver.src" value="${ver.dir}/src" />
		<property name="util.dir" value="${dist.dir}/${util-module}" />
		<property name="test.dir" value="${dist.dir}/test" />
		<!-- directories for creating a Harvest List Editor distribution -->
		<property name="dist.dir.hle" value="disthle" />
		<property name="ver.dir.hle"
			value="${dist.dir.hle}/harvest-list-editor-${release}" />
		<property name="pkg.dir" value="./package" />
		<property name="ecogrid.stublib.dir" value="../seek/projects/ecogrid/build/lib" />

		<property name="package.home" value="edu/ucsb/nceas/metacat" />

		<!-- set up svn -->
		<property name="svnant.lib" value="lib" />
		<property name="svnant.jar" value="${svnant.lib}/svnant.jar" />
		<property name="svnClientAdapter.jar"
			value="${svnant.lib}/svnClientAdapter.jar" />
		<property name="svnjavahl.jar"
			value="${svnant.lib}/svnjavahl.jar" />
		<property name="svn.utilitiesUrl"
			value="https://code.ecoinformatics.org/code/utilities/tags/${utilities-tag}" />
		<property name="svn.ecogridUrl"
			value="https://code.ecoinformatics.org/code/seek/trunk/projects/ecogrid/" />
		<!--  property name="svn.utilitiesExportPath" value="${knbdir}" / -->

		<!-- load the svn task -->
		<path id="svn.classpath">
			<pathelement location="${svnjavahl.jar}" />
			<pathelement location="${svnant.jar}" />
			<pathelement location="${svnClientAdapter.jar}" />
		</path>
		<taskdef resource="svntask.properties"
			classpathref="svn.classpath" />

		<condition property="utilities.required">
			<or>
				<not>
					<available file="lib/httpclient.jar" />
				</not>
				<not>
					<available file="lib/utilities.jar" />
				</not>
				<not>
					<available file="${utilitiesdir}" type="dir" />
				</not>
			</or>
		</condition>
		<!-- peer.utilities.required is used when there is no utilities 
			directory at ${utilitiesdir} -->
		<condition property="peer.utilities.required">
			<or>
				<not>
					<available file="${utilitiesdir}" type="dir" />
				</not>
			</or>
		</condition>
	</target>

	<target name="prepare" depends="init">
		<mkdir dir="${build.dir}" />
		<mkdir dir="${build.src}" />
		<mkdir dir="${build.dest}" />
		<mkdir dir="${build.javadocs}" />
		<mkdir dir="${build.tmp}" />

		<copy todir="${build.src}" filtering="yes">
			<fileset dir="${srcdir}">
				<include name="edu/ucsb/nceas/dbadapter/**" />
				<include name="edu/ucsb/nceas/shared/**" />
				<include name="edu/ucsb/nceas/metacat/Version.java" />
				<include name="edu/ucsb/nceas/metacat/accesscontrol/AccessControlInterface.java" />
				<include name="edu/ucsb/nceas/metacat/cart/**" />
				<include name="edu/ucsb/nceas/metacat/database/**" />
				<include name="edu/ucsb/nceas/metacat/properties/**" />
				<exclude name="edu/ucsb/nceas/metacat/properties/SkinPropertyService.java" />
				<exclude name="edu/ucsb/nceas/metacat/properties/ConfigurableProperties.java" />
				<include name="edu/ucsb/nceas/metacat/scheduler/**" />
				<include name="edu/ucsb/nceas/metacat/shared/**" />
				<include name="edu/ucsb/nceas/metacat/util/**" />
				<exclude name="edu/ucsb/nceas/metacat/util/ConfigurationUtil.java" />
				<exclude name="edu/ucsb/nceas/metacat/util/DocumentUtil.java" />
				<exclude name="edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java" />
				<exclude name="edu/ucsb/nceas/metacat/util/GeoserverUtil.java" />
				<exclude name="edu/ucsb/nceas/metacat/util/OrganizationUtil.java" />
				<include name="edu/ucsb/nceas/metacat/AuthInterface.java" />
				<include name="edu/ucsb/nceas/metacat/AuthLdap.java" />
				<include name="edu/ucsb/nceas/metacat/AuthTLSException.java" />
				<include name="edu/ucsb/nceas/metacat/AuthSession.java" />
				<include name="edu/ucsb/nceas/metacat/MetacatVersion.java" />
				<include name="edu/ucsb/nceas/metacat/service/SessionService.java" />
				<include name="edu/ucsb/nceas/metacat/service/ServiceService.java" />
				<include name="edu/ucsb/nceas/workflowscheduler/**" />
				<include name="org/kepler/executionWS/**" />
				<exclude name="**/CVS*" />
				<exclude name="**/.#*" />
			</fileset>
		</copy>
	</target>

	<taskdef resource="axis-tasks.properties"
		classpathref="compile.classpath" />

	<target name="generateStubs" depends="prepare">
		<echo
			message=" Generating stubs for execution service from ${/tmp/KeplerWebService.wsdl}" />
		<axis-wsdl2java verbose="true" output="${srcdir}"
			url="/tmp/KeplerWebService.wsdl" />
	</target>

	<target name="compile" depends="prepare, utilities"
		description="Compiles java code to build dir, and copies metacat props files there">

		<javac srcdir="${build.src}" destdir="${build.dest}"
			debug="${debug}"
			excludes="**/*.sql **/client/*.java **/harvesterClient/*.java">
			<classpath>
				<path refid="compile.classpath" />
			</classpath>
		</javac>
	</target>

	<target name="jar" depends="compile"
		description="Compiles and jars metacat java code to metacat.jar in build dir ">

		<delete file="${build.dir}/${name}.jar" />
		<jar jarfile="${build.dir}/${name}.jar" basedir="${build.dest}"
			excludes="**/protocols/ **/harvesterClient/" />
	</target>

	<target name="utilities" depends="config,getpeerutilities"
		if="utilities.required">
		<ant dir="${utilitiesdir}" target="clean" inheritAll="false" />
		<ant dir="${utilitiesdir}" target="jar" inheritAll="false" />
		<copy file="${utilitiesdir}/lib/httpclient.jar" todir="lib" />
		<copy file="${utilitiesdir}/build/utilities.jar" todir="lib" />
	</target>

	<target name="getpeerutilities" depends="prepare"
		if="peer.utilities.required"
		description="Checks utilities out of svn and copies it to your utilitiesdir if it does not already exist">
		<echo message="Exporting utiities files from svn repository:" />
		<!-- input message="Please enter svn repo username:" addproperty="svn.username" / -->
		<!-- input message="Please enter svn repo password:" addproperty="svn.password" / -->
		<!--  svn username="${svn.username}" password="${svn.password}" -->
		<svn>
			<export srcUrl="${svn.utilitiesUrl}"
				destPath="${utilitiesdir}" />
		</svn>

		<!--  ant dir="${utilitiesdir}" inheritAll="false"  target="dist" / -->
	</target>

	<target name="getutilities" depends="prepare"
		description="Checks utility out of svn and copies it to your metacat cvs sandbox">
		<echo>Enter CVS password:</echo>
		<cvs cvsRoot="${cvsroot}" package="${util-module}"
			tag="${utilities-tag}" dest="${build.tmp}" />
	</target>

	<target name="install" depends="init, war"
		description="* Full Install For Development *">
		<copy file="${dist.dir}/${workflowscheduler.context}.war"
			todir="${app.deploy.dir}" />
		<delete dir="${app.deploy.dir}/${workflowscheduler.context}" />
		<tstamp>
			<format property="NOW" pattern="MM/dd/yyyy hh:mm:ss aa" />
		</tstamp>
		<echo>Dev install completed at ${NOW}</echo>
	</target>

	<target name="war" depends="warPrepare"
		description="Create a web archive (WAR) for servlet deployment">
		<mkdir dir="${dist.dir}" />
		<war destfile="${dist.dir}/${workflowscheduler.context}.war"
			webxml="${build.war}/web.xml">
			<fileset dir="${war.context}" />
			<lib dir="${war.lib}" />
			<webinf dir="${war.webinf}" />
		</war>
	</target>

	<target name="warPrepare" depends="jar"
		description="Prepare files for creating a web archive (WAR)">

		<property name="war.lib" value="${build.war}/lib" />
		<property name="war.webinf" value="${build.war}/WEB-INF" />
		<property name="war.context"
			value="${build.war}/${workflowscheduler.context}" />
		<property name="war.webinf.sql" value="${war.webinf}/sql" />
		<property name="war.webinf.scripts"
			value="${war.webinf}/scripts" />
		<mkdir dir="${war.lib}" />
		<mkdir dir="${war.webinf}" />
		<mkdir dir="${war.context}" />
		<mkdir dir="${war.webinf.sql}" />

		<copy file="${build.dir}/${name}.jar" todir="${war.lib}" />
		<copy todir="${war.lib}" filtering="no">
			<fileset dir="lib">
				<include name="cos.jar" />
				<include name="postgresql-8.0-312.jdbc3.jar" />
				<include name="quartz-1.5.2.jar" />
				<include name="utilities.jar" />
				<include name="log4j-1.2.12.jar" />
				<include name="xalan.jar" />
			</fileset>
			<fileset dir="lib/lsid_lib">
				<include name="commons-logging-1.0.4.jar" />
				<include name="commons-discovery.jar" />
				<include name="commons-discovery-0.2.jar" />
				<include name="wsdl4j-1.5.1.jar" />
				<include name="saaj.jar" />
				<include name="axis.jar" />
				<include name="jaxrpc.jar" />
			</fileset>
			<fileset dir="lib/spatial/geoserver/WEB-INF/lib">
				<include name="commons-httpclient-2.0.jar" />
			</fileset>
			<fileset dir="${ecogrid.stublib.dir}">
				<include name="org.ecoinformatics.ecogrid.AuthenticationService-stub.jar" />
				<include name="org.ecoinformatics.ecogrid.AuthorizationService-stub.jar" />
			</fileset>
		</copy>

		<!-- MCD added next - Remove the tomcat5 reference-->
		<copy file="lib/${name}/${name}.web.xml" tofile="${build.war}/web.xml" />
		<copy file="lib/${name}/${name}.properties" todir="${war.webinf}"
			filtering="yes" />
		<!-- copy file="lib/${name}/${name}.properties.metadata.xml"
			todir="${war.webinf}" filtering="no" / -->
		<!--  copy file="lib/auth.properties.metadata.xml"
			todir="${war.webinf}" filtering="no" / -->
		<copy file="lib/log4j.properties" todir="${war.webinf}"
			filtering="yes" />

		<copy todir="${war.webinf.sql}" filtering="yes">
			<fileset dir="src">
				<include name="**/*.sql" />
			</fileset>
		</copy>
		<copy todir="${war.webinf.scripts}" filtering="yes">
			<fileset dir="src/scripts" />
		</copy>
		<copy todir="${war.webinf.scripts}"
			file="src/perl/Metacat/blib/lib/auto/Metacat/autosplit.ix"
			failonerror="false" />
	</target>

	<target name="clean" depends="init"
		description="deletes build dir and files that can be regenerated form the release">
		<delete dir="${build.dir}" />
		<delete dir="${dist.dir}" />
	</target>

	<target name="localclean" depends="clean"
		description="deletes even jars that depend on external sources such as stylesheets and jars">
		<delete file="lib/httpclient.jar" />
		<delete file="lib/utilities.jar" />
	</target>

	<target name="fullclean" depends="localclean"
		description="deletes code and eml">
		<delete includeEmptyDirs="true" failonerror="false">
			<fileset dir="${style-common-cvsrelpath}">
				<include name="${eml-css}" />
				<include name="eml-*/*.xsl" />
				<include name="eml-*" />
			</fileset>
			<fileset dir="${schema-cvsrelpath}">
				<include name="eml-*/*.xsd" />
			</fileset>
			<fileset dir="${ecogrid-dir}">
				<include name="build.properties" />
				<include name="buildfiles/metacatImpl.xml" />
			</fileset>
		</delete>
	</target>

	<target name="jdoc" depends="prepare"
		description="generates javadoc documentation">
		<javadoc packagenames="edu.ucsb.nceas.*"
			sourcepath="${build.src}" destdir="${build.javadocs}" author="true"
			version="true" use="true" windowtitle="${Name} API"
			doctitle="&lt;h1&gt;${Name}&lt;/h1&gt;"
			bottom="&lt;i&gt;Copyright &#169; 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.&lt;/i&gt;">
			<classpath>
				<path refid="compile.classpath" />
			</classpath>
		</javadoc>
	</target>

	<target name="dist"
		depends="jar,getutilities"
		description="prepares a full release distribution">
		<mkdir dir="${dist.dir}" />
		<delete dir="${ver.dir}" />
		<mkdir dir="${ver.dir}" />
		<copy todir="${ver.dir}">
			<fileset dir="."
				excludes="**/CVS* **/.#* src/** test/** build/** docs/** ${dist.dir}/** ${dist.dir.hle}/** metacat*.tar.gz metacat*.tar metacat*.zip" />
		</copy>
		<copy todir="${ver.dir}" file="build.xml" />
		<copy todir="${ver.dir}" file="build.properties" />

		<copy todir="${ver.dir}/docs" filtering="yes">
			<fileset dir="docs" excludes="**/*gif **/*jpg **/*png" />
		</copy>
		<copy todir="${ver.dir}/docs" filtering="no">
			<fileset dir="docs" includes="**/*gif **/*jpg **/*png" />
		</copy>
		<copy todir="${ver.dir}/docs/dev">
			<fileset dir="${build.dir}/docs" />
		</copy>
		<copy todir="${ver.dir}/src">
			<fileset dir="${build.dir}/src" />
		</copy>

		<mkdir dir="${ver.dir}/tests/servertestfiles" />
		<copy todir="${ver.dir}/test/servertestfiles">
			<fileset dir="./test/servertestfiles" />
		</copy>
	</target>
</project>