<?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="buildsource" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">

<!-- Set Properties -->


  <!-- User settings -->
  <property environment="env"/>
  <property file="local.properties"/>

  <property file="${user.home}/ant.properties"/>
  <!-- Set property lib dir -->
  <property name="properties.dir" value="${basedir}/tools/ant/properties"/>
  <!-- Significant dirs -->
  <property file="${properties.dir}/dirs.properties"/>
  <!-- Compiler settings -->
  <property file="${properties.dir}/sane${sanity}.properties"/>
  <!-- Public api -->
  <property file="${javadoctools.dir}/publishedapi.ant"/>

   <!-- You can override this property in local.properties to fetch from an alternative location -->
   <property name="javasedoc.url" value="https://docs.oracle.com/javase/9/docs/api"/>
   <property name="j2eedoc.url" value="https://docs.oracle.com/javaee/7/api"/>
   <property name="javasedoc.local" value="packageListLoc-se-9"/>
   <property name="j2eedoc.local" value="packageListLoc-j2ee-7"/>

<!-- These properties are used by the Release build process. -->
  <condition property="isWindows">
    <os family="windows"/>
  </condition>

  <condition property="isUnix">
    <not>
      <os family="windows"/>
    </not>
  </condition>

<!-- Testing properties -->

  <!-- Must set java.security.manager=allow for JDK 18 onward -->
  <condition property="mustAllowSecurityManager">
    <available classname="java.lang.runtime.ObjectMethods"/>
  </condition>

  <condition property="java.security.manager" value="allow">
    <and>
      <isset property="mustAllowSecurityManager"/>
    </and>
  </condition>

  <target name="z"><echo message="java.security.manager = ${java.security.manager}"/></target>

<!-- <echoproperties/> -->

<!-- Targets -->
  <target
      name="buildsource"
      depends="checkCompilerLevel,storeless,optional,runner,versioninfo,localeinfo,binscripts"
      description="Compile the product source (does not build the tests)."
  />
  <target
      name="all"
      depends="demo,testing,runmessagecheck"
      description="Compile all of the source, including tests as well as production code."
  />

<!-- ==================================================================== -->
<!--                       Initialize targets                             -->
<!-- ==================================================================== -->

   <target name="version_check">
    <antversion property="version.running" />
    <fail message="FATAL ERROR:  The running Ant version, ${version.running}, is too old.">
        <condition>
            <not>
                <antversion atleast="1.10.6" />
            </not>
        </condition>
    </fail>
   </target>

   <target name="init" unless="init.done" depends="version_check,install_junit,setCompilerProperties,make-generated-dirs,make-release-dirs">
    <tstamp/>

    <!-- Create the emtpy dir that we put in the boot classpath to
         prevent the default Java runtime libraries from being loaded.
      -->
    <mkdir dir="${empty}"/>

    <!-- generate sanity state.properties if one does not exist -->
    <available property="state.available" file="${state.file}"/>
    <antcall target="ensuresanitystate"/>
    <property file="${state.file}"/>
    <property file="${properties.dir}/sane${sanity}.properties"/>
    <antcall target="setissane"/>
    <available property="atLeastJava11" classname="java.lang.invoke.ConstantBootstraps"/>
    <property name="init.done" value="true"/>
  </target>

  <target name="makeOutDirs">
    <mkdir dir="${out.dir}"/>

    <mkdir dir="${out.build.dir}"/>
    <mkdir dir="${out.client.dir}"/>
    <mkdir dir="${out.demo.dir}"/>
    <mkdir dir="${out.drda.dir}"/>
    <mkdir dir="${out.engine.dir}"/>
    <mkdir dir="${out.optional.dir}"/>
    <mkdir dir="${out.run.dir}"/>
    <mkdir dir="${out.shared.dir}"/>
    <mkdir dir="${out.storeless.dir}"/>
    <mkdir dir="${out.stubs.dir}"/>
    <mkdir dir="${out.testing.dir}"/>
    <mkdir dir="${out.pptesting.dir}"/>
    <mkdir dir="${out.tools.dir}"/>
  </target>

   <target name="make-generated-dirs">

    <mkdir dir="${generated.dir}"/>
    <mkdir dir="${generated.bin.dir}"/>
    <mkdir dir="${generated.src.dir}"/>
    <mkdir dir="${generated.src.engine.dir}"/>
    <mkdir dir="${generated.src.shared.dir}"/>
    <mkdir dir="${generated.src.tools.dir}"/>
    <mkdir dir="${generated.src.tests.dir}"/>
    <mkdir dir="${generated.sanity.dir}"/>
    <mkdir dir="${generated.ij.dir}"/>
    <mkdir dir="${generated.sql.dir}"/>
    <mkdir dir="${generated.engine.locale.dir}"/>
    <mkdir dir="${generated.cache.dir}"/>
    <mkdir dir="${generated.toursdb.dir}"/>

   </target>

   <target name="make-release-dirs">

    <mkdir dir="${release.base}"/>
    <mkdir dir="${release.dir}"/>
    <mkdir dir="${snapshot.dir}"/>

   </target>

  <target name="setissane">
    <condition property="is.sane">
      <equals arg1="${sanity}" arg2="true"/>
    </condition>
  </target>

  <target name="ensuresanitystate" unless="state.available">
    <antcall target="evaluate.sane"/>
  </target>
  <target name="evaluate.sane">
    <condition property="generate.sane">
      <or>
        <equals arg1="${sane}" arg2="true"/>
        <not>
          <isset property="sane"/>
        </not>
      </or>
    </condition>
    <antcall target="ensuresanitystate.sane"/>
    <antcall target="ensuresanitystate.insane"/>
  </target>
  <target name="ensuresanitystate.sane" if="generate.sane">
    <antcall target="sane"/>
  </target>
  <target name="ensuresanitystate.insane" unless="generate.sane">
    <antcall target="insane"/>
  </target>

  <target name="showenv" depends="init" unless="showenv.done">
    <echo level="info" message=""/>
    <echo level="info" message="Ant environment:"/>
    <echo level="info" message="  Base Directory: ${basedir}"/>
    <echo level="info" message="  Build output: ${out.dir}"/>
    <echo level="info" message="  Compiler: ${build.compiler}"/>
    <echo level="info" message="  Sane = ${sane}"/>
    <echo level="info" message="  Proceed = ${proceed}"/>
    <echo level="info" message=""/>
    <property name="showenv.done" value="true"/>
  </target>

  <!--  Make sure compiler level is Java 8 level or higher -->
  <target name="checkCompilerLevel">

    <available property="compilerAtCorrectLevel" classname="java.sql.ShardingKey"/>
    <fail unless="compilerAtCorrectLevel" message="Compiler level must be Java 9 or later."/>
    
  </target>

<!-- ==================================================================== -->
<!--                     Download junit 3.8.2                             -->
<!-- ==================================================================== -->


   <!-- You can override this property in local.properties to fetch from an alternative location -->
   <property name="junit.url" value="https://repo1.maven.org/maven2/junit/junit/3.8.2/junit-3.8.2.jar"/> 
   <target name="junit_check">
       <!-- check if junit is set, if set, if junit.jar is really there, if not, error out  -->
       <fail message="junit property is set to ${junit}, but there is no junit.jar there.">
           <condition>
               <and>
                   <isset property="junit"/>
                   <not>
                       <available file="${junit}"/>
                   </not>
               </and>
           </condition>
       </fail>
       <condition property="junitfile" value="${junit}">
           <and>
               <isset property="junit"/>
           </and>
       </condition>
       <condition property="junitfile" value="${basedir}/tools/java/junit.jar">
           <not>
               <isset property="junit"/>
           </not>
       </condition>
       <available file="${junitfile}" property="junit.exists"/>
   </target>

   <target name="install_junit" depends="junit_check" unless="junit.exists" description="installs junit.jar into derby">
       <get src="${junit.url}" dest="${basedir}/tools/java/junit.jar" verbose="true" ignoreerrors="true"/>
   </target>

