<?xml version="1.0" encoding="UTF-8"?>
<!--
// $Id: //open/dev/farrago/build.xml#147 $
// Farrago is an extensible data management system.
// Copyright (C) 2005-2009 The Eigenbase Project
// Copyright (C) 2005-2009 SQLstream, Inc.
// Copyright (C) 2005-2009 LucidEra, Inc.
// Portions Copyright (C) 2003-2009 John V. Sichi
//
// 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 approved by The Eigenbase Project.
//
// 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
-->

<!-- Farrago ant script for developer builds -->

<!-- These XML ENTITY "macros" help avoid redundancy in property -->
<!-- settings. They can be used with <jvmarg> or <arg> as the line -->
<!-- attribute. -->
<!DOCTYPE project [

<!ENTITY FarragoProps
"
-Dnet.sf.farrago.home=${farrago.dir}
-Dnet.sf.farrago.catalog=${project.catalog.dir}
-Djava.util.logging.config.file=${FarragoTrace.properties}
-Djava.security.auth.login.config=jaas.config
${farrago.test.jvmargs}
">

<!ENTITY FarragoSqlLineProps
"
&FarragoProps;
-Dsqlline.historyFile=${sqlline.hist.file}
">

]>

<project name="farrago" basedir="." default="all">

  <!-- import settings defined by initBuild.sh with highest precedence -->
  <property file="initBuild.properties"/>

  <!-- import local property overrides; these take precedence over
  later definitions in this file -->
  <property file="customBuild.properties"/>

  <!-- Definitions for Farrago build properties and macros -->
  <import file="buildMacros.xml"/>


  <!-- Directories -->

  <!-- directory for Farrago compiled classes which go into plugin .jars -->
  <property name="plugin.classes.dir" location="${farrago.plugin.dir}/classes"/>

  <!-- directory for JUnit run output -->
  <property name="testlog.dir" location="${farrago.dir}/testlog"/>

  <!-- directory in which javadoc should be generated -->
  <property name="javadoc.dir" location="${farrago.dir}/doc/api"/>

  <!-- directory for unit test SQL scripts -->
  <property name="unitsql.dir" location="${farrago.dir}/unitsql"/>

  <!-- directory for regression test SQL scripts -->
  <property name="regressionsql.dir" location="${farrago.dir}/regressionsql"/>

  <!-- directory for unit test LURQL scripts -->
  <property name="unitlurql.dir" location="${farrago.dir}/testcases/lurql"/>

  <!-- directory containing definition of LURQL parser -->
  <property name="lurql.parser.dir"
    location="${farrago.src.dir}/org/eigenbase/lurql/parser"/>

  <!-- The version of ANT we require. -->
  <property name="required.ant.version" value="1.7.0"/>

  <!-- ant.version not set in subant targets in 1.7.0, see issues.apache.org 42263 -->
  <!-- using ant.version causes saffron cruisecontrol to fail, thus, a workaround -->
  <condition property="is.correct.ant.version">
    <antversion atleast="${required.ant.version}"/>
  </condition>

  <!-- Files -->


  <!-- Template developer configuration file. -->
  <property name="FarragoConfTemplate.xmi"
    location="${farrago.xmi.dir}/FarragoConfTemplate.xmi"/>

  <!-- Developer configuration file generated from template. -->
  <property name="FarragoConf.xmi"
    location="${farrago.xmi.dir}/FarragoConf.xmi"/>

  <!-- file prefix for Netbeans/HSQLDB catalog storage -->
  <property name="catalog.mdrStorage"
    location="${farrago.catalog.dir}/FarragoCatalog"/>

  <property name="coverage.dir" value="${farrago.dir}/coverage"/>

  <!-- NOTE:  this has to use true/false (not 1/0) for MDR import -->
  <property name="fennel.disabled" value="false"/>
  <condition property="fennel.disabled.istrue">
    <istrue value="${fennel.disabled}"/>
  </condition>

  <!-- Set to a path to enable Fennel JNI handle tracing during tests. -->
  <property name="trace.fennel.handles" value=""/>

  <!-- a fileset of all files for which tags should be built -->
  <fileset dir="${farrago.dir}" id="fileset.taggable">
    <include name="catalog/java/**/*.java"/>
    <include name="src/**/*.jj"/>
    <include name="src/**/*.java"/>
    <include name="examples/**/*.java"/>
    <include name="examples/**/package.java"/>
    <include name="src/**/package.html"/>
    <exclude name="src/**/parser/impl/*"/>
    <exclude name="examples/**/parserimpl/*"/>
  </fileset>

  <!-- a fileset of all SQL unit tests -->
  <fileset dir="${unitsql.dir}" id="fileset.unitsql">
    <include name="**/*.sql"/>
    <exclude name="runner/**/*.sql"/>
    <exclude name="med/scott.sql" unless="oracle.test"/>
  </fileset>
  <pathconvert property="fileset.unitsql" refid="fileset.unitsql"
    pathsep="${line.separator}" dirsep="${file.separator}" />
  <property name="FarragoSqlTestWrapper.java"
    location=
    "${farrago.src.dir}/net/sf/farrago/test/FarragoSqlTestWrapper.java"/>

  <!-- a fileset of all SQL regression tests -->
  <fileset dir="${regressionsql.dir}" id="fileset.regressionsql">
    <include name="**/*.sql"/>
  </fileset>
  <pathconvert property="fileset.regressionsql"
    refid="fileset.regressionsql"
    pathsep="${line.separator}" dirsep="${file.separator}" />

  <!-- a fileset of all SQL concurrency tests -->
  <fileset dir="${unitsql.dir}" id="fileset.concurrentsql">
    <include name="**/*.mtsql"/>
  </fileset>
  <pathconvert property="fileset.concurrentsql" refid="fileset.concurrentsql"
    pathsep="${line.separator}" dirsep="${file.separator}" />

  <!-- a fileset of all LURQL unit tests -->
  <fileset dir="${unitlurql.dir}" id="fileset.unitlurql">
    <include name="**/*.lurql"/>
  </fileset>
  <pathconvert property="fileset.unitlurql" refid="fileset.unitlurql"
    pathsep="${line.separator}" dirsep="${file.separator}" />

  <!-- newline for use in constructing strings -->
  <property name="nl" value="${line.separator}"/>


  <!-- Classpaths -->

  <!-- thirdparty classpath for main build (after catalog codegen) -->
  <path id="farrago.build.3p.classpath">
    <pathelement path="${farrago.3p.classpath}"/>
    <pathelement location="${sqlline.lib.dir}/sqlline.jar"/>
    <pathelement location="${sqlline.lib.dir}/jline.jar"/>
    <pathelement location="${jgrapht.dir}/jgrapht-jdk1.5.jar"/>
    <pathelement location="${diffj.dir}/share/diffj/diffj.jar" />
  </path>
  <property name="farrago.build.3p.classpath"
    refid="farrago.build.3p.classpath"/>

  <!-- classpath for main build (after catalog codegen) -->
  <path id="farrago.build.classpath">
    <pathelement path="${farrago.build.3p.classpath}"/>
    <pathelement location="${farrago.catalog.src.dir}"/>
  </path>
  <property name="farrago.build.classpath" refid="farrago.build.classpath"/>

  <!-- classpath for plugin build) -->
  <path id="plugin.build.classpath">
    <pathelement path="${farrago.build.classpath}"/>
    <pathelement location="${farrago.classes.dir}"/>
  </path>
  <property name="plugin.build.classpath" refid="plugin.build.classpath"/>

  <!-- sourcepath for debugging -->
  <path id="farrago.sourcepath">
    <pathelement location="${farrago.catalog.src.dir}"/>
    <pathelement location="${farrago.src.dir}"/>
    <pathelement location="${sqlline.dir}/src"/>
    <pathelement location="${junit.dir}/src.jar"/>
    <pathelement location="${rmijdbc.dir}/src"/>
    <pathelement location="${open.dir}/thirdparty/netbeans/mdr/src"/>
    <pathelement
      location="${open.dir}/thirdparty/netbeans/mdr/extras/jdbcstorage/src"/>
  </path>
  <property name="farrago.sourcepath" refid="farrago.sourcepath"/>

  <!-- 
    Detect whether Oracle is available. If the Oracle driver is found under
    ORACLE_HOME, we assume that there is an Oracle database at
    'jdbc:oracle:thin:@localhost:1521:xe', and that the scott/tiger schema is
    populated; so we enable certain SQL/MED test(s). 
  -->
  <!-- no test for undefined env var, so all this complexity -->
  <property name="oracle.home" value="${env.ORACLE_HOME}"/>
  <property name="oracle.jar" value="jdbc/lib/ojdbc14.jar"/>
  <condition property="oracle.available">
    <available
      classname="oracle.jdbc.driver.OracleDriver"
      classpath="${oracle.home}/${oracle.jar}" />
  </condition>

  <!-- classpath for running tests via ant -->
  <path id="test.classpath">
    <pathelement path="${farrago.sqlline.classpath}"/>
    <pathelement path="${ant.classpath}"/>
    <pathelement path="${test.emma.classpath}" />
    <pathelement location="${diffj.dir}/share/diffj/diffj.jar" />
    <fileset dir="">
      <include name="${oracle.home}/${oracle.jar}" if="oracle.test"/>
    </fileset>
  </path>
  <property name="test.classpath" refid="test.classpath"/>

  <path id="emma.test.classpath">
    <pathelement location="${emma.farrago.classes.dir}"/>
    <pathelement path="${emma.classpath}"/>
    <pathelement path="${test.classpath}"/>
  </path>
  <property name="emma.test.classpath" refid="emma.test.classpath"/>

  <!-- classpath for reentrantly invoking ant from createUserRepository -->
  <path id="createUserRepository.classpath">
    <pathelement path="${farrago.run.classpath}"/>
    <pathelement path="${ant.classpath}"/>
  </path>
  <property name="createUserRepository.classpath"
    refid="createUserRepository.classpath"/>

  <!-- Fennel Defaults, can override in customBuild.properties -->
  <property name="fennel.databaseInitSize" value="1000"/>
  <property name="fennel.tempInitSize" value="1000"/>
  <property name="fennel.checkpointInterval" value="300"/>
  <property name="fennel.cachePageSize" value="4096"/>
  <property name="fennel.cachePagesMax" value="1000"/>
  <property name="fennel.cachePagesInit" value="1000"/>
  <property name="fennel.groupCommitInterval" value="30"/>

  <!-- Targets -->

  <!-- default target:  assumes catalog has already been created -->
  <target name="all"
    depends="compile, rmi, buildJdbcPlugin"/>

  <!-- create rmi stubs and skeletons -->
  <target name="rmi" depends="compile">
    <rmic base="${farrago.classes.dir}"
      classpathref="farrago.build.classpath">
      <include name="**/server/FarragoRJConnectionServer.class" />
      <include name="**/server/FarragoRJMedDataWrapperServer.class" />
      <include name="**/server/FarragoRJDriverServer.class" />
    </rmic>
  </target>

  <target name="compile"
    depends="generateResources,sqlParser,ddlParser,lurqlParser">
    <farrago.javaCompileClient
      srcdir="${farrago.src.dir}"
      destdir="${farrago.classes.dir}"
      classpathref="farrago.build.classpath">
      <include name="org/eigenbase/util14/**/*.java" />
      <include name="org/eigenbase/util/property/**/*.java" />
      <include name="net/sf/farrago/fennel/tuple/**/*.java" />
      <include name="net/sf/farrago/release/**/*.java" />
      <include name="net/sf/farrago/jdbc/*.java" />
      <include name="net/sf/farrago/jdbc/client/**/*.java" />
      <include name="net/sf/farrago/jdbc/param/**/*.java" />
      <include name="net/sf/farrago/jdbc/rmi/**/*.java" />
    </farrago.javaCompileClient>
    <!-- have to fork and bump up the heap because Farrago's getting fat! -->
    <farrago.javaCompile
      fork="true"
      memoryMaximumSize="512m"
      deprecation="off"
      srcdir="${farrago.src.dir}"
      destdir="${farrago.classes.dir}"
      classpathref="farrago.build.classpath">
      <include name="**/*.java" />
      <exclude name="**/namespace/jdbc/**/*.java" />
      <exclude name="org/eigenbase/inventory/**/*.java" />
      <exclude name="**/Jdk15Test.java" if="farrago.javasrc.14" />
    </farrago.javaCompile>
  </target>

  <!-- compile only packages needed by Saffron -->
  <target name="compile.saffron.deps" 
    depends="mungeJdbc, generateResources,sqlParser,lurqlParser">
    <farrago.javaCompileClient
      srcdir="${farrago.src.dir}"
      destdir="${farrago.classes.dir}"
      classpathref="farrago.build.classpath">
      <include name="org/eigenbase/util14/**/*.java" />
      <include name="org/eigenbase/util/property/**/*.java" />
    </farrago.javaCompileClient>
    <farrago.javaCompile
      deprecation="off"
      srcdir="${farrago.src.dir}"
      destdir="${farrago.classes.dir}"
      classpathref="farrago.build.classpath">
      <include name="org/eigenbase/**/*.java" />
      <include name="com/disruptivetech/farrago/volcano/**/*.java" />
      <exclude name="org/eigenbase/inventory/**/*.java" />
    </farrago.javaCompile>
  </target>

  <!-- create classes directory -->
  <target name="makeClassesDir">
    <mkdir dir="${farrago.classes.dir}"/>
    <mkdir dir="${plugin.classes.dir}"/>
  </target>

  <!-- test only packages needed by Saffron -->
  <target name="test.saffron.deps" depends="compile.saffron.deps">
    <mkdir dir="${testlog.dir}"/>
    <junit printsummary="yes" fork="yes" failureproperty="junit.failure"
      tempdir="${testlog.dir}">
      <classpath refid="farrago.run.classpath"/>
      <jvmarg line="${assertions.jvmarg}"/>
      <jvmarg line="&FarragoProps;"/>
      <formatter type="plain"/>
      <batchtest todir="${testlog.dir}" unless="junit.class">
        <fileset dir="${farrago.classes.dir}">
          <include name="org/eigenbase/**/*Test.class"/>
          <include name="com/disruptivetech/farrago/volcano/**/*Test.class"/>
        </fileset>
      </batchtest>
      <test todir="${testlog.dir}" if="junit.class"
        name="${junit.class}" />
    </junit>
    <delete file="${FarragoTrace.log}.lck"/>
    <fail message="Test failure(s)" if="junit.failure"/>
  </target>

  <!-- create the FarragoMedJdbc plugin jar -->
  <target name="buildJdbcPlugin"
    depends="checkJdbcPluginUptodate" unless="plugin.jdbc.uptodate">
    <farrago.javaCompile
      srcdir="${farrago.src.dir}"
      destdir="${plugin.classes.dir}"
      classpathref="plugin.build.classpath">
      <include name="**/namespace/jdbc/**/*.java" />
    </farrago.javaCompile>
    <antcall target="buildJdbcPluginJar"/>
  </target>

  <target name="buildJdbcPluginJar">
    <jar jarfile="${farrago.plugin.dir}/FarragoMedJdbc.jar">
      <fileset dir="${plugin.classes.dir}">
        <include name="**/namespace/jdbc/**/*.class" />
      </fileset>
      <manifest>
        <attribute
          name="DataWrapperClassName"
          value="net.sf.farrago.namespace.jdbc.MedJdbcForeignDataWrapper" />
      </manifest>
    </jar>
  </target>

  <target name="checkJdbcPluginUptodate">
    <uptodate property="plugin.jdbc.uptodate"
      targetfile="${farrago.plugin.dir}/FarragoMedJdbc.jar">
      <srcfiles dir="${farrago.src.dir}"
        includes="**/namespace/jdbc/**/*.java"/>
    </uptodate>
  </target>

  <!-- cleans for non-catalog-generated code -->
  <target name="clean" depends="cleanTestLogs">
    <delete includeEmptyDirs="true" quiet="true">
      <fileset dir="${farrago.classes.dir}"
        includes="**/*.class,**/*.properties,**/*.xml"/>
      <fileset dir="${plugin.classes.dir}" includes="**/*.class"/>
      <fileset dir="${farrago.plugin.dir}" includes="**/*.jar"/>
      <fileset dir="${farrago.classes.dir}"
        includes="net/sf/farrago/dynamic/**"/>
      <fileset dir="${farrago.dir}" includes="junit*.properties"/>
      <fileset dir="${farrago.dir}" includes="hs_err_pid*.log"/>
      <fileset dir="${farrago.src.dir}/net/sf/farrago/resource">
        <include name="*.java"/>
      </fileset>
      <fileset dir="${farrago.src.dir}/org/eigenbase/resource">
        <include name="*.java"/>
      </fileset>
      <fileset dir="${farrago.parser.ddl.dir}/impl" includes="*.java,*.jj"/>
      <fileset dir="${farrago.parser.sql.dir}/impl" includes="*.java,*.jj"/>
      <fileset 
        dir="${farrago.src.dir}/examples/rng/src/net/sf/farrago/rng/parserimpl" 
        includes="*.java,*.jj"/>
      <fileset 
        dir="${farrago.src.dir}/examples/rng/src/net/sf/farrago/rng/resource" 
        includes="*.java"/>
      <fileset dir="${lurql.parser.dir}" includes="*.java"/>
      <!-- TODO jvs 22-Mar-2009:  get rid of this in a few months -->
      <fileset dir="${farrago.src.dir}/com/lucidera/lurql/parser" 
        includes="*.java"/>
    </delete>
  </target>

  <target name="cleanTestLogs">
    <delete includeEmptyDirs="true" quiet="true">
      <fileset dir="${testlog.dir}" includes="*.xml"/>
      <fileset dir="${testlog.dir}" includes="*.txt"/>
      <fileset dir="${testlog.dir}" includes="*.log"/>
      <fileset dir="${testlog.dir}" includes="*.bcp"/>
      <fileset dir="${testlog.dir}" includes="*.dif"/>
      <fileset dir="${testlog.dir}" includes="*.err"/>
      <fileset dir="${testlog.dir}" includes="*.history"/>
      <fileset dir="${unitsql.dir}" includes="**/*.log"/>
      <fileset dir="${unitsql.dir}/syslib/depts_files">
        <include name="*"/>
      </fileset>
      <fileset dir="${unitsql.dir}/syslib/dates_files">
        <include name="*"/>
      </fileset>
      <fileset dir="${unitsql.dir}/syslib/sales_files">
        <include name="*"/>
      </fileset>
      <fileset dir="${unitlurql.dir}" includes="**/*.log"/>
      <fileset dir="${regressionsql.dir}" includes="**/*.log"/>
      <fileset dir="${unitsql.dir}/med/flatfiles">
        <include name="example2.bcp"/>
        <include name="example.ctl"/>
        <include name="noheader.bcp"/>
        <include name="nulldata.bcp"/>
        <include name="withnulls.bcp"/>
        <include name="headerswithwhitespacenobcp.bcp"/>
        <include name="buggy.bcp"/>
      </fileset>
    </delete>
    <delete quiet="true" file="${FarragoTrace.log}"/>
  </target>

  <!-- Creates an unconfigured catalog.  This is useful for extension
       projects that make configuration changes and want to store their
       catalog in an out-of-process database (e.g., postgres). -->
  <target name="createUnconfiguredCatalog"
          depends="makeClassesDir,configureReposStorage">
    <antcall target="createClasspathFile"/>
    <antcall target="compileCatalog"/>
    <antcall target="createMdrTestData"/>
  </target>

  <!-- creates catalog and populates with initial metadata -->
  <target name="createCatalog" depends="makeClassesDir,configureReposStorage">
    <antcall target="createClasspathFile"/>
    <antcall target="compileCatalog"/>
    <antcall target="createMdrTestData"/>
    <antcall target="saveUnconfiguredCatalog"/>
    <antcall target="importConfig"/>
    <antcall target="backupCatalog"/>
    <antcall target="populateTestData"/>
    <!-- NOTE:  redundant backup is an intentional checkpoint; in case
    populateTestData fails, it can be debugged from restored empty catalog -->
    <antcall target="backupCatalog"/>
    <antcall target="createJaasConfig"/>
  </target>

  <!-- see http://pub.eigenbase.org/wiki/Jdbc4Transition -->
  <target name="mungeJdbc">
    <ac:if xmlns:ac="antlib:net.sf.antcontrib">
      <equals arg1="${ant.java.version}" arg2="1.5"/>
      <then>
        <copy todir="${farrago.jdbc4.gen.dir}">
          <fileset dir="${farrago.dir}/jdbc4" includes="*.java"
            excludes="Unwrappable*.java"/>
        </copy>
        <copy file="${farrago.dir}/jdbc4/Unwrappable14.java"
          tofile="${farrago.jdbc4.gen.dir}/Unwrappable.java"/>
        <copy file="${farrago.dir}/jdbc4/UnwrappableRJConnection14.java"
          tofile="${farrago.jdbc4.gen.dir}/UnwrappableRJConnection.java"/>
      </then>
      <else>
        <copy file="${farrago.dir}/jdbc4/Unwrappable16.java"
          tofile="${farrago.jdbc4.gen.dir}/Unwrappable.java"/>
        <copy file="${farrago.dir}/jdbc4/UnwrappableRJConnection16.java"
          tofile="${farrago.jdbc4.gen.dir}/UnwrappableRJConnection.java"/>
      </else>
    </ac:if>
  </target>

  <target name="createCatalogIfNotUptodate" depends="checkCatalogUptodate"
      unless="catalog.uptodate">
    <antcall target="createCatalog"/>
  </target>

  <!-- creates ReposStorage.properties from a default template unless
       it already exists -->
  <target name="configureReposStorage" unless="ReposStorage.configured">
    <!-- Does nothing if the file already exists.  See switchTo* targets. -->
    <copy file="${farrago.catalog.dir}/templates/HsqldbHibernateRepos.properties"
      tofile="${farrago.ReposStorage.propfile}">
      <filterchain>
        <tokenfilter>
          <replacestring from="{SCHEMA}" to="${farrago.catalog.schema}"/>
        </tokenfilter>
      </filterchain>
    </copy>
  </target>

  <!-- creates ReposStorage.properties from the default Postgres+Netbeans
       template -->
  <target name="switchToPsqlReposStorage">
    <copy file="${farrago.catalog.dir}/templates/PostgresRepos.properties"
      tofile="${farrago.ReposStorage.propfile}" overwrite="true">
      <filterchain>
        <tokenfilter>
          <replacestring
            from="jdbc:postgresql://localhost/test"
            to="jdbc:postgresql://localhost/${farrago.catalog.schema}"/>
        </tokenfilter>
      </filterchain>
    </copy>
  </target>

  <!-- creates ReposStorage.properties from the default Mysql+Hibernate
       template -->
  <target name="switchToMysqlHibernateReposStorage">
    <copy file="${farrago.catalog.dir}/templates/MysqlHibernateRepos.properties"
      tofile="${farrago.ReposStorage.propfile}" overwrite="true">
      <filterchain>
        <tokenfilter>
          <replacestring from="{SCHEMA}" to="${farrago.catalog.schema}"/>
        </tokenfilter>
      </filterchain>
    </copy>
  </target>

  <!-- creates ReposStorage.properties from the default HSQLDB+Hibernate
       template -->
  <target name="switchToHsqldbHibernateReposStorage">
    <copy file="${farrago.catalog.dir}/templates/HsqldbHibernateRepos.properties"
      tofile="${farrago.ReposStorage.propfile}" overwrite="true">
      <filterchain>
        <tokenfilter>
          <replacestring from="{SCHEMA}" to="${farrago.catalog.schema}"/>
        </tokenfilter>
      </filterchain>
    </copy>
  </target>

  <!-- creates ReposStorage.properties from the default
       template (which happens to be Hibernate+HSQLDB) -->
  <target name="switchToDefaultReposStorage">
    <antcall target="switchToHsqldbHibernateReposStorage"/>
  </target>

  <!-- creates ReposStorage.properties from the default HSQLDB+Netbeans
       template -->
  <target name="switchToHsqldbReposStorage">
    <copy file="${farrago.catalog.dir}/templates/HsqldbRepos.properties"
      tofile="${farrago.ReposStorage.propfile}" overwrite="true"/>
  </target>

  <!-- configures the Hibernate second level cache, if necessary -->
  <target name="configureCatalogCache">
    <farrago.setReposProvider/>

    <ac:if xmlns:ac="antlib:net.sf.antcontrib">
      <equals arg1="${farrago.enki.provider}" arg2="ENKI_HIBERNATE"/>
      <then>
        <copy 
            file="${farrago.catalog.dir}/templates/EnkiEhCache.xml"
            tofile="${farrago.classes.dir}/FarragoEhCache.xml"/>
      </then>
    </ac:if>
  </target>

  <target name="compileCatalog"
    depends="cleanCatalog,generateSqlTestWrapper,createRepository"/>

  <!-- creates the plugin/jaas.config file from template -->
  <target name="createJaasConfig">
    <copy file="${farrago.plugin.dir}/templates/jaas.config.tmpl"
      tofile="${farrago.plugin.dir}/jaas.config">
      <filterset>
        <filter token="FARRAGO_LOGIN_MODULE" value="net.sf.farrago.test.FarragoMockLoginModule"/>
      </filterset>
    </copy>
  </target>

  <!-- initialize catalog repository -->
  <target name="createRepository"
    depends="configureTrace, convertExtMetamodel, configureCatalogCache">
    <mkdir dir="${farrago.catalog.dir}"/>
    <mkdir dir="${farrago.catalog.src.dir}"/>
    <farrago.synthesizeMetamodel
      extMofBasename="ExtModel"
      extPresent=""
      xmiDir="${farrago.xmi.dir}"/>
    <farrago.mdrFork target="forked_generateMetamodelCode"/>
    <farrago.javaCompile
      srcdir="${farrago.catalog.src.dir}"
      destdir="${farrago.catalog.src.dir}"
      classpathref="farrago.3p.classpath">
      <include name="**/*.java"/>
    </farrago.javaCompile>

    <ac:if xmlns:ac="antlib:net.sf.antcontrib">
      <equals arg1="${farrago.enki.provider}" arg2="ENKI_HIBERNATE"/>
      <then>
        <farrago.mdrFork target="forked_configureMetamodelSchema"/>
      </then>
    </ac:if>

    <farrago.mdrFork target="forked_importMetamodel"/>
    <farrago.mdrFork target="forked_createCatalogRepository"/>
    <antcall target="compile.saffron.deps"/>
    <antcall target="generateMetadataFactory"/>
    <antcall target="all"/>
  </target>

  <target name="forked_generateMetamodelCode" depends="farrago.mdr_taskdef">
    <farrago.setReposProvider/>

    <mdr logConfigFile="${FarragoMdrBuildTrace.properties}">
      <mapJava
        file="${FarragoMetamodel.xmi}"
        extent="FarragoMetamodel"
        dir="${farrago.catalog.src.dir}"
        generatorClass="${farrago.enki.generator}"/>
    </mdr>

    <delete quiet="true">
      <fileset dir="." includes="mdr.bt?"/>
    </delete>
  </target>

  <target name="forked_configureMetamodelSchema" depends="farrago.mdr_taskdef">
    <farrago.setReposProvider/>

    <mkdir dir="${farrago.catalog.sql.dir}"/>

    <mdr
        propertiesFile="${farrago.ReposStorage.propfile}"
        logConfigFile="${FarragoMdrBuildTrace.properties}">
      <propertyset>
        <propertyref name="FARRAGO_CATALOG_DIR"/>
      </propertyset>
      <exportSchema
        mode="model"
        dir="${farrago.catalog.src.dir}"
        extent="FarragoMetamodel"/>
      <applyTablePrefix output="${farrago.catalog.sql.dir}">
        <fileset dir="${farrago.catalog.src.dir}">
          <include name="**/*.sql"/>
        </fileset>
      </applyTablePrefix>
    </mdr>

    <property 
        file="${farrago.ReposStorage.propfile}"
        prefix="gensch"/>

    <echo>
      Configuring repository schema at:
      ${gensch.net.sf.farrago.dev.connection.schema.url}
    </echo>
    <sql
        driver="${gensch.net.sf.farrago.dev.connection.driver_class}"
        url="${gensch.net.sf.farrago.dev.connection.schema.url}"
        userid="${gensch.net.sf.farrago.dev.connection.username}"
        password="${gensch.net.sf.farrago.dev.connection.password}"
        classpathref="farrago.3p.classpath">
      <!-- Ant will alphaebtize if these are in the same fileset. 
           Keep provider.sql first, since it logically belongs first. -->
      <fileset dir="${farrago.catalog.sql.dir}">
        <include name="**/provider.sql"/>
      </fileset>
      <fileset dir="${farrago.catalog.sql.dir}">
        <include name="**/create.sql"/>
      </fileset>
    </sql>
  </target>

  <target name="importMetamodel">
    <farrago.mdrFork target="forked_importMetamodel"/>
  </target>

  <target name="forked_importMetamodel" depends="farrago.mdr_taskdef">
    <farrago.setReposProvider/>

    <mdr
        propertiesFile="${farrago.ReposStorage.propfile}"
        logConfigFile="${FarragoMdrBuildTrace.properties}">
      <propertyset>
        <propertyref name="FARRAGO_CATALOG_DIR"/>
      </propertyset>
      <createExtent name="FarragoMetamodel"/>
      <importXmi
        file="${FarragoMetamodel.xmi}"
        extent="FarragoMetamodel"/>
    </mdr>
  </target>

  <target name="forked_createCatalogRepository" depends="farrago.mdr_taskdef">
    <mdr 
        propertiesFile="${farrago.ReposStorage.propfile}"
        logConfigFile="${FarragoMdrBuildTrace.properties}">
      <propertyset>
        <propertyref name="FARRAGO_CATALOG_DIR"/>
      </propertyset>
      <createExtent
        name="FarragoCatalog"
        extent="FarragoMetamodel"
        package="Farrago"/>
      <writeDTD
        file="${farrago.xmi.dir}/FarragoCatalog.dtd"
        extent="FarragoCatalog"/>
    </mdr>
  </target>

  <!-- generate developer configuration file and import it -->
  <target name="importConfig">
    <copy file="${FarragoConfTemplate.xmi}"
      tofile="${FarragoConf.xmi}" overwrite="true"/>

    <antcall target="copyFennelResources"/>

    <replace file="${FarragoConf.xmi}">
      <replacefilter token="@databaseInitSize@" value="${fennel.databaseInitSize}"/>
      <replacefilter token="@tempInitSize@" value="${fennel.tempInitSize}"/>
      <replacefilter token="@checkpointInterval@" value="${fennel.checkpointInterval}"/>
      <replacefilter token="@cachePageSize@" value="${fennel.cachePageSize}"/>
      <replacefilter token="@cachePagesMax@" value="${fennel.cachePagesMax}"/>
      <replacefilter token="@cachePagesInit@" value="${fennel.cachePagesInit}"/>
      <replacefilter token="@groupCommitInterval@" value="${fennel.groupCommitInterval}"/>
      <replacefilter token="@fennel.disabled@" value="${fennel.disabled}"/>
      <replacefilter token="@resourceDir@" value="$${FARRAGO_HOME}/catalog/fennel"/>
      <replacefilter token="@jniHandleTraceFile@" value="${trace.fennel.handles}"/>
      <replacefilter token="@calcVirtualMachine@" value="CALCVM_AUTO"/>
    </replace>
    <farrago.mdrFork target="forked_importConfig"/>
  </target>

  <!-- set up the default trace configuration file -->
  <target name="configureTrace">
    <mkdir dir="${farrago.trace.dir}"/>
    <farrago.configureTrace
      propFile="${FarragoTrace.properties}" logFile="${FarragoTrace.log}"/>
    <farrago.configureTrace
      propFile="${FarragoMdrBuildTrace.properties}" logFile="${FarragoMdrBuildTrace.log}"/>
  </target>

  <target name="forked_importConfig" depends="farrago.mdr_taskdef">
    <mdr
        propertiesFile="${farrago.ReposStorage.propfile}"
        logConfigFile="${FarragoMdrBuildTrace.properties}">
      <propertyset>
        <propertyref name="FARRAGO_CATALOG_DIR"/>
      </propertyset>
      <importXmi
        file="${FarragoConf.xmi}"
        extent="FarragoCatalog"/>
    </mdr>
  </target>

  <!-- write initial metadata to catalog -->
  <target name="populateCatalog">
    <farrago.javaExec classpathref="farrago.run.classpath"
      classname="net.sf.farrago.db.FarragoDatabase"/>
  </target>

  <!-- write sample schema to catalog -->
  <target name="populateTestData" depends="populateCatalog,populateTestSchema"/>

  <!-- determine list of all SQL scripts to run during catalog init -->
  <target name="determineInitSql" >
    <farrago.setReposProvider/>

    <ac:if xmlns:ac="antlib:net.sf.antcontrib">
      <equals arg1="${farrago.enki.provider}" arg2="ENKI_HIBERNATE"/>
      <then>
        <copy todir="${farrago.initsql.dir}" overwrite="true">
          <fileset dir="${farrago.initsql.dir}/templates">
            <include name="*.hibernate.tmpl"/>
          </fileset>
          <mapper type="glob" from="*.hibernate.tmpl" to="*"/>
        </copy>
      </then>
      <else>
        <copy todir="${farrago.initsql.dir}" overwrite="true">
          <fileset dir="${farrago.initsql.dir}/templates">
            <include name="*.default.tmpl"/>
          </fileset>
          <mapper type="glob" from="*.default.tmpl" to="*"/>
        </copy>
      </else>
    </ac:if>
          

    <filelist dir="${farrago.initsql.dir}" id="filelist.initsql"
      files="createStorageWrappers.sql,createReposStorageServers.sql,createSqljSchema.sql,createJdbcViews.sql,createSalesSchema.sql,createMgmtViews.sql"/>
    <pathconvert property="filelist.initsql" refid="filelist.initsql"
      pathsep="${line.separator}" dirsep="${file.separator}" />
  </target>

  <target name="populateTestSchema" depends="determineInitSql">
    <junit printsummary="yes" fork="yes" haltonerror="yes" haltonfailure="yes"
      tempdir="${testlog.dir}">
      <classpath refid="farrago.sqlline.classpath"/>
      <jvmarg line="${assertions.jvmarg}"/>
      <jvmarg line="&FarragoSqlLineProps;"/>
      <sysproperty key="net.sf.farrago.fileset.unitsql"
        value="${filelist.initsql}"/>
      <formatter type="plain"/>
      <formatter type="xml"/> <!-- for integration builds -->
      <test todir="${testlog.dir}" name="net.sf.farrago.test.FarragoSqlTest" />
    </junit>
  </target>

  <!-- save the unconfigured catalog contents -->
  <target name="saveUnconfiguredCatalog">
    <farrago.backupCatalog
      backupDir="${farrago.catalog.unconfigured.dir}"
      catalogOnly="true"/>

    <antcall target="exportCatalog"/>
    <copy
      todir="${farrago.catalog.unconfigured.dir}" 
      file="${farrago.xmi.dir}/FarragoCatalogExport.xmi"/>
  </target>

  <!-- back up the current catalog contents -->
  <target name="backupCatalog">
    <farrago.backupCatalog/>
  </target>

  <!-- restore catalog from backup -->
  <target name="restoreCatalog" depends="cleanCatalogData">
    <farrago.restoreCatalog/>
  </target>

  <!-- delete the catalog and everything generated for it -->
  <target name="cleanCatalog" depends="clean,cleanCatalogData">
    <delete file="${FarragoExtMetamodel.xmi}"/>
    <delete file="${FarragoExtMetamodelSansDiagrams.xmi}"/>
    <delete file="${FarragoExtMetamodelTransformed.xmi}"/>
    <delete file="${FarragoMetamodel.xmi}"/>
    <delete file="${FarragoMetamodelUnresolved.xmi}"/>
    <delete file="${farrago.xmi.dir}/FarragoCatalog.dtd"/>
    <delete
      file="${farrago.src.dir}/net/sf/farrago/FarragoMetadataFactory.java"/>
    <delete
      file="${farrago.src.dir}/net/sf/farrago/FarragoMetadataFactoryImpl.java"/>
    <delete dir="${farrago.catalog.src.dir}"/>
    <delete file="${FarragoSqlTestWrapper.java}"/>
    <delete dir="${farrago.catalog.dir}/fennel"/>
    <delete file="${FarragoMdrBuildTrace.log}"/>
    <delete quiet="true">
      <fileset dir="${farrago.jdbc4.gen.dir}" includes="*.java"/>
    </delete>
  </target>

  <!-- delete catalog data only -->
  <target name="cleanCatalogData">
    <farrago.cleanCatalog dropStorage="true"/>
  </target>

  <target name="exportCatalog">
    <farrago.mdrFork target="forked_exportCatalog"/>
  </target>

  <target name="forked_exportCatalog" depends="farrago.mdr_taskdef">
    <mdr
        propertiesFile="${farrago.ReposStorage.propfile}"
        logConfigFile="${FarragoMdrBuildTrace.properties}">
      <propertyset>
        <propertyref name="FARRAGO_CATALOG_DIR"/>
      </propertyset>
      <exportXmi
        file="${farrago.xmi.dir}/FarragoCatalogExport.xmi"
        extent="FarragoCatalog"
        xmiVersion = "1.2"/>
    </mdr>
  </target>

  <target name="exportMetamodel">
    <farrago.mdrFork target="forked_exportMetamodel"/>
  </target>

  <target name="forked_exportMetamodel" depends="farrago.mdr_taskdef">
    <mdr
        propertiesFile="${farrago.ReposStorage.propfile}"
        logConfigFile="${FarragoMdrBuildTrace.properties}">
      <propertyset>
        <propertyref name="FARRAGO_CATALOG_DIR"/>
      </propertyset>
      <exportXmi
        file="${farrago.xmi.dir}/FarragoMetamodelExport.xmi"
        extent="FarragoMetamodel"
        xmiVersion = "1.2"/>
    </mdr>
  </target>

  <target name="convertExtMetamodel">
    <farrago.extractArgoModel
      umlFile="${FarragoExtMetamodel.uml}"
      umlBasename="FarragoExtMetamodel"
      mofBasename="FarragoExtMetamodel"
      xmiDir="${farrago.xmi.dir}"/>
    <xslt style="${farrago.xmi.dir}/transformFEM.xsl"
      in="${FarragoExtMetamodel.xmi}"
      out="${FarragoExtMetamodelTransformed.xmi}" />
    <replace file="${FarragoExtMetamodelTransformed.xmi}"
      token="org.omg.xmi.namespace.Model" value="omg.org/mof.Model/1.3" />
  </target>

  <target name="checkResourceUptodate">
    <!--
         Set jdbc.url.port.default in customBuild.properties to
         override JDBC listener port.
    -->
    <farrago.configureReleaseProperties
        file="${farrago.classes.dir}/FarragoRelease.properties"/>

    <!-- REVIEW: SWZ: 10/4/2005: We should also check the locale-specific
         properties files generated by resgen to see that they're up-to-date.
         However, there doesn't seem to be an Ant mapper that maps
         FooResource.xml to FooResource*.properties and I don't want to
         enumerate the locales here.  Checking just FooResource.properties
         should do for now. -->
    <condition property="resource.uptodate">
      <and>
        <uptodate
          srcfile="${farrago.resource.dir}/FarragoResource.xml"
          targetfile="${farrago.resource.dir}/FarragoResource.java"/>
        <uptodate
          srcfile="${farrago.resource.dir}/FarragoResource.xml"
          targetfile="${farrago.resource.properties.dir}/FarragoResource.properties"/>
        <uptodate
          srcfile="${farrago.resource.dir}/FarragoInternalQuery.xml"
          targetfile="${farrago.resource.dir}/FarragoInternalQuery.java"/>
        <uptodate
          srcfile="${farrago.resource.dir}/FarragoInternalQuery.xml"
          targetfile="${farrago.resource.properties.dir}/FarragoInternalQuery.properties"/>
        <uptodate
          srcfile="${eigenbase.resource.dir}/EigenbaseResource.xml"
          targetfile="${eigenbase.resource.dir}/EigenbaseResource.java"/>
        <uptodate
          srcfile="${eigenbase.resource.dir}/EigenbaseResource.xml"
          targetfile="${eigenbase.resource.properties.dir}/EigenbaseResource.properties"/>
      </and>
    </condition>
  </target>

  <target name="generateResources"
    depends="makeClassesDir,checkResourceUptodate,copyFennelResources"
    unless="resource.uptodate">
    <!-- Exception classes need to exist for reflection -->
    <farrago.javaCompile
      srcdir="${farrago.src.dir}"
      destdir="${farrago.classes.dir}"
      classpathref="farrago.3p.classpath">
      <include name="**/EigenbaseException.java" />
      <include name="**/EigenbaseContextException.java" />
      <include name="**/EigenbaseFeatureException.java" />
      <include name="**/SqlValidatorException.java" />
    </farrago.javaCompile>
    <taskdef name="resgen" classname="org.eigenbase.resgen.ResourceGenTask">
      <classpath refid="farrago.run.classpath"/>
    </taskdef>
    <resgen
      srcdir="${farrago.src.dir}"
      destdir="${farrago.src.dir}"
      resdir="${farrago.classes.dir}"
      style="functor"
      locales="en_US">
      <include name="net/sf/farrago/resource/FarragoResource.xml"/>
    </resgen>
    <resgen
      srcdir="${farrago.src.dir}"
      destdir="${farrago.src.dir}"
      resdir="${farrago.classes.dir}"
      style="functor"
      locales="en_US">
      <include name="net/sf/farrago/resource/FarragoInternalQuery.xml"/>
    </resgen>
    <resgen
      srcdir="${farrago.src.dir}"
      destdir="${farrago.src.dir}"
      resdir="${farrago.classes.dir}"
      style="functor"
      locales="en_US">
      <include name="org/eigenbase/resource/EigenbaseResource.xml"/>
    </resgen>
  </target>

  <target name="checkFennelResourceUptodate">
    <condition property="resource.fennel.uptodate">
      <uptodate>
        <srcfiles
          dir="${fennel.dir}/common"
          includes="*.properties"/>
        <regexpmapper
          from="(.*)\.properties"
          to="${farrago.catalog.dir}/fennel/\1.properties"/>
      </uptodate>
    </condition>
  </target>

  <target
    name="copyFennelResources"
    depends="checkFennelResourceUptodate"
    unless="resource.fennel.uptodate">

    <mkdir dir="${farrago.catalog.dir}/fennel"/>
    <copy todir="${farrago.catalog.dir}/fennel" preservelastmodified="true">
      <fileset dir="${fennel.dir}/common" includes="*.properties"/>
    </copy>
  </target>

  <target name="checkParserUptodate">
    <uptodate property="sqlParser.uptodate"
      targetfile="${farrago.parser.sql.dir}/impl/SqlParserImpl.java">
      <srcfiles dir="${farrago.parser.sql.dir}">
        <include name="Parser.jj"/>
        <include name="CommonParser.jj"/>
      </srcfiles>
    </uptodate>
    <uptodate property="parser.uptodate"
      targetfile="${farrago.parser.ddl.dir}/impl/FarragoParserImpl.java">
      <srcfiles refid="farrago.parser.ddl"/>
      <srcfiles refid="farrago.parser.common.ddl"/>
      <srcfiles refid="farrago.parser.common.sql"/>
    </uptodate>
    <uptodate property="lurqlParser.uptodate"
      targetfile="${lurql.parser.dir}/LurqlParser.java">
      <srcfiles dir="${lurql.parser.dir}">
        <include name="LurqlParser.jj"/>
      </srcfiles>
    </uptodate>
  </target>

  <target name="checkCatalogUptodate">
    <uptodate property="catalog.uptodate"
      targetfile="${farrago.dir}/catalog/java/net/sf/farrago/FarragoPackage.java">
      <srcfiles dir="${farrago.dir}/catalog/xmi">
        <include name="FarragoExtMetamodel.uml"/>
        <include name="*.xsl"/>
      </srcfiles>
    </uptodate>
  </target>

  <!-- Generate the DDL parser. Generated files are:
       TokenMgrError.java, ParseException.java,
       JavaCharStream.java, Token.java -->
  <target name="ddlParser" depends="checkParserUptodate"
    unless="parser.uptodate">
    <farrago.generateParser
      combined="${farrago.parser.ddl.dir}/impl/CombinedParser.jj">
      <components>
        <fileset refid="farrago.parser.ddl"/>
        <fileset refid="farrago.parser.common.ddl"/>
        <fileset refid="farrago.parser.common.sql"/>
      </components>
    </farrago.generateParser>
  </target>

  <target name="lurqlParser" depends="checkParserUptodate"
    unless="lurqlParser.uptodate">
    <javacc
      target="${lurql.parser.dir}/LurqlParser.jj"
      javacchome="${javacc.dir}"/>
  </target>

  <!-- Generate the SQL parser. Generated files are:
       TokenMgrError.java, ParseException.java,
       JavaCharStream.java, Token.java, ASCII_UCodeESC_CharStream.java -->
  <target name="sqlParser" depends="checkParserUptodate"
    unless="sqlParser.uptodate">
    <farrago.generateParser
      combined="${farrago.parser.sql.dir}/impl/CombinedParser.jj">
      <components>
        <filelist dir="${farrago.parser.sql.dir}" files="Parser.jj"/>
        <fileset refid="farrago.parser.common.sql"/>
      </components>
    </farrago.generateParser>
  </target>

  <target name="jjDoc" description="Converts parser to human-readable BNF form">
    <jjdoc
      target="${farrago.parser.sql.dir}/impl/CombinedParser.jj"
      outputfile="doc/combinedParserBnf.html"
      javacchome="${javacc.dir}"/>
    <jjdoc
      target="${farrago.parser.ddl.dir}/impl/CombinedParser.jj"
      outputfile="doc/combinedDdlParserBnf.html"
      javacchome="${javacc.dir}"/>
  </target>

  <!-- run all JUnit test cases (or a single test case chosen with -->
  <!-- property junit.class, normally from script junitSingle) -->
  <!-- MaxPermSize setting is required to prevent PermGen space OOM's -->
  <target name="junit" depends="cleanTestLogs">
    <farrago.antFork target="forked_junit" classpathref="test.classpath">
      <jvmargs>
        <jvmarg line="-Xmx512m"/>
        <jvmarg line="-Xss1536k"/>
        <jvmarg line="-XX:MaxPermSize=256m"/>
        <jvmarg line="${assertions.jvmarg}"/>
        <jvmarg line="&FarragoSqlLineProps;"/>
        <syspropertyset>
          <propertyref builtin="commandline"/>
        </syspropertyset>
      </jvmargs>
    </farrago.antFork>
    <delete file="${FarragoTrace.log}.lck"/>
  </target>

  <target name="forked_junit">
    <farrago.runTests>
      <testfileset>
        <fileset dir="${farrago.classes.dir}">
          <exclude name="**/test/regression/*Test.class"/>
          <exclude name="**/test/concurrent/*Test.class"/>
          <include name="**/*Test.class"/>
        </fileset>
      </testfileset>
      <junitargs>
        <sysproperty key="net.sf.farrago.fileset.unitsql"
          value="${fileset.unitsql}"/>
        <sysproperty key="org.eigenbase.fileset.unitlurql"
          value="${fileset.unitlurql}"/>
      </junitargs>
    </farrago.runTests>
  </target>

  <!-- ************** test ******************
  Split 'test' to 'test-only' and 'test-only-setup' so Emma can plugin a instr.
  -->

  <target name="test" depends="test-only-setup,test-only">
  </target>

  <target name="test-only-setup">
    <antcall target="checkTrace"/>
    <antcall target="checkOracle"/>
    <antcall target="cleanExamples"/>
    <antcall target="createCatalog"/>
    <antcall target="buildExamples"/>
    <antcall target="buildJdbcPlugin"/>
  </target>

  <target name="test-only">
    <antcall target="testRngPlugin"/>
    <antcall target="exportCatalog"/>
    <antcall target="testDmv"/>
    <antcall target="testMiniplanner"/>
    <antcall target="testMqlPlugin"/>
    <antcall target="junit"/>
    <antcall target="regressionWithoutBuild"/>
    <antcall target="testCleanup"/>
    <antcall target="compareCatalogExport"/>
    <antcall target="macker"/>
    <antcall target="checkSourceFilePreambles"/>
    <antcall target="checkJavadoc"/>
  </target>

  <target name="checkTrace">
    <property file="${FarragoTrace.properties}" prefix="TRACE"/>
    <ac:if xmlns:ac="antlib:net.sf.antcontrib">
      <equals arg1="${TRACE.net.sf.farrago.dynamic.level}" arg2="FINE"/>
      <then>
        <fail>
