<?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=".">

<!-- Set Properties -->
  <!-- User settings -->
  <property file="local.properties"/>
  <property file="${user.home}/ant.properties"/>
  <!-- Set property lib dir -->
  <property name="properties.dir" value="tools/ant/properties"/>
  <!-- Significant dirs -->
  <property file="${properties.dir}/dirs.properties"/>
  <!-- Compiler settings -->
  <property file="${properties.dir}/sane${sanity}.properties"/>

<!-- Targets -->

  <target name="buildsource" depends="checkCompilerLevel,init,prebuild,setCompilerProperties,engine,storeless,tools,drda,client,build,versioninfo,localeinfo"/>
  <target name="all" depends="buildsource,demo,testing,pptesting"/>

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

  <target name="init" unless="init.done" depends="setInitialProperties">

    <tstamp/>
    <mkdir dir="${out.dir}"/>
    <!-- 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"/>
    <property name="init.done" value="true"/>
  </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>

  <target name="checkCompilerLevel" description="Make sure compiler level is Java 5 level or higher.">

    <property name="dummy.src" value="z.java"/>
    <property name="dummy.class" value="z.class"/>
    <echo file="${dummy.src}" message="public class z {}"/>
    <delete file="${dummy.class}"/>

    <javac source="1.5" srcdir="${basedir}" failonerror="false">
      <include name="${dummy.src}"/>
    </javac>

    <available property="compilerAtCorrectLevel" file="${dummy.class}"/>

    <delete file="${dummy.src}"/>
    <delete file="${dummy.class}"/>

    <fail unless="compilerAtCorrectLevel" message="Compiler level must be Java 5 or later."/>
  </target>
  
  <!-- checkVMLevel:
       This target determines to some degree the JVM version used to run ant.
       The resulting properties will indicate the VM level, and may for instance
       be checked before running junit tests requiring a certain JVM version.
  -->
  <target name="checkVMLevel">
    <!-- The java.lang.ManagementFactory class was new in J2SE 5.0 -->
    <available classname="java.lang.management.ManagementFactory" 
               property="vmLevelIsAtLeast1.5"/>
  </target>

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

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

  <target name="ckversioninfo">
    <condition property="versioninfo.available">
      <and>
        <available file="${out.dir}/org/apache/derby/info/DBMS.properties"/>
        <available file="${out.dir}/org/apache/derby/info/tools.properties"/>
        <available file="${out.dir}/org/apache/derby/info/net.properties"/>
        <available file="${out.dir}/org/apache/derby/info/dnc.properties"/>
      </and>
    </condition>
  </target>

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

    <antcall target="infowriter">
      <param name="info.buildnumber" value="1"/>
      <param name="info.iname" value="Apache Derby Embedded Engine"/>
      <param name="info.ename" value="Apache Derby"/>
      <param name="info.productfile" value="codeline"/>
      <param name="info.file" value="${out.dir}/org/apache/derby/info/DBMS.properties"/>
    </antcall>
    <antcall target="infowriter">
      <param name="info.buildnumber" value="1"/>
      <param name="info.iname" value="Apache Derby Tools"/>
      <param name="info.ename" value="Apache Derby"/>
      <param name="info.productfile" value="codeline"/>
      <param name="info.file" value="${out.dir}/org/apache/derby/info/tools.properties"/>
    </antcall>
    <antcall target="infowriter">
      <param name="info.buildnumber" value="1"/>
      <param name="info.iname" value="Apache Derby Network Server"/>
      <param name="info.ename" value="Apache Derby"/>
      <param name="info.productfile" value="codeline"/>
      <param name="info.file" value="${out.dir}/org/apache/derby/info/net.properties"/>
    </antcall>
    <antcall target="infowriter">
      <param name="info.buildnumber" value="1"/>
      <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.dir}/org/apache/derby/info/dnc.properties"/>
    </antcall>
  </target>

  <target name="cleanversion">
    <delete file="${out.dir}/org/apache/derby/info/DBMS.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/tools.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/net.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/dnc.properties"/>
  </target>

  <target name="setCompilerProperties" unless="dontAutosetProps"
          description="Set the ant variables which identify the compiler classpaths. Remove the autosetProps logic when this target becomes mandatory."
          depends="prebuild">

<!--     <antcall target="printCompilerProperties"> <param name="checkEvent" value="Before"/> </antcall> -->

    <taskdef
      name="setJdkProperties"
      classname="org.apache.derbyPreBuild.PropertySetter"
      classpath="${out.dir}"
    />

    <setJdkProperties/>

