<?xml version="1.0" encoding="UTF-8"?>

<!-- $This file is distributed under the terms of the license in LICENSE$ -->

<!-- ====================================================================== 
     A tool to migrate RDB data into TDB.
     ====================================================================== -->

<project name="RDB-migration" default="describe">

	<property name="working.dir" location=".work" />
	<property name="src.dir" location="src" />
	<property name="lib.dir" location="lib" />

	<!-- ================================= 
	      target: describe              
	     ================================= -->
	<target name="describe"
	        description="--> Describe the targets (this is the default).">
		<echo>
	all - Compiles and runs the RDB migration tool.
	    </echo>
	</target>

	<!-- ================================= 
	      target: all              
	     ================================= -->
	<target name="all"
	        depends="clean, run"
	        description="Build from scratch and run the migration.">
	</target>

	<!-- - - - - - - - - - - - - - - - - - 
          target: clean                      
         - - - - - - - - - - - - - - - - - -->
	<target name="clean">
		<delete dir="${working.dir}" />
	</target>

	<!-- - - - - - - - - - - - - - - - - - 
          target: setup                      
         - - - - - - - - - - - - - - - - - -->
	<target name="setup" depends="getBuildProperties, getRuntimeProperties">
		<mkdir dir="${working.dir}" />
	</target>

	<!-- - - - - - - - - - - - - - - - - - 
		  target: getBuildProperties                      
		 - - - - - - - - - - - - - - - - - -->
	<target name="getBuildProperties">
		<property name="vivo.distribution.dir" location="../.." />
		<property name="build.properties.file"
		          location="${vivo.distribution.dir}/build.properties" />
		<fail message="You must create a &quot;${build.properties.file}&quot; file.">
			<condition>
				<not>
					<available file="${build.properties.file}" />
				</not>
			</condition>
		</fail>

		<property file="${build.properties.file}" />
		<fail unless="vitro.core.dir"
		      message="${build.properties.file} must contain a value for vitro.core.dir" />
		<fail unless="vitro.home"
		      message="${build.properties.file} must contain a value for vitro.home" />
	</target>

	<!-- - - - - - - - - - - - - - - - - - 
		  target: getRuntimeProperties                      
		 - - - - - - - - - - - - - - - - - -->
	<target name="getRuntimeProperties">
		<property name="runtime.properties.file"
		          location="${vitro.home}/runtime.properties" />
		<fail message="You must create a &quot;${runtime.properties.file}&quot; file.">
			<condition>
				<not>
					<available file="${runtime.properties.file}" />
				</not>
			</condition>
		</fail>

		<property file="${runtime.properties.file}" />
		<fail unless="VitroConnection.DataSource.url"
		      message="${runtime.properties.file} must contain a value for VitroConnection.DataSource.url" />
		<fail unless="VitroConnection.DataSource.username"
		      message="${runtime.properties.file} must contain a value for VitroConnection.DataSource.username" />
		<fail unless="VitroConnection.DataSource.password"
		      message="${runtime.properties.file} must contain a value for VitroConnection.DataSource.password" />
	</target>

	<!-- - - - - - - - - - - - - - - - - - 
          target: compile                      
         - - - - - - - - - - - - - - - - - -->
	<target name="compile" depends="setup">
		<path id="main.compile.classpath">
			<fileset dir="${lib.dir}" includes="*.jar" />
		</path>

		<javac srcdir="${src.dir}"
		       destdir="${working.dir}"
		       debug="true"
		       deprecation="true"
		       encoding="UTF8"
		       includeantruntime="false"
		       optimize="true"
		       source="1.7">
			<classpath refid="main.compile.classpath" />
		</javac>
	</target>

	<!-- - - - - - - - - - - - - - - - - - 
          target: run                      
         - - - - - - - - - - - - - - - - - -->
	<target name="run" depends="compile">
		<path id="migrate.run.classpath">
			<pathelement location="${working.dir}" />
			<path refid="main.compile.classpath" />
		</path>

		<java classname="edu.cornell.mannlib.vivo.utilities.rdbmigration.RdbMigrator"
		      fork="no"
		      failonerror="true">
			<arg value="${vitro.home}" />
			<arg value="${VitroConnection.DataSource.url}" />
			<arg value="${VitroConnection.DataSource.username}" />
			<arg value="${VitroConnection.DataSource.password}" />
			<jvmarg value="-Xms512m"/>
			<jvmarg value="-Xmx2048m"/>
			<classpath refid="migrate.run.classpath" />
		</java>
	</target>

</project>