<?xml version="1.0" encoding="UTF-8"?>
<!--
 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.
-->

<!-- ======================================================================== -->
<!--                                                                          -->
<!--  maven Buildfile                                                         -->
<!--                                                                          -->
<!-- $Id$ -->
<!--                                                                          -->
<!-- ======================================================================== -->

<project
  xmlns:pom="pom"
  xmlns:j="jelly:core"
  xmlns:deploy="deploy"
  default="jar:jar">

  <!-- Allow any user specific values to override the defaults -->
  <property file="${user.home}/build.properties" />

  <!-- ================================================================== -->
  <!-- X D O C : I N I T   P O S T   G O A L                              -->
  <!-- ================================================================== -->
  <postGoal name="xdoc:init">
    <!-- copy database.dtd to docs dir -->
    <copy
      file="${maven.src.dir}/dtd/database.dtd"
      tofile="target/docs/database.dtd.txt"
    />
  </postGoal>

  <!-- ================================================================== -->
  <!-- D I S T : B U I L D _ B I N   P R E   G O A L                      -->
  <!-- ================================================================== -->
  <!-- copies jars, ... to the ${maven.dist.bin.assembly.dir}             -->
  <!-- to include them in the binary dists                                -->
  <!-- ================================================================== -->
  <preGoal name="dist:build-bin">
    <!-- include listed dependencies -->
    <j:forEach var="dep" items="${pom.dependencies}">
      <j:if test="${dep.getProperty('dist.bundle') != null &amp;&amp; dep.getProperty('dist.bundle').equalsIgnoreCase('true')}">
        <copy todir="${maven.dist.bin.assembly.dir}/lib"
              file="${maven.repo.local}/${dep.getArtifactDirectory()}/jars/${dep.getArtifact()}"/>
      </j:if>
    </j:forEach>

    <!--copy build-torque.xml to the right place -->
    <copy
      file="${maven.src.dir}/conf/build-torque.xml"
      todir="${maven.dist.bin.assembly.dir}"
    />
    <copy
      file="${maven.src.dir}/conf/build.properties"
      todir="${maven.dist.bin.assembly.dir}"
    />
    <copy
      file="${maven.src.dir}/conf/default.properties"
      todir="${maven.dist.bin.assembly.dir}"
    />
    <copy todir="${maven.dist.bin.assembly.dir}/src/schema">
      <fileset dir="${maven.src.dir}/schema">
        <include name="id-table-schema.xml" />
      </fileset>
    </copy>

    <copy todir="${maven.dist.bin.assembly.dir}">
      <fileset file='${basedir}/common/NOTICE'/>
      <fileset file='${basedir}/common/LICENSE.txt'/>
    </copy>
  </preGoal>

  <!-- ================================================================== -->
  <!-- D I S T : B U I L D _ S R C   P R E   G O A L                      -->
  <!-- ================================================================== -->
  <!-- copies files to the right place to satisfy pom <extends>           -->
  <!-- ================================================================== -->
  <preGoal name="dist:build-src">
    <copy todir="${maven.dist.src.assembly.dir}/common">
      <fileset dir="${basedir}/common">
        <include name="project.xml"/>
        <include name="project.properties"/>
        <include name="NOTICE"/>
        <include name="LICENSE.txt"/>
      </fileset>
    </copy>
  </preGoal>

  <!-- ================================================================== -->
  <!-- R U N T I M E T E S T                                              -->
  <!-- ================================================================== -->
  <goal
    name="runtime:test"
    prereqs="runtime:prepare"
    description="runtime tests (set torque.testProfile in your build.properties)">

    <ant antfile="build-test.xml"
         target="test"
         inheritAll="false"/>
  </goal>

  <goal
    name="runtime:test-classpath"
    prereqs="runtime:prepare"
    description="runtime tests using useClasspath property (set torque.testProfile in your build.properties)">

    <ant antfile="build-test.xml"
         target="test-classpath"
         inheritAll="false"/>
  </goal>

  <goal
    name="runtime:prepare"
    prereqs="jar:jar">

    <!-- Set values in test profile -->
    <property file="${torque.testProfile}"/>

    <!-- Use the profile as the build.properties file
         in the dist directory so that it is customizable
         by each tester. -->
    <echo message="Copying profile into distribution directory: ${torque.testProfile}"/>

    <filter token="APPLICATION_ROOT" value="."/>
    <filter token="DATABASE" value="${torque.database}"/>
    <filter token="DATABASE_DEFAULT" value="${torque.defaultDatabase}"/>
    <filter token="DATABASE_URL" value="${torque.database.url}"/>
    <filter token="DATABASE_USER" value="${torque.database.user}"/>
    <filter token="DATABASE_DRIVER" value="${torque.database.driver}"/>
    <filter token="DATABASE_PASSWORD" value="${torque.database.password}"/>
    <filter token="DATABASE_ID_METHOD" value="${torque.idMethod}"/>
    <filter token="DATABASE_ADAPTER" value="${torque.database}"/>

    <copy
      tofile="${torque.distDir}/build.properties"
      file="${torque.testProfile}"
      overwrite="yes"
    />

    <!-- copy test schemas -->
    <copy
      todir="${torque.distDir}/schema"
      filtering="yes"
      overwrite="yes">
      <fileset dir="${rttest.dir}">
        <include name="**/*.xml"/>
      </fileset>
    </copy>

    <!-- copy test sources -->
    <copy todir="${torque.distDir}/src/java">
      <fileset dir="${rttest.dir}"/>
    </copy>

    <copy
      tofile="${build.test}/rttest/build-torque.xml"
      file="${src.dir}/conf/build-torque.xml"
      overwrite="yes"
    />
    <copy
      tofile="${build.test}/rttest/default.properties"
      file="${src.dir}/conf/default.properties"
      overwrite="yes"
    />

    <!-- copy libs -->
    <deploy:copy-deps todir="${build.test}/rttest/lib"/>
    <copy file="${maven.build.dir}/${maven.final.name}.jar"
          todir="${build.test}/rttest/lib"/>
    <copy file="${torque.testDatabaseJar}"
          todir="${build.test}/rttest/lib"/>

    <!-- copy templates -->
    <copy todir="${build.test}/rttest/templates">
      <fileset dir="${src.dir}/templates"/>
    </copy>

    <!-- copy Torque.properties -->
    <copy
      tofile="${build.test}/rttest/Torque.properties"
      file="src/conf/master/Torque.master"
      filtering="yes"
      overwrite="yes"
    />

  </goal>


</project>