<!--     <antcall target="printCompilerProperties"> <param name="checkEvent" value="After"/> </antcall> -->

    <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"/>

  </target>

  <target name="setInitialProperties" if="dontAutosetProps"
          description="Set the initial properties for this build script. This duplicates the property setting block in setCompilerProperties. Once we make setCompilerProperties mandatory, this target should be removed."
          >

    <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"/>

  </target>

  <target name="printCompilerProperties">

    <echo message="${checkEvent} j14lib = ${j14lib}"/>
    <echo message="${checkEvent} java14compile.classpath = ${java14compile.classpath}"/>
    <echo message="${checkEvent} j15lib = ${j15lib}"/>
    <echo message="${checkEvent} java15compile.classpath = ${java15compile.classpath}"/>

  </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>  


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

  <target name="buildlocaleinfo">
    <antcall target="localeinfowriter">
      <param name="info.buildnumber" value="1"/>
      <param name="info.iname" value="_${locale.iname}"/>
      <param name="info.ename" value="${locale.ename}"/>
      <param name="info.file" value="${out.dir}/org/apache/derby/info/locale_${locale.iname}.properties"/>
    </antcall>
  </target>

  <target name="localeinfowriter">
    <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>
  </target>

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

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

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

  <target name="checklocaleinfo">
    <condition property="localeinfo.available">
      <and>
        <available file="${out.dir}/org/apache/derby/info/locale_cs.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_de_DE.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_es.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_fr.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_hu.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_it.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_ja_JP.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_ko_KR.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_pl.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_pt_BR.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_ru.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_zh_CN.properties"/>
        <available file="${out.dir}/org/apache/derby/info/locale_zh_TW.properties"/>
      </and>
    </condition>
  </target>

  <target name="cleanlocale">
    <delete file="${out.dir}/org/apache/derby/info/locale_cs.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_de_DE.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_es.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_fr.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_hu.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_it.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_ja_JP.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_ko_KR.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_pl.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_pt_BR.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_ru.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_zh_CN.properties"/>
    <delete file="${out.dir}/org/apache/derby/info/locale_zh_TW.properties"/>
  </target>

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

  <target name="engine" depends="shared,state,parsers">
    <ant dir="${derby.engine.src.dir}"/>
    <antcall target="build"/>
    <ant dir="${derby.engine.dir}/loc"/>
    <antcall target="class_size_catalog"/>
  </target>
	 <target name="engine_169_opt" depends="engine">
	 	  <ant dir="${derby.engine.src.dir}" target="engine_169_opt"/>
	 </target>
	
  <target name="tools" depends="engine">
    <ant dir="${derby.tools.src.dir}"/>
  </target>
	
  <target name="storeless" depends="engine">
  	<ant dir="${derby.storeless.src.dir}"/>
  </target>
	
  <target name="shared" depends="init,state">
    <ant dir="${derby.shared.src.dir}"/>
  </target>
  
  <target name="drda" depends="engine">
    <ant dir="${derby.drda.src.dir}"/>
    <ant dir="${derby.tools.src.dir}" target="tools_run"/>
  </target>

  <target name="client" depends="engine,shared">
    <ant dir="${derby.client.src.dir}"/>
  </target>

  <target name="prebuild">
    <ant dir="${derby.build.src.dir}/org/apache/derbyPreBuild"/>
  </target>

  <target name="build">
    <ant dir="${derby.build.src.dir}"/>
  </target>

  <target name="demo" depends="buildsource">
    <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,demo">
    <ant dir="${derby.testing.src.dir}"/>
  </target>
	
  <!-- Build the package private tests -->
  <target name="pptesting" depends="testing">
    <ant dir="${derby.testing.src.dir}/org/apache/derby"/>
  </target>


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

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

  <property name="state.file" value="${derby.engine.src.dir}/state.properties"/>
  <property file="${state.file}"/>
  <target name="state" if="needstate"
          depends="showenv,getstate"
          description="Build SanityState.java">
    <echo level="info" message="  Generating SanityState.java..."/>
    <property name="sane" value="true"/>
    <filter token="SANE" value="${sane}"/>
    <copy file="${sanity.dir}/SanityState.tmpl"
          tofile="${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 file="${derby.engine.src.dir}/state.properties"/>
    <delete file="${sanity.dir}/SanityState.java"/>
    <delete dir="${sanity.out.dir}"/>
  </target>

<!-- =================================================================== -->
<!--                 Remove all built objects (except jars)              -->
<!-- =================================================================== -->
  <target name="clobber" depends="clean,cleanstate,cleanparsers,cleanmessages,cleancatalog,cleantoursdb"/>

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

<!-- ==================================================================== -->
<!--                         Build parsers                                -->
<!-- ==================================================================== -->
  <target name="parsers"
          description="Build the parsers">
    <ant dir="${derby.tools.dir}/impl/tools"  target="parser"/>
    <ant dir="${derby.engine.dir}/impl/sql"  target="parser"/>
  </target>

  <target name="genParser" depends="chkparser" unless="parser.done">
    <echo level="info" message="  ${msg}"/>
    <delete>
      <fileset dir="${directory}" includes="${rmfiles}"/>
    </delete>
    <java classname="javacc"
          classpath="${javacc}"
                dir="${directory}"
               fork="yes"
        failonerror="true">
      <arg value="${jjfile}"/>
    </java>
    <!-- Qualify reference to tokenImage to fix issue with inheritence -->
    <!-- IBM JDK 1.3.1. See DERBY-1078                                 -->
    <replaceregexp file="${directory}/${chkfile}" match="tokenImage" 
                   replace="${constantsfile}.tokenImage"/>
  </target>

  <target name="chkparser">
    <uptodate property="parser.done"
              targetfile="${directory}/${chkfile}" >
      <srcfiles dir="${directory}" includes="${jjfile}" />
    </uptodate>
  </target>