Trace net.sf.farrago.dynamic.level=FINE
will cause ant test to fail or run very slowly;
please disable it and try again.
        </fail>
      </then>
    </ac:if>
  </target>

  <target name="checkOracle">
    <ac:if xmlns:ac="antlib:net.sf.antcontrib">
      <and>
        <isset property="oracle.test"/>
        <not>
          <isset property="oracle.available"/>
        </not>
      </and>
      <then>
        <fail>
Oracle tests were requested via oracle.test, but Oracle is not available.
        </fail>
      </then>
    </ac:if>
  </target>

  <!-- run all regression test cases -->
  <target name="regression" depends="cleanTestLogs">
    <antcall target="regressionWithoutBuild"/>
  </target>

  <!-- run all regression test cases; -->
  <!-- for use only as a subtarget to avoid destroying test logs from junit -->
  <target name="regressionWithoutBuild">
    <farrago.antFork target="forked_regressionWithoutBuild"
      classpathref="test.classpath">
      <jvmargs>
        <jvmarg line="${assertions.jvmarg}"/>
        <jvmarg line="&FarragoSqlLineProps;"/>
        <syspropertyset>
          <propertyref builtin="commandline"/>
        </syspropertyset>
      </jvmargs>
    </farrago.antFork>
    <delete file="${FarragoTrace.log}.lck"/>
  </target>

  <target name="forked_regressionWithoutBuild">
    <farrago.runTests>
      <testfileset>
        <fileset dir="${farrago.classes.dir}">
          <include name="**/regression/*Test.class"/>
          <include name="**/concurrent/*Test.class"/>
        </fileset>
      </testfileset>
      <junitargs>
        <sysproperty key="net.sf.farrago.fileset.regressionsql"
          value="${fileset.regressionsql}"/>
        <sysproperty key="net.sf.farrago.fileset.concurrentsql"
          value="${fileset.concurrentsql}"/>
      </junitargs>
    </farrago.runTests>
  </target>

  <!-- NOTE:  these have to run forked in specific order -->
  <target name="testRngPlugin">
    <delete dir="${farrago.dir}/testgen/upgrade" quiet="true"/>
    <mkdir dir="${farrago.dir}/testgen/upgrade/backup"/>
    <farrago.runSqlTest
      file="${farrago.dir}/examples/rng/unitsql/createPreUpgrade.sql"/>
    <!-- backup pre-upgrade catalog -->
    <farrago.backupCatalog backupDir="${farrago.dir}/testgen/upgrade/backup"/>
    <farrago.runSqlTest
      file="${farrago.dir}/examples/rng/unitsql/installPlugin.sql"/>
    <farrago.runSqlTest
      file="${farrago.dir}/examples/rng/unitsql/testPlugin.sql"/>
    <!-- restore from pre-upgrade catalog -->
    <delete quiet="true">
      <fileset dir="${farrago.catalog.dir}"
        includes="*.dat,FarragoCatalogDump.xmi"/>
    </delete>
    <!-- Restore only the Fennel files and a catalog dump from before the
         plugin was installed. -->
    <copy todir="${farrago.catalog.dir}">
      <fileset dir="${farrago.dir}/testgen/upgrade/backup"
          includes="*.dat"/>
    </copy>
    <copy todir="${farrago.catalog.dir}">
      <fileset dir="${farrago.dir}/testgen/upgrade"
        includes="FarragoCatalogDump.xmi"/>
    </copy>
    <!-- this will import pre-upgrade catalog contents -->
    <farrago.runSqlTest
      file="${farrago.dir}/examples/rng/unitsql/verifyReplaceCatalog.sql"/>
  </target>

  <!-- For MQL, don't run the connected.sql test since it 
       requires an Internet connection -->
  <target name="testMqlPlugin">
    <farrago.runSqlTest
      file="${farrago.dir}/ext/mql/unitsql/disconnected.sql"/>
  </target>

  <!-- TODO:  verify actual .dot output -->
  <target name="testDmv">
    <farrago.runSqlTest
      file="${farrago.dir}/examples/dmv/test.sql"/>
  </target>

  <target name="testMiniplanner">
    <farrago.runSqlTest
      file="${farrago.dir}/examples/miniplan/unitsql/miniplan.sql"/>
  </target>

  <target name="testCleanup">
    <farrago.runSqlTest
      file="${farrago.dir}/initsql/testCleanup.sql"/>
  </target>

  <!-- if this task fails, it means some test has polluted the catalog -->
  <target name="compareCatalogExport">
    <farrago.compareCatalogExport
      log.dir="${testlog.dir}/CatalogLeak"
      export.file="${farrago.xmi.dir}/FarragoCatalogExport.xmi" />
  </target>

  <target name="generateTestSql" depends="compile">
    <farrago.javaExec classpathref="farrago.run.classpath"
      classname="org.eigenbase.test.SqlTestGen"/>
  </target>

  <!-- debug a JUnit test case; called from script junitDebug -->
  <target name="jswat.junit" depends="cleanTestLogs">
    <fail message="property junit.class not defined" unless="junit.class"/>
    <farrago.jswatDebug
      classpath="${farrago.sqlline.classpath}"
      sourcepath="${farrago.sourcepath}"
      classname="junit.textui.TestRunner">
      <jvmargs>
        <arg value="-Dnet.sf.farrago.fileset.unitsql=${fileset.unitsql}"/>
        <arg value="-Dorg.eigenbase.fileset.unitlurql=${fileset.unitlurql}"/>
        <arg line="&FarragoSqlLineProps;"/>
      </jvmargs>
      <programargs>
        <arg value="${junit.class}"/>
      </programargs>
    </farrago.jswatDebug>
  </target>

  <!-- Generate the Fennel C++ proxy classes for FEM -->
  <target name="generateFemCpp" depends="compile">
    <ant antfile="p4fem.xml"/>
    <javah
      classpathref="farrago.run.classpath"
      class="net.sf.farrago.fennel.FennelStorage"
      outputFile="${open.dir}/fennel/farrago/NativeMethods.h"/>
    <farrago.javaExec
      classname="net.sf.farrago.catalog.codegen.ProxyGen"
      classpathref="farrago.run.classpath">
      <arg value="${fennel.dir}/farrago/FemGeneratedClasses.h"/>
      <arg value="${fennel.dir}/farrago/FemGeneratedMethods.h"/>
      <arg value="${fennel.dir}/common/FemGeneratedEnums.h"/>
      <arg value="FEM.Fennel"/>
      <arg value="Fem"/>
    </farrago.javaExec>


    <!-- not strictly part of fem, but it is JNI code -->
