<?xml version="1.0"?>

<project name="biouml.examples.sql" default="help" basedir=".">

	<property file="build.properties" />
	<property name="JDBC_CLASSPATH" value="../../../../plugins/com.mysql.jdbc_3.1.13/mysql-connector-java-3.1.13-bin.jar" />
	<property name="BASE_SRC" value="../../../../src" />
	<property name="TOPDIR" value="${BASE_SRC}/.." />
	<property name="OUT" value="../out" />
	<property name="PLUGINS" value="../plugins" />
	<property name="BASE_BUILD_FILE" value="${BASE_SRC}/build.xml" />

	<target name="help">
		<echo>
            create.db   -  create necessary tables in database
            plugin.sql  -  compile and deploy plugin
            run         -  run biouml application
            test.molecule  - run test for "molecule" collection
            test.relation  - run test for "relation" collection
        </echo>
	</target>

	<target name="create.db">
		<echo>Creating tables...</echo>
		<sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" classpath="${JDBC_CLASSPATH}">
			<transaction src="tables.sql" />
			<transaction src="data.sql" />
		</sql>
	</target>

	<target name="local_settings">
		<ant antfile="${BASE_BUILD_FILE}" target="local_settings_tofile" />
		<property file=".local.properties" />
	</target>

	<target name="compile" depends="local_settings">
		<echo message="Building BioUML..." />
		<ant antfile="${BASE_BUILD_FILE}" target="plugin.all" />

		<echo message="Compiling plugin..." />
		<mkdir dir="${OUT}" />
		<javac srcdir="." destdir="${OUT}" classpath="${RUN_CLASSPATH};${BUILD_CLASSPATH}" debug="on" deprecation="off" optimize="off">
			<include name="**/*.java" />
			<exclude name="**/_test/*.java" />
		</javac>
	</target>

	<target name="plugin.sql" depends="compile">
		<echo message="Creating plugin..." />
		<jar jarfile="${PLUGINS}/sql_example.jar" compress="true">
			<fileset dir="${OUT}">
				<patternset>
					<include name="biouml/examples/sql/**/*.class" />
					<exclude name="biouml/examples/sql/_test/**/*.class" />
				</patternset>
			</fileset>
			<fileset dir=".">
				<patternset>
					<include name="biouml/examples/sql/**/*.gif" />
					<include name="biouml/examples/sql/**/*.jpg" />
					<include name="biouml/examples/sql/resources/*.html" />
				</patternset>
			</fileset>
		</jar>

		<echo message="Deploying plugin..." />
		<property name="PLUGIN_TARGET_DIR" value="${PLUGIN_DIR}/biouml.examples.sql_${VERSION}" />
		<mkdir dir="${PLUGIN_TARGET_DIR}" />
		<copy todir="${PLUGIN_TARGET_DIR}">
			<fileset dir="${PLUGINS}" />
		</copy>
	</target>

	<target name="run" depends="plugin.sql">
		<echo message="Running BioUML..." />
		<java classname="org.eclipse.core.launcher.Main" dir="${TOPDIR}" fork="yes">
			<jvmarg value="-Xmx512m" />
			<classpath>
				<pathelement path="${TOPDIR}/startup.jar" />
			</classpath>
			<arg line="-application biouml.workbench.launcher examples/databases/sql/data data_resources" />
		</java>
	</target>

	<target name="compile.tests" depends="plugin.sql">
		<ant antfile="${BASE_BUILD_FILE}" target="ctest" />
		<echo message="Compiling test..." />
		<property name="TEST_CLASSPATH" value="${RUN_CLASSPATH};${BUILD_CLASSPATH};${JUNIT};${COMMON}" />
		<javac srcdir="." destdir="${OUT}" classpath="${TEST_CLASSPATH}" debug="on" deprecation="off" optimize="off">
			<include name="**/_test/*.java" />
		</javac>
	</target>

	<target name="run.test" depends="compile.tests">
		<java classname="junit.${testui}.TestRunner" fork="yes">
			<classpath>
				<pathelement path="${OUT};${RUN_CLASSPATH};${JUNIT};${JUNITX};${ECLIPSE_JARS};${ENSEMBL_JAR};${MYSQL_JAR};${SQLSERVER_JAR};${PLUGIN_DIR}/biouml.plugins.matlab_${VERSION}" />
			</classpath>
			<jvmarg value="-Drepository=${projects.java.dir}/${PROJECT_NAME}/data" />
			<arg value="-noloading" />
			<arg value="${test}" />
		</java>
	</target>

	<target name="test.molecule">
		<echo message="Molecule test running..." />
		<ant target="run.test">
			<property name="testui" value="swingui" />
			<property name="test" value="biouml.examples.sql._test.MyMoleculeSqlTransformerTest" />
		</ant>
	</target>

	<target name="test.relation">
		<echo message="Relation test running..." />
		<ant target="run.test">
			<property name="testui" value="swingui" />
			<property name="test" value="biouml.examples.sql._test.MyRelationSqlTransformerTest" />
		</ant>
	</target>

</project>