<!-- =================================================================== -->
<!--                     Remove parser-generated files                   -->
<!-- =================================================================== -->
  <target name="cleanparsers">
    <delete>
      <fileset dir="${derby.engine.dir}/impl/sql/compile" includes="SQLParser.java,SQLParserTokenManager.java,SQLParserConstants.java,TokenMgrError.java"/>
    </delete>
    <delete>
      <fileset dir="${derby.tools.dir}/impl/tools/ij"
            includes="ij.java,ijTokenManager.java,ijConstants.java,Token.java,mtGrammar.java,mtGrammarConstants.java,mtGrammarTokenManager.java,CharStream.java,SimpleCharStream.java,TokenMgrError.java"/>
    </delete>
  </target>

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

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

  <!-- Note that checking the up-to-date status of the files scanned by  -->
  <!-- ClassSizeCrawler will not always result in the ClassSizeCatalog   -->
  <!-- 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 ClassSizeCatalog may have changed significantly since the     -->
  <!-- last build, run cleancatalog and rebuild to regenerate it.        -->

  <target name="class_size_catalog" depends="cscuptodate" unless="csc.uptodate"
          description="create the class size catalog -- a java file">
    <java classname="org.apache.derbyBuild.ClassSizeCrawler"
          fork="yes"
          failonerror="yes">
      <classpath>
        <pathelement path="${out.dir}"/>
        <pathelement path="${compile.classpath}"/>
      </classpath>
      <jvmarg value="-DWS=${workspace}"/>
      <jvmarg value="-DclassDir=${out.dir}"/>
      <jvmarg value="-Dout=${derby.engine.src.dir}/${derby.dir}/iapi/services/cache/ClassSizeCatalog.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.services.cache.CachedItem"/>
      <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="1.4"
      target="1.4"
      bootclasspath="${empty}"
      nowarn="on"
      debug="${debug}"
      depend="${depend}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      proceed="${proceed}"
      verbose="${verbose}"
      srcdir="${derby.engine.src.dir}"
      destdir="${out.dir}">
      <classpath>
        <pathelement path="${compile.classpath}"/>
      </classpath>
      <include name="${derby.dir}/iapi/services/cache/ClassSizeCatalog.java"/>
    </javac>

  </target>

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

  <target name="cleancatalog"
          description="Remove the generated catalog java file.">
    <delete file="${derby.engine.dir}/iapi/services/cache/ClassSizeCatalog.java"/>
  </target>

