<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<project default="toursdb" basedir=".">

<!-- Set Properties -->
  <property name="lib.dir" value="../../../lib"/>

<!-- Targets -->

  <target name="toursdb" depends="compile,buildschema,loadtables,jarup"/>

  <target name="compile">
    <echo level="info" message="Begin building toursdb"/>
    <javac srcdir="..">
      <include name="toursdb/insertMaps.java"/>
    </javac>
  </target>

  <target name="buildschema">
    <java classname="org.apache.derby.tools.ij"
          output="toursdb.out"
          failonerror="true"
          dir="." fork="true">
      <classpath>
        <pathelement path="${lib.dir}/derby.jar"/>
        <pathelement path="${lib.dir}/derbytools.jar"/>
      </classpath>
      <sysproperty key="ij.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <sysproperty key="ij.database" value="jdbc:derby:toursdb;create=true"/>
      <arg value="ToursDB_schema.sql"/>
    </java>
  </target>

  <target name="loadtables">
    <java classname="org.apache.derby.tools.ij"
          output="toursdb.out" append="true"
          failonerror="true"
          dir="." fork="true">
      <classpath>
        <pathelement path="${lib.dir}/derby.jar"/>
        <pathelement path="${lib.dir}/derbytools.jar"/>
      </classpath>
      <sysproperty key="ij.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <sysproperty key="ij.database" value="jdbc:derby:toursdb;create=true"/>
      <arg value="loadTables.sql"/>
    </java>
    <java classname="toursdb.insertMaps"
          output="toursdb.out" append="true"
          failonerror="true"
          dir="." fork="true">
      <classpath>
        <pathelement path="${lib.dir}/derby.jar"/>
        <pathelement path="${lib.dir}/derbytools.jar"/>
        <pathelement path=".."/>
      </classpath>
    </java>
    <java classname="org.apache.derby.tools.ij"
          output="toursdb.out" append="true"
          failonerror="true"
          dir="." fork="true">
      <classpath>
        <pathelement path="${lib.dir}/derby.jar"/>
        <pathelement path="${lib.dir}/derbytools.jar"/>
      </classpath>
      <arg value="disconnect.sql"/>
    </java>
  </target>

  <target name="jarup"> 
    <zip destfile="toursdb.jar"
         basedir="toursdb"/>
    <echo level="info" message="Finished building toursdb"/>
  </target>

</project>