<!--    <javah
      classpathref="farrago.run.classpath"
      class="net.sf.farrago.fennel.FennelPseudoUuidGenerator"
      outputFile="${open.dir}/fennel/farrago/JniPseudoUuid.h"/> -->
  </target>

  <!-- Generate FarragoMetadataFactory -->
  <target name="generateMetadataFactory">
    <antcall target="extractFemTimestamp"/>
    <property file="${farrago.xmi.dir}/femTimestamp.txt"/>
    <!-- FactoryGen.class needed for code generation -->
    <farrago.javaCompile
      srcdir="${farrago.src.dir}"
      destdir="${farrago.classes.dir}"
      classpathref="farrago.build.classpath">
      <include name="**/FactoryGen.java" />
    </farrago.javaCompile>
    <farrago.javaExec
      classname="net.sf.farrago.catalog.codegen.FactoryGen"
      classpathref="farrago.run.classpath">
      <arg
        value="${farrago.src.dir}/net/sf/farrago/FarragoMetadataFactory.java"/>
      <arg
        value="${farrago.src.dir}/net/sf/farrago/FarragoMetadataFactoryImpl.java"/>
      <arg value="net.sf.farrago"/>
      <arg value="FarragoMetadataFactory"/>
      <arg value="FarragoMetadataFactoryImpl"/>
      <arg value="net.sf.farrago.FarragoPackage"/>
      <arg value="FarragoCatalog"/>
      <arg value="${fem.timestamp}"/>
    </farrago.javaExec>
  </target>

  <target name="extractFemTimestamp">
    <farrago.extractModelTimestamp umlFile="${FarragoExtMetamodel.uml}"
      outFile="${farrago.xmi.dir}/femTimestamp.txt"/>
  </target>

  <!-- Debugging target for listing repository extents -->
  <target name="printRepositoryExtents" depends="farrago.mdr_taskdef">
    <mdr 
        propertiesFile="${farrago.ReposStorage.propfile}"
        logConfigFile="${FarragoMdrBuildTrace.properties}">
      <propertyset>
        <propertyref name="FARRAGO_CATALOG_DIR"/>
      </propertyset>
      <printExtentNames/>
    </mdr>
  </target>

  <target name="macker">
    <path id="macker.classpath">
      <fileset dir="${macker.dir}/lib" includes="*.jar"/>
      <fileset dir="${macker.dir}/build" includes="macker.jar"/>
    </path>
    <taskdef name="macker"
      classname="net.innig.macker.ant.MackerAntTask"
      classpathref="macker.classpath"/>

    <macker maxMessages="10">
      <rules dir="${farrago.src.dir}" includes="**/*macker*.xml" />
      <classes dir="${farrago.classes.dir}">
        <include name="**/*.class" />
      </classes>
    </macker>
  </target>

  <target name="findbugs">
    <taskdef name="findbugs"
      classname="edu.umd.cs.findbugs.anttask.FindBugsTask" />
    <findbugs home="${findbugs.dir}" 
      jvmargs="-Xms1024m -Xmx1024m"
      output="emacs" 
      outputFile="findbugs.txt">
      <sourcePath path="${farrago.src.dir}"/>
      <auxClasspath path="${farrago.sqlline.classpath}"/>
      <class location="${farrago.classes.dir}"/>
    </findbugs>
  </target>

  <!-- Verify that all source files have the required headers -->
  <!-- TODO:  see if this works in non-Linux environments -->
  <target name="checkSourceFilePreambles">
    <exec os="Linux" dir="${farrago.dir}" failonerror="true"
      executable="${fennel.dir}/build/checkPreambleFarrago.sh">
    </exec>
  </target>

  <!-- Ensure that javadoc has no warnings/errors. -->
  <target name="checkJavadoc" unless="codecov.build">
    <record name="javadoc-complaints.log" action="start" 
      emacsmode="true" loglevel="warn"/>
    <antcall target="javadoc"/>
    <record name="javadoc-complaints.log" action="stop"/>
    <loadfile srcFile="javadoc-complaints.log" property="javadoc.complaints">
      <filterchain>
        <filterreader classname="org.apache.tools.ant.filters.LineContains">
          <param type="negate" value="true"/>
          <param type="contains" value="Error fetching URL"/>
        </filterreader>
        <striplinebreaks />
      </filterchain>
    </loadfile>
    <fail if="javadoc.complaints"
        message="Javadoc reported warnings or errors; see javadoc-complaints.log for details"/>
    <delete file="javadoc-complaints.log"/>
    <!-- Save disk space since we're just checking. -->
    <antcall target="cleanJavadoc"/>
  </target>

  <target name="cleanJavadoc">
    <delete includeEmptyDirs="true" quiet="true">
      <fileset dir="${javadoc.dir}" includes="**/*"/>
    </delete>
  </target>

  <!-- Beautify Farrago source code.  This currently requires
       the commercial Triemax version of Jalopy, which needs to
       be installed manually under thirdparty/jalopy. -->
  <target name="jalopy">
    <taskdef name="jalopy"
      classname="com.triemax.JalopyTask">
      <classpath>
        <fileset dir="${jalopy.dir}/lib">
          <include name="*.jar"/>
        </fileset>
      </classpath>
    </taskdef>
    <jalopy backup="false" convention="${farrago.src.dir}/jalopy.xml" 
      threads="2" classpathref="farrago.jalopy.classpath" history="NONE" 
      force="true">
      <fileset dir="${farrago.src.dir}">
        <include name="**/*.java"/>
        <exclude name="org/eigenbase/inventory/**/*.java"/>
      </fileset>
    </jalopy>
  </target>

  <!-- generate Emacs tags -->
  <target name="etags">
    <farrago.createEmacsTags filesetPropertyName="fileset.taggable"/>
  </target>

  <!-- generate Farrago javadoc -->
  <target name="javadoc">
    <antcall target="cleanJavadoc"/>
    <!-- remove stray package.html files under classes to avoid 'multiple
         sources of package comments' errors -->
    <delete includeEmptyDirs="false" quiet="true">
      <fileset dir="${farrago.classes.dir}" includes="**/package.html"/>
    </delete>
    <mkdir dir="${javadoc.dir}"/>
    <antcall target="javadoc-with-or-without-ydoc"/>
  </target>

  <target name="javadoc-with-or-without-ydoc"
      depends="javadoc-with-ydoc,javadoc-without-ydoc"/>


  <!-- Generate javadoc using the yDoc doclet to generate UML
       diagrams.  To call this target, set ydoc.home to the root of
       your installation (e.g. "/usr/local/ydoc-2.2_03-jdk1.5"),
       obtain a license (free for open-source use) and place the
       license as ${ydoc.home}/resources/ydoc.license. -->
  <target name="javadoc-with-ydoc" if="ydoc.home">
    <property name="ps" value="${path.separator}"/>
    <javadoc
      maxmemory="1024m"
      private="true"
      destdir="${javadoc.dir}"
      source="${farrago.javasrc.version}"
      classpathref="farrago.javadoc.classpath">
      <tag dir="src" includes="customJavadocTags.txt"/>
      <packageset dir="${farrago.catalog.src.dir}">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.src.dir}">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/examples/plannerviz/src">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/examples/miniplan/src">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/ext/mql/src">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/examples/rng/src">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/examples/rng/catalog/java">
        <include name="**"/>
      </packageset>
      <link href="http://www.netbeans.org/download/dev/javadoc/org-netbeans-api-mdr"/>
      <link href="http://java.sun.com/products/jmi/jmi-1_0-fr-doc"/>
      <link href="http://java.sun.com/j2se/1.5.0/docs/api"/>
      <link href="http://www.junit.org/junit/javadoc/3.8.1"/>
      <link href="http://www.janino.net/javadoc"/>
      <link href="http://www.csg.is.titech.ac.jp/openjava/OpenJava_1.1/htdocs"/>
      <link href="${enki.dir}/javadoc"/>
      <doclet
          name="ydoc.doclets.YStandard"
          path="${ydoc.home}/lib/ydoc.jar${ps}${ydoc.home}/lib/class2svg.jar${ps}${ydoc.home}/resources${ps}${ydoc.home}/doc">
        <param name="-author"/>
        <param name="-generic"/>
        <param name="-umlautogen"/>
        <param name="-tag" value="y.precondition"/>
        <param name="-tag" value="y.postcondition"/>
        <param name="-tag" value="y.complexity"/>
        <param name="-tag" value="param"/>
        <param name="-tag" value="return"/>
        <param name="-tag" value="see"/>
        <param name="-tag" value="y.uml"/>
      </doclet>
    </javadoc>
  </target>

  <target name="javadoc-without-ydoc" unless="ydoc.home">
    <javadoc
      maxmemory="1024m"
      private="true"
      destdir="${javadoc.dir}"
      source="${farrago.javasrc.version}"
      classpathref="farrago.javadoc.classpath">
      <tag dir="src" includes="customJavadocTags.txt"/>
      <packageset dir="${farrago.catalog.src.dir}">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.src.dir}">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/examples/plannerviz/src">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/examples/miniplan/src">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/ext/mql/src">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/examples/rng/src">
        <include name="**"/>
      </packageset>
      <packageset dir="${farrago.dir}/examples/rng/catalog/java">
        <include name="**"/>
      </packageset>
      <link href="http://www.netbeans.org/download/dev/javadoc/org-netbeans-api-mdr"/>
      <link href="http://java.sun.com/products/jmi/jmi-1_0-fr-doc"/>
      <link href="http://java.sun.com/j2se/1.5.0/docs/api"/>
      <link href="http://www.junit.org/junit/javadoc/3.8.1"/>
      <link href="http://www.janino.net/javadoc"/>
      <link href="http://www.csg.is.titech.ac.jp/openjava/OpenJava_1.1/htdocs"/>
      <link href="${enki.dir}/javadoc"/>
    </javadoc>
  </target>

  <!-- create the documentation tarball -->
  <target name="buildDoc"
    depends="cleanExamples, createCatalog, buildExamples, javadoc, jjDoc">
    <delete file="${farrago.dir}/doc.tar" />
    <delete file="${farrago.dir}/doc.tar.gz" />
    <tar tarfile="${farrago.dir}/doc.tar">
      <tarfileset dir="${farrago.dir}" includes="doc/**" excludes="**/*.vsd"/>
    </tar>
    <gzip zipfile="${farrago.dir}/doc.tar.gz"
              src="${farrago.dir}/doc.tar" />
    <delete file="${farrago.dir}/doc.tar" />
  </target>

  <!-- run JSwat on sqlline in interactive mode -->
  <target name="jswat.sqlline" depends="all">
    <farrago.jswatDebug
      classpath="${farrago.sqlline.classpath}"
      sourcepath="${farrago.sourcepath}"
      classname="sqlline.SqlLine">
      <jvmargs>
        <arg line="&FarragoSqlLineProps;"/>
      </jvmargs>
      <programargs>
        <arg value="-u jdbc:farrago: -d net.sf.farrago.jdbc.engine.FarragoJdbcEngineDriver -n sa"/>
      </programargs>
    </farrago.jswatDebug>
  </target>

  <!-- Dump the file classpath.gen for use outside of ant -->
  <target name="createClasspathFile">
    <delete file="${file.classpath}" quiet="true"/>
    <concat destfile="${file.classpath}">cccp</concat>
    <replace file="${file.classpath}" token="cccp"
      value="${farrago.sqlline.classpath}"/>
  </target>
  <property name="file.classpath"
    location="${farrago.dir}/classpath.gen"/>

  <!-- Create an MDR repository for use by SQL/MED tests -->
  <target name="createMdrTestData" depends="farrago.mdr_taskdef">
    <delete quiet="true">
      <fileset dir="unitsql/ddl" includes="mdr.bt?"/>
    </delete>
    <mdr logConfigFile="${FarragoMdrBuildTrace.properties}">
      <storageProperty
        name="org.eigenbase.enki.implementationType" 
        value="NETBEANS_MDR"/>
      <storageProperty
        name="org.netbeans.mdr.persistence.Dir"
        value="${farrago.dir}/unitsql/ddl/mdr"/>

      <createExtent name="TestMof"/>
    </mdr>
  </target>

  <target name="testLeaks" depends="all,cleanTestLogs" >
    <farrago.javaExec classpathref="farrago.run.classpath"
      classname="net.sf.farrago.test.TestLeaks">
    </farrago.javaExec>
  </target>

  <target name="testLeaksJmp" depends="all,cleanTestLogs" >
    <farrago.javaExec classpathref="farrago.run.classpath"
      classname="net.sf.farrago.test.TestLeaks">
      <jvmarg line="-Xrunjmp:nomethods,nomonitors"/>
      <arg value="jmp"/>
    </farrago.javaExec>
  </target>

  <!-- run JSwat on Farrago as an RmiJdbc server -->
  <target name="jswat.server" depends="all">
    <farrago.jswatDebug
      classpath="${farrago.run.classpath}"
      sourcepath="${farrago.sourcepath}"
      classname="net.sf.farrago.server.FarragoServer">
      <jvmargs>
        <arg line="&FarragoProps;"/>
      </jvmargs>
    </farrago.jswatDebug>
  </target>

  <!-- verify that ReposStorage.properties is correctly configured
       for storage via JDBC -->
  <target name="verifyReposSqlStorage" depends="configureReposStorage">
    <farrago.setReposProvider/>

    <ac:if xmlns:ac="antlib:net.sf.antcontrib">
      <equals arg1="${farrago.enki.provider}" arg2="NETBEANS_MDR"/>
      <then>
        <loadproperties srcFile="${farrago.ReposStorage.propfile}">
          <filterchain>
            <tokenfilter>
              <replacestring
                from="MDRStorageProperty.org.netbeans.mdr.persistence."
                to=""/>
            </tokenfilter>
          </filterchain>
        </loadproperties>
        <sql
          driver="${jdbcimpl.driverClassName}"
          url="${jdbcimpl.url}"
          userid="${jdbcimpl.userName}"
          password="${jdbcimpl.password}"
          classpath="${farrago.3p.classpath}"
          rdbms="nonexistentSQL">
          <![CDATA[bogus]]>
        </sql>
        <echo message="Successfully connected to ${jdbcimpl.url}"/>
      </then>
    </ac:if>

    <ac:if xmlns:ac="antlib:net.sf.antcontrib">
      <equals arg1="${farrago.enki.provider}" arg2="ENKI_HIBERNATE"/>
      <then>
        <loadproperties srcFile="${farrago.ReposStorage.propfile}"/>
        <sql
          driver="${hibernate.connection.driver_class}"
          url="${hibernate.connection.url}"
          userid="${hibernate.connection.username}"
          password="${hibernate.connection.password}"
          classpath="${farrago.3p.classpath}"
          rdbms="nonexistentSQL">
          <![CDATA[bogus]]>
        </sql>
        <echo message="Successfully connected to ${hibernate.connection.url}"/>
      </then>
    </ac:if>
  </target>

  <target name="buildExamples" depends="compile">
    <ant antfile="examples/plannerviz/build.xml" inheritAll="false"/>
    <ant antfile="examples/rng/build.xml" target="createPlugin"
      inheritAll="false"/>
    <ant antfile="examples/miniplan/build.xml"
      inheritAll="false"/>
    <ant antfile="ext/mql/build.xml"
      inheritAll="false"/>
  </target>

  <target name="cleanExamples">
    <ant antfile="examples/plannerviz/build.xml" target="clean"
      inheritAll="false"/>
    <ant antfile="examples/rng/build.xml" target="clean"
      inheritAll="false"/>
    <ant antfile="examples/miniplan/build.xml" target="clean"
      inheritAll="false"/>
    <ant antfile="ext/mql/build.xml" target="clean"
      inheritAll="false"/>
  </target>

  <!-- Below is all experimental stuff for the user repository -->
  <!-- WARNING: With the introduction of Enki, these will not work unless
       the MDR provider is Netbeans, and even then it is untested.
       (SWZ, 2008-02-14) -->
  <property name="JdbcStorage.prefix"
    value="MDRStorageProperty.org.netbeans.mdr.persistence.jdbcimpl"/>

  <target name="createUserRepository">
    <farrago.antFork target="forked_createUserRepository"
      classpathref="createUserRepository.classpath">
      <jvmargs>
        <jvmarg line="${assertions.jvmarg}"/>
        <jvmarg line="&FarragoProps;"/>
        <sysproperty
          key="org.netbeans.mdr.storagemodel.StorageFactoryClassName"
          value="org.netbeans.mdr.persistence.jdbcimpl.JdbcStorageFactory"/>
        <sysproperty
          key="${JdbcStorage.prefix}.url"
          value="jdbc:farrago:"/>
        <sysproperty
          key="${JdbcStorage.prefix}.schemaName"
          value="MDR"/>
        <sysproperty
          key="${JdbcStorage.prefix}.userName"
          value="MDR"/>
        <sysproperty
          key="${JdbcStorage.prefix}.driverClassName"
          value="net.sf.farrago.jdbc.engine.FarragoJdbcEngineDriver"/>
        <sysproperty
          key="${JdbcStorage.prefix}.datatype.streamable"
          value="VARBINARY(10000)"/>
      </jvmargs>
    </farrago.antFork>
  </target>

  <target name="jswat.createUserRepository" depends="all">
    <farrago.jswatDebug
      classpath="${createUserRepository.classpath}"
      sourcepath="${farrago.sourcepath}"
      classname="org.apache.tools.ant.Main">
      <jvmargs>
        <arg value="-Dorg.netbeans.mdr.storagemodel.StorageFactoryClassName=org.netbeans.mdr.persistence.jdbcimpl.JdbcStorageFactory"/>
        <arg value="-D${JdbcStorage.prefix}.url=jdbc:farrago:"/>
        <arg value="-D${JdbcStorage.prefix}.userName=MDR"/>
        <arg value="-D${JdbcStorage.prefix}.schemaName=MDR"/>
        <arg value="-D${JdbcStorage.prefix}.driverClassName=net.sf.farrago.jdbc.engine.FarragoJdbcEngineDriver"/>
        <arg value="-D${JdbcStorage.prefix}.datatype.streamable=VARBINARY(10000)"/>
        <arg line="&FarragoProps;"/>
      </jvmargs>
      <programargs>
        <arg value="forked_createUserRepository"/>
      </programargs>
    </farrago.jswatDebug>
  </target>

  <target name="forked_createUserRepository" depends="farrago.mdr_taskdef">
    <mdr
        propertiesFile="${farrago.ReposStorage.propfile}"
        logConfigFile="${FarragoMdrBuildTrace.properties}">
      <propertyset>
        <propertyref name="FARRAGO_CATALOG_DIR"/>
      </propertyset>
      <createExtent name="FarragoMetamodel"/>
      <printExtentNames/>
      <importXmi
        file="${FarragoMetamodel.xmi}"
        extent="FarragoMetamodel"/>
      <printExtentNames/>
      <createExtent
        name="FarragoCatalog"
        extent="FarragoMetamodel"
        package="Farrago"/>
      <printExtentNames/>
      <importXmi
        file="${FarragoConf.xmi}"
        extent="FarragoCatalog"/>
    </mdr>
  </target>

  <!-- End experimental stuff for the user repository -->

  <!-- TODO 24-Sept-2005:  replace this with apt task from ant 1.7 -->
  <target name="generateInventoryReport" depends="compile">
    <pathconvert property="sources.gen"
      pathsep="${line.separator}" dirsep="${file.separator}">
      <path>
        <fileset dir="${farrago.src.dir}">
          <include name="**/*.java" />
        </fileset>
      </path>
    </pathconvert>
    <echo message="${sources.gen}" file="sources.gen"/>
    <exec dir="${farrago.dir}" failonerror="true"
      executable="${javahome.dir}/bin/apt">
      <arg value="-s"/>
      <arg value="${farrago.dir}/inventorys"/>
      <arg value="-nocompile"/>
      <arg value="-classpath"/>
      <arg pathref="farrago.sqlline.classpath"/>
      <arg value="-d"/>
      <arg value="${farrago.dir}/inventoryd"/>
      <arg value="-factory"/>
      <arg value="org.eigenbase.inventory.EigenbaseInventoryGenerator"/>
      <arg value="@sources.gen"/>
    </exec>
  </target>

  <target name="createEclipseProject">
    <pathconvert property="eclipse.libpath" refid="farrago.build.3p.classpath"
      pathsep="&quot;/&gt;&lt;classpathentry kind=&quot;lib&quot; path=&quot;"/>
    <copy file="${farrago.dir}/eclipse/farrago.project" overwrite="true"
        tofile="${farrago.dir}/.project">
    </copy>
    <copy file="${farrago.dir}/eclipse/farrago.classpath" overwrite="true"
        tofile="${farrago.dir}/.classpath">
      <filterset>
        <filter token="LIBPATH" value="${eclipse.libpath}"/>
      </filterset>
    </copy>
    <copy todir="${farrago.dir}/.settings" overwrite="true">
      <fileset dir="${farrago.dir}/eclipse/.settings"/>
    </copy>
  </target>

  <target name="generateSqlTestWrapper"
    description="Generate JUnit test wrappers for all unitsql scripts">
    <farrago.generateSqlTestWrapper
      filesetref="fileset.unitsql"
      outputfile="${FarragoSqlTestWrapper.java}"
      rootpath="${farrago.dir}${file.separator}"
      packagename="net.sf.farrago.test"
      classname="FarragoSqlTestWrapper"/>
  </target>

  <target name="cov">
    <antcall target="emmaClean"/>
    <antcall target="emmaTest"/>
    <antcall target="emmaReport"/>
  </target>

  <target name="emmaClean">
    <delete dir="${emma.farrago.classes.dir}" quiet="true"/>
    <delete quiet="true">
        <fileset dir="${farrago.dir}" includes="coverage.*"/>
        <fileset dir="${coverage.dir}"/>
    </delete>
    <mkdir dir="${coverage.dir}"/>
    <mkdir dir="${emma.farrago.classes.dir}"/>
  </target>

  <target name="emmaInstr">
    <mkdir dir="${emma.farrago.classes.dir}"/>
    <emma verbosity="verbose">
      <instr
        mode="copy"
        outdir="${emma.farrago.classes.dir}"
        metadatafile="${farrago.dir}/coverage.em"
        instrpath="${farrago.classes.dir}">
        <filter excludes="*_Stub*"/>
      </instr>
    </emma>
  </target>

  <target name="emmaTest">
    <antcall target="checkTrace"/>
    <antcall target="cleanExamples"/>
    <antcall target="createCatalog"/>
    <antcall target="buildExamples"/>
    <!-- since some classes get built in here, instrument at the last minute-->
    <antcall target="emmaInstr"/>
    <antcall target="testRngPlugin"/>
    <antcall target="exportCatalog"/>
    <antcall target="emmaJunit"/>
    <!-- comment out the following since I merged junit and regression in
    emmaJunit-->
    <!--    <antcall target="regressionWithoutBuild"/>-->
    <antcall target="testCleanup"/>
    <antcall target="compareCatalogExport"/>
    <antcall target="macker"/>
    <antcall target="checkSourceFilePreambles"/>
  </target>

  <target name="emmaReport">
    <emma verbosity="verbose">
      <report sourcepath="${farrago.src.dir}">
        <infileset dir="${farrago.dir}" includes="*.em, *.ec"/>

        <html outfile="${coverage.dir}/coverage.html"/>
        <xml outfile="${coverage.dir}/coverage.xml"/>
        <txt outfile="${coverage.dir}/coverage.txt"/>
      </report>
    </emma>
  </target>