<!-- ==================================================================== -->
<!--                     Build version info files                         -->
<!-- ==================================================================== -->

  <target name="versioninfo" depends="ckversioninfo,writeversioninfo"/>

  <target name="ckversioninfo">
    <condition property="versioninfo.available">
      <and>
        <available file="${out.engine.dir}/org/apache/derby/info/engine/info.properties"/>
        <available file="${out.tools.dir}/org/apache/derby/info/tools/info.properties"/>
        <available file="${out.drda.dir}/org/apache/derby/info/net/info.properties"/>
        <available file="${out.client.dir}/org/apache/derby/info/client/info.properties"/>
        <available file="${out.shared.dir}/org/apache/derby/info/shared/info.properties"/>
        <available file="${out.testing.dir}/org/apache/derby/info/tsting/info.properties"/>
      </and>
    </condition>
  </target>

  <target name="writeversioninfo" depends="setCompilerProperties" unless="versioninfo.available">
    <mkdir dir="${out.engine.dir}/org/apache/derby/info/"/>
    <mkdir dir="${out.engine.dir}/org/apache/derby/info/engine"/>

    <mkdir dir="${out.tools.dir}/org/apache/derby/info"/>
    <mkdir dir="${out.tools.dir}/org/apache/derby/info/tools"/>

    <mkdir dir="${out.drda.dir}/org/apache/derby/info"/>
    <mkdir dir="${out.drda.dir}/org/apache/derby/info/net"/>

    <mkdir dir="${out.client.dir}/org/apache/derby/info"/>
    <mkdir dir="${out.client.dir}/org/apache/derby/info/client"/>

    <mkdir dir="${out.shared.dir}/org/apache/derby/info"/>
    <mkdir dir="${out.shared.dir}/org/apache/derby/info/shared"/>

    <mkdir dir="${out.testing.dir}/org/apache/derby/info"/>
    <mkdir dir="${out.testing.dir}/org/apache/derby/info/tsting"/>

    <infowriter
      info.buildnumber="1"
      info.iname="Apache Derby Embedded Engine"
      info.ename="Apache Derby"
      info.productfile="codeline"
      info.file="${out.engine.dir}/org/apache/derby/info/engine/info.properties"/>

    <infowriter
      info.buildnumber="1"
      info.iname="Apache Derby Tools"
      info.ename="Apache Derby"
      info.productfile="codeline"
      info.file="${out.tools.dir}/org/apache/derby/info/tools/info.properties"/>

    <infowriter
      info.buildnumber="1"
      info.iname="Apache Derby Network Server"
      info.ename="Apache Derby"
      info.productfile="codeline"
      info.file="${out.drda.dir}/org/apache/derby/info/net/info.properties"/>

    <infowriter 
      info.buildnumber="1"
      info.iname="Apache Derby Network Client"
      info.ename="Apache Derby"
      info.productfile="codeline"
      info.file="${out.client.dir}/org/apache/derby/info/client/info.properties"/>

    <infowriter
      info.buildnumber="1"
      info.iname="Apache Derby Shared Utilities"
      info.ename="Apache Derby"
      info.productfile="codeline"
      info.file="${out.shared.dir}/org/apache/derby/info/shared/info.properties"/>
  </target>

  <target name="cleanversion">
    <delete file="${out.engine.dir}/org/apache/derby/info/engine/info.properties"/>
    <delete file="${out.tools.dir}/org/apache/derby/info/tools/info.properties"/>
    <delete file="${out.drda.dir}/org/apache/derby/info/net/info.properties"/>
    <delete file="${out.client.dir}/org/apache/derby/info/client/info.properties"/>
    <delete file="${out.shared.dir}/org/apache/derby/info/shared/info.properties"/>
    <delete file="${out.testing.dir}/org/apache/derby/info/tsting/info.properties"/>
  </target>

  <!-- Set the ant variables which identify the compiler classpaths. -->
  <target name="setCompilerProperties" unless="compilerPropsAlreadySet" depends="prebuild">

    <property file="${properties.dir}/defaultcompiler.properties"/>
    <property file="${properties.dir}/${build.compiler}.properties"/>
    <!-- Compile-time classpath`< properties files -->
    <property file="${properties.dir}/extrapath.properties"/>

    <property file="${properties.dir}/compilepath.properties"/>
    <!-- Release and version info -->
    <property file="${properties.dir}/release.properties"/>

    <property name="compilerPropsAlreadySet" value="true"/>

  </target>

<!-- ==================================================================== -->
<!--                         Info writer build target                     -->
<!-- ==================================================================== -->

  <target name="infowriter">
    <propertyfile file="${info.file}" comment="${copyright.comment}">
      <entry key="derby.version.major" value="${major}"/>
      <entry key="derby.version.minor" value="${minor}"/>
      <entry key="derby.version.maint" value="${maint}"/>
      <entry key="derby.version.drdamaint" value="${drdamaint}"/>
      <entry key="derby.build.number" value="${info.buildnumber}"/>
      <entry key="derby.product.technology.name" value="${info.iname}"/>
      <entry key="derby.product.external.name" value="${info.ename}"/>
      <entry key="derby.product.external.version" value="${eversion}"/>
      <entry key="derby.version.beta" value="${beta}"/>
      <entry key="derby.product.vendor" value="${vendor}"/>
      <entry key="derby.product.file" value="${info.productfile}"/>
    </propertyfile>
  </target>  

  <macrodef name="infowriter">
    <attribute name="info.buildnumber"/>
    <attribute name="info.iname"/>
    <attribute name="info.ename"/>
    <attribute name="info.productfile"/>
    <attribute name="info.file"/>
    <sequential>
      <propertyfile file="@{info.file}" comment="${copyright.comment}">
        <entry key="derby.version.major"            value="${major}"/>
        <entry key="derby.version.minor"            value="${minor}"/>
        <entry key="derby.version.maint"            value="${maint}"/>
        <entry key="derby.version.drdamaint"        value="${drdamaint}"/>
        <entry key="derby.build.number"             value="@{info.buildnumber}"/>
        <entry key="derby.product.technology.name"  value="$@{info.iname}"/>
        <entry key="derby.product.external.name"    value="@{info.ename}"/>
        <entry key="derby.product.external.version" value="${eversion}"/>
        <entry key="derby.version.beta"             value="${beta}"/>
        <entry key="derby.product.vendor"           value="${vendor}"/>
        <entry key="derby.product.file"             value="@{info.productfile}"/>
      </propertyfile>
    </sequential>
  </macrodef>  

    <!--
        Create the release properties file and check it in

        Args:

            bumpID    true or false, depending on whether you want to increment the last digit of the release id (defaults to false)
    -->
  <target name="writeAndCheckinReleaseProperties" depends="writeRelProps,promptforsvncredentials">

    <!-- Check in the new release id. -->
    <antcall target="checkinfile">
       <param name="checkinComment" value="Derby release ID set to: ${derby.release.id.new}"/>
       <param name="fileName" value="${releasePropertyFile}"/>
    </antcall>
    
  </target>  

    <!--
        Create the release properties file.

        Args:

            bumpID    true or false, depending on whether you want to increment the last digit of the release id (defaults to false)
    -->
  <target name="writeRelProps" depends="init,prebuild,promptforreleaseid">

    <taskdef
      name="writeAndCheckinReleaseProperties"
      classname="org.apache.derbyPreBuild.ReleaseProperties"
      classpath="${out.build.dir}:${derby.shared.src.dir}"
    />

    <property name="releasePropertyFile" value="${properties.dir}/release.properties"/>
    <property name="bumpID" value="false"/>

    <writeAndCheckinReleaseProperties
      releaseID="${derby.release.id}"
      releasePropertiesFileName="${releasePropertyFile}"
      bump="${bumpID}"
    />

    <!--
        If we were asked to bump the release id, then the actual release id
        will be different from the original id passed into this target.
    -->
    <echo message="Derby release ID set to: ${derby.release.id.new}"/>
    
  </target>  

<!-- ==================================================================== -->
<!--                   Locale info writer build target                    -->
<!-- ==================================================================== -->

  <macrodef name="buildlocaleinfo">
    <attribute name="locale.iname"/>
    <attribute name="locale.ename"/>
    <attribute name="info.buildnumber"/>
    <attribute name="info.productfile"/>
    <attribute name="locale.output.dir"
               default="${out.dir}/${locale.stub}@{locale.iname}/org/apache/derby/info/${locale.stub}@{locale.iname}"/>
    <sequential>
      <mkdir dir="@{locale.output.dir}"/>

      <localeinfowriter
        info.buildnumber="1"
        info.iname="_@{locale.iname}"
        info.ename="@{locale.ename}"
        info.file="@{locale.output.dir}/info.properties"
        info.productfile="@{info.productfile}"
      />
    </sequential>
  </macrodef>

  <macrodef name="localeinfowriter">
    <attribute name="info.buildnumber"/>
    <attribute name="info.iname"/>
    <attribute name="info.ename"/>
    <attribute name="info.productfile"/>
    <attribute name="info.file"/>
    <sequential>
      <propertyfile file="@{info.file}" comment="${copyright.comment}">
        <entry key="derby.locale.version.major" value="${major}"/>
        <entry key="derby.locale.version.minor" value="${minor}"/>
        <entry key="derby.locale.version.maint" value="${maint}"/>
        <entry key="derby.locale.build.number" value="@{info.buildnumber}"/>
        <entry key="derby.locale.technology.name" value="@{info.iname}"/>
        <entry key="derby.locale.external.name" value="@{info.ename}"/>
        <entry key="derby.version.beta" value="${beta}"/>
        <entry key="derby.locale.vendor" value="${vendor}"/>
        <entry key="derby.product.file" value="@{info.productfile}"/>
      </propertyfile>
    </sequential>
  </macrodef>

 
<!-- ==================================================================== -->
<!--                           Build Locale info                          -->
<!-- ==================================================================== -->

  <target name="localeinfo"
          depends="checklocaleinfo,checkmessages"
          unless="localeinfo.available">

    <buildlocaleinfo
      locale.iname="cs"
      locale.ename="Czech/International [cs]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="de_DE"
      locale.ename="German/Germany [de_DE]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="es"
      locale.ename="Spanish/International [es]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="fr"
      locale.ename="French/International [fr]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="hu"
      locale.ename="Hungarian/International [hu]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="it"
      locale.ename="Italian/International [it]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="ja_JP"
      locale.ename="Japanese/Japan [ja_JP]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="ko_KR"
      locale.ename="Korean/Korea [ko_KR]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="pl"
      locale.ename="Polish/International [pl]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="pt_BR"
      locale.ename="Portuguese/Brazil [pt_BR]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="ru"
      locale.ename="Russian/International [ru]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="zh_CN"
      locale.ename="Simplified_Chinese/PR_China [zh_CN]"
      info.buildnumber="1"
      info.productfile="codeline"/>
    <buildlocaleinfo
      locale.iname="zh_TW"
      locale.ename="Chinese/Taiwan_Traditional [zh_TW]"
      info.buildnumber="1"
      info.productfile="codeline"/>
  </target>

  <target name="checklocaleinfo">
    <condition property="localeinfo.available">
      <and>
        <available file="${out.dir}/${locale.stub}cs/org/apache/derby/info/${locale.stub}cs/info.properties"/>
        <available file="${out.dir}/${locale.stub}de_DE/org/apache/derby/info/${locale.stub}de_DE/info.properties"/>
        <available file="${out.dir}/${locale.stub}es/org/apache/derby/info/${locale.stub}es/info.properties"/>
        <available file="${out.dir}/${locale.stub}fr/org/apache/derby/info/${locale.stub}fr/info.properties"/>
        <available file="${out.dir}/${locale.stub}hu/org/apache/derby/info/${locale.stub}hu/info.properties"/>
        <available file="${out.dir}/${locale.stub}it/org/apache/derby/info/${locale.stub}it/info.properties"/>
        <available file="${out.dir}/${locale.stub}ja_JP/org/apache/derby/info/${locale.stub}ja_JP/info.properties"/>
        <available file="${out.dir}/${locale.stub}ko_KR/org/apache/derby/info/${locale.stub}ko_KR/info.properties"/>
        <available file="${out.dir}/${locale.stub}pl/org/apache/derby/info/${locale.stub}pl/info.properties"/>
        <available file="${out.dir}/${locale.stub}pt_BR/org/apache/derby/info/${locale.stub}pt_BR/info.properties"/>
        <available file="${out.dir}/${locale.stub}ru/org/apache/derby/info/${locale.stub}ru/info.properties"/>
        <available file="${out.dir}/${locale.stub}zh_CN/org/apache/derby/info/${locale.stub}zh_CN/info.properties"/>
        <available file="${out.dir}/${locale.stub}zh_TW/org/apache/derby/info/${locale.stub}zh_TW/info.properties"/>
      </and>
    </condition>
  </target>

  <target name="cleanlocale">
    <delete file="${out.dir}/${locale.stub}cs/org/apache/derby/info/${locale.stub}cs/info.properties"/>
    <delete file="${out.dir}/${locale.stub}de_DE/org/apache/derby/info/${locale.stub}de_DE/info.properties"/>
    <delete file="${out.dir}/${locale.stub}es/org/apache/derby/info/${locale.stub}es/info.properties"/>
    <delete file="${out.dir}/${locale.stub}fr/org/apache/derby/info/${locale.stub}fr/info.properties"/>
    <delete file="${out.dir}/${locale.stub}hu/org/apache/derby/info/${locale.stub}hu/info.properties"/>
    <delete file="${out.dir}/${locale.stub}it/org/apache/derby/info/${locale.stub}it/info.properties"/>
    <delete file="${out.dir}/${locale.stub}ja_JP/org/apache/derby/info/${locale.stub}ja_JP/info.properties"/>
    <delete file="${out.dir}/${locale.stub}ko_KR/org/apache/derby/info/${locale.stub}ko_KR/info.properties"/>
    <delete file="${out.dir}/${locale.stub}pl/org/apache/derby/info/${locale.stub}pl/info.properties"/>
    <delete file="${out.dir}/${locale.stub}pt_BR/org/apache/derby/info/${locale.stub}pt_BR/info.properties"/>
    <delete file="${out.dir}/${locale.stub}ru/org/apache/derby/info/${locale.stub}ru/info.properties"/>
    <delete file="${out.dir}/${locale.stub}zh_CN/org/apache/derby/info/${locale.stub}zh_CN/info.properties"/>
    <delete file="${out.dir}/${locale.stub}zh_TW/org/apache/derby/info/${locale.stub}zh_TW/info.properties"/>
  </target>

  <target name="checkmessages" depends="checkmessages-done"
          unless="checkmessages.done">
    <java classname="org.apache.derbyBuild.MessageVetter"
          classpath="${out.build.dir}"
          fork="yes"
          failonerror="true">
      <arg file="${out.engine.dir}/org/apache/derby/loc"/>
      <arg file="${out.drda.dir}/org/apache/derby/loc/drda"/>
    </java>
    <touch file="${generated.dir}/checkmessages.done"/>
  </target>

  <target name="checkmessages-done">
    <uptodate property="checkmessages.done"
              targetfile="${generated.dir}/checkmessages.done">
      <srcresources>
        <fileset dir="${out.engine.dir}/org/apache/derby/loc"
                 includes="*.properties"/>
        <fileset dir="${out.drda.dir}/org/apache/derby/loc/drda"
                 includes="*.properties"/>
      </srcresources>
    </uptodate>
  </target>

<!-- ==================================================================== -->
<!--                   Derby Engine build target                     -->
<!-- ==================================================================== -->

  <target name="engine" depends="engine_properties_copy,class_size_catalog">
  </target>

  <target name="engine_properties_copy"
          depends="locales"
          description="Build Derby engine">

    <copy todir="${out.engine.dir}/${derby.dir}">
       <fileset dir="${derby.engine.dir}">
         <include name="modules.properties"/>
       </fileset>
    </copy>

    <copy
      file="${derby.engine.src.dir}/org/apache/derby/impl/jdbc/metadata.properties"
      tofile="${out.engine.dir}/org/apache/derby/impl/jdbc/metadata.properties"/>

    <copy
      file="${derby.engine.src.dir}/org/apache/derby/impl/sql/catalog/metadata_net.properties"
      tofile="${out.engine.dir}/org/apache/derby/impl/sql/catalog/metadata_net.properties"/>

  </target>

  <target name="compiles_engine_and_derbyBuild" depends="felixStubs,shared,engine_parser">
    <!-- compiles engine module java files (fixed and generated by parser) -->
    <!-- ${derby.engine.src.dir}     : java/org.apache.derby.engine -->
    <!-- ${generated.src.engine.dir} : generated/java/org.apache.derby.engine -->
    <!-- and -->
    <!-- ${derby.build.src.dir}      : java/build -->
    <!--                               org/apache/derbyBuild/** -->
    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.engine.src.dir}:${generated.src.engine.dir}"
      destdir="${out.engine.dir}">
      <compilerarg value="-Xlint:unchecked"/>
      <modulepath>
        <pathelement location="${out.shared.dir}"/>
        <pathelement location="${osgi}"/>
      </modulepath>
    </javac>

    <copy file="${derby.build.src.dir}/org/apache/derbyBuild/odbcgen_fragments.properties"
          tofile="${out.build.dir}/org/apache/derbyBuild/odbcgen_fragments.properties"/>

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.build.src.dir}"
      destdir="${out.build.dir}">
      <classpath>
        <pathelement path="${java.home}/../lib/tools.jar"/>
        <pathelement path="${ant.core.lib}"/>
        <pathelement path="${out.shared.dir}"/>
        <pathelement path="${out.engine.dir}"/>
      </classpath>
      <include name="org/apache/derbyBuild/**"/>
      <compilerarg value="-Xlint:unchecked"/>
      <compilerarg value="-Xlint:deprecation"/>
    </javac>
  </target>

  <target name="locales" depends="split"/>

  <!-- Initialization-->
  <target name="locales_init" depends="compiles_engine_and_derbyBuild">
    <property name="msgStub" value="messages_"/>

    <!-- Define the task which creates the engine's messages_en.properties -->
    <taskdef
      name="buildMessages"
      classname="org.apache.derbyBuild.MessageBuilder"
      classpath="${out.build.dir}"
    />

    <property name="messageDescriptors" value="${derby.locales.dir}/messages.xml"/>
    <property name="englishMessages" value="${generated.engine.locale.dir}/${msgStub}en.properties"/>

    <uptodate
      property="messagesUpToDate"
      targetfile="${englishMessages}"
    >
      <srcfiles file="${messageDescriptors}"/>
      <srcfiles dir="${derby.build.dir}" includes="*.java"/>
    </uptodate>
  </target>

  <!-- Generate english messages from xml descriptors-->
  <target name="buildMessages" depends="locales_init" unless="messagesUpToDate">

    <mkdir dir="${gen.doc.dir}" />

    <buildMessages
      xmlSourceFile="${messageDescriptors}"
      propertiesTargetFile="${englishMessages}"
      ditaTargetFile="${sqlstateTables}"
    />

  </target>

  <target name="split" depends="buildMessages,verifysplit">

    <antcall target="doSplit">
      <param name="msgdir" value="${generated.engine.locale.dir}"/>
      <param name="localeSuffix" value="en"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="cs"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="de_DE"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="es"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="hu"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="ja_JP"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="ko_KR"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="qq_PP_testOnly"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="pl"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="pt_BR"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="ru"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="zh_CN"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="zh_TW"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="it"/>
    </antcall>
    <antcall target="doSplit">
      <param name="msgdir" value="${derby.locales.dir}"/>
      <param name="localeSuffix" value="fr"/>
    </antcall>
  </target>

  <target name="doSplit" depends="splitprops,noSplit,chksplit" unless="split.done">
    <mkdir dir="${loc.engine.dir}"/>
    <mkdir dir="${loc.client.dir}"/>

    <mkdir dir="${generated.src.dir}/${locale.stub}${localeSuffix}"/>
    <mkdir dir="${generated.src.dir}/${locale.stub}${localeSuffix}/org/apache/derby/info/${locale.stub}${localeSuffix}"/>
    <mkdir dir="${locale.output.dir}"/>
    <mkdir dir="${locale.output.dir}/org/apache/derby/loc/${locale.stub}${localeSuffix}"/>

    <copy overwrite="true"
          file="${derby.locales.src.dir}/module-info.template"
          tofile="${generated.src.dir}/${locale.stub}${localeSuffix}/module-info.java">
      <filterset>
        <filter token="LOCALE" value="${localeSuffix}"/>
      </filterset>
    </copy>

    <copy overwrite="true"
          file="${derby.locales.src.dir}/DerbyModule.template"
          tofile="${generated.src.dir}/${locale.stub}${localeSuffix}/org/apache/derby/info/${locale.stub}${localeSuffix}/DerbyModule.java">
      <filterset>
        <filter token="LOCALE" value="${localeSuffix}"/>
      </filterset>
    </copy>

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${generated.src.dir}/${locale.stub}${localeSuffix}"
      destdir="${locale.output.dir}">
      <compilerarg value="-Xlint:unchecked"/>
      <modulepath>
        <pathelement location="${out.shared.dir}"/>
      </modulepath>
    </javac>

    <java classname="org.apache.derbyBuild.splitmessages"
          classpath="${out.build.dir}:${out.shared.dir}"
          fork="yes"
          failonerror="true">
      <arg value="${loc.engine.dir}"/> 
      <arg value="${loc.client.dir}"/> 
      <arg value="${locale.output.dir}/org/apache/derby/loc"/> 
      <arg value="${split.properties}"/>
    </java>
    <touch file="${split.donefile}"/>
  </target>

  <target name="splitprops">
    <property name="split.properties" value="${msgdir}/${msgStub}${localeSuffix}.properties"/>
    <property name="locale.output.dir" value="${out.dir}/${locale.stub}${localeSuffix}"/>
    <property name="split.donefile" value="${loc.engine.dir}/${msgStub}${localeSuffix}.done"/>
  </target>

  <target name="chksplit">
    <uptodate property="split.done"
              targetfile="${split.donefile}" >
      <srcfiles dir="${derby.locales.dir}" includes="${msgStub}${localeSuffix}.properties" />
    </uptodate>
  </target>

  <target name="verifysplit">
    <available classname="org.apache.derbyBuild.splitmessages"
               property="splitmsgs.available">
      <classpath>
        <pathelement path="${out.build.dir}"/>
        <pathelement path="${out.shared.dir}"/>
      </classpath>
    </available>
  </target>

  <target name="noSplit" unless="splitmsgs.available">
    <echo level="error" message=""/>
    <echo level="error" message="***** SplitMessages not available *****"/>
    <echo level="error" message=" ***** Run &quot;all&quot; target first *****"/>
    <echo level="error" message=""/>
    <fail message="  Exiting ant build..."/>
  </target>

  <target name="engine_parser" depends="make-generated-dirs,setCompilerProperties">

    <genParser
                msg="Generating SQL parser..."
            outroot="${generated.src.engine.dir}"
            srcroot="org.apache.derby.engine"
          directory="${derby.dir}/impl/sql/compile"
            rmfiles="implparser_rm.files"
             jjfile="sqlgrammar.jj"
            chkfile="SQLParser.java"
      constantsfile="SQLParserConstants"
    />

    <!--
      The following files were generated:

      CharStream.java
      ParseException.java
      SQLParser.java
      SQLParserConstants.java
      SQLParserTokenManager.java
      Token.java
      TokenMgrError.java

      3 of those files are checked into the codeline:

      CharStream.java
      ParseException.java
      Token.java

      We don't want generated code to clash with the checked-in versions. So
      we delete the conflicting classes here.
    -->
    <delete>
      <fileset dir="${generated.src.engine.dir}/${derby.dir}/impl/sql/compile">
        <include name="CharStream.java"/>
        <include name="ParseException.java"/>
        <include name="Token.java"/>
      </fileset>
    </delete>

    <!-- Reduce the visibility of these files from public to package. -->
    <replaceregexp match="^public (class|interface)" replace="\1" flags="m">
      <fileset dir="${generated.src.engine.dir}/${derby.dir}/impl/sql/compile">
        <include name="SQLParser.java"/>
        <include name="SQLParserConstants.java"/>
        <include name="SQLParserTokenManager.java"/>
        <include name="TokenMgrError.java"/>
      </fileset>
    </replaceregexp>

  </target>

  <!-- end of expanding 'engine' target of java\org.apache.derby.engine\build.xml -->

  <target name="tools" depends="engine,client,parser">

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.tools.src.dir}:${generated.src.tools.dir}"
      destdir="${out.tools.dir}">
      <compilerarg value="-Xlint"/>
      <modulepath>
        <pathelement location="${out.shared.dir}"/>
        <pathelement location="${out.engine.dir}"/>
        <pathelement location="${out.client.dir}"/>
      </modulepath>
    </javac>

    <copy todir="${loc.tools.dir}" flatten="true">
      <fileset dir="${derby.tools.locales.dir}">
        <include name="sysinfoMessages.properties"/>
        <include name="toolsmessages.properties"/>
      </fileset>
    </copy>

    <copyLocalization localization="en"/>
    <copyLocalization localization="cs"/>
    <copyLocalization localization="de_DE"/>
    <copyLocalization localization="es"/>
    <copyLocalization localization="hu"/>
    <copyLocalization localization="ja_JP"/>
    <copyLocalization localization="ko_KR"/>
    <copyLocalization localization="qq_PP_testOnly"/>
    <copyLocalization localization="pl"/>
    <copyLocalization localization="pt_BR"/>
    <copyLocalization localization="ru"/>
    <copyLocalization localization="zh_CN"/>
    <copyLocalization localization="zh_TW"/>
    <copyLocalization localization="it"/>
    <copyLocalization localization="fr"/>
  </target>

  <macrodef name="copyLocalization">
    <attribute name="localization"/>
    <attribute name="locale.output.dir"
               default="${out.dir}/${locale.stub}@{localization}/org/apache/derby/loc/tools/${locale.stub}@{localization}"
               description="e.g. : classes\locale_en\org\apache\derby\loc\tools\locale_en"/>
    <sequential>
      <mkdir dir="@{locale.output.dir}"/>
      <copy todir="@{locale.output.dir}">
        <fileset dir="${derby.tools.locales.dir}">
          <include name="sysinfoMessages_@{localization}.properties"/>
          <include name="toolsmessages_@{localization}.properties"/>
        </fileset>
      </copy>
    </sequential>
  </macrodef>

  <target name="parser" depends="make-generated-dirs,setCompilerProperties">

    <genParser
                msg="Generating ij parser..."
            outroot="${generated.src.tools.dir}"
            srcroot="org.apache.derby.tools"
          directory="${derby.dir}/impl/tools/ij"
            rmfiles="ijimplparser_rm.files"
             jjfile="ij.jj"
            chkfile="ij.java"
      constantsfile="ijConstants"
    />

    <genParser
                msg="Generating mtGrammar parser..."
            outroot="${generated.src.tools.dir}"
            srcroot="org.apache.derby.tools"
          directory="${derby.dir}/impl/tools/ij"
            rmfiles="mtparser_rm.files"
             jjfile="mtGrammar.jj"
            chkfile="mtGrammar.java"
      constantsfile="mtGrammarConstants"
    />

    <!--
      The following files were just generated:

      CharStream.java
      ij.java
      ijConstants.java
      ijTokenManager.java
      mtGrammar.java
      mtGrammarConstants.java
      mtGrammarTokenManager.java
      ParseException.java
      SimpleCharStream.java
      Token.java
      TokenMgrError.java

      1 of those files is checked into the codeline:

      ParseException.java

      We don't want generated code to clash with the checked-in versions. So
      we delete the conflicting class here.
    -->
    <delete>
      <fileset dir="${generated.src.tools.dir}/${derby.dir}/impl/tools/ij">
        <include name="ParseException.java"/>
      </fileset>
    </delete>

    <!-- reduce the visibility of these files from public to package protection -->
    <property name="ijConstants.src" value="${generated.src.tools.dir}/${derby.dir}/impl/tools/ij/ijConstants.java"/>
    <property name="ijTokenManager.src" value="${generated.src.tools.dir}/${derby.dir}/impl/tools/ij/ijTokenManager.java"/>

    <replaceregexp file="${ijConstants.src}" match="public interface" replace="interface"/>
    <replaceregexp file="${ijTokenManager.src}" match="public class" replace="class"/>

  </target>

  <target name="optional" depends="tools"
          description="Build Derby optional tools">

    <property name="cur.dir.optional" value="optional"/>

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.optional.src.dir}:${generated.src.dir}"
      destdir="${out.optional.dir}">
      <modulepath>
        <pathelement path="${out.shared.dir}"/>
        <pathelement path="${out.engine.dir}"/>
        <pathelement path="${out.tools.dir}"/>
        <pathelement path="${lucene_core}"/>
        <pathelement path="${lucene_a_co}"/>
        <pathelement path="${lucene_qp}"/>
        <pathelement path="${json_simple}"/>
      </modulepath>
      <include name="${derby.dir}/${cur.dir.optional}/**"/>
      <compilerarg value="-Xlint:unchecked"/>
      <compilerarg value="-Xlint:deprecation"/>
    </javac>
  </target>

  <target name="runner" depends="drda"
          description="Build Derby command runner">

    <property name="cur.dir.run" value="run"/>

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.run.src.dir}:${generated.src.dir}"
      destdir="${out.run.dir}">
      <include name="${derby.dir}/${cur.dir.run}/**"/>
      <compilerarg value="-Xlint:unchecked"/>
      <compilerarg value="-Xlint:deprecation"/>
      <modulepath>
        <pathelement location="${out.shared.dir}"/>
        <pathelement location="${out.drda.dir}"/>
        <pathelement location="${out.tools.dir}"/>
      </modulepath>
    </javac>
  </target>

  <target name="storeless" depends="engine"
    description="Build storeless engine support code">

    <mkdir dir="${out.storeless.dir}"/>
    <copy todir="${out.storeless.dir}/${derby.dir}">
      <fileset dir="${derby.storeless.src.dir}/${derby.dir}">
        <include name="modules.properties"/>
      </fileset>
    </copy>
    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.storeless.src.dir}"
      destdir="${out.storeless.dir}">
      <classpath>
        <pathelement path="${out.engine.dir}"/>
        <pathelement path="${out.shared.dir}"/>
      </classpath>
      <compilerarg value="-Xlint:unchecked"/>
    </javac>
  </target>

  <target name="shared" depends="state">

    <echo level="info" message="building generated sanity info"/>
    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${generated.src.shared.dir}:${derby.shared.src.dir}"
      destdir="${out.shared.dir}">
      <compilerarg value="-Xlint:unchecked"/>
    </javac>
  </target>
  
  <target name="drda" depends="drda.compile,odbcMeta"/>

  <target name="drda.compile" depends="tools"> 

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.drda.src.dir}"
      destdir="${out.drda.dir}">
      <compilerarg value="-Xlint:unchecked"/>
      <modulepath>
        <pathelement location="${servlet24}"/>
        <pathelement location="${out.engine.dir}"/>
        <pathelement location="${out.shared.dir}"/>
        <pathelement location="${out.tools.dir}"/>
      </modulepath>
    </javac>

    <copy todir="${drdaloc.dir}" flatten="true">
      <fileset dir="${derby.drda.locales.dir}">
        <include name="messages*.properties"/>
        <include name="servlet*.properties"/>
      </fileset>
    </copy>
  </target>

<!-- Generate ODBC-compliant metadata statements from JDBC metadata       -->
<!-- Doing so involves three steps:                                       -->
<!-- 1. Get a fresh copy of the metadata.properties file (from the source -->
<!--    dir, since that one hasn't been modified by the ODBC generation   -->
<!--    code), to be safe.                                                -->
<!-- 2. Run the ODBC metadata generator program, which reads the metadata -->
<!--    file from step 1 and creates an output file that has all of the   -->
<!--    queries from metadata.properties PLUS any ODBC versions of those  -->
<!--    queries that are required for ODBC compliance.  The name of this  -->
<!--    output file is "odbc_metadata.properties".                        -->
<!-- 3. Move odbc_metadata.properties to clobber the metadata.properties  -->
<!--    file that is in the BUILD directory (not the one in the source    -->
<!--    dir).                                                             -->

  <target name="odbcMeta" depends="odbcprops,verifyodbcgen,noODBC,chkodbcgen" unless="odbcgen.done">
    <delete file="${metadata.out.dir}/metadata.properties"/>
    <copy file="${derby.metadata.src.dir}/metadata.properties" tofile="${metadata.out.dir}/metadata.properties"/>
    <java classname="org.apache.derbyBuild.ODBCMetadataGenerator"
          classpath="${out.build.dir}:${out.engine.dir}"
          dir="${metadata.out.dir}"
          fork="yes"
          failonerror="true">
    </java>
    <move file="${metadata.out.dir}/odbc_metadata.properties" tofile="${metadata.out.dir}/metadata.properties"/>
    <touch file="${odbc.donefile}"/>
  </target>

  <target name="odbcprops">
    <property name="odbc.donefile" value="${metadata.out.dir}/odbcmeta.done"/>
  </target>

  <target name="chkodbcgen">
    <uptodate property="odbcgen.done"
              targetfile="${odbc.donefile}" >
      <srcfiles dir="${metadata.out.dir}" includes="metadata.properties" />
      <srcfiles dir="${out.build.dir}/org/apache/derbyBuild" includes="ODBCMetadataGenerator.class,odbcgen_fragments.properties" />
    </uptodate>
  </target>

  <target name="verifyodbcgen">
    <available classname="org.apache.derbyBuild.ODBCMetadataGenerator"
               property="odbcgen.available">
      <classpath>
        <pathelement path="${out.build.dir}"/>
      </classpath>
    </available>
  </target>

  <target name="noODBC" unless="odbcgen.available">
    <echo level="error" message=""/>
    <echo level="error" message="***** ODBC Metadata not available *****"/>
    <echo level="error" message=" ***** Run &quot;all&quot; target first *****"/>
    <echo level="error" message=""/>
    <fail message="  Exiting ant build..."/>
  </target>

  <target name="client" depends="shared">

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.client.src.dir}"
      destdir="${out.client.dir}">
      <compilerarg value="-Xlint"/>
      <modulepath>
        <pathelement location="${out.shared.dir}"/>
      </modulepath>
   </javac>
  </target>

  <target name="prebuild" depends="makeOutDirs">

    <property file="${properties.dir}/defaultcompiler.properties"/>

    <!-- Needed by ReleaseProperties -->
    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="true"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.shared.src.dir}"
      destdir="${out.shared.dir}"
      includeantruntime="false"
      includes="org/apache/derby/shared/common/info/PropertyNames.java"
    >
      <classpath>
        <pathelement path="${ant.core.lib}"/>
      </classpath>
      <compilerarg value="-Xlint:unchecked"/>
    </javac>

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="true"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.build.src.dir}"
      destdir="${out.build.dir}"
      includeantruntime="false"
      includes="org/apache/derbyPreBuild/*.java"
    >
      <classpath>
        <pathelement path="${ant.core.lib}"/>
        <pathelement path="${out.shared.dir}"/>
      </classpath>
      <compilerarg value="-Xlint:unchecked"/>
    </javac>

  </target>

  <target name="demo" depends="vti-demo">
    <ant dir="${derby.demo.src.dir}"/>
  </target>

  <target name="vti-demo" depends="buildsource">
    <ant dir="${derby.demo.src.dir}" target="compile-vtidemo"/>
  </target>

  <target name="testing" depends="buildsource,buildtestinginfo">
    <ant dir="${derby.testing.src.dir}"/>
    <ant dir="${derby.pptesting.src.dir}"/>
  </target>
	
  <target name="build-test-jars" description="Build jar files used in tests." depends="buildsource" >

    <ant dir="${derby.testing.src.dir}" target="build-test-jars" />

  </target>

  <!-- Run the MessageBundleTest -->
  <target name="runmessagecheck">
    <java   fork="true" 
       classname="org.apache.derbyBuild.MessageBundleTest"
     failonerror="true"
       classpath="${out.build.dir}:${out.shared.dir}:${out.engine.dir}"
     />
  </target>

  <!-- Run the RefreshJarDriftTest -->
  <target name="refreshjardriftcheck"
          description="Fix discrepancies between the actual and expected contents of the Derby jar files.">
    <java   
       fork="true" 
       classname="org.apache.derbyBuild.JarDriftTest"
       failonerror="true"
       classpath="${out.build.dir}">
      <arg value="refresh"/>
    </java>
  </target>

  <!-- Run the JarDriftTest -->
  <target name="jardriftcheck"
          description="Report discrepancies between the actual and expected contents of the Derby jar files.">
    <java   
       fork="true" 
       classname="org.apache.derbyBuild.JarDriftTest"
       failonerror="true"
       classpath="${out.build.dir}"
     />
  </target>

<!-- ==================================================================== -->
<!--                     Build SanityState.java                           -->
<!-- ==================================================================== -->

  <target name="getstate">
    <condition property="needstate">
      <or>
        <not>
          <equals arg1="${sane}" arg2="${sanity}"/>
        </not>
        <not>
          <available file="${generated.sanity.dir}/SanityState.java"/>
        </not>
      </or>
    </condition>
  </target>

  <property name="state.file" value="${generated.sanity.dir}/state.properties"/>
  <property file="${state.file}"/>

  <!-- Build SanityState.java -->
  <target name="state" if="needstate" depends="showenv,getstate">
    <echo level="info" message="  Generating SanityState.java..."/>
    <property name="sane" value="true"/>
    <filter token="SANE" value="${sane}"/>
    <copy file="${sanity.dir}/SanityState.tmpl"
          tofile="${generated.sanity.dir}/SanityState.java"
          overwrite="yes" filtering="on"/>
    <property name="header" value="Generated file - do not modify!"/>
    <propertyfile file="${state.file}" comment="${header}">
      <entry key="sanity" value="${sane}" type="string"/>
    </propertyfile>
    <delete dir="${sanity.out.dir}"/>
  </target>

<!-- =================================================================== -->
<!--                     Remove SanityState.java file                    -->
<!-- =================================================================== -->
  <target name="cleanstate">
    <delete dir="${generated.sanity.dir}"/>
    <delete dir="${sanity.out.dir}"/>
  </target>

<!-- =================================================================== -->
<!--                 Remove all built objects (except jars)              -->
<!-- =================================================================== -->
  <target
      name="clobber"
      depends="clean,cleangenerated,cleanstate,cleanreleasefiles"
      description="Remove all build artifacts."
  >
    <delete file="${out.base}/changenumber.properties"/>
    <delete file="${basedir}/jacoco.exec"/>
  </target>

<!-- =================================================================== -->
<!--                       Remove the tree of generated intermediate sources                            -->
<!-- =================================================================== -->
  <target name="cleangenerated">
    <delete dir="${generated.dir}"/>
  </target>

<!-- =================================================================== -->
<!--                       Remove output tree                            -->
<!-- =================================================================== -->
  <target name="clean">
    <delete dir="${out.dir}"/>
    <delete dir="${generated.dir}"/>
  	<delete dir="${out.storeless.dir}"/>
  </target>

<!-- ==================================================================== -->
<!--                         Build parsers                                -->
<!-- ==================================================================== -->

  <!-- Top level target for building both of the javacc parsers -->
  <target name="parsers">
    <ant dir="${derby.tools.dir}/impl/tools"  target="parser"/>
    <ant dir="${derby.engine.dir}/impl/sql"  target="parser"/>
  </target>

  <macrodef name="genParser">
    <attribute name="chkfile"/>
    <attribute name="constantsfile"/>
    <attribute name="directory"/>
    <attribute name="msg"/>
    <attribute name="jjfile"/>
    <attribute name="outroot"/>
    <attribute name="rmfiles"/>
    <attribute name="srcroot"/>
    <sequential>
      <echo level="info" message="  @{msg}"/>
      <delete>
        <fileset dir="@{outroot}/@{directory}" includes="@{rmfiles}"/>
      </delete>
      <java classname="javacc"
            classpath="${javacc}"
                  dir="${derbysrc.dir}/@{srcroot}/@{directory}"
                 fork="yes"
          failonerror="true">
        <arg value="-OUTPUT_DIRECTORY=@{outroot}/@{directory}"/>
        <arg value="@{jjfile}"/>
      </java>
      <!-- Qualify reference to tokenImage to fix issue with inheritence -->
      <!-- IBM JDK 1.3.1. See DERBY-1078                                 -->
      <replaceregexp file="@{outroot}/@{directory}/@{chkfile}" match="tokenImage" 
                    replace="@{constantsfile}.tokenImage"/>
    </sequential>
  </macrodef>

<!-- =================================================================== -->
<!--                     Build the stub FELIX (OSGI) implementation                 -->
<!-- =================================================================== -->
  <target name="felixStubs" depends="state">
    <mkdir dir="${out.stubs.dir}"/>
    <mkdir dir="${out.felix.dir}"/>

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.felix.src.dir}"
      destdir="${out.felix.dir}">
      <compilerarg value="-Xlint:unchecked"/>
     </javac>

  </target>

<!-- =================================================================== -->
<!--                     Build the Unix shell scripts under bin          -->
<!-- =================================================================== -->

<target name="binscripts" depends="check-binscripts" unless="binscripts.done">

  <makebinscript script="dblook"/>
  <makebinscript script="ij"/>
  <makebinscript script="sysinfo"/>
  <makebinscript script="NetworkServerControl"/>
  <makebinscript script="startNetworkServer"/>
  <makebinscript script="stopNetworkServer"/>

  <!-- All the scripts should be executable. -->
  <chmod perm="+x" dir="${generated.bin.dir}" includes="*"/>

</target>

<macrodef name="makebinscript">
  <attribute name="script"/>
  <sequential>
    <concat destfile="${generated.bin.dir}/@{script}">
      <fileset file="bin/templates/derby_common.sh"/>
      <fileset file="bin/templates/@{script}"/>
    </concat>
  </sequential>
</macrodef>

<target name="check-binscripts">
  <dependset>
    <srcfileset file="bin/templates/derby_common.sh"/>
    <targetfileset dir="${generated.bin.dir}"/>
  </dependset>
  <uptodate property="binscripts.done">
    <srcfiles dir="bin/templates" excludes="derby_common.sh"/>
    <globmapper from="*" to="${generated.bin.dir}/*"/>
  </uptodate>
</target>

<!-- =================================================================== -->
<!--                     Remove generated message files                   -->
<!-- =================================================================== -->
  <target name="cleanmessages">
    <delete>
      <fileset dir="${generated.engine.locale.dir}" includes="messages_en.properties"/>
    </delete>
  </target>

<!-- =================================================================== -->
<!--                     Class Size Catalog build                        -->
<!-- =================================================================== -->

  <!--
      Create the class size catalog, a java file

      Note that checking the up-to-date status of the files scanned by
      ClassSizeCrawler will not always result in the ClassSizeCatalogImpl
      being updated properly. We would have to be able to scan the full
      dependency tree. This does prevent recompilation in most cases,
      and requires it in the most obvious. If there is concern that
      the ClassSizeCatalogImpl may have changed significantly since the
      last build, run clobber and rebuild to regenerate it.
  -->

  <target name="class_size_catalog" depends="compiles_engine_and_derbyBuild,cscuptodate" unless="csc.uptodate">
    <java classname="org.apache.derbyBuild.ClassSizeCrawler"
          fork="yes"
          failonerror="yes">
      <classpath>
        <pathelement path="${out.build.dir}:${out.engine.dir}"/>
      </classpath>
      <jvmarg value="-DWS=${workspace}"/>
      <jvmarg value="-DclassDir=${out.engine.dir}"/>
      <jvmarg value="-Dout=${generated.cache.dir}/ClassSizeCatalogImpl.java"/>
      <jvmarg value="-Dprefix.1=org.apache.derby.iapi.types"/>            
      <jvmarg value="-Dprefix.2=org.apache.derby.impl"/>
      <arg value="org.apache.derby.iapi.types.DataValueDescriptor"/>
      <arg value="org.apache.derby.impl.store.raw.data.RecordId"/>
      <arg value="org.apache.derby.iapi.store.raw.ContainerKey"/>
      <arg value="org.apache.derby.iapi.services.cache.SizedCacheable"/>
      <arg value="java.lang.ref.WeakReference"/>
      <arg value="java.math.BigDecimal"/>
      <arg value="java.util.ArrayList"/>
      <arg value="java.util.GregorianCalendar"/>
      <arg value="java.util.Vector"/>
    </java>

    <javac
      source="${min.version}"
      target="${min.version}"
      nowarn="on"
      debug="${debug}" debuglevel="${debuglevel}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${generated.src.engine.dir}"
      destdir="${out.engine.dir}">
      <include name="${derby.dir}/iapi/services/cache/ClassSizeCatalogImpl.java"/>
      <modulepath>
		    <pathelement location="${out.shared.dir}"/>
		    <pathelement location="${out.engine.dir}"/>
		    <pathelement location="${osgi}"/>
      </modulepath>
    </javac>

  </target>

  <target name="cscuptodate">
    <condition property="csc.uptodate">
      <and>
        <uptodate srcfile="${derby.engine.dir}/iapi/types/DataValueDescriptor.java"
                  targetfile="${out.engine.dir}/org/apache/derby/iapi/types/DataValueDescriptor.class"/>
        <uptodate srcfile="${derby.engine.dir}/impl/store/raw/data/RecordId.java"
                  targetfile="${out.engine.dir}/org/apache/derby/impl/store/raw/data/RecordId.class"/>
        <uptodate srcfile="${derby.engine.dir}/iapi/store/raw/ContainerKey.java"
                  targetfile="${out.engine.dir}/org/apache/derby/iapi/store/raw/ContainerKey.class"/>
        <uptodate srcfile="${derby.engine.dir}/iapi/services/cache/SizedCacheable.java"
                  targetfile="${out.engine.dir}/org/apache/derby/iapi/services/cache/SizedCacheable.class"/>
        <available file="${generated.src.engine.dir}/${derby.dir}/iapi/services/cache/ClassSizeCatalogImpl.java"/>
      </and>
    </condition>
  </target>

<!-- =================================================================== -->
<!--                     Generate sanity.properties                      -->
<!-- =================================================================== -->

  <target name="sane" depends="make-generated-dirs">
    <propertyfile file="${state.file}" comment="${header}">
      <entry key="sanity" value="true" type="string"/>
    </propertyfile>
    <delete dir="${sanity.out.dir}"/>
  </target>
  <target name="insane" depends="make-generated-dirs">
    <propertyfile file="${state.file}" comment="${header}">
      <entry key="sanity" value="false" type="string"/>
    </propertyfile>
    <delete dir="${sanity.out.dir}"/>
  </target>


<!-- =================================================================== -->
<!--                           Javadoc targets                           -->
<!-- =================================================================== -->

  <!-- javadoc specific properties -->

  <property name="public.api.dir" value="${out.javadoc.dir}/publishedapi"/>
  <property name="javadoc.temp.dir" value="${out.javadoc.dir}/temp"/>
  <property name="javadoc.exclusions" value="${javadoc.temp.dir}/javadoc_exclusions"/>
  <property name="javadoc.inclusions" value="${javadoc.temp.dir}/javadoc_inclusions"/>

  <!-- Helper target to build the JavaDocs and zip them up.
       Introduced to achieve a higher degree of platform independence when
       pulling JavaDocs from continuous integration systems and build systems.
   -->
  <target name="javadoc-with-bundle" depends="javadoc">
    <property name="javadoc.bundle" value="${out.javadoc.dir}/javadocs.zip"/>
    <delete file="${javadoc.bundle}" quiet="true"/>
    <zip destfile="${javadoc.bundle}"
         basedir="${out.javadoc.dir}"/>
  </target>

  <target
      name="javadoc"
      depends="publishedapi,derbydocs,toolsdocs,grammardocs,demodocs"
      description="Build all of the javadoc, including the public api, the production javadoc, and the testing javadoc."
  />

  <target name="publishedapi" depends="initjars">
 
    <delete dir="${public.api.dir}"/>
    <mkdir dir="${public.api.dir}"/>
 
    <antcall target="publishedapi-workhorse"/>

  </target>

<!-- ==================================================================== -->
<!--                     Download Java SE and J2EE's "package-list"s      -->
<!-- ==================================================================== -->

   <target name="packagelist_check">
     <condition property="javadoc_local.exists">
       <and>
       <available file="${javasedoc.local}/package-list" property="javasedoc.exists"/>
       <available file="${j2eedoc.local}/package-list" property="j2eedoc.exists"/>
       </and>
     </condition>
   </target>

   <target name="install_packagelists" depends="packagelist_check" unless="javadoc_local.exists" description="downloads Java SE and J2EE package lists to local cache">
       <mkdir dir="${javasedoc.local}"/>
       <mkdir dir="${j2eedoc.local}"/>
       <get src="${javasedoc.url}/package-list" dest="${javasedoc.local}/" verbose="true" ignoreerrors="false"/>
       <get src="${j2eedoc.url}/package-list" dest="${j2eedoc.local}/" verbose="true" ignoreerrors="false"/>
   </target>

  <!--
    This target used to be called twice, once to build the JDBC3 public api
    and then a second time to build the JDBC4 api. Now it is only called once,
    for the single JDBC4+ api.

    If behind a firewall, the links to Java SE and J2EE javadocs may
    fail.  You can manually download the package-list files into the
    folders ./packageListLoc-se-8 and ./packageListLoc-j2ee-7 instead
    to get a correct build.
  -->
  <target name="publishedapi-workhorse" depends="initjars,set-doclint,install_packagelists">
 
    <javadoc
             modulesourcepath="${javasrc.dir}:${generated.src.dir}"
             modulepath="${osgi}:${servlet24}:${junit}:${lucene_core}:${lucene_a_co}:${lucene_qp}:${json_simple}"
             modulenames="${module.name.client},${module.name.runner}"

             breakiterator="true"
             access="public"
             destdir="${public.api.dir}"
    	     Overview="${basedir}/published_api_overview.html"
             Windowtitle="Apache Derby ${major}.${minor} API Documentation"   
             Header="Apache Derby ${major}.${minor}"
             bottom="Apache Derby ${major}.${minor} API Documentation  -  &lt;i&gt;Copyright &amp;copy; 2004,${copyright.year} The Apache Software Foundation. All Rights Reserved.&lt;/i&gt;">

      <Doctitle> Apache Derby ${major}.${minor} API Documentation</Doctitle>   

      <link offline="true" href="${javasedoc.url}"
                         packagelistLoc="${javasedoc.local}" />
      <link offline="true" href="${j2eedoc.url}"
                     packagelistLoc="${j2eedoc.local}" />

      <fileset dir="${derby.shared.src.dir}"
               includes="org/apache/derby/shared/common/security/SystemPermission.java"/>

      <fileset dir="${derby.engine.src.dir}"
                   includes="org/apache/derby/agg/Aggregator.java,
                             org/apache/derby/authentication/UserAuthenticator.java,
                             org/apache/derby/catalog/SequencePreallocator.java,
                             org/apache/derby/mbeans/CacheManagerMBean.java,
                             org/apache/derby/mbeans/JDBCMBean.java,
                             org/apache/derby/mbeans/Management.java,
                             org/apache/derby/mbeans/ManagementMBean.java,
                             org/apache/derby/mbeans/VersionMBean.java,
                             org/apache/derby/vti/AwareVTI.java,
                             org/apache/derby/vti/ForeignTableVTI.java,
                             org/apache/derby/vti/ForwardingVTI.java,
                             org/apache/derby/vti/RestrictedVTI.java,
                             org/apache/derby/vti/Restriction.java,
                             org/apache/derby/vti/StringColumnVTI.java,
                             org/apache/derby/vti/VTICosting.java,
                             org/apache/derby/vti/VTIContext.java,
                             org/apache/derby/vti/VTIEnvironment.java,
                             org/apache/derby/vti/VTITemplate.java"
      />

      <fileset dir="${derby.drda.src.dir}"
                   includes="org/apache/derby/drda/NetServlet.java,
                             org/apache/derby/drda/NetworkServerControl.java,
                             org/apache/derby/mbeans/drda/NetworkServerMBean.java"
      />

      <fileset dir="${derby.tools.src.dir}"
                   includes="org/apache/derby/jdbc/BasicClientConnectionPoolDataSource40.java,
                             org/apache/derby/jdbc/BasicClientDataSource40.java,
                             org/apache/derby/jdbc/BasicClientXADataSource40.java,
                             org/apache/derby/jdbc/BasicEmbeddedConnectionPoolDataSource40.java,
                             org/apache/derby/jdbc/BasicEmbeddedDataSource40.java,
                             org/apache/derby/jdbc/BasicEmbeddedXADataSource40.java,
                             org/apache/derby/jdbc/ClientConnectionPoolDataSource.java,
                             org/apache/derby/jdbc/ClientDataSource.java,
                             org/apache/derby/jdbc/ClientDriver.java,
                             org/apache/derby/jdbc/ClientXADataSource.java,
                             org/apache/derby/jdbc/EmbeddedConnectionPoolDataSource.java,
                             org/apache/derby/jdbc/EmbeddedDataSource.java,
                             org/apache/derby/jdbc/EmbeddedDriver.java,
                             org/apache/derby/jdbc/EmbeddedXADataSource.java,
                             org/apache/derby/tools/dblook.java,
                             org/apache/derby/tools/ij.java,
                             org/apache/derby/tools/sysinfo.java"
      />

      <fileset dir="${derby.optional.src.dir}"
                   includes="org/apache/derby/optional/api/LuceneIndexDescriptor.java,
                             org/apache/derby/optional/api/LuceneUtils.java,
                             org/apache/derby/optional/api/SimpleJsonUtils.java,
                             org/apache/derby/optional/api/SimpleJsonVTI.java"
      />

      <arg value="-Xdoclint:none"/>
      <arg value="-notimestamp"/>
      <arg value="-quiet"/>
    </javadoc>

    <!-- Copy the logo needed by the Doctitle attribute above -->
    <copy file="${javadoctools.dir}/logo/derby_logo64.png" 
          todir="${public.api.dir}/resources"/>     

    <!-- Copy the module diagrams used by the overview -->
    <antcall target="copyJava9ModuleDiagrams"><param name="svg.dir" value="${public.api.dir}"/></antcall>
    <antcall target="copyJava11ModuleDiagrams"><param name="svg.dir" value="${public.api.dir}"/></antcall>

  </target>

  <!-- Copy module diagrams to the correct place for Java 9 and Java 10 -->
  <target name="copyJava9ModuleDiagrams" unless="atLeastJava11">
    <copy todir="${svg.dir}">
      <fileset dir="${javadoctools.dir}/moduleDiagrams"/>
    </copy>
  </target>

  <!-- Copy module diagrams to the correct place for Java 11 -->
  <target name="copyJava11ModuleDiagrams" if="atLeastJava11">
    <copy file="${javadoctools.dir}/moduleDiagrams/client.svg" 
          todir="${svg.dir}/org.apache.derby.client"/>     
    <copy file="${javadoctools.dir}/moduleDiagrams/commons.svg" 
          todir="${svg.dir}/org.apache.derby.commons"/>     
    <copy file="${javadoctools.dir}/moduleDiagrams/engine.svg" 
          todir="${svg.dir}/org.apache.derby.engine"/>     
    <copy file="${javadoctools.dir}/moduleDiagrams/optionaltools.svg" 
          todir="${svg.dir}/org.apache.derby.optionaltools"/>     
    <copy file="${javadoctools.dir}/moduleDiagrams/runner.svg" 
          todir="${svg.dir}/org.apache.derby.runner"/>     
    <copy file="${javadoctools.dir}/moduleDiagrams/server.svg" 
          todir="${svg.dir}/org.apache.derby.server"/>     
    <copy file="${javadoctools.dir}/moduleDiagrams/tools.svg" 
          todir="${svg.dir}/org.apache.derby.tools"/>

    <available property="test.javadoc.exists" file="${svg.dir}/org.apache.derby.tests"/>
    <antcall target="copyJava11testModuleDiagram"/>

  </target>

  <!-- Copy module diagram for the tests module to the correct place for Java 11 -->
  <target name="copyJava11testModuleDiagram" if="test.javadoc.exists">
    <copy file="${javadoctools.dir}/moduleDiagrams/tests.svg" 
          todir="${svg.dir}/org.apache.derby.tests"/>     
  </target>

  <target name="derbydocs" depends="initjars,set-doclint">

    <delete dir="${out.javadoc.dir}/engine"/>
    <mkdir dir="${out.javadoc.dir}/engine"/>

    <javadoc
        modulesourcepath="${javasrc.dir}:${generated.src.dir}"
        modulepath="${osgi}:${servlet24}:${lucene_core}:${lucene_a_co}:${lucene_qp}:${json_simple}:${junit}"
        modulenames="${module.name.commons},${module.name.engine},${module.name.client},${module.name.server},${module.name.tools},${module.name.optionaltools},${module.name.runner},${module.name.tests}"

        packagenames="org.*"
        additionalparam="-J"
        access="private"
        breakiterator="yes"
        useexternalfile="yes"
        destdir="${out.javadoc.dir}/engine"
    	Overview="${basedir}/published_api_overview.html"
        windowtitle="Apache Derby V${major}.${minor} Internals"
        doctitle="Apache Derby V${major}.${minor} Internals"
        bottom="Apache Derby V${major}.${minor} Internals - &lt;i&gt;Copyright &amp;copy; 2004,${copyright.year} The Apache Software Foundation. All Rights Reserved.&lt;/i&gt;"
      >

        <taglet name="org.apache.derbyBuild.javadoc.FormatIdTaglet" 
                path="${out.build.dir}"/>
        <taglet name="org.apache.derbyBuild.javadoc.PurposeTaglet" 
                path="${out.build.dir}"/>
        <taglet name="org.apache.derbyBuild.javadoc.UpgradeTaglet" 
                path="${out.build.dir}"/>
        <taglet name="org.apache.derbyBuild.javadoc.DiskLayoutTaglet" 
                path="${out.build.dir}"/>
        <taglet name="org.apache.derbyBuild.javadoc.EndFormatTaglet" 
                path="${out.build.dir}"/>

      <arg value="-Xdoclint:none"/>
      <arg value="--show-module-contents"/><arg value="all"/>
      <arg value="-notimestamp"/>
      <arg value="-quiet"/>
    </javadoc>

    <!-- Copy the module diagrams used by the module overviews -->
    <antcall target="copyJava9ModuleDiagrams">
      <param name="svg.dir" value="${out.javadoc.dir}/engine"/>
    </antcall>
    <antcall target="copyJava11ModuleDiagrams">
      <param name="svg.dir" value="${out.javadoc.dir}/engine"/>
    </antcall>

  </target>

  <target name="toolsdocs">

    <delete dir="${out.javadoc.dir}/tools"/>
    <mkdir dir="${out.javadoc.dir}/tools"/>

    <antcall target="dojjdocs">
      <param name="jjtodoc" value="${derby.tools.dir}/impl/tools/ij/ij.jj"/>
      <param name="jjdoctarget" value="${out.javadoc.dir}/tools/ij.html"/>
    </antcall>

  </target>

  <target name="demodocs" depends="init,set-doclint">

    <delete dir="${out.javadoc.dir}/demo"/>
    <mkdir dir="${out.javadoc.dir}/demo"/>

    <javadoc
        additionalparam="-J"
        packagenames="org.apache.derbyDemo.vtis.*"
        access="private"
        breakiterator="yes"
        useexternalfile="yes"
        classpath="${out.all.dir};"
        destdir="${out.javadoc.dir}/demo"
        windowtitle="Apache Derby Demos"
        doctitle="Apache Derby Demos"
    >
     <fileset dir="${derby.demo.src.dir}/vtis/java"/>
      <arg value="${xarg.doclint}"/>
      <arg value="-notimestamp"/>
      <arg value="-quiet"/>
    </javadoc>


  </target>

  <target name="grammardocs">

    <delete dir="${out.javadoc.dir}/language"/>
    <mkdir dir="${out.javadoc.dir}/language"/>	

    <antcall target="dojjdocs">
      <param name="jjtodoc" value="${derby.engine.dir}/impl/sql/compile/sqlgrammar.jj"/>
      <param name="jjdoctarget" value="${out.javadoc.dir}/language/sqlgrammar.html"/>
    </antcall>

  </target>

  <target name="dojjdocs">

    <java classname="jjdoc" fork="yes">
      <classpath path="${javatools.dir}/javacc.jar"/>
      <arg value="-NOONE_TABLE"/>
      <arg value="-output_file=${jjdoctarget}"/>
      <arg value="${jjtodoc}"/>
    </java>

  </target>

  <target name="cleandocs">

    <delete dir="${out.javadoc.dir}"/>

  </target>

  <!-- Set the doclint variable depending on whether this is Java 8. Use a harmless arg if not on Java 8 -->
  <target name="set-doclint">
    <condition property="xarg.doclint" value="-Xdoclint:none" else="-J-mx500M">
      <available classname="java.sql.SQLType"/>
    </condition>
  </target>


<!-- =================================================================== -->
<!-- Eclipse Plugin                                                     -->
<!-- =================================================================== -->
  <target name="plugin" depends= "buildjars">
       <echo level="info" message="Begining Derby Eclipse plugin build"/>
       <property name="plugin.tmp.dir" value ="plugintmp"/>
       <mkdir dir="${derby.jar.dir}/${plugin.tmp.dir}"/>

       <java classname="org.apache.derbyBuild.eclipse.DerbyEclipsePlugin">
               <arg value="${derby.jar.dir}/${plugin.tmp.dir}"/>
               <classpath>
                       <pathelement path="${out.build.dir}"/>
               </classpath>
       </java>

       <property file="${derby.jar.dir}/${plugin.tmp.dir}/plugintmp.properties"/>
       <echo level="info" message="Derby Eclipse plugin build: ${plugin.derby.version.build.number}"/>

       <property name="plugin.dir" value ="plugins"/>
       <property name="plugin.core.dir" value ="${plugin.derby.core}_${plugin.derby.version}"/>

       <mkdir dir="${derby.jar.dir}/${plugin.tmp.dir}/${plugin.dir}/${plugin.core.dir}"/>

       <copy todir="${derby.jar.dir}/${plugin.tmp.dir}/${plugin.dir}/${plugin.core.dir}">
               <fileset dir="${derby.jar.dir}" includes="derby*.jar" excludes="derbyTesting.jar,derbyLocale*.jar,derbyrun.jar"/>
       </copy>
       <copy todir="${derby.jar.dir}/${plugin.tmp.dir}/${plugin.dir}/${plugin.core.dir}">
               <fileset dir="${derby.jar.dir}/${plugin.tmp.dir}" includes="plugin*.xml"/>
       </copy>

       <copy todir="${derby.jar.dir}/${plugin.tmp.dir}/${plugin.dir}/${plugin.core.dir}" file="LICENSE"/>
       <copy todir="${derby.jar.dir}/${plugin.tmp.dir}/${plugin.dir}/${plugin.core.dir}" file="NOTICE"/>

       <!-- copy the plugin properties for use by the release target -->
       <copy file="${derby.jar.dir}/${plugin.tmp.dir}/plugintmp.properties" todir="${release.base}"/>

       <delete file="${derby.jar.dir}/${plugin.tmp.dir}/plugintmp.properties"/>
       <delete file="${derby.jar.dir}/${plugin.tmp.dir}/plugin.xml"/>

       <!-- ZIP to create the final Derby plug-in -->

       <zip zipfile="${derby.jar.dir}/${plugin.derby.core.zipfile}_${plugin.derby.version}.zip" compress="true" basedir="${derby.jar.dir}/${plugin.tmp.dir}"/>
       <delete dir="${derby.jar.dir}/${plugin.tmp.dir}"/>
  </target>

<!-- =================================================================== -->
<!--                               Jar targets                           -->
<!-- =================================================================== -->

  <target name="buildjarsclean" depends="cleanjars,buildjars"/>

  <target
      name="buildjars"
      depends="derbysharedjar,derbyjar,derbynetjar,derbyclientjar,derbytoolsjar,derbyoptionaltoolsjar,derbyrunjar,derbywar,derbylocalejars,derbytestingjar,jardriftcheck"
      description="Build all of the Derby jar files."

  />

  <target name="initjars" depends="setsanityname,getsvnversion">
    <property name="derby.jar.dir" value="${jarsdist.dir}/${sanity.name}"/>
    <property name="derby.jar.topdir" value="${jarsdist.dir}"/>
    <mkdir dir="${derby.jar.dir}"/>
    <mkdir dir="${derby.jar.dir}/lists"/>

    <tstamp>
      <format 
          property="javadoc.ts" 
          pattern="EEE yyyy-MM-dd HH:mm:ssZ" 
          locale="en, us"/>
    </tstamp>
    <property 
        name="javadoc.Footer" 
        value="Built on ${javadoc.ts}, from revision ${changenumber}"/>
  
  </target>


<!-- - - - - - - - - - - - - - - derby.jar target - - - - - - - - - - - -->

  <target name="derbyjar" depends="initjars">

    <echo level="info" message="Beginning derby.jar ${sanity.name} build"/>

    <!-- purge lists directory to avoid unnecessary content from other jars -->
    <delete>
      <fileset dir="${derby.jar.dir}/lists" includes="**/*"/>
    </delete>

    <mkdir dir="${derby.jar.dir}/lists/org/apache/derby"/>
    <java classname="org.apache.derbyBuild.propertyconfig" fork="yes">
      <arg value="${out.engine.dir}/org/apache/derby/modules.properties"/>
      <arg value="derby"/>
      <arg value="${derby.jar.dir}/lists/org/apache/derby/modules.properties"/>
      <classpath>
        <pathelement path="${out.build.dir}"/>
      </classpath>
    </java>

    <!-- This next antcall generates a new properties file for the build.  -->
    <!-- If a changenumber is passed into the build via a property file or -->
    <!-- on the command line, the build number will be inserted into the   -->
    <!-- build at this point.                                              -->
 
    <echo level="info" message=" creating new DBMS.properties file"/>
    <antcall target="infowriter">
      <param name="info.iname" value="Apache Derby Embedded Engine"/>
      <param name="info.ename" value="Apache Derby"/>
      <param name="info.buildnumber" value="${changenumber}"/>
      <param name="info.productfile" value="derby.jar"/>
      <param name="info.file" value="${out.engine.dir}/org/apache/derby/info/engine/info.properties"/>
    </antcall>

    <!-- copy boilerplate common to derby jar files -->
    <antcall target="meta-inf-common"/>

    <!-- declare the embedded driver for autoloading by the JDBC 4 DriverManager -->
    <antcall target="declare-autoloadable-driver">
      <param name="driver.name" value="org.apache.derby.iapi.jdbc.AutoloadedDriver"/>
    </antcall>

    <antcall target="make-core-derbyjar-manifest">
      <param name="manifest.file" value="${derby.jar.dir}/lists/smf.mf"/>
    </antcall>

    <!-- add extra osgi bits to manifest -->

    <manifest file="${derby.jar.dir}/lists/smf.mf"  mode="update">
      <attribute name="Bundle-Activator" value="org.apache.derby.osgi.EmbeddedActivator"/>
      <attribute name="Bundle-SymbolicName" value="derby"/>
      <attribute name="DynamicImport-Package" value="*"/>
      <attribute name="Export-Package" value="org.apache.derby.authentication,org.apache.derby.database,org.apache.derby.io,org.apache.derby.jdbc,org.apache.derby.vti"/> 
    </manifest> 

    <jar destfile="${derby.jar.dir}/derby.jar"
         basedir="${out.engine.dir}"
         excludes="**/D_*,**/*.done,**/*Test.class,**/_Suite.class,**/modules.properties"
         compress="true"
         filesonly="true"
         manifest="${derby.jar.dir}/lists/smf.mf">
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/**,
                         org/apache/derby/modules.properties"/>
   </jar>

  </target>

  <!-- Add localized jars to the classpath -->
  <target name="make-locale-classpath-manifest">
      <manifest file="${manifest.file}" mode="${manifest.mode}">
          <attribute name="Class-Path" value="derbyshared.jar derbyLocale_cs.jar derbyLocale_de_DE.jar derbyLocale_es.jar derbyLocale_fr.jar derbyLocale_hu.jar derbyLocale_it.jar derbyLocale_ja_JP.jar derbyLocale_ko_KR.jar derbyLocale_pl.jar derbyLocale_pt_BR.jar derbyLocale_ru.jar derbyLocale_zh_CN.jar derbyLocale_zh_TW.jar"/>
      </manifest>
  </target>

  <target name="make-core-derbyjar-manifest">

    <manifest file="${manifest.file}">
      <attribute name="Bundle-Vendor" value="Apache Software Foundation"/>
      <attribute name="Bundle-Name" value="Apache Derby ${major}.${minor}"/>
      <attribute name="Bundle-Version" value="${major}.${minor}.${maint}.${changenumber}"/>
      <attribute name="Bundle-ManifestVersion" value="2"/>
      	<attribute name="Sealed" value="true"/>
    	<section name="org/apache/derby/jdbc/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    </manifest> 

    <antcall target="make-locale-classpath-manifest">
        <param name="manifest.file" value="${manifest.file}"/>
        <param name="manifest.mode" value="update"/>
    </antcall>

  </target>

<!-- - - - - - - - - - - - -  derbytools.jar target - - - - - - - - - - -->

  <target name="derbytoolsjar" depends="initjars">

    <echo level="info" message="Beginning derbytools.jar ${sanity.name} build"/>

    <!-- purge lists directory to avoid unnecessary content from other jars -->
    <delete>
      <fileset dir="${derby.jar.dir}/lists" includes="**/*"/>
    </delete>

    <echo level="info" message=" creating new tools info.properties file "/>
    <antcall target="infowriter">
      <param name="info.buildnumber" value="${changenumber}"/>
      <param name="info.iname" value="Apache Derby Tools"/>
      <param name="info.ename" value="Apache Derby"/>
      <param name="info.productfile" value="derbytools.jar"/>
      <param name="info.file" value="${out.tools.dir}/org/apache/derby/info/tools/info.properties"/>
    </antcall>

    <!-- copy boilerplate common to derby jar files -->
    <antcall target="meta-inf-common"/>
    <antcall target="make-locale-classpath-manifest">
        <param name="manifest.file" value="${derby.jar.dir}/lists/smftools.mf"/>
        <param name="manifest.mode" value="replace"/>
    </antcall>

    <manifest file="${derby.jar.dir}/lists/smftools.mf">
      <attribute name="Class-Path" value="derby.jar derbyclient.jar derbynet.jar"/>
    </manifest> 
 	
    <delete file="${derby.jar.dir}/derbytools.jar"/>
    <jar destfile="${derby.jar.dir}/derbytools.jar"
         basedir="${out.tools.dir}"
         excludes="org/apache/derby/impl/tools/ij/SimpleCharStream.class,
                   org/apache/derby/impl/tools/ij/mt*.class"
         manifest="${derby.jar.dir}/lists/smftools.mf"
         compress="true"
         filesonly="true">
	  <fileset dir="${derby.tools.src.dir}"
               includes="org/apache/derby/impl/tools/planexporter/resources/*.xsl"/>
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/**"/>
    </jar>
  </target>

<!-- - - - - - - - - - - - -  derbyoptionaltools.jar target - - - - - - - - - - -->

  <target name="derbyoptionaltoolsjar" depends="initjars">

    <echo level="info" message="Beginning derbyoptionaltools.jar ${sanity.name} build"/>

    <!-- purge lists directory to avoid unnecessary content from other jars -->
    <delete>
      <fileset dir="${derby.jar.dir}/lists" includes="**/*"/>
    </delete>

    <echo level="info" message=" creating new optionaltools info.properties file "/>
    <antcall target="infowriter">
      <param name="info.buildnumber" value="${changenumber}"/>
      <param name="info.iname" value="Apache Derby Optional Tools"/>
      <param name="info.ename" value="Apache Derby"/>
      <param name="info.productfile" value="derbyoptionaltools.jar"/>
      <param name="info.file" value="${out.optional.dir}/org/apache/derby/optional/info.properties"/>
    </antcall>

    <!-- copy boilerplate common to derby jar files -->
    <antcall target="meta-inf-common"/>
    <manifest file="${derby.jar.dir}/lists/smfoptionaltools.mf">
      <attribute name="Bundle-Vendor" value="Apache Software Foundation"/>
      <attribute name="Bundle-Name" value="Apache Derby ${major}.${minor}"/>
      <attribute name="Bundle-Version" value="${major}.${minor}.${maint}.${changenumber}"/>
      <attribute name="Bundle-ManifestVersion" value="2"/>
      <attribute name="Sealed" value="true"/>
    </manifest> 

    <antcall target="make-locale-classpath-manifest">
        <param name="manifest.file" value="${derby.jar.dir}/lists/smfoptionaltools.mf"/>
        <param name="manifest.mode" value="update"/>
    </antcall>

    <delete file="${derby.jar.dir}/derbyoptionaltools.jar"/>
    <jar destfile="${derby.jar.dir}/derbyoptionaltools.jar"
         basedir="${out.optional.dir}"
         manifest="${derby.jar.dir}/lists/smfoptionaltools.mf"
         compress="true"
         filesonly="true">
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/**"/>
    </jar>
  </target>

<!-- - - - - - - - - - - - - - derbynet.jar target - - - - - - - - - - - -->

  <target name="derbynetjar" depends="initjars">

    <echo level="info" message="Beginning derbynet.jar ${sanity.name} build"/>

    <!-- purge lists directory to avoid unnecessary content from other jars -->
    <delete>
      <fileset dir="${derby.jar.dir}/lists" includes="**/*"/>
    </delete>

    <echo level="info" message=" creating new net info.properties file "/>
    <antcall target="infowriter">
      <param name="info.buildnumber" value="${changenumber}"/>
      <param name="info.iname" value="Apache Derby Network Server"/>
      <param name="info.ename" value="Apache Derby"/>
      <param name="info.productfile" value="derbynet.jar"/>
      <param name="info.file" value="${out.drda.dir}/org/apache/derby/info/net/info.properties"/>
    </antcall>

    <!-- copy boilerplate common to derby jar files -->
    <antcall target="meta-inf-common"/>

    <manifest file="${derby.jar.dir}/lists/smfnet.mf">
      <attribute name="Main-Class" value="org.apache.derby.drda.NetworkServerControl"/>
      <attribute name="Class-Path" value="derby.jar derbyshared.jar derbytools.jar"/>
      	<attribute name="Sealed" value="true"/>
    </manifest> 

    <delete file="${derby.jar.dir}/derbynet.jar"/>
    <jar destfile="${derby.jar.dir}/derbynet.jar"
         basedir="${out.drda.dir}"
         compress="true"
         filesonly="true"
    	 manifest="${derby.jar.dir}/lists/smfnet.mf">
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/**"/>
    </jar>

  </target>

<!-- - - - - - - - - - - - - - derbyclient.jar target - - - - - - - - -->

 <target name="derbyclientjar" depends="initjars">

    <echo level="info" message="Beginning derbyclient.jar ${sanity.name} build"/>

    <!-- purge lists directory to avoid unnecessary content from other jars -->
    <delete>
      <fileset dir="${derby.jar.dir}/lists" includes="**/*"/>
    </delete>

    <mkdir dir="${out.client.dir}/org/apache/derby/info/"/>
    <antcall target="infowriter">
      <param name="info.buildnumber" value="${changenumber}"/>
      <param name="info.iname" value="Apache Derby Network Client"/>
      <param name="info.ename" value="Apache Derby"/>
      <param name="info.productfile" value="codeline"/>
      <param name="info.file" value="${out.client.dir}/org/apache/derby/info/client/info.properties"/>
    </antcall>

    <!-- copy boilerplate common to derby jar files -->
    <antcall target="meta-inf-common"/>
    <antcall target="make-core-derbyjar-manifest">
      <param name="manifest.file" value="${derby.jar.dir}/lists/smfclient.mf"/>
    </antcall>

    <!-- add extra osgi bits to manifest -->

    <manifest file="${derby.jar.dir}/lists/smfclient.mf"  mode="update">
      <attribute name="Bundle-SymbolicName" value="derbyclient"/>
      <attribute name="DynamicImport-Package" value="*"/>
      <attribute name="Export-Package" value="org.apache.derby.jdbc"/> 
    </manifest> 

    <!-- declare the client driver for autoloading by the JDBC 4 DriverManager -->
    <antcall target="declare-autoloadable-driver">
      <param name="driver.name" value="org.apache.derby.client.ClientAutoloadedDriver"/>
    </antcall>

    <delete file="${derby.jar.dir}/derbyclient.jar"/>

    <jar destfile="${derby.jar.dir}/derbyclient.jar"
         basedir="${out.client.dir}"
         compress="true"
         filesonly="true"
         update="true"
         excludes="org/apache/derby/loc/clientmessages_qq_PP_testOnly.properties,
                   **/*Test.class,
                   **/_Suite.class"
    	 manifest="${derby.jar.dir}/lists/smfclient.mf">
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/**"/>
    </jar>
  </target>


<!-- - - - - - - - - - - - - - derbyshared.jar target - - - - - - - - - - - -->

  <target name="derbysharedjar" depends="initjars">

    <echo level="info" message="Beginning derbyshared.jar ${sanity.name} build"/>

    <!-- purge lists directory to avoid unnecessary content from other jars -->
    <delete>
      <fileset dir="${derby.jar.dir}/lists" includes="**/*"/>
    </delete>

    <echo level="info" message=" creating new shared.properties file "/>
    <antcall target="infowriter">
      <param name="info.buildnumber" value="${changenumber}"/>
      <param name="info.iname" value="Apache Derby Shared Utilities"/>
      <param name="info.ename" value="Apache Derby"/>
      <param name="info.productfile" value="derbyshared.jar"/>
      <param name="info.file" value="${out.shared.dir}/org/apache/derby/info/shared/info.properties"/>
    </antcall>

    <!-- copy boilerplate common to derby jar files -->
    <antcall target="meta-inf-common"/>
    <antcall target="make-locale-classpath-manifest">
        <param name="manifest.file" value="${derby.jar.dir}/lists/smfshared.mf"/>
        <param name="manifest.mode" value="update"/>
    </antcall>

    <delete file="${derby.jar.dir}/derbyshared.jar"/>
    <jar destfile="${derby.jar.dir}/derbyshared.jar"
         basedir="${out.shared.dir}"
         compress="true"
         filesonly="true"
    	 manifest="${derby.jar.dir}/lists/smfshared.mf"/>

  </target>

<!-- - - - - - - - - - - - - - derbyrun.jar target  - - - - - - - - - -->
   
  <target name="derbyrunjar" depends="initjars">

    <echo level="info" message="Beginning derbyrun.jar build"/>

    <!-- purge lists directory to avoid unnecessary content from other jars -->
    <delete>
      <fileset dir="${derby.jar.dir}/lists" includes="**/*"/>
    </delete>

    <!-- copy boilerplate common to derby jar files -->
    <antcall target="meta-inf-common"/>
    
    <manifest file="${derby.jar.dir}/lists/smfcmd.mf">
      <attribute name="Main-Class" value="org.apache.derby.run.run"/>
      <attribute name="Class-Path" value="derby.jar derbyclient.jar derbytools.jar derbynet.jar derbyoptionaltools.jar derbyshared.jar"/>
    </manifest> 
 	
    <jar destfile="${derby.jar.dir}/derbyrun.jar"
         basedir="${out.run.dir}"
         compress="true"
         filesonly="true"
         update="true"
    	 manifest="${derby.jar.dir}/lists/smfcmd.mf">
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/LICENSE,META-INF/NOTICE"/>
    </jar>

  </target>
<!-- - - - - - - - - - - - - - derby.war target - - - - - - - - - - - -->

 <target name="derbywar" depends="initjars">

    <echo level="info" message="Beginning derby.war  build"/>
    <delete file="${derby.jar.dir}/derby.war"/>
    <zip zipfile="${derby.jar.dir}/derby.war" compress="true" basedir="tools/j2ee/derby"/>
  </target>

<!-- - - - - - - - - - - - - - locale jar targets - - - - - - - - - - - -->

  <target name="derbylocalejars" depends="initjars">
 
    <!-- purge lists directory to avoid unnecessary content from other jars -->
    <delete>
      <fileset dir="${derby.jar.dir}/lists" includes="**/*"/>
    </delete>

    <!-- copy boilerplate common to derby jar files -->
    <antcall target="meta-inf-common"/>

    <!-- call macro localejar for each locale -->

    <localejar
      locale.iname="cs"
      locale.ename="Czech/International [cs]"/>
    <localejar
      locale.iname="de_DE"
      locale.ename="German/Germany [de_DE]"/>
    <localejar
      locale.iname="es"
      locale.ename="Spanish/International [es]"/>
    <localejar
      locale.iname="fr"
      locale.ename="French/International [fr]"/>
    <localejar
      locale.iname="hu"
      locale.ename="Hungarian/International [hu]"/>
    <localejar
      locale.iname="it"
      locale.ename="Italian/International [it]"/>
    <localejar
      locale.iname="ja_JP"
      locale.ename="Japanese/Japan [ja_JP]"/>
    <localejar
      locale.iname="ko_KR"
      locale.ename="Korean/Korea [ko_KR]"/>
    <localejar
      locale.iname="pl"
      locale.ename="Polish/International [pl]"/>
    <localejar
      locale.iname="pt_BR"
      locale.ename="Portuguese/Brazil [pt_BR]"/>
    <localejar
      locale.iname="ru"
      locale.ename="Russian/International [ru]"/>
    <localejar
      locale.iname="zh_CN"
      locale.ename="Simplified_Chinese/PR_China [zh_CN]"/>
    <localejar
      locale.iname="zh_TW"
      locale.ename="Chinese/Taiwan_Traditional [zh_TW]"/>

  </target>

  <macrodef name="localejar">
    <attribute name="locale.iname"/>
    <attribute name="locale.ename"/>
    <attribute name="locale.output.dir"
               default="${out.dir}/${locale.stub}@{locale.iname}/org/apache/derby/info/${locale.stub}@{locale.iname}"/>
    <sequential>

      <echo level="info" message="Building derbyLocale_@{locale.iname}.jar"/>

      <localeinfowriter
        info.buildnumber="${changenumber}"
              info.iname="_@{locale.iname}"
              info.ename="@{locale.ename}"
              info.file="@{locale.output.dir}/info.properties"
        info.productfile="derbyLocale_@{locale.iname}.jar"/>

      <jar destfile="${derby.jar.dir}/derbyLocale_@{locale.iname}.jar"
          basedir="${out.dir}/${locale.stub}@{locale.iname}"
          compress="true"
          filesonly="true"
        >
        <fileset dir="${derby.jar.dir}/lists"
                includes="META-INF/LICENSE,META-INF/NOTICE"/>
      </jar>
    </sequential>
  </macrodef>

<!-- - - - - - - - - - - - derby testing jar target - - - - - - - - - - -->

  <target name="derbytestingjar" depends="initjars,ckderbytesting" if="derbyTesting.available">
    <!-- generate tsting info property file -->
    <antcall target="tstinginfowriter">
      <param name="info.buildnumber" value="${changenumber}"/>
      <param name="info.iname" value="tsting"/>
      <param name="info.productfile" value="derbyTesting.jar"/>
      <param name="info.file" value="${out.testing.dir}/org/apache/derby/info/tsting/info.properties"/>
    </antcall>

    <delete file="${derby.jar.dir}/derbyTesting.jar"/>
    <jar destfile="${derby.jar.dir}/derbyTesting.jar"
         basedir="${out.testing.dir}"
         compress="true"
         filesonly="true"/>

  </target>

  <target name="ckderbytesting">
    <available file="${out.testing.dir}/org/apache/derbyTesting"
               property="derbyTesting.available"/>
  </target>

  <target name="buildtestinginfo">
    <antcall target="tstinginfowriter">
      <param name="info.buildnumber" value="1"/>
      <param name="info.iname" value="tsting"/>
      <param name="info.productfile" value="derbyTesting.jar"/>
      <param name="info.file" value="${out.testing.dir}/org/apache/derby/info/tsting/info.properties"/>
    </antcall>
  </target>

  <target name="tstinginfowriter">
    <propertyfile file="${info.file}" comment="${copyright.comment}">
      <entry key="derby.tsting.version.major" value="${major}"/>
      <entry key="derby.tsting.version.minor" value="${minor}"/>
      <entry key="derby.tsting.version.maint" value="${maint}"/>
      <entry key="derby.tsting.build.number" value="${info.buildnumber}"/>
      <entry key="derby.tsting.technology.name" value="${info.iname}"/>
      <entry key="derby.tsting.external.name" value="${info.iname}"/>
      <entry key="derby.version.beta" value="${beta}"/>
      <entry key="derby.tsting.vendor" value="${vendor}"/>
      <entry key="derby.product.file" value="${info.productfile}"/>
    </propertyfile>
  </target>

<!-- - - - - - - - - - - -  jar build helper targets  - - - - - - - - - -->

  <target name="setsanityname" depends="init,setissane,sanitynamesane,sanitynameinsane"/>

  <target name="sanitynamesane" if="is.sane">
    <property name="sanity.name" value="sane"/>
  </target>

  <target name="sanitynameinsane" unless="is.sane">
    <property name="sanity.name" value="insane"/>
  </target>


   <target name="getsvnversion" unless="changenumber">
     <exec executable="svnversion"
           failifexecutionfails="no"
           output="${out.base}/changenumber.properties">
       <arg value="${basedir}"/>
       <arg value="-n"/>
     </exec>
     <loadfile srcFile="${out.base}/changenumber.properties"
               failonerror="false"
               property="changenumber">
       <filterchain>
         <striplinebreaks/>
       </filterchain>
     </loadfile>    
     <condition property="changenumber" value="???">
       <not>
         <isset property="changenumber"/>
       </not>
     </condition>
     <echo level="info" message="Revision number set to ${changenumber}."/>
   </target>

  <target name="cleanjars" depends="setsanityname">
    <delete dir="${jarsdist.dir}/${sanity.name}"/>
  </target>

<!-- - - - - - - - - - - -  release build helper targets  - - - - - - - - - -->

   <!-- Update both subversion clients for building release distributions -->
   <target name="updatesvnclients" depends="updatesvncode,updatesvndoc"/>

   <target name="updatesvncode">
     <exec executable="svn">
       <arg value="update"/>
       <arg value="${basedir}"/>
     </exec>
   </target>
   <target name="updatesvndoc">
     <exec executable="svn">
       <arg value="update"/>
       <arg value="${docs.root}"/>
     </exec>
   </target>

   <!-- Verify that both the code and docs clients have no in-flight edits -->
   <target name="checksvnclientsclean" unless="debug.release.build">

      <antcall target="checksvnclean">
         <param name="client.root" value="${docs.root}"/>
      </antcall>

      <antcall target="checksvnclean">
         <param name="client.root" value="${basedir}"/>
      </antcall>

   </target>

   <!-- Check that a subversion client has no files checked out -->
   <target name="checksvnclean">
     <exec executable="svn"
           outputproperty="svnstatusoutput"
     >
       <arg value="status"/>
       <arg value="${client.root}"/>
     </exec>

     <fail message="Cannot build a release. The ${client.root} subversion client is not clean: ${svnstatusoutput}">
         <condition>
             <not><equals arg1="${svnstatusoutput}" arg2="" trim="true"/></not>
         </condition>
     </fail>     
   </target>

   <!-- Checkin the generated error documentation to the docs client -->
   <target name="copyerrordocs">

     <!-- Build the SQLState tables -->
     <antcall target="all">
        <param name="sane" value="true"/>
        <param name="sanity" value="true"/>
        <param name="sanity.name" value="sane"/>
        <param name="deprecation" value="off"/>
     </antcall>

     <property name="refdir" value="${docs.root}/src/ref"/>

     <copy file="${sqlstateTables}" todir="${refdir}"/>

      <antcall target="checkinfile">
         <param name="checkinComment" value="Check in SQLState tables as part of building a release."/>
         <param name="fileName" value="${refdir}/rrefexcept71493.dita"/>
      </antcall>

   </target>

   <!-- Build the NOTICE file and check it in -->
   <target name="buildnotice">

     <property file="${properties.dir}/release.properties"/>
     <property name="noticefile" value="${basedir}/NOTICE"/>

     <!-- plug in the current copyright year -->
     <copy overwrite="true" file="${derby.notice.src.dir}/preamble.txt" tofile="${noticefile}">
       <filterset>
         <filter token="COPYRIGHT_YEAR" value="${copyright.year}"/>
       </filterset>
     </copy>

     <antcall target="appendnotice"><param name="sourcefile" value="initialgrant.txt"/></antcall>
     <antcall target="appendnotice"><param name="sourcefile" value="nisttestgrant.txt"/></antcall>
     <antcall target="appendnotice"><param name="sourcefile" value="felix.txt"/></antcall>
     <antcall target="appendnotice"><param name="sourcefile" value="lucene.txt"/></antcall>
     <antcall target="appendnotice"><param name="sourcefile" value="simpleJson.txt"/></antcall>
     <antcall target="appendnotice"><param name="sourcefile" value="tomcat.txt"/></antcall>
     
      <antcall target="checkinfile">
         <param name="checkinComment" value="Check in NOTICE as part of building a release."/>
         <param name="fileName" value="${noticefile}"/>
      </antcall>

   </target>

   <!--
       Append a file to the notice file

       Args:
           noticefile   Destination NOTICE file
           sourcefile  Source file to append.
   -->
   <target name="appendnotice">
     <concat destfile="${noticefile}" append="true">
        <filelist files="${derby.notice.src.dir}/separator.txt,${derby.notice.src.dir}/${sourcefile}"/>
     </concat>
   </target>

   <!--
       Checkin in-flight edits. Do not checkin files if we are running in debug mode.

       Args:
           checkinComment   This is the subversion checkin comment.
           fileName   This is the name of the file to checking (could be the root of the client).
   -->
   <target name="checkinfile" unless="debug.release.build">

     <property name="checkinMessage" value="${release.base}/tmp.checkin.message"/>
     <property name="fullComment" value="[RELEASE CHECKIN] ${checkinComment}"/>

     <echo file="${checkinMessage}" message="${fullComment}"/>
     <echo message="Checking in ${fileName} with this comment: ${fullComment}"/>

     <exec executable="svn" failonerror="true">
       <arg value="commit"/>
       <arg value="--username"/>
       <arg value="${svn.username}"/>
       <arg value="--password"/>
       <arg value="${svn.password}"/>
       <arg value="-F"/>
       <arg value="${checkinMessage}"/>
       <arg value="${fileName}"/>
     </exec>

     <!-- Bring the docs client up to date again -->
     <antcall target="updatesvndoc"/>

   </target>

   <!-- Targets used to specify the correct ant executable -->
   <target name="ant-exec-windows" unless="isUnix">
     <property name="ant.exec" value="ant.bat"/>
   </target>

   <target name="ant-exec-unix" unless="isWindows">
     <property name="ant.exec" value="ant"/>
   </target>

   <!-- Build the user documentation -->
   <target name="builduserdocs" depends="ant-exec-windows,ant-exec-unix,checkdocsroot">

     <property file="${properties.dir}/release.properties"/>
     <property file="${properties.dir}/defaultcompiler.properties"/>

     <antcall target="getsvnversion"/>

     <ant dir="${docs.root}" target="clobber"/>

     <exec executable="${ant.exec}" dir="${docs.root}">
       <env key="ANT_OPTS" value="-Xmx512m"/>
       <env key="CLASSPATH" path="${docs.root}/lib/fop.jar"/>
       <arg value="-Drelease.id.short=${eversion}"/>
       <arg value="-Drelease.id.long=${release.id.long}"/>
       <arg value="-Dcopyright.year=${copyright.year}"/>
       <arg value="-Dminimum.jdk=${min.version}"/>
       <arg value="-Dsubversion.revision=${changenumber}"/>
       <arg value="all"/>
     </exec>

   </target>

<!-- - - - - - - - - - - - - - targets for populating META-INF  - - - - - - - - - - - -->

  <!-- copy boilerplate common to derby jar files -->

  <target name="meta-inf-common">
 
    <mkdir dir="${derby.jar.dir}/lists/META-INF"/>
    <copy todir="${derby.jar.dir}/lists/META-INF">
      <fileset dir="${basedir}" includes="LICENSE*,NOTICE*"/>
    </copy>

  </target>

  <!--
    Declare the jdbc driver for autoloading under JDBC 4.

    Parameters:

      driver.name   Class name of driver to be autoloaded by JDBC 4 DriverManager
  -->

  <target name="declare-autoloadable-driver">
 
    <mkdir dir="${derby.jar.dir}/lists/META-INF/services"/>
    <echo level="info" file="${derby.jar.dir}/lists/META-INF/services/java.sql.Driver">${driver.name}
</echo>

  </target>


<!-- =================================================================== -->
<!--       IDE build targets used by the projects under tools/ide/       -->
<!-- =================================================================== -->

  <!-- Target used by NetBeans to build all code modules and all jars. -->
  <target name="nb-buildall" depends="all,buildjarsclean"/>


<!-- =================================================================== -->
<!--                         Nightly build targets                       -->
<!-- =================================================================== -->

  <target name="buildworld">

    <property name="proceed" value="true"/>

    <!-- Build insane product jars -->
    <antcall target="clobber"/>
    <antcall target="insane"/>
    <antcall target="all"/>
    <antcall target="buildjars"/>

    <!-- Build sane product jars -->
    <antcall target="clobber"/>
    <antcall target="sane"/>
    <antcall target="all"/>
    <antcall target="buildjars"/>

    <!-- Build everything else -->
    <antcall target="javadoc"/>

  </target>

  <!-- 
     cibuild - target suitable for continuous integration builds.
     Clobbers/cleans everything it can, then builds the jars
     and the javadoc. 
  -->
  <target name="cibuild"
	depends="clobber,cleanjars,cleandocs,junit-clean,gump_all"/>

  <target name="gump_all" depends="all,buildjars,javadoc"/>

  <target name="snapshot" depends="clobber,snapshotError,init,initjars">
    <antcall target="insane"/>
    <antcall target="all"/>
    <antcall target="buildjars"/>
    <antcall target="publishedapi"/>

    <java classname="org.apache.derbyBuild.maintversion2props">
        <classpath path="${out.build.dir}"/>
        <arg value="${out.engine.dir}/org/apache/derby/info/engine/info.properties"/>
        <arg value="${snapshot.dir}/maintversion.properties"/>
    </java>
    <property file="${snapshot.dir}/maintversion.properties"/>
    <zip destfile="${snapshot.dir}/db-derby-snapshot-${major}.${minor}.${interim}.${point}-${changenumber}.zip">
      <zipfileset prefix="db-derby-snapshot-${major}.${minor}.${interim}.${point}-${changenumber}/lib" dir="${jarsdist.dir}/insane" includes="*.jar,*.war"/>
      <zipfileset prefix="db-derby-snapshot-${major}.${minor}.${interim}.${point}-${changenumber}" dir="${basedir}" includes="bin/**,LICENSE,NOTICE,README,javadoc/publishedapi/**" excludes="bin/templates/**"/>
    </zip>
    <tar destfile="${snapshot.dir}/db-derby-snapshot-${major}.${minor}.${interim}.${point}-${changenumber}.tar.gz"
         compression="gzip">
      <tarfileset prefix="db-derby-snapshot-${major}.${minor}.${interim}.${point}-${changenumber}/lib" dir="${jarsdist.dir}/insane" includes="*.jar,*.war"/>
      <tarfileset prefix="db-derby-snapshot-${major}.${minor}.${interim}.${point}-${changenumber}" dir="${basedir}" includes="bin/**,LICENSE,NOTICE,README,javadoc/publishedapi/**" excludes="bin/templates/**"/>
    </tar>

    <!-- debug archives - DERBY-178 --> 
    <zip destfile="${snapshot.dir}/db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}.zip">
      <zipfileset prefix="db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}/lib" dir="${jarsdist.dir}/sane" includes="*.jar,*.war"/>
      <zipfileset prefix="db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}" dir="${basedir}" includes="bin/**,LICENSE,NOTICE,README,javadoc/publishedapi/**" excludes="bin/templates/**"/>
    </zip>
    <tar destfile="${snapshot.dir}/db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}.tar.gz"
         compression="gzip">
      <tarfileset prefix="db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}/lib" dir="${jarsdist.dir}/sane" includes="*.jar,*.war"/>
      <tarfileset prefix="db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}" dir="${basedir}" includes="bin/**,LICENSE,NOTICE,README,javadoc/publishedapi/**" excludes="bin/templates/**"/>
    </tar>

  </target>

  <target name="snapshotError" if="is.sane">
    <echo level="error" message="Please run the snapshot using an insane build,"/>
    <echo level="error" message="but don't forget to generate a sane build into jars/sane also."/>
    <echo level="error" message="Either run &quot;ant -Dsane=false snapshot&quot;, or run"/>
    <echo level="error" message="the insane target before running the snapshot target."/>
    <echo level="error" message="For more information, see:"/>
    <echo level="error" message="http://wiki.apache.org/db-derby/DerbySnapshotOrRelease"/>

    <echo level="error" message=""/>
    <fail message="Exiting snapshot build..."/>
  </target>

<!-- =================================================================== -->
<!--                         Junit utility targets                       -->
<!-- =================================================================== -->

  <!-- Basic initialization for Junit tests (doesn't configure classpath). -->
  <target name="junit-init-nocp">
    <tstamp prefix="derby.junit">
      <format property="standardtime" pattern="yyyy-MM-dd hh:mm aa zzz"/>
    </tstamp>
    <property name="derby.junit.jvm" value="${java.home}/bin/java"/>
    <property name="derby.junit.timestamp" value="${derby.junit.DSTAMP}_${derby.junit.TSTAMP}"/>
    <mkdir dir="junit_${derby.junit.timestamp}/testout"/>

    <!-- Set a dummy value for the JaCoCo agent option when running without
         JaCoCo for code coverage. Required because ant doesn't (yet) handle
         empty variables passed to jvmarg. See also target jacoco-enable. -->
    <!-- The purpose of the system property derby.tests.jacoco.agent is to
         allow the Derby test framework to pass on the correct -javaagent
         option when spawning VMs. -->
    <condition property="derby.tests.jacoco.agent" value="-Dderby.dummy.prop=X">
      <not>
        <isset property="derby.tests.jacoco.agent"/>            
      </not>
    </condition>
  </target>

  <target name="junit-init" depends="junit-init-nocp">
    <!-- Set up the default classpath to use with JUnit tests. junit tasks
         should include the following entries in the order specified in 
         their nested classpath structure:
                <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
                <pathelement path="${derby.junit.classpath}"/>

         The preferences:
           1) User-specified derby.junit.classpath
           2) Jars (insane preferred over sane)
           3) classes-directory

         Note also that the user's CLASSPATH environment variable is appended
         to the JUnit classpath, but in most cases Derby classes here will be
         shadowed by one of the above entries. It is recommended to not have
         any Derby classes in the CLASSPATH environment variable.
     -->

    <!-- See if the jars have been built
         (skipped if derby.junit.classpath is set) -->
    <condition property="tmp.jars" value="${jarsdist.dir}/insane">
        <and>
            <available file="${jarsdist.dir}/insane/"/>
            <not>
                <isset property="derby.junit.classpath"/>
            </not>
        </and>
    </condition>
    <condition property="tmp.jars" value="${jarsdist.dir}/sane">
        <and>
            <available file="${jarsdist.dir}/sane/"/>
            <not>
                <isset property="derby.junit.classpath"/>
            </not>
        </and>
    </condition>

    <!-- Use classes-directory if not using jars and not overriden by user -->
    <condition property="derby.junit.classpath" value="${out.all.dir}">
        <not>
            <or>
                <isset property="derby.junit.classpath"/>
                <isset property="tmp.jars"/>
            </or>
        </not>
    </condition>

    <!-- Property to trigger informational message. -->
    <condition property="emit.junit.lowmem.jars">
        <isset property="tmp.jars"/>
    </condition>

    <!-- We have to set this to something, so point it to a src dir that
         always exists (with no jars). -->
    <condition property="derby.junit.test.jars" value="${basedir}/java/build">
        <not>
            <isset property="tmp.jars"/>
        </not>
    </condition>
    <condition property="derby.junit.test.jars" value="${tmp.jars}">
        <isset property="tmp.jars"/>
    </condition>

    <property file="${properties.dir}/extrapath.properties"/>

    <antcall target="emit-junit-classpath-jars"/>
    <antcall target="emit-junit-classpath"/>
  </target>

  <target name='emit-junit-classpath-jars' if='emit.junit.lowmem.jars'>
        <echo message="Running with jars: ${derby.junit.test.jars}" level='info'/>
        <echo message="CLASSPATH (environment variable): ${env.CLASSPATH}" level='info'/>
  </target>

  <target name='emit-junit-classpath' unless='emit.junit.lowmem.jars'>
        <echo message="Running with classes or user specified classpath: ${derby.junit.classpath}" level='info'/>
        <echo message="CLASSPATH (environment variable): ${env.CLASSPATH}" level='info'/>
   </target>

  <target name="junit-sysinfo" depends="junit-init">
    <java classname="org.apache.derby.tools.sysinfo"
          output="junit_${derby.junit.timestamp}/sysinfo.txt">
        <classpath path="${out.all.dir}"/>
    </java>
  </target>

  <target
      name="junit-clean"
      description="Remove the output produced by the JUnit tests."
  >
    <delete includeEmptyDirs="true">
      <fileset dir="${basedir}" includes="junit*/**"/>
    </delete>
  </target>
	  <!--
	  Autoloading tests need to be run in a separate JVM thus
	  as a separate test. This target runs the test a number of 
	  times, each with a different setting for jdbc.drivers.
	  When run with jar files on java SE 6/JDBC 4 the run without
	  setting jdbc.drivers will test that autoloading from
	  the manifest file works. The settings with jdbc.drivers
	  test the auto-loading in non JDBC 4 environments and
	  that setting jdbc.drivers in JDBC 4 does not cause issues.
	   -->
	
  <target name="junit-core" depends="junit-init">
    <condition property="derbyTesting.oldReleasePath" value="">
      <not>
        <isset property="derbyTesting.oldReleasePath"/>
      </not>
    </condition>
         <!--
         Specifying max heap size (maxmemory) for JVMs spawned by this
         target, since the default max heap size on most systems is
         currently too low for some of the test suites. See DERBY-2988.
         -->
  	 <junit printsummary="on"
           fork="yes" forkmode="perTest"
           jvm="${derby.junit.jvm}" maxmemory="512m"
           showoutput="yes"
           dir="junit_${derby.junit.timestamp}"
           tempdir="junit_${derby.junit.timestamp}"
  	 	   errorproperty="tests.failed"
  	       failureproperty="tests.failed">
      <jvmarg value="${derby.tests.jacoco.agent}"/>
      <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>
      <sysproperty key="derby.tests.jacoco.agent" value="${derby.tests.jacoco.agent}"/>
      <sysproperty key="derbyTesting.oldReleasePath" value="${derbyTesting.oldReleasePath}"/>
      <!-- This property is needed to keep EMMA silent when measuring codecoverage -->
      <sysproperty key="emma.verbosity.level" value="silent"/>
      <!-- Pass on properties from the command line to the spawned VM. -->
      <syspropertyset id="system-properties-passed-on">
        <propertyref builtin="commandline"/>
      </syspropertyset>
      <!-- Use the system property below to debug lacking java security permissions -->
<!--      <sysproperty key="java.security.debug" value="access:failure"/> -->
      <formatter type="xml"/>
<test name="org.apache.derbyTesting.junit.EnvTest"
    todir="junit_${derby.junit.timestamp}"/>  	 	
<test name="org.apache.derbyTesting.functionTests.tests.derbynet._Suite"
	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.tools._Suite"
  	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.demo._Suite"
  	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.lang._Suite"
	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.jdbcapi._Suite"
	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.store._Suite"
	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.engine._Suite"
	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationSuite"
    todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.unitTests.junit._Suite"
    todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.upgradeTests._Suite"
  	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.suites.EncryptionSuite"
	todir="junit_${derby.junit.timestamp}"/>

      <classpath>
            <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
     	    <pathelement path="${derby.junit.classpath}"/>
            <!-- ant 1.7 finds junit.jar if it is on the classpath of the <junit> task -->
            <pathelement location="${javatools.dir}/junit.jar"/>
            <pathelement location="${lucene_core}"/>
            <pathelement location="${lucene_a_co}"/>
            <pathelement location="${lucene_qp}"/>
            <pathelement location="${json_simple}"/>
      </classpath>
    </junit>
  </target>

  <!--
    Run the simplest form of any system test. Provides a sanity
    check that the functionality works. This target is not intended
    to have long running tests, just enough to ensure the test works
    and Derby works with the test.
  -->
  <target name="junit-system-mini" depends="junit-init">
        <!--
             Specifying max heap size (maxmemory) for JVMs spawned by this
             target, since the default max heap size on most systems is
             currently too low for some of the test suites. See DERBY-2988.
         -->
        <junit printsummary="on"
               fork="yes" forkmode="perTest"
               jvm="${derby.junit.jvm}" maxmemory="512m"
               showoutput="yes"
               dir="junit_${derby.junit.timestamp}"
               tempdir="junit_${derby.junit.timestamp}"
               errorproperty="tests.failed"
               failureproperty="tests.failed">
          <jvmarg value="${derby.tests.jacoco.agent}"/>
          <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>
          <sysproperty key="derby.tests.jacoco.agent" value="${derby.tests.jacoco.agent}"/>
          <!-- Pass on properties from the command line to the spawned VM. -->
          <syspropertyset id="system-properties-passed-on">
            <propertyref builtin="commandline"/>
          </syspropertyset>
          <formatter type="xml"/>

    <test name="org.apache.derbyTesting.system.oe.test.OETest"
        todir="junit_${derby.junit.timestamp}"/>
          <classpath>
               <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
               <pathelement path="${derby.junit.classpath}"/>
               <pathelement location="${javatools.dir}/junit.jar"/>
          </classpath>
         </junit>
  </target>
	  
  <target name="junit-jdbc4" depends="junit-init">
    <antcall target="junit-jdbc4-workhorse"/>
  </target>

  <!--
    This target is called by junit-jdbc after reading the VM level.
  -->
  <target name="junit-jdbc4-workhorse" depends="junit-init">
  	 <junit printsummary="on"
           fork="yes" forkmode="perTest"
           showoutput="yes"
           dir="junit_${derby.junit.timestamp}"
           tempdir="junit_${derby.junit.timestamp}"
  	 	   errorproperty="tests.failed"
  	       failureproperty="tests.failed">
      <jvmarg value="${derby.tests.jacoco.agent}"/>
      <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>
      <sysproperty key="derby.tests.jacoco.agent" value="${derby.tests.jacoco.agent}"/>
      <!-- Pass on properties from the command line to the spawned VM. -->
      <syspropertyset id="system-properties-passed-on">
        <propertyref builtin="commandline"/>
      </syspropertyset>
      <formatter type="xml"/>
  	 	
      <test name="org.apache.derbyTesting.functionTests.tests.jdbc4._Suite"
      	todir="junit_${derby.junit.timestamp}"/>
        <classpath>
            <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
       	    <pathelement path="${derby.junit.classpath}"/>
            <pathelement location="${javatools.dir}/junit.jar"/>
        </classpath>
      </junit>	
  </target>

  <!-- low memory suite runs with 16MB heap  -->
  <target name="junit-lowmem"  depends="junit-init">
  	 <junit printsummary="on"
           fork="yes" forkmode="perTest"
           jvm="${derby.junit.jvm}" maxmemory="16m"
           showoutput="yes"
           dir="junit_${derby.junit.timestamp}"
           tempdir="junit_${derby.junit.timestamp}"
  	 	   errorproperty="tests.failed"
  	       failureproperty="tests.failed">
      <jvmarg value="${derby.tests.jacoco.agent}"/>
      <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>
      <sysproperty key="derby.tests.jacoco.agent" value="${derby.tests.jacoco.agent}"/>
      <!-- Pass on properties from the command line to the spawned VM. -->
      <syspropertyset id="system-properties-passed-on">
        <propertyref builtin="commandline"/>
      </syspropertyset>
      <formatter type="xml"/>
  	 	
      <test name="org.apache.derbyTesting.functionTests.tests.memory._Suite"
      	todir="junit_${derby.junit.timestamp}"/>
        <classpath>
            <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
       	    <pathelement path="${derby.junit.classpath}"/>
            <pathelement location="${javatools.dir}/junit.jar"/>
        </classpath>
      </junit>	
  </target>

  <!-- Runs Derby's JMX tests -->
  <target name="junit-jmx" depends="junit-init">
    <junit  printsummary="on"
            fork="yes" forkmode="once"
            showoutput="yes"
            dir="junit_${derby.junit.timestamp}"
            tempdir="junit_${derby.junit.timestamp}"
            errorproperty="tests.failed"
            failureproperty="tests.failed">
        <jvmarg value="${derby.tests.jacoco.agent}"/>
        <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>
        <sysproperty key="derby.tests.jacoco.agent" value="${derby.tests.jacoco.agent}"/>
        <!-- Pass on properties from the command line to the spawned VM. -->
        <syspropertyset id="system-properties-passed-on">
          <propertyref builtin="commandline"/>
        </syspropertyset>
        <formatter type="xml"/>

        <test name="org.apache.derbyTesting.functionTests.tests.management._Suite"
              todir="junit_${derby.junit.timestamp}"/>

        <classpath>
            <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
            <pathelement path="${derby.junit.classpath}"/>
            <pathelement location="${javatools.dir}/junit.jar"/>
        </classpath>
    </junit>
  </target>

  <!-- Run the package private tests against the classes directories. -->
  <target name="junit-pptesting" depends="junit-init-nocp">
    <junit  printsummary="on"
            fork="yes" forkmode="once"
            showoutput="yes"
            dir="junit_${derby.junit.timestamp}"
            tempdir="junit_${derby.junit.timestamp}"
            errorproperty="tests.failed"
            failureproperty="tests.failed">
        <jvmarg value="${derby.tests.jacoco.agent}"/>
        <sysproperty key="derby.tests.jacoco.agent" value="${derby.tests.jacoco.agent}"/>
        <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>
        <!-- Pass on properties from the command line to the spawned VM. -->
        <syspropertyset id="system-properties-passed-on">
          <propertyref builtin="commandline"/>
        </syspropertyset>
         <formatter type="xml"/>

        <test name="org.apache.derby.PackagePrivateTestSuite"
                todir="junit_${derby.junit.timestamp}"/>

        <classpath>
            <pathelement location="${out.pptesting.dir}"/>
            <pathelement location="${javatools.dir}/junit.jar"/>
            <pathelement location="${out.build.dir}"/>
            <pathelement location="${out.client.dir}"/>
            <pathelement location="${out.drda.dir}"/>
            <pathelement location="${out.engine.dir}"/>
            <pathelement location="${out.optional.dir}"/>
            <pathelement location="${out.run.dir}"/>
            <pathelement location="${out.shared.dir}"/>
            <pathelement location="${out.testing.dir}"/>
            <pathelement location="${out.tools.dir}"/>

            <pathelement location="${out.dir}/${locale.stub}cs}"/>
            <pathelement location="${out.dir}/${locale.stub}de_DE}"/>
            <pathelement location="${out.dir}/${locale.stub}es}"/>
            <pathelement location="${out.dir}/${locale.stub}fr}"/>
            <pathelement location="${out.dir}/${locale.stub}hu}"/>
            <pathelement location="${out.dir}/${locale.stub}it}"/>
            <pathelement location="${out.dir}/${locale.stub}ja_JP}"/>
            <pathelement location="${out.dir}/${locale.stub}ko_KR}"/>
            <pathelement location="${out.dir}/${locale.stub}pl}"/>
            <pathelement location="${out.dir}/${locale.stub}pt_BR}"/>
            <pathelement location="${out.dir}/${locale.stub}ru}"/>
            <pathelement location="${out.dir}/${locale.stub}zh_CN}"/>
            <pathelement location="${out.dir}/${locale.stub}zh_TW}"/>
        </classpath>
    </junit>
  </target>

  <!-- Run a single junit test or suite -->
  <target name="junit-single"
          depends="junit-init"
          description="Run one JUnit test with the classpath"
          >
    <condition property="noTestclassSet" value="">
      <not>
        <isset property="derby.junit.testclass"/>
      </not>
    </condition>
    <fail if="noTestclassSet">No testclass selected! Set property derby.junit.testclass</fail>
    <junit printsummary="on"
           fork="yes" forkmode="perTest"
           jvm="${derby.junit.jvm}" maxmemory="512m"
           showoutput="yes"
           dir="junit_${derby.junit.timestamp}"
           tempdir="junit_${derby.junit.timestamp}"
           errorproperty="tests.failed"
           failureproperty="tests.failed">
      <jvmarg value="${derby.tests.jacoco.agent}"/>
      <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>
      <sysproperty key="derby.tests.jacoco.agent" value="${derby.tests.jacoco.agent}"/>
      <!-- This property is needed to keep EMMA silent when measuring codecoverage -->
      <sysproperty key="emma.verbosity.level" value="silent"/>
      <!-- Pass on properties from the command line to the spawned VM. -->
      <syspropertyset id="system-properties-passed-on">
        <propertyref builtin="commandline"/>
      </syspropertyset>
      <formatter type="xml"/>
      
      <test name="${derby.junit.testclass}" todir="junit_${derby.junit.timestamp}"/>

      <classpath>
            <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
     	    <pathelement path="${derby.junit.classpath}"/>
            <pathelement location="${javatools.dir}/junit.jar"/>
            <pathelement location="${lucene_core}"/>
            <pathelement location="${lucene_a_co}"/>
            <pathelement location="${lucene_qp}"/>
            <pathelement location="${json_simple}"/>
      </classpath>
    </junit>
      
  </target>
   
  <target
      name="junit-all"
      depends="junit-pptesting,junit-core,junit-jdbc4,junit-jmx,junit-lowmem"
      description="Run the JUnit tests."
  />
 
  <target name="junitreport" depends="junit-all,junit-html"/>
  
  <!-- Convert the junit xml format to HTML -->
  <target name="junit-html" depends="junit-sysinfo">
    <junitreport todir="junit_${derby.junit.timestamp}">
      <fileset dir="junit_${derby.junit.timestamp}">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="frames" todir="junit_${derby.junit.timestamp}"/>
    </junitreport>

    <replace token="Unit Test Results"
             value="Apache Derby Test Results - ${derby.junit.standardtime}&lt;br&gt;JVM: ${java.vm.vendor} ${java.vm.version}"
             file="junit_${derby.junit.timestamp}/overview-summary.html"/>

    <!--
        Insert a link to sysinfo.txt after the first h2 element in
        overview-frame.html. (We use the replaceregexp task instead of
        the replace task since we want to replace the first occurrence
        only. The replace task replaces all occurrences.)
    -->
    <replaceregexp
        match="&lt;/h2&gt;"
        replace="&lt;/h2&gt;&lt;h2&gt;&lt;a href=&quot;sysinfo.txt&quot; target=&quot;classFrame&quot;&gt;sysinfo&lt;/a&gt;&lt;/h2&gt;"
        file="junit_${derby.junit.timestamp}/overview-frame.html"/>
  	
  	<fail if="tests.failed">Tests Failed!</fail>
  </target>

  <target name="l10ncheck"> 
    <ant dir="${derbysrc.dir}/../tools/l10n"/>
  </target>  
	
	<!-- Run the junit-all target with the classpath set to include
	     the main derby jar files. Requires that the caller have
	     junit.jar in CLASSPATH due to some bug in ant that is
	     fixed in version 1.7.
	-->
	<target name="junit-all-codeline-jars"
	    depends="junit-all-codeline-jars-set-properties,junit-all">
		<fail if="tests.failed">Tests Failed!</fail>
	</target>

    <!-- Run the junit-system-mini target with the classpath set to include
         the main derby jar files. Requires that the caller have
         junit.jar in CLASSPATH due to some bug in ant that is
         fixed in version 1.7.
    -->
    <target name="junit-system-mini-codeline-jars"
        depends="junit-all-codeline-jars-set-properties,junit-system-mini">
        <fail if="tests.failed">Tests Failed!</fail>
    </target>	
	
    <!-- Run the junit-single target with the classpath set to include
         the main derby jar files. Requires that the caller have
         junit.jar in CLASSPATH due to some bug in ant that is
         fixed in version 1.7.
    -->
    <target name="junit-single-codeline-jars"
        depends="junit-all-codeline-jars-set-properties,junit-single">
        <fail if="tests.failed">Tests Failed!</fail>
    </target>

	<target name="junit-all-codeline-jars-set-properties" depends="setsanityname">
		<property name="derby.jar.base" value="${jarsdist.dir}/${sanity.name}"/>
	    <property name="derby.junit.classpath"
	        value="${derby.jar.base}/derbyTesting.jar:${derby.jar.base}/derbynet.jar:${derby.jar.base}/derbytools.jar:${derby.jar.base}/derbyclient.jar"/>
	</target>
	
<!-- =================================================================== -->
<!--                        Old harness test targets                     -->
<!-- =================================================================== -->
<!-- The old harness tests are being phased out, so just borrow some     -->
<!-- functionality from the JUnit setup.                                 -->

<target name="test-derbyall"
        depends="junit-init"
        description="Old harness tests with classpath"
        >
    <path id="derbyall.classpath">
      <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
   	  <pathelement path="${derby.junit.classpath}"/>
      <pathelement location="${javatools.dir}/junit.jar"/>
    </path>
    <echo message="Classpath used for derbyall: ${toString:derbyall.classpath}"/>
    <mkdir dir="junit_${derby.junit.timestamp}/derbyall"/>
    <java classname="org.apache.derbyTesting.functionTests.harness.RunSuite"
        fork="yes" dir="junit_${derby.junit.timestamp}/derbyall">
      <jvmarg value="${derby.tests.jacoco.agent}"/>
      <sysproperty key="jvmflags" value="${derby.tests.jacoco.agent}"/>
      <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>
      <!-- Note the duplicate specification, don't know why it's needed. -->
      <sysproperty key="testSpecialProps" value="noSecurityManager=true^noSecurityManager=true"/>
      <arg value="derbyall"/>
      <env key="CLASSPATH" value="${toString:derbyall.classpath}"/>
    </java>
  </target>

<!-- =================================================================== -->
<!--                      Run tests with a module path                   -->
<!-- =================================================================== -->

  <target name="test-derbyall-with-modulepath"
          depends="junit-init"
          description="Old harness tests with module path"
  >
    <path id="derbyall.classpath">
      <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
   	  <pathelement path="${derby.junit.classpath}"/>
      <pathelement location="${javatools.dir}/junit.jar"/>
    </path>
    <echo message="Modulepath used for derbyall: ${toString:derbyall.classpath}"/>
    <mkdir dir="junit_${derby.junit.timestamp}/derbyall"/>
    <java 
          modulepath="${toString:derbyall.classpath}"
          module="org.apache.derby.tests"
          classname="org.apache.derbyTesting.functionTests.harness.RunSuite"
          fork="yes"
          dir="junit_${derby.junit.timestamp}/derbyall"
    >
      <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>
      <jvmarg value="--add-modules"/>
      <jvmarg value="org.apache.derby.tests,junit"/>
      <arg value="derbyall"/>
    </java>
  </target>

  <target name="test-junit-all-with-modulepath"
          depends="junit-init"
          description="JUnit tests with module path"
  >
    <path id="junit.all.classpath">
      <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
      <pathelement location="${javatools.dir}/junit.jar"/>
      <pathelement location="${lucene_core}"/>
      <pathelement location="${lucene_a_co}"/>
      <pathelement location="${lucene_qp}"/>
      <pathelement location="${json_simple}"/>
    </path>

    <echo message="Modulepath used for JUnit tests with modulepath: ${toString:junit.all.classpath}"/>
    <mkdir dir="junit_${derby.junit.timestamp}/junit-all"/>

    <java 
          modulepath="${toString:junit.all.classpath}"
          module="junit"
          classname="junit.textui.TestRunner"
          fork="yes"
          dir="junit_${derby.junit.timestamp}/junit-all"
    >
      <sysproperty key="derbyTesting.oldReleasePath" value="${derbyTesting.oldReleasePath}"/>
      <sysproperty key="derbyTesting.oldVersionsPath" value="${derbyTesting.oldVersionsPath}"/>
      <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>

      <jvmarg value="--add-modules"/>
      <jvmarg value="org.apache.derby.tests"/>

      <arg value="org.apache.derbyTesting.functionTests.suites.All"/>
    </java>
  </target>

  <!-- Run a single junit test or suite with the modulepath -->
  <target name="junit-single-with-modulepath"
          depends="junit-init"
          description="Run one JUnit test with the module path"
  >
    <condition property="noTestclassSet" value="">
      <not>
        <isset property="derby.junit.testclass"/>
      </not>
    </condition>
    <fail if="noTestclassSet">No testclass selected! Set property derby.junit.testclass</fail>
    <path id="junit.all.classpath">
      <fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
      <pathelement location="${javatools.dir}/junit.jar"/>
      <pathelement location="${lucene_core}"/>
      <pathelement location="${lucene_a_co}"/>
      <pathelement location="${lucene_qp}"/>
      <pathelement location="${json_simple}"/>
    </path>

    <echo message="Modulepath used for JUnit tests with modulepath: ${toString:junit.all.classpath}"/>
    <mkdir dir="junit_${derby.junit.timestamp}/junit-all"/>

    <java 
          modulepath="${toString:junit.all.classpath}"
          module="junit"
          classname="junit.textui.TestRunner"
          fork="yes"
          dir="junit_${derby.junit.timestamp}/junit-all"
    >
      <sysproperty key="derbyTesting.oldReleasePath" value="${derbyTesting.oldReleasePath}"/>
      <sysproperty key="derbyTesting.oldVersionsPath" value="${derbyTesting.oldVersionsPath}"/>
      <syspropertyset> <propertyref prefix="java.security" /> </syspropertyset>

      <jvmarg value="--add-modules"/>
      <jvmarg value="org.apache.derby.tests"/>

      <arg value="${derby.junit.testclass}"/>
    </java>
  </target>

<!-- =================================================================== -->
<!--                         EMMA utility targets                        -->
<!-- =================================================================== -->

<!--
There are three "top-level" targets that use EMMA:

'emma-clean' will delete any classes and jar files that have been instrumented
with EMMA.

Before using the 'emma-all' and 'emma-single' targets, you should build jar
files using the 'buildjars' target.

'emma-all' will instrument your jar files using EMMA, and run the 'junit-all' 
target, before producting code coverage reports from the testrun.

'emma-single' will instrument your jar files using EMMA, and run the 
'junit-single' target, before producing code coverage reports from the testrun.
To select which test or suite to run with the 'emma-single' target you must set
the system property derby.junit.testclass to the full classname of the suite or
test you want to run.

These targets use EMMA code, and depend upon emma.jar and emma_ant.jar being 
copied to your tools/java/ directory. You can download these from
http://emma.sourceforge.net/downloads.html.

If you use ant 1.6.5 you will have to add junit to your classpath, with ant 1.7
you should not have to do this.
-->

    <!-- directory that will contain the instrumented jar-files: -->
    <property name="emmabase" value="${jarsdist.dir}/emma"/>
    <property name="instrumented.jars" value="${emmabase}/lib"/>
    <property name="instrumented.classes" value="${emmabase}/classes"/>

    <target name="emma-clean">
        <delete includeEmptyDirs="true">
            <fileset dir="${jarsdist.dir}" includes="emma/**"/>
        </delete>
    </target>

    <target name="emma-init" depends="initjars">
        <!-- EMMA distribution: -->
        <path id="emma.lib">
            <pathelement location="${emma}"/>
            <pathelement location="${emma_ant}"/>
        </path>
        <taskdef resource="emma_ant.properties" classpathref="emma.lib"/>
        <mkdir dir="${emmabase}"/>
    </target>
    
    <target name="emma-instrumentation" depends="emma-init,junit-init-nocp">
        <!-- Apply emma instrumentation to the classes in instrpath and copy to destdir -->
	<emma verbosity="verbose">
            <instr outfile="junit_${derby.junit.timestamp}/coverage.em" destdir="${emmabase}" merge="true" mode="fullcopy">
	        <instrpath>
                    <pathelement path="${derby.jar.dir}/derbyrun.jar"/>
                </instrpath>
            </instr>
	</emma>
        <!-- Change the classpath used for junit tests to use the jars instrumented by EMMA -->
        <property name="derby.junit.classpath" value="${emma}:${derby.jar.dir}/derbyTesting.jar:${instrumented.jars}/derbyrun.jar"/>
    </target>
    
    <target name="emma-all" depends="emma-instrumentation,junit-all,emma-report">
        <fail if="tests.failed">EMMA instrumented tests failed!</fail>
        <echo level="info" message="Finished measuring code coverage with EMMA."/>
    </target>

    <target name="emma-single" depends="emma-instrumentation,junit-single,emma-report">
        <fail if="tests.failed">EMMA instrumented test failed!</fail>
        <echo level="info" message="Finished measuring code coverage with EMMA."/>
    </target>
    
    <target name="emma-report" depends="emma-instrumentation">
        <emma>
            <report verbosity="verbose" depth="method">
                <sourcepath>
                    <pathelement path="${derby.client.src.dir}" />
                    <pathelement path="${derby.drda.src.dir}" />
                    <pathelement path="${derby.engine.src.dir}" />
                    <pathelement path="${derby.shared.src.dir}" />
                    <pathelement path="${derby.storeless.src.dir}" />
                    <pathelement path="${derby.tools.src.dir}" />
                </sourcepath>
                <infileset dir="junit_${derby.junit.timestamp}" includes="coverage.em,coverage*.ec" />
                <!-- Three reports: txt, xml and html -->
                <txt outfile="junit_${derby.junit.timestamp}/coverage.txt"/>
                <xml outfile="junit_${derby.junit.timestamp}/coverage.xml"/>
                <html outfile="junit_${derby.junit.timestamp}/coverage.html"/>
            </report>
        </emma>
    </target>

<!-- ==================================================================== -->
<!--                   JaCoCo code coverage targets -->
<!-- ==================================================================== -->

    <target name="jacoco-complete"
            depends="clobber,sane,all,buildjars,jacoco-enable,test-derbyall,junit-all,jacoco-report"
            description="Runs all the Derby tests with JaCoCo to obtain code coverage">
    </target>

    <target name="jacoco-derbyall"
            depends="jacoco-enable,test-derbyall,jacoco-report"
            description="Runs the derbyall test with JaCoCo to obtain code coverage">
    </target>

    <target name="jacoco-junit"
            depends="jacoco-enable,junit-all,jacoco-report"
            description="Runs all the Derby JUnit tests with JaCoCo to obtain code coverage">
    </target>

    <target name="jacoco-junit-single"
            depends="jacoco-enable,junit-single,jacoco-report"
            description="Runs the specified Derby JUnit test with JaCoCo to obtain code coverage">
    </target>

<!-- The below JaCoCo targets are helper targets and have not been written to
     be invoked directly. -->

    <target name="jacoco-report" depends="getsvnversion">
      <jacoco:merge destfile="junit_${derby.junit.timestamp}/merged.exec">
        <fileset dir="junit_${derby.junit.timestamp}" includes="**/jacoco.exec*"/>
      </jacoco:merge>

      <jacoco:report>
        <executiondata>
          <file file="junit_${derby.junit.timestamp}/merged.exec"/>
        </executiondata>

        <structure name="Apache Derby Code Coverage (revision ${changenumber}, JRE ${java.specification.version})">
          <classfiles>
            <fileset dir="classes">
              <include name="org/apache/derby/**/*.class"/>
                <!-- Ignore testing classes for now.
                     Maybe in a separate report? -->
                <!-- <include name="org/apache/derbyTesting/**/*.class"/> -->
            </fileset>
          </classfiles>
          <sourcefiles encoding="UTF-8">
            <fileset dir="java/${module.name.client}"/>
            <fileset dir="java/${module.name.server}"/>
            <fileset dir="java/${module.name.engine}"/>
            <fileset dir="java/${module.name.commons}"/>
            <fileset dir="java/${module.name.runner}"/>
            <fileset dir="java/${module.name.tests}"/>
            <fileset dir="java/${module.name.tools}"/>
            <fileset dir="java/${module.name.optionaltools}"/>
            <fileset dir="generated/java/${module.name.commons}"/>
            <fileset dir="generated/java/${module.name.engine}"/>
            <fileset dir="generated/java/${module.name.tests}"/>
            <fileset dir="generated/java/${module.name.tools}"/>
          </sourcefiles>
        </structure>

        <html destdir="junit_${derby.junit.timestamp}/coverage-report"/>
        <!-- Alternative report formats that are available.
        <csv destfile="junit_${derby.junit.timestamp}/coverage-jacoco.csv"/>
        <html destfile="junit_${derby.junit.timestamp}/coverage-jacoco.html.zip"/>
        <xml destfile="junit_${derby.junit.timestamp}/coverage-jacoco.xml"/>
        -->

      </jacoco:report>
    </target>

    <target name="jacoco-enable">
      <!-- Make sure we have the required JaCoCo files. -->
      <fail message="missing jacocoant.jar and/or jacocoagent.jar in tools/java">
        <condition>
          <not>
            <and>
              <available file="${basedir}/tools/java/jacocoant.jar"/>
              <available file="${basedir}/tools/java/jacocoagent.jar"/>
            </and>
          </not>
        </condition>
      </fail>
      <!-- Add the JaCoCo targets/tasks. -->
      <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
        <classpath path="${basedir}/tools/java/jacocoant.jar"/> 
      </taskdef>
      <!-- Generate the property required to enable JaCoCo.
           Exclude invalid class file loaded in DatabaseClassLoadingTest.
      -->
      <jacoco:agent property="derby.tests.jacoco.agent"
        sessionid="derby-ant"
        excludes="*/emc:org/apache/derby/exe/*"/>
    </target>

<!-- ==================================================================== -->
<!--                         Release Candidates  -->
<!-- ==================================================================== -->

    <target
        name="release"
        depends="prepareforrelease"
        description="Build the release distributions."
    >
      <ant antfile="${basedir}/tools/release/build.xml" target="release"/>

      <!-- sign all of the artifacts -->
      <ant antfile="${basedir}/tools/release/build.xml" target="sign"/>

      <!-- remove cruft -->
      <delete dir="${crlf.dir}"/>
      <delete dir="${lf.dir}"/>
      <delete file="${release.dir}/maintversion.properties"/>

       <!-- the release candidate has been built. now we can bump the release id.  -->
       <antcall target="writeAndCheckinReleaseProperties">
          <param name="bumpID" value="true"/>
       </antcall>

    </target>

    <!-- do most of the ant calls to prepare a release -->
    <target name="prepareforrelease" depends="checkdocsroot,checksvnclientsclean,promptforreleaseproperties,checkstateremoved,checksanenotset,cleanalljars,cleandocs,clobber,cleanreleasefiles">

        <!-- set the release id -->
        <antcall target="writeAndCheckinReleaseProperties">
           <param name="bumpID" value="false"/>
        </antcall>

        <!-- update the NOTICE file with the current copyright year and check NOTICE in -->
        <antcall target="buildnotice"/>

        <!-- copy the generated sqlstate tables to the docs client and check it in -->
        <antcall target="copyerrordocs"/>

        <!-- sync the clients to guarantee that we are up-to-date -->
        <antcall target="updatesvnclients"/>

        <antcall target="clobber"/>
        <antcall target="all">
           <param name="sane" value="true"/>
           <param name="sanity" value="true"/>
           <param name="sanity.name" value="sane"/>
           <param name="deprecation" value="off"/>
        </antcall>
        <antcall target="buildjars">
           <param name="sane" value="true"/>
           <param name="sanity" value="true"/>
           <param name="sanity.name" value="sane"/>
        </antcall>

        <antcall target="clobber"/>
        <antcall target="snapshot">
           <param name="sane" value="false"/>
           <param name="sanity" value="false"/>
           <param name="sanity.name" value="insane"/>
            <param name="deprecation" value="off"/>
        </antcall>

        <antcall target="publishedapi">
            <param name="deprecation" value="off"/>
        </antcall>

        <!-- build the docs now that the sqlstate tables are up to date -->
        <antcall target="builduserdocs"/>

        <!-- finish by removing the state.properties file, so we can do it again -->
        <antcall target="cleanstate"/>
    </target>

    <!--
        Prompt for release-building inputs if they were not specified in properties already

        This target must be called in a dependency list rather than via antcall. That is
        because properties set in dependent targets percolate back up to the caller.
        Properties set in antcalled targets are wiped out when you return to the caller.

        Sneaky, very, very sneaky.
    -->
    <target name="promptforreleaseproperties" depends="promptforsvncredentials,promptforpgpcredentials,promptforreleaseid"/>

    <!-- Define the task which prompts for missing properties -->
    <target name="defineprompt" depends="prebuild">

        <taskdef
          name="promptForProperty"
          classname="org.apache.derbyPreBuild.PropertyPrompt"
          classpath="${out.build.dir}"
        />

    </target>

    <!-- Prompt for subversion credentials if they are missing -->
    <target name="promptforsvncredentials" depends="defineprompt">

        <promptForProperty
          propertyName="svn.username"
          prompt="Enter your Apache subversion username >  "
        />

        <promptForProperty
          propertyName="svn.password"
          prompt="Enter your Apache subversion password >  "
        />

    </target>

    <!-- Prompt for key-signing credentials if they are missing -->
    <target name="promptforpgpcredentials" depends="defineprompt">

        <promptForProperty
          propertyName="pgp.passphrase"
          prompt="Enter your pgp passphrase >  "
        />

    </target>

    <!-- Prompt for release id if it is missing -->
    <target name="promptforreleaseid" depends="defineprompt">

        <promptForProperty
          propertyName="derby.release.id"
          prompt="Enter the id of this release (e.g., 10.7.1.0) >  "
        />

        <!-- Replace the dots with underscores, see https://issues.apache.org/jira/browse/DERBY-7093 -->
        <loadresource property="derby.release.download.page.name">
          <propertyresource name="derby.release.id"/>
          <filterchain>
            <tokenfilter>
              <filetokenizer/>
              <replacestring from="." to="_"/>
            </tokenfilter>
          </filterchain>
        </loadresource>

    </target>

    <!-- Prompt for branch id if it is missing -->
    <target name="promptforbranch" depends="defineprompt">

        <promptForProperty
          propertyName="branch.id"
          prompt="Enter the name of the branch (e.g., 10.7) >  "
        />

    </target>

    <!-- Prompt for location of binary zip distribution if it is missing -->
    <target name="promptforbinaryzipdist" depends="defineprompt">

        <promptForProperty
          propertyName="derby.release.binzip"
          prompt="Enter the location of the binary zip distribution for the release (e.g., /Users/me/release/db-derby-10.7.1.0-bin.zip) >  "
        />

    </target>

    <!-- Prompt for root of documentation client if it is missing -->
    <target name="promptfordocsroot" depends="defineprompt">

        <promptForProperty
          propertyName="docs.root"
          prompt="Enter the root of the subversion docs client (e.g., /Users/me/derby/docs/trunk) >  "
        />

    </target>

    <!--
        Prompt for whether we should continue. The user is offered a Y/N choice.

        Args:
            prompt
    -->
    <target name="prompttocontinue" depends="defineprompt">

        <fail message="Did not expect that property prompt.to.continue would be set. Make sure that this target is only invoked via antcall and not in a dependency list.">
            <condition>
                <isset property="prompt.to.continue"/>             
            </condition>
        </fail>     

        <promptForProperty
          propertyName="prompt.to.continue"
          prompt="${prompt}  Continue? (Y/N) >  "
        />

        <fail message="Terminating.">
            <condition>
              <not>
                <equals casesensitive="false" arg1="${prompt.to.continue}" arg2="Y"/>
              </not>
            </condition>
        </fail>     

    </target>

    <target name="checkstateremoved" depends="state.exists">
        <fail message="Cannot build a release; please remove java/engine/state.properties by running ant cleanstate (or run ant clobber)">
            <condition>
                <isset property="state.prepare.available"/>             
            </condition>
        </fail>     
    </target>

    <target name="state.exists">
        <!-- check if state.properties file does *not* exist without generating it  -->
        <!-- if it exists, the sane property is already loaded, messing up the prepare process -->
        <available file="${derby.engine.src.dir}/state.properties" property="state.prepare.available"/>
    </target>

    <target name="checkdocsroot" depends="promptfordocsroot">
        <!-- make sure that docs.root points into a docs tree  -->
        <fail message="Cannot build a release; docs.root does not point at your documentation client: ${docs.root}">
            <condition>
              <not><available file="${docs.root}/src/conrefs.dita"/></not>
            </condition>
        </fail>

        <!-- make sure that the doc-building classes are visible to ant  -->
        <fail message="Cannot build a release; fop.jar is not visible in the docs client.">
            <condition>
              <not><available file="${docs.root}/lib/fop.jar"/></not>
            </condition>
        </fail>     
    </target>

    <target name="checksanenotset">
        <!-- check that sane is *not* set elsewhere, e.g. $HOME/ant.properties -->
        <echo level="info" message="sane : ${sane}"/>
        <fail message="Cannot build a release; please do not set sane to either true or false">
            <condition>
                <isset property="sane"/>             
            </condition>
        </fail>     
    </target>

    <target name="cleanreleasefiles">
        <delete dir="${release.base}"/>
    </target>

    <target name="cleanalljars">
        <delete dir="${jarsdist.dir}"/>
    </target>

    <target
        name="createBranch"
        depends="checkdocsroot,checksvnclientsclean,getsvnversion"
        description="Create a new branch (both docs and code)."
    >
      <antcall target="updatesvnclients"/>
      <antcall target="getsvnversion"/>

      <property file="${properties.dir}/release.properties"/>

      <antcall target="prompttocontinue">
         <param name="prompt" value="Creating ${eversion} branch starting at revision ${changenumber}."/>
      </antcall>

      <antcall target="branchrepository">
         <param name="startingRevision" value="${changenumber}"/>
         <param name="sourceURL" value="https://svn.apache.org/repos/asf/db/derby/code/trunk/"/>
         <param name="targetURL" value="https://svn.apache.org/repos/asf/db/derby/code/branches/${eversion}/"/>
         <param name="checkinComment" value="Created the ${eversion} code branch."/>
      </antcall>

      <antcall target="branchrepository">
         <param name="startingRevision" value="${changenumber}"/>
         <param name="sourceURL" value="https://svn.apache.org/repos/asf/db/derby/docs/trunk/"/>
         <param name="targetURL" value="https://svn.apache.org/repos/asf/db/derby/docs/branches/${eversion}/"/>
         <param name="checkinComment" value="Created the ${eversion} docs branch."/>
      </antcall>

    </target>

    <!--
        Branch one of the repositories

        Args:
            startingRevision  subversion revision number of initial set of files
            sourceURL  points at the source (trunk) repository
            targetURL  location of the new (branch) repository
            checkinComment   one line description of the new branch
    -->
    <target name="branchrepository">

      <exec executable="svn">
        <arg value="copy"/>
        <arg value="${sourceURL}"/>
        <arg value="${targetURL}"/>
        <arg value="-m"/>
        <arg value="${checkinComment}"/>
      </exec>

    </target>

<!-- ==================================================================== -->
<!--                         Release Publication  -->
<!-- ==================================================================== -->

    <!-- Repackage the docs for publication on the website -->
    <target name="repackagedocs" depends="promptforwebsite,promptforbranch,promptforbinaryzipdist">

        <fail message="Cannot repackage the docs. Cannot find ${derby.release.binzip}">
            <condition>
              <not>
                <available file="${derby.release.binzip}"/>
              </not>
            </condition>
        </fail>

        <basename property="zipstub" file="${derby.release.binzip}" suffix=".zip"/>
        <echo message="${zipstub}"/>

        <property name="repackage.dir" value="${release.base}/repackagedocs"/>
        <property name="unpacked.dir" value="${repackage.dir}/unpacked"/>
        <property name="pruned.dir" value="${website.root}/build/site/docs/${branch.id}"/>
        <property name="pruned.docs.dir" value="${pruned.dir}/docs"/>
        <property name="pruned.publicapi.dir" value="${pruned.dir}/publishedapi"/>

        <delete dir="${repackage.dir}"/>
        <mkdir dir="${unpacked.dir}"/>
        <mkdir dir="${pruned.dir}"/>
        <mkdir dir="${pruned.docs.dir}"/>
        <mkdir dir="${pruned.publicapi.dir}"/>

        <unzip src="${derby.release.binzip}" dest="${unpacked.dir}"/>

        <move todir="${pruned.docs.dir}"><fileset dir="${unpacked.dir}/${zipstub}/docs"/></move>
        <move todir="${pruned.publicapi.dir}"><fileset dir="${unpacked.dir}/${zipstub}/javadoc"/></move>
        <delete dir="${unpacked.dir}"/>

        <antcall target="movepdf"><param name="userguide" value="adminguide"/></antcall>
        <antcall target="movepdf"><param name="userguide" value="devguide"/></antcall>
        <antcall target="movepdf"><param name="userguide" value="getstart"/></antcall>
        <antcall target="movepdf"><param name="userguide" value="ref"/></antcall>
        <antcall target="movepdf"><param name="userguide" value="security"/></antcall>
        <antcall target="movepdf"><param name="userguide" value="tools"/></antcall>
        <antcall target="movepdf"><param name="userguide" value="tuning"/></antcall>

        <move todir="${pruned.dir}"><fileset dir="${pruned.docs.dir}/html"/></move>
        <delete dir="${pruned.docs.dir}"/>

        <!-- Delete the obsolete Japanese and Brazilian variants -->
        <delete dir="${pruned.dir}/ja_JP"/>
        <delete dir="${pruned.dir}/pt_BR"/>

    </target>

    <!-- Move the pdf files into the html directory so that everything is in one place -->
    <target name="movepdf">
        <move todir="${pruned.docs.dir}/html/${userguide}">
          <fileset dir="${pruned.docs.dir}/pdf/${userguide}"/>
        </move>
        <delete dir="${pruned.docs.dir}/pdf/${userguide}"/>
    </target>

    <!-- Transform the release notes for publication on the website. This creates the download page for the release -->
    <target name="transformrelnotes" depends="promptforreleaseid,promptforwebsite">

        <property name="relnotes.target.dir" value="${website.root}/src/documentation/content/xdocs/releases" />

        <fail message="Cannot transform the release notes. The web site client does not look correct.">
            <condition>
              <not>
                <available file="${relnotes.target.dir}"/>
              </not>
            </condition>
        </fail>

        <property name="relnotes.src" value="${basedir}/RELEASE-NOTES.html" />

        <taskdef
          name="transformReleaseNotes"
          classname="org.apache.derbyBuild.ReleaseNotesTransformer"
          classpath="${out.build.dir}"
        />
        <transformReleaseNotes
            inputFileName="${relnotes.src}"
            outputFileName="${relnotes.target.dir}/release-${derby.release.download.page.name}.html"
            cliXconfFileName="${website.root}/src/documentation/conf/cli.xconf"
            releaseId="${derby.release.id}"
        />

        <!-- Copy the cgi script which enables mirroring for the new release -->
        <copy
            file="${relnotes.target.dir}/release-template.cgi"
            tofile="${relnotes.target.dir}/release-${derby.release.download.page.name}.cgi"
          />

    </target>

    <!-- Prompt for and sanity check the root of your website client -->
    <target name="promptforwebsite" depends="defineprompt">

        <promptForProperty
          propertyName="website.root"
          prompt="Enter the root directory of your Derby website client (e.g. /Users/me/derby/site/trunk) >  "
        />

    </target>

</project>