<!-- =================================================================== -->
<!--                          Remove toursdb.jar                         -->
<!-- =================================================================== -->

  <target name="cleantoursdb"
          description="Remove the generated sample database.">
    <delete file="${derby.demo.src.dir}/toursdb/toursdb.jar"/>
    <delete file="${derby.demo.src.dir}/toursdb/toursdb.out"/>
    <delete file="${derby.demo.src.dir}/toursdb/derby.log"/>
    <delete dir="${derby.demo.src.dir}/toursdb/toursdb"/>
  </target>

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

  <target name="sane">
    <propertyfile file="${state.file}" comment="${header}">
      <entry key="sanity" value="true" type="string"/>
    </propertyfile>
    <delete file="${sanity.dir}/SanityState.java"/> 
    <delete dir="${sanity.out.dir}"/>
  </target>
  <target name="insane">
    <propertyfile file="${state.file}" comment="${header}">
      <entry key="sanity" value="false" type="string"/>
    </propertyfile>
    <delete file="${sanity.dir}/SanityState.java"/>
    <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"/>
  <property name="javadoc.tool.jdk14" value="${java.home}/../bin/javadoc"/>
  <property name="javadoc.tool.jdk16" value="${jdk16}/bin/javadoc"/>

  <target name="javadoc"
    depends="init-javadoc-tool,init,initjars,publishedapi,derbydocs,toolsdocs,grammardocs,testingdocs"/>

  <target name="init-javadoc-tool" depends="init-javadoc-not-jdk16,init-javadoc-jdk16"/>

  <target name="init-javadoc-not-jdk16" unless="jdk16">
    <property name="javadoc.tool" value="${javadoc.tool.jdk14}"/>
  </target>

  <target name="init-javadoc-jdk16" if="jdk16">
    <property name="javadoc.tool" value="${javadoc.tool.jdk16}"/>
  </target>

  <target name="publishedapi" depends="init-javadoc-tool,initjars">
 
    <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}"/>
  
    <delete dir="${public.api.dir}"/>
    <mkdir dir="${public.api.dir}"/>

    <antcall target="public-jdbc3-api"/>
    <antcall target="public-jdbc4-api"/>


  </target>

  <!--
    Build the jdbc3 public api. Called by publishedapi target.
  -->
  <target name="public-jdbc3-api">
 
    <antcall target="publishedapi-workhorse">
      <param name="javadocTool" value="${javadoc.tool.jdk14}"/>
      <param name="extraApi" value="publishedapi_jdbc3.ant"/>
    </antcall>

  </target>

  <!--
    Build the jdbc4 public api. Called by publishedapi target.
  -->
  <target name="public-jdbc4-api" if="jdk16">

    <move todir="${out.javadoc.dir}/jdbc3">
      <fileset dir="${public.api.dir}"/>
    </move>

    <mkdir dir="${public.api.dir}"/>

    <antcall target="publishedapi-workhorse">
      <param name="javadocTool" value="${javadoc.tool.jdk16}"/>
      <param name="extraApi" value="publishedapi_jdbc4.ant"/>
    </antcall>

    <move todir="${out.javadoc.dir}/jdbc4">
      <fileset dir="${public.api.dir}"/>
    </move>

    <mkdir dir="${public.api.dir}"/>

    <move todir="${public.api.dir}/jdbc3">
      <fileset dir="${out.javadoc.dir}/jdbc3"/>
    </move>

    <move todir="${public.api.dir}/jdbc4">
      <fileset dir="${out.javadoc.dir}/jdbc4"/>
    </move>

  </target>

  <!--
    This target is called twice, once to build the JDBC3 public api
    and then a second time to build the JDBC4 api.

    javadocTool  Which javadoc tool to use: jdk14 or jdk16 tool
    extraApi     Extra files to include in the public api.
  -->
  <target name="publishedapi-workhorse" depends="initjars">
 
    <!--  Only include the files we want customers to see.  -->
    <mkdir dir="${javadoc.temp.dir}"/>
    <antcall target="include-in-javadoc">
      <param name="more_inclusions" value="publishedapi.ant"/>
    </antcall>
    <antcall target="include-in-javadoc">
      <param name="more_inclusions" value="${extraApi}"/>
    </antcall>

    <javadoc sourcepath="${out.javadoc.dir}/sourcedir"
             executable="${javadocTool}"
             classpath="${compile.classpath};${osgi};${servlet24};${out.dir}"
             breakiterator="true"
             destdir="${public.api.dir}"
    	     Overview="${basedir}/published_api_overview.html"
             Windowtitle="Apache Derby ${major}.${minor} API Documentation"   
             Header="Apache Derby ${major}.${minor}"
             Footer="${javadoc.Footer}"
             bottom="Apache Derby ${major}.${minor} API Documentation  -  &lt;i&gt;Copyright &amp;copy; 2004,2008 The Apache Software Foundation. All Rights Reserved.&lt;/i&gt;">   
      <Doctitle> Apache Derby ${major}.${minor} API Documentation</Doctitle>   
      <fileset dir="${derby.engine.src.dir}"
               includesfile="${javadoc.inclusions}"/>
      <fileset dir="${derby.client.src.dir}"
               includesfile="${javadoc.inclusions}"/>
      <fileset dir="${derby.drda.src.dir}"
               includesfile="${javadoc.inclusions}"/>
      <fileset dir="${derby.tools.src.dir}"
               includesfile="${javadoc.inclusions}"/>
    </javadoc>

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

  </target>


  <target name="derbydocs" depends="init-javadoc-tool,initjars">

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

    <!-- Some of the link tags are lost when using nested filesets. Fool  -->
    <!-- javadoc into creating relative links by seeding it with the list -->
    <!-- of packages that have @link tags in their package.htmls          -->
    <copy file="${javadoctools.dir}/package-list" 
          todir="${out.javadoc.dir}/engine"/>

    <!--  Build scripts and other cruft choke javadoc. Exclude these files.  -->
    <mkdir dir="${javadoc.temp.dir}"/>
    <antcall target="exclude-from-javadoc">
      <param name="more_exclusions" value="derbydocs_exclusions.ant"/>
    </antcall>
    <antcall target="derbydocs-not-jdk16-excludes"/>

    <javadoc
        executable="${javadoc.tool}"
        additionalparam="-J-mx320M"
        packagenames="org.*"
        access="private"
        breakiterator="yes"
        useexternalfile="yes"
        classpath="${out.dir};${java14compile.classpath};${jars.extras};${osgi}"
        destdir="${out.javadoc.dir}/engine"
        windowtitle="Apache Derby V${major}.${minor} Internals"
        doctitle="Apache Derby V${major}.${minor} Internals"
        Footer="${javadoc.Footer}"
        bottom="Apache Derby V${major}.${minor} Internals - &lt;i&gt;Copyright &amp;copy; 2004,2007 The Apache Software Foundation. All Rights Reserved.&lt;/i&gt;">
        <taglet name="org.apache.derbyBuild.javadoc.FormatIdTaglet" 
                path="${basedir}/classes"/>
        <taglet name="org.apache.derbyBuild.javadoc.PurposeTaglet" 
                path="${basedir}/classes"/>
        <taglet name="org.apache.derbyBuild.javadoc.UpgradeTaglet" 
                path="${basedir}/classes"/>
        <taglet name="org.apache.derbyBuild.javadoc.DiskLayoutTaglet" 
                path="${basedir}/classes"/>
        <taglet name="org.apache.derbyBuild.javadoc.EndFormatTaglet" 
                path="${basedir}/classes"/>
      <fileset dir="${derby.engine.src.dir}"
               excludesfile="${javadoc.exclusions}"/>
      <fileset dir="${derby.client.src.dir}"
               excludesfile="${javadoc.exclusions}"/>
      <fileset dir="${derby.drda.src.dir}"
               excludesfile="${javadoc.exclusions}"/>
      <fileset dir="${derby.shared.src.dir}"
               excludesfile="${javadoc.exclusions}"/>
      <fileset dir="${derby.tools.src.dir}"
               excludesfile="${javadoc.exclusions}"/> 
      <link href="."/>
    </javadoc>

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

  </target>

  <!--
     Optionally include extra JDBC4 support in public API.
  -->
  <target name="publishedapi-jdk16-includes" if="jdk16">

    <!--  Include extra JDBC4 support.  -->
    <antcall target="include-in-javadoc">
      <param name="more_inclusions" value="publishedapi_jdbc4.ant"/>
    </antcall>

  </target>

  <!--
     Include more files in the javadoc. Successive calls to this
     target append more inclusions to the master file that tells
	 javadoc which files to notice.

	 Parameters:

	     more_inclusions    Additional file to append to master inclusions file.
  -->
  <target name="include-in-javadoc">
    <concat destfile="${javadoc.inclusions}" append="yes">
       <filelist dir="${javadoctools.dir}" 
         files="${more_inclusions}"
       />
    </concat>
  </target>

  <!--
     Optionally exclude the JDBC4 classes, which choke the jdk14 javadoc tool.
  -->
  <target name="derbydocs-not-jdk16-excludes" unless="jdk16">

    <antcall target="exclude-from-javadoc">
      <param name="more_exclusions" value="derbydocs_jdbc4_exclusions.ant"/>
    </antcall>

  </target>

  <!--
     Exclude more files from the javadoc. Successive calls to this
     target append more exclusions to the master file that tells
	 javadoc which files to ignore.

	 Parameters:

	     more_exclusions    Additional file to append to master exclusions file.
  -->
  <target name="exclude-from-javadoc">
    <concat destfile="${javadoc.exclusions}" append="yes">
       <filelist dir="${javadoctools.dir}" 
         files="${more_exclusions}"
       />
    </concat>
  </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-javadoc-tool,init">

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

    <javadoc
        executable="${javadoc.tool}"
        additionalparam="-J-mx320M"
        packagenames="org.apache.derbyDemo.vtis.*"
        access="private"
        breakiterator="yes"
        useexternalfile="yes"
        classpath="${out.dir}"
        destdir="${out.javadoc.dir}/demo"
        windowtitle="Apache Derby Demos"
        doctitle="Apache Derby Demos"
    >
     <fileset dir="${derby.demo.src.dir}/vtis/java"/>
    </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;${compile.classpath}"/>
      <arg value="-NOONE_TABLE"/>
      <arg value="-output_file=${jjdoctarget}"/>
      <arg value="${jjtodoc}"/>
    </java>

  </target>

  <target name="testingdocs" depends="testing-javadoc-16,testing-javadoc-14"/>
  
  <target name="testing-javadoc-16" if="jdk16">
    <antcall target="testing-javadoc">
      <param name="derbyTesting.javadoc.excludes" value=""/>
      <param name="derbyTesting.javadoc.vmlevel" value="1.6"/>
    </antcall>
  </target>

  <target name="testing-javadoc-14" unless="jdk16">
    <antcall target="testing-javadoc">
      <param name="derbyTesting.javadoc.excludes"
             value="org.apache.derbyTesting.functionTests.tests.jdbc4"/>
      <param name="derbyTesting.javadoc.vmlevel" value="1.4"/>
    </antcall>
  </target>

  <target name="testing-javadoc" depends="init-javadoc-tool,initjars">
    <javadoc
       executable="${javadoc.tool}"
       additionalparam="-J-mx320M"
       packagenames="org.*"
       access="private"
       breakiterator="yes"
       classpath="${out.dir};${java14compile.classpath};${jars.extras};${osgi};${junit}"
       destdir="${out.javadoc.dir}/testing"
       windowtitle="Apache Derby V${major}.${minor} Test Javadoc"
       doctitle="Apache Derby V${major}.${minor} Test Javadoc"
       Footer="${javadoc.Footer}"
       bottom="Apache Derby V${major}.${minor} Internals - &lt;i&gt;Copyright &amp;copy; 2004,2008 The Apache Software Foundation. All Rights Reserved.&lt;/i&gt;"
       source="${derbyTesting.javadoc.vmlevel}"
       sourcepath="${derby.testing.src.dir}"
       excludepackagenames="${derbyTesting.javadoc.excludes}"/>
  </target>

  <target name="cleandocs">

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

  </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.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"/>
       </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"/>

       <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,initjars,derbyjar,derbytoolsjar,derbynetjar,derbyclientjar,derbyrunjar,derbywar,derbylocalejars,derbytestingjar"/>
  <target name="buildjars" depends="initjars,derbyjar,derbytoolsjar,derbynetjar,derbyclientjar,derbyrunjar,derbywar,derbylocalejars,derbytestingjar"/>

  <target name="initjars" depends="setsanityname,getsvnversion,setCompilerProperties">
    <property name="derby.jar.dir" value="${basedir}/jars/${sanity.name}"/>
    <property name="derby.jar.topdir" value="${basedir}/jars"/>
    <mkdir dir="${derby.jar.dir}"/>
    <mkdir dir="${derby.jar.dir}/lists"/>
    <loadfile srcFile="${basedir}/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="jdbc4_classlist_edit" if="jdk16">
    <!-- uncomment jdbc4 classes if jdk 1.6 is available -->
    <echo level="info" message="uncommenting jdbc4 classes"/>
    <replaceregexp file="${jar.classlist}"
     match="^#jdbc4_optional_(.*)"
     replace="\1"
     byline="true"/>
  </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>
         
    <concat destfile="${derby.jar.dir}/lists/otherDerbyClasses.properties">
      <fileset dir="${basedir}/tools/jar" includes="*DBMS*.properties"/>
    </concat>

    <antcall target="jdbc4_classlist_edit">
      <param name="jar.classlist" value="${derby.jar.dir}/lists/otherDerbyClasses.properties"/>
    </antcall>

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

    <!-- filter out EmbeddedActivator if osgi.jar is not available -->
    <antcall target="filteractivator"/>

    <echo level="info" message=" creating derby.jar class list "/>
    <java classname="org.apache.derbyBuild.classlister" fork="yes">
      <jvmarg value="-DcloudscapeOnly=true"/>
      <jvmarg value="-Doutputfile=${derby.jar.dir}/lists/derby.list"/>
      <arg value="${derby.jar.dir}/lists/otherDerbyClasses.properties"/> 
      <arg value="${derby.jar.dir}/lists/org/apache/derby/modules.properties"/>
      <classpath>
        <pathelement path="${out.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.dir}//org/apache/derby/info/DBMS.properties"/>
    </antcall>
    <echo level="info" file="${derby.jar.dir}/lists/derby.list"
          append="true"
          message="org/apache/derby/info/DBMS.properties"/>

    <!-- 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.jdbc.AutoloadedDriver"/>
    </antcall>

    <!-- the next two targets are orthogonal. Only one will be executed, -->
    <!-- depending on whether or not osgi.jar is available.              -->
    <antcall target="derbyjarwithosgi"/>
    <antcall target="derbyjarwithoutosgi"/>

    <!-- add non-class files to jar -->

    <jar destfile="${derby.jar.dir}/derby.jar" 
         update="true"
         filesonly="true"
         compress="true">
      <fileset dir="${out.dir}"
               includes="org/apache/derby/loc/m?_en.properties,
                         org/apache/derby/loc/m??_en.properties,
                         org/apache/derby/loc/sysinfoMessages.properties,
                         org/apache/derby/loc/toolsmessages.properties,
                         org/apache/derby/impl/jdbc/metadata.properties,
                         org/apache/derby/impl/sql/catalog/metadata_net.properties,
                         org/apache/derby/info/DBMS.properties"/>
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/**,
                         org/apache/derby/modules.properties"/>
    </jar>

  </target>

  <target name="filteractivator" depends="checkosgijar" if="osgijar.unavailable">

    <replaceregexp file="${derby.jar.dir}/lists/otherDerbyClasses.properties"
                   match="derby.module.osgi.activator=org.apache.derby.osgi.EmbeddedActivator"
                   replace=""/>

  </target>

  <target name="derbyjarwithoutosgi" depends="checkosgijar" if="osgijar.unavailable">

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

    <jar destfile="${derby.jar.dir}/derby.jar"
         basedir="${out.dir}"
	 includesfile="${derby.jar.dir}/lists/derby.list"
         compress="true"
         filesonly="true"
         manifest="${derby.jar.dir}/lists/smf.mf"/>

  </target>

  <target name="derbyjarwithosgi" depends="checkosgijar" if="osgijar.available">

    <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.dir}"
	 includesfile="${derby.jar.dir}/lists/derby.list"
         compress="true"
         filesonly="true"
         manifest="${derby.jar.dir}/lists/smf.mf"/>

  </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="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="Sealed" value="true"/>
    	<section name="org/apache/derby/impl/tools/sysinfo/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    	<section name="org/apache/derby/iapi/services/context/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    	<section name="org/apache/derby/iapi/services/info/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    	<section name="org/apache/derby/jdbc/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    	<section name="org/apache/derby/info/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    	<section name="org/apache/derby/iapi/services/i18n/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
        <section name="org/apache/derby/iapi/tools/i18n/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    	<section name="org/apache/derby/loc/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
      	<section name="org/apache/derby/tools/">
    	  <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="setsanityname">

    <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 tools.list "/>
    <java classname="org.apache.derbyBuild.classlister" fork="yes">
      <jvmarg value="-Ddb2jtools=true"/>
      <jvmarg value="-Doutputfile=${derby.jar.dir}/lists/derbytools.list"/>
      <arg value="${basedir}/tools/jar/tools.properties"/>
      <classpath>
        <pathelement path="${out.dir}"/>
      </classpath>
    </java>
    <replace file="${derby.jar.dir}/lists/derbytools.list" token="$$$$" value="$$"/>

    <echo level="info" message=" creating new tools.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.dir}/org/apache/derby/info/tools.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>

    <delete file="${derby.jar.dir}/derbytools.jar"/>
    <jar destfile="${derby.jar.dir}/derbytools.jar"
         basedir="${out.dir}"
         includesfile="${derby.jar.dir}/lists/derbytools.list"
         compress="true"
         filesonly="true"/>
    <jar destfile="${derby.jar.dir}/derbytools.jar"
         manifest="${derby.jar.dir}/lists/smftools.mf"
         compress="true"
         filesonly="true"
         update="true">
      <fileset dir="${out.dir}"
               includes="org/apache/derby/loc/sysinfoMessages.properties,
                         org/apache/derby/loc/toolsmessages.properties,
                         org/apache/derby/info/tools.properties"/>
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/**"/>
    </jar>

  </target>

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

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

    <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 net.list"/> 
    <java classname="org.apache.derbyBuild.classlister" fork="yes">
      <jvmarg value="-Ddb2jdrda=true"/>
      <jvmarg value="-Doutputfile=${derby.jar.dir}/lists/derbynet.list"/>
      <arg value="${basedir}/tools/jar/net.properties"/>
      <classpath>
        <pathelement path="${out.dir}"/>
      </classpath>
    </java>

    <echo level="info" message=" creating new net.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.dir}/org/apache/derby/info/net.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"/>
      	<attribute name="Sealed" value="true"/>
    	<section name="org/apache/derby/impl/drda/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    	<section name="org/apache/derby/impl/tools/sysinfo/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
      	<section name="org/apache/derby/tools/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    	<section name="org/apache/derby/loc/">
    	  <attribute name="Sealed" value="false"/>
    	</section>
    </manifest> 

    <delete file="${derby.jar.dir}/derbynet.jar"/>
    <jar destfile="${derby.jar.dir}/derbynet.jar"
         basedir="${out.dir}"
         includesfile="${derby.jar.dir}/lists/derbynet.list"
         compress="true"
         filesonly="true"/>
    <jar destfile="${derby.jar.dir}/derbynet.jar"
         compress="true"
         filesonly="true"
         update="true"
    	 manifest="${derby.jar.dir}/lists/smfnet.mf">
      <fileset dir="${out.dir}"
               includes="org/apache/derby/loc/drda/**,
                         org/apache/derby/loc/sysinfoMessages.properties,
                         org/apache/derby/info/net.properties,
                         org/apache/derby/drda/server.policy"/>
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/**"/>
    </jar>

  </target>

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

 <target name="derbyclientjar" depends="setsanityname,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>

    <copy file="${basedir}/tools/jar/dnc.properties"
          tofile="${derby.jar.dir}/lists/dnc.properties"/>

    <antcall target="jdbc4_classlist_edit">
      <param name="jar.classlist" value="${derby.jar.dir}/lists/dnc.properties"/>
    </antcall>

    <java classname="org.apache.derbyBuild.classlister" fork="yes">
      <jvmarg value="-Doutputfile=${derby.jar.dir}/lists/dnc.list"/>
      <arg value="${derby.jar.dir}/lists/dnc.properties"/>
      <classpath>
        <pathelement path="${out.dir}"/> 
      </classpath>
    </java>

    <echo level="info" message=" creating new dnc.properties file "/>

    <mkdir dir="${out.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.dir}/org/apache/derby/info/dnc.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>

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

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

    <jar destfile="${derby.jar.dir}/derbyclient.jar"
         compress="true"
         filesonly="true"
         update="true"
    	 manifest="${derby.jar.dir}/lists/smfclient.mf">
      <fileset dir="${out.dir}"
               includesfile="${derby.jar.dir}/lists/dnc.list"/>
      <fileset dir="${out.dir}"
               includes="org/apache/derby/info/dnc.properties,
                         org/apache/derby/loc/sysinfoMessages.properties,
                         org/apache/derby/loc/clientmessages*.properties"
               excludes="org/apache/derby/loc/clientmessages_qq_PP_testOnly.properties"/>
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/**"/>
    </jar>
  </target>

<!-- - - - - - - - - - - - - - derbyrun.jar target  - - - - - - - - - -->
   
  <target name="derbyrunjar" depends="setsanityname,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.iapi.tools.run"/>
      <attribute name="Class-Path" value="derby.jar derbyclient.jar derbytools.jar derbynet.jar"/>
    </manifest> 
 	
    <jar destfile="${derby.jar.dir}/derbyrun.jar"
         compress="true"
         filesonly="true"
         update="true"
    	 manifest="${derby.jar.dir}/lists/smfcmd.mf">
      <fileset dir="${out.dir}"
               includes="org/apache/derby/iapi/tools/run.class"/>
      <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 localejar for each locale -->

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

  <target name="localejar">
 
    <echo level="info" message="Building derbyLocale_${locale.iname}.jar"/>

    <!-- generate new locale property file -->
    <antcall target="localeinfowriter">
      <param name="info.buildnumber" value="${changenumber}"/>
      <param name="info.iname" value="_${locale.iname}"/>
      <param name="info.ename" value="${locale.ename}"/>
      <param name="info.productfile" value="derbyLocale_${locale.iname}.jar"/>
      <param name="info.file" value="${out.dir}/org/apache/derby/info/locale_${locale.iname}.properties"/>
    </antcall>   
    <jar destfile="${derby.jar.dir}/derbyLocale_${locale.iname}.jar"
         compress="true"
	 filesonly="true">
      <fileset dir="${out.dir}"
	       includes="org/apache/derby/info/*_${locale.iname}.properties,
	                 org/apache/derby/loc/*_${locale.iname}.properties,
	                 org/apache/derby/loc/drda/*_${locale.iname}.properties"/>
      <fileset dir="${derby.jar.dir}/lists"
               includes="META-INF/LICENSE,META-INF/NOTICE"/>
    </jar>
  </target>
    
<!-- - - - - - - - - - - - derby testing jar target - - - - - - - - - - -->

  <target name="derbytestingjar" depends="initjars,ckderbytesting" if="derbyTesting.available">
    <zip destfile="${derby.jar.dir}/derbyTesting.jar" filesonly="true" compress="true">
      <fileset dir="${out.dir}" includes="org/apache/derbyTesting/**,SimpleApp*,org/apache/derby/impl/tools/ij/mt*.class,org/apache/derby/impl/tools/ij/SimpleCharStream.class,org/apache/derby/impl/drda/TestProto.class,org/apache/derby/impl/store/access/conglomerate/QualifierUtil.class,org/apache/derby/loc/m*_qq_PP_testOnly*,toursdb/*"/>
    </zip>
  </target>

  <target name="ckderbytesting">
    <available file="${out.dir}/org/apache/derbyTesting"
               property="derbyTesting.available"/>
  </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="checkosgijar" depends="setosgiavailable,setosgiunavailable"/>
  <target name="setosgiavailable">
    <condition property="osgijar.available">
      <available file="${osgi}"/>
    </condition>
  </target>
  <target name="setosgiunavailable">
    <condition property="osgijar.unavailable">
      <not>
        <available file="${osgi}"/>
      </not>
    </condition>
  </target>

   <target name="getsvnversion">
     <exec executable="svnversion"
           failifexecutionfails="no"
           output="${basedir}/changenumber.properties">
       <arg value="${basedir}"/>
       <arg value="-n"/>
     </exec>
   </target>

  <target name="cleanjars" depends="setsanityname">
    <delete dir="${basedir}/jars/${sanity.name}"/>
  </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>


<!-- =================================================================== -->
<!--                         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="plugin"/>
    <antcall target="publishedapi"/>

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

    <!-- debug archives - DERBY-178 --> 
    <zip destfile="${basedir}/snapshot/db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}.zip">
      <zipfileset prefix="db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}/lib" dir="${basedir}/jars/sane" includes="*.jar,*.war"/>
      <zipfileset prefix="db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}" dir="${basedir}" includes="bin/**,LICENSE,NOTICE,CHANGES,README,javadoc/publishedapi/**"/>
    </zip>
    <tar destfile="${basedir}/snapshot/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="${basedir}/jars/sane" includes="*.jar,*.war"/>
      <tarfileset prefix="db-derby-snapshot-debug-${major}.${minor}.${interim}.${point}-${changenumber}" dir="${basedir}" includes="bin/**,LICENSE,NOTICE,README,javadoc/publishedapi/**"/>
    </tar>

    <copy file="${basedir}/jars/insane/derby_core_plugin_${major}.${minor}.${interim}.zip"
          tofile="${basedir}/snapshot/derby_core_plugin_${major}.${minor}.${interim}.${changenumber}.zip"/>
  </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                       -->
<!-- =================================================================== -->

  <target name="junit-init">
    <tstamp prefix="derby.junit">
      <format property="standardtime" pattern="yyyy-MM-dd hh:mm aa zzz"/>
    </tstamp>
    <property name="derby.junit.jvm" value="java"/>
    <property name="derby.junit.timestamp" value="${derby.junit.DSTAMP}_${derby.junit.TSTAMP}"/>
    <mkdir dir="junit_${derby.junit.timestamp}/testout"/>
  </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.dir}"/>
    </java>
  </target>

  <target name="junit-clean">
    <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="derby.junit.classpath" value="">
      <not>
        <isset property="derby.junit.classpath"/>
      </not>
    </condition>
    <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">
      <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"/>
      <!-- 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.jdbcapi.AutoloadTest"
  	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.jdbcapi.JDBCDriversEmbeddedTest"
	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.jdbcapi.JDBCDriversClientTest"
	todir="junit_${derby.junit.timestamp}"/>
<test name="org.apache.derbyTesting.functionTests.tests.jdbcapi.JDBCDriversAllTest"
	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.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>
     	    <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"/>
      </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">
        <condition property="derby.junit.classpath" value="">
          <not>
            <isset property="derby.junit.classpath"/>
          </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">
          <formatter type="xml"/>

    <test name="org.apache.derbyTesting.system.oe.test.OETest"
        todir="junit_${derby.junit.timestamp}"/>
          <classpath>
               <pathelement path="${derby.junit.classpath}"/>
               <pathelement location="${javatools.dir}/junit.jar"/>
          </classpath>
         </junit>
  </target>
	  
  <!-- only execute jdbc4 suite if we have a pointer to a 1.6 VM -->
  <target name="junit-jdbc4" if="jdk16" depends="junit-init">
    <condition property="derby.junit.classpath" value="">
      <not>
        <isset property="derby.junit.classpath"/>
      </not>
    </condition>
  	 <junit printsummary="on"
           fork="yes" forkmode="perTest"
           jvm="${jdk16}/bin/java"
           showoutput="yes"
           dir="junit_${derby.junit.timestamp}"
           tempdir="junit_${derby.junit.timestamp}"
  	 	   errorproperty="tests.failed"
  	       failureproperty="tests.failed">
      <formatter type="xml"/>
  	 	
      <test name="org.apache.derbyTesting.functionTests.tests.jdbc4._Suite"
      	todir="junit_${derby.junit.timestamp}"/>
        <classpath>
       	    <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="checkVMLevel,junit-init" if="vmLevelIsAtLeast1.5">
    <condition property="derby.junit.classpath" value="">
      <not>
        <isset property="derby.junit.classpath"/>
      </not>
    </condition>
  	 <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">
      <formatter type="xml"/>
  	 	
      <test name="org.apache.derbyTesting.functionTests.tests.memory._Suite"
      	todir="junit_${derby.junit.timestamp}"/>
        <classpath>
       	    <pathelement path="${derby.junit.classpath}"/>
            <pathelement location="${javatools.dir}/junit.jar"/>
        </classpath>
      </junit>	
  </target>

  <!-- Runs Derby's JMX tests if the required VM level (1.5 or higher) is detected -->
  <target name="junit-jmx" depends="checkVMLevel,junit-init" if="vmLevelIsAtLeast1.5">
    <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">
        <formatter type="xml"/>

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

        <classpath>
            <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">
    <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">
        <formatter type="xml"/>

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

        <classpath>
            <pathelement location="${out.pptesting.dir}"/>
            <pathelement location="${out.dir}"/>
            <pathelement location="${javatools.dir}/junit.jar"/>
        </classpath>
    </junit>
  </target>

  <!-- Run a single junit test or suite -->
  <target name="junit-single" depends="junit-init">
    <condition property="derby.junit.classpath" value="">
      <not>
        <isset property="derby.junit.classpath"/>
      </not>
    </condition>
    <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">
      <!-- This property is needed to keep EMMA silent when measuring codecoverage -->
      <sysproperty key="emma.verbosity.level" value="silent"/>
      <formatter type="xml"/>
      
      <test name="${derby.junit.testclass}" todir="junit_${derby.junit.timestamp}"/>

      <classpath>
     	    <pathelement path="${derby.junit.classpath}"/>
            <pathelement location="${javatools.dir}/junit.jar"/>
      </classpath>
    </junit>
      
  </target>
   
  <target name="junit-all" depends="junit-core,junit-jdbc4,junit-jmx,junit-lowmem">
  </target>
 
  <target name="junitreport" depends="junit-sysinfo,junit-all">
    <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>

    <!-- fix up unterminated elements in overview-frame.html -->
    <replace token="href=&quot;stylesheet.css&quot;&gt;"
             value="href=&quot;stylesheet.css&quot;/&gt;&lt;/META&gt;"
             file="junit_${derby.junit.timestamp}/overview-frame.html"/>
    <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"/>

    <xslt style="${basedir}/tools/ant/xsl/sysinfo_junitreport.xsl"
          in="junit_${derby.junit.timestamp}/overview-frame.html"
          out="junit_${derby.junit.timestamp}/overview-frame2.html"/>
    <move file="junit_${derby.junit.timestamp}/overview-frame2.html"
          tofile="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="${basedir}/jars/${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>
	
	

<!-- =================================================================== -->
<!--                         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="${emmabase}" includes="**"/>
        </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">
        <!-- 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}/derby.jar"/>
                    <pathelement path="${derby.jar.dir}/derbyclient.jar"/>
                    <pathelement path="${derby.jar.dir}/derbynet.jar"/>
                    <pathelement path="${derby.jar.dir}/derbytools.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}/derbyclient.jar:${instrumented.jars}/derbynet.jar:${instrumented.jars}/derbytools.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.demo.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>

</project>