<!-- combine junit and regression targets -->
  <target name="emma-forked_junit">
    <farrago.runTests>
      <testfileset>
        <fileset dir="${emma.farrago.classes.dir}">
<!--          <exclude name="**/test/regression/*Test.class"/>
          <exclude name="**/test/concurrent/*Test.class"/>-->
<!--          <include name="net/sf/farrago/test/FarragoQueryTest.class"/>-->
          <exclude name="**/*ServerTest.class"/>
          <include name="**/*Test.class"/>
        </fileset>
      </testfileset>
      <junitargs>
        <sysproperty key="net.sf.farrago.fileset.unitsql"
          value="${fileset.unitsql}"/>
        <sysproperty key="org.eigenbase.fileset.unitlurql"
          value="${fileset.unitlurql}"/>
        <sysproperty key="net.sf.farrago.fileset.regressionsql"
          value="${fileset.regressionsql}"/>
        <sysproperty key="net.sf.farrago.fileset.concurrentsql"
          value="${fileset.concurrentsql}"/>
      </junitargs>
    </farrago.runTests>
  </target>

  <target name="emmaJunit" depends="cleanTestLogs">
    <farrago.antFork target="emma-forked_junit" classpathref="emma.test.classpath">
      <jvmargs>
        <jvmarg line="${assertions.jvmarg}"/>
        <jvmarg line="&FarragoProps;"/>
        <syspropertyset>
          <propertyref builtin="commandline"/>
        </syspropertyset>
      </jvmargs>
    </farrago.antFork>
    <delete file="${FarragoTrace.log}.lck" quiet="true"/>
  </target>

</project>
