<project name="Xbean" default="default" basedir=".">

  <property name="build.compiler" value="javac1.4"/>
  <property name="product.version" value="1.0.0"/>

  <target name="usage">
    <echo message="The following ant targets are defined:"/>
    <echo message="usage    - this help text"/>
    <echo message="build    - builds our public interface jars so others can compile"/>
    <echo message="deploy   - builds our implementation jar (xbean.jar)"/>
    <echo message="clean    - cleans out the xbeans directories"/>
    <echo message="builddrt - builds, but does not run, the xbean drt"/>
    <echo message="drt      - runs the xbean drt"/>
  </target>

  <target name="clean">
    <delete dir="build"/>
  </target>

  <target name="deploy" depends="sources, xbean, drt.jar, random.jar" />

  <target name="sources" depends="dirs">
    <zip destfile="build/ar/xbeansrc.zip" basedir="." excludes="build/**"/>
  </target>

  <target name="xbean" depends="xbean.jar">
    <copy file="build/lib/xbean.jar" tofile="build/ar/xbean.jar"/>
  </target>

  <target name="dirs">
    <mkdir dir="build"/>
    <mkdir dir="build/classes"/>
    <mkdir dir="build/lib"/>
    <mkdir dir="build/ar"/>
    <mkdir dir="build/src"/>
    <mkdir dir="build/private"/>
    <mkdir dir="build/private/classes"/>
    <mkdir dir="build/private/lib"/>
  </target>

  <target name="drt" >
      <echo message="Running random tester"/>
       <java classname="Random" fork="true" failonerror="true">
          <classpath>
            <pathelement location="build/ar/xbean.jar"/>
            <pathelement location="build/private/lib/easypo.jar"/>
            <pathelement location="build/private/lib/random.jar"/>
          </classpath>
         <jvmarg value="-ea"/>
         <arg line="-seed 0 -i 20 -noquery"/>
       </java>

    <mkdir dir="build/test/output"/>
    <echo message="Running xbean product drt tests"/>
    <echo message="JUnit output being sent to xbean/build/test/output/drt-product.txt"/>
    <junit fork="yes" printsummary="yes" haltonfailure="yes" showoutput="yes">
      <jvmarg value="-ea"/>
      <sysproperty key="xbean.rootdir" value="${basedir}"/>
      <sysproperty key="treeasserts" value="true"/>
      <classpath>
        <pathelement location="external/lib/junit.jar"/>
        <pathelement location="build/ar/xbean.jar"/>
        <pathelement location="build/private/lib/drt.jar"/>
        <pathelement location="build/private/lib/easypo.jar"/>
        <pathelement location="build/private/lib/schemas.jar"/>
        <pathelement location="build/private/lib/xstypes.jar"/>
        <pathelement location="build/private/lib/enumtest.jar"/>
      </classpath>
      <formatter type="plain"/>
      <test name="drtcases.SmokeTests" outfile="build/test/output/drt-product" />
    </junit>
  </target>

  <target name="builddrt" depends="drt.jar, random.jar, eric"/>

  <target name="eric" depends="erictest.jar"/>

  <target name="default" depends="deploy, builddrt"/>

  <target name="redeploy" depends="clean, deploy"/>

  <!-- oldxbean.jar target =========================================== -->

  <target name="oldxbean.jar">
    <copy file="external/lib/oldxbean.jar" tofile="build/private/lib/oldxbean.jar"/>
  </target>

  <!-- bootstrap target ============================================== -->

  <target name="bootstrap" depends="xbean">

    <!-- after xbean.jar is built, move it out of the way and clean the project -->
    <tempfile property="bootstrap.jarfile" prefix="oldxbean" suffix=".jar"/>
    <move file="build/ar/xbean.jar" tofile="${bootstrap.jarfile}"/>
    <antcall target="clean" inheritAll="false"/>

    <!-- then move it back into place as oldxbean.jar and do another build -->
    <move file="${bootstrap.jarfile}" tofile="build/private/lib/oldxbean.jar"/>
    <antcall target="xbean" inheritAll="false"/>

    <!-- compare the contents of the first jar to the contents of the second jar -->
    <antcall target="zipcompare.classes" inheritAll="false"/>
    <java classname="zipcompare.ZipCompare"
          classpath="build/private/classes/zipcompare"
          fork="true"
          failonerror="true">
      <arg line="build/ar/xbean.jar build/private/lib/oldxbean.jar"/>
    </java>

    <!-- when everything succeeds, check out oldxbean.jar from perforce -->
    <echo message="==================================="/>
    <echo message="Results match! Bootstrap succeeded."/>
    <echo message="==================================="/>
    <echo message="Attempting to copy oldxbean.jar"/>
    <echo message="If the copy fails, you must check out oldxbean.jar"/>
    <!-- copy oldxbean.jar whether or not perforce succeeded -->
    <echo message="overwriting old external/lib/oldxbean.jar"/>
    <copy file="build/private/lib/oldxbean.jar" tofile="external/lib/oldxbean.jar"/>
  </target>

  <!-- zipcompare (for checking bootstrap) ============================ -->

  <target name="zipcompare.classes">
    <mkdir dir="build/private/classes/zipcompare"/>
    <javac srcdir="src/zipcompare"
           destdir="build/private/classes/zipcompare"
           debug="on"/>
  </target>

  <!-- test target ================================================== -->

  <path id="test.compile.path">
    <pathelement location="external/lib/junit.jar"/>
    <pathelement location="build/ar/xbean.jar"/>
    <pathelement location="build/private/lib/easypo.jar"/>
    <pathelement location="build/private/lib/ericschema.jar"/>
    <pathelement location="build/private/lib/schemas.jar"/>
    <pathelement location="build/private/lib/enumtest.jar"/>
    <pathelement location="build/private/lib/xstypes.jar"/>
    <pathelement location="build/classes/xmlinputstream"/>
  </path>

  <path id="test.run.path">
    <pathelement location="build/ar/xbean.jar"/>
    <pathelement location="external/lib/junit.jar"/>
  </path>

  <!-- builddrt target ============================================== -->

  <target name="drt.classes" depends="dirs, easypo.jar, schemas.jar, xstypes.jar, enumtest.jar">
    <mkdir dir="build/private/classes/drt"/>
    <javac
       srcdir="test/src/drt"
       destdir="build/private/classes/drt"
       classpathref="test.compile.path"
       source="1.4"
       debug="on"/>
  </target>

  <target name="drt.jar" depends="drt.classes">
    <jar jarfile="build/private/lib/drt.jar" basedir="build/private/classes/drt"/>
  </target>

  <!-- stsschema (for testing) target ================================ -->

  <path id="scomp.run.path">
    <pathelement location="build/lib/xbean.jar"/>
  </path>

  <target name="stsschema.check">
    <uptodate property="stsschema.notRequired" targetfile="build/private/lib/stsschema.jar">
      <srcfiles dir="test/src/stsschema" includes="**/*.xsd"/>
      <srcfiles dir="build/ar" includes="xbean.jar"/>
    </uptodate>
  </target>

  <target name="stsschema.jar" depends="stsschema.check, dirs, xbean" unless="stsschema.notRequired">
    <java classname="${schema_compiler}" classpathref="scomp.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="-out build/private/lib/stsschema.jar test/src/stsschema"/>
    </java>
  </target>

  <!-- soaptest target ============================================ -->

  <target name="soaptest.classes" depends="dirs, stsschema.jar">
    <mkdir dir="build/private/classes/soaptest"/>
    <javac srcdir="test/src/soaptest" destdir="build/private/classes/soaptest" source="1.4" debug="on">
      <classpath>
        <pathelement location="external/lib/jdom.jar"/>
        <pathelement location="external/lib/junit.jar"/>
        <pathelement location="build/ar/xbean.jar"/>
        <pathelement location="build/private/lib/stsschema.jar"/>
      </classpath>
    </javac>

  </target>

  <target name="soaptest.jar" depends="soaptest.classes">
    <jar jarfile="build/private/lib/soaptest.jar" basedir="build/private/classes/soaptest"/>
  </target>

  <!-- erictest target ============================================= -->

  <target name="erictest.classes" depends="dirs, xbean, ericschema.jar">
    <mkdir dir="build/private/classes/erictest"/>
    <javac
       srcdir="test/src/erictest"
       destdir="build/private/classes/erictest"
       classpathref="test.compile.path"
       source="1.4"
       debug="on"/>
  </target>

  <target name="erictest.jar" depends="erictest.classes">
    <jar jarfile="build/private/lib/erictest.jar" basedir="build/private/classes/erictest"/>
  </target>

  <!-- random target ============================================= -->

  <target name="random.classes" depends="dirs, xbean, easypo.jar">
    <mkdir dir="build/private/classes/random"/>
    <javac
       srcdir="test/src/random"
       destdir="build/private/classes/random"
       classpathref="test.compile.path"
       source="1.4"
       debug="on"/>
  </target>

  <target name="random.jar" depends="random.classes">
    <jar jarfile="build/private/lib/random.jar" basedir="build/private/classes/random"/>
  </target>

  <!-- teststore target ============================================= -->

  <target name="teststore.classes" depends="dirs">
    <mkdir dir="build/private/classes/teststore"/>
    <javac srcdir="test/src/teststore" destdir="build/private/classes/teststore" source="1.4" debug="on">
      <classpath>
        <pathelement location="build/private/classes/simpletypes"/>
        <pathelement location="build/private/classes/xmlcomp"/>
        <pathelement location="build/private/classes/typestore"/>
        <pathelement location="build/private/classes/xmlpublic"/>
        <pathelement location="build/private/classes/typeimpl"/>
      </classpath>
    </javac>

  </target>

  <target name="teststore.jar" depends="teststore.classes">
    <jar jarfile="build/private/lib/teststore.jar" basedir="build/private/classes/teststore"/>
  </target>

  <!-- simpletypes (for testing) target ============================= -->

  <target name="simpletypes.check">
    <uptodate property="simpletypes.notRequired" targetfile="build/private/lib/simpletypes.jar">
      <srcfiles dir="test/cases/schema/simple" includes="**/*.xsd"/>
      <srcfiles dir="build/private/lib" includes="xbean.jar"/>
    </uptodate>
  </target>

  <target name="simpletypes.jar" depends="simpletypes.check, dirs" unless="simpletype.notRequired">
    <java classname="${schema_compiler}" classpathref="scomp.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="-name schema.test.simple -out build/private/lib/simpletypes.jar test/cases/schema/simple"/>
    </java>
  </target>

  <!-- easypo (for testing) target ================================== -->

  <target name="easypo.check">
    <uptodate property="easypo.notRequired" targetfile="build/private/lib/easypo.jar">
      <srcfiles dir="test/src/easypo" includes="**/*"/>
      <srcfiles dir="build/ar" includes="xbean.jar"/>
    </uptodate>
  </target>

  <target name="easypo.jar" depends="easypo.check, dirs, xbean" unless="easypo.notRequired">
    <java classname="${schema_compiler}" classpathref="scomp.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="-out build/private/lib/easypo.jar test/src/easypo"/>
    </java>
  </target>

  <!-- schemas (for testing) target ================================ -->

  <target name="schemas.check">
    <uptodate property="schemas.notRequired" targetfile="build/private/lib/schemas.jar">
      <srcfiles dir="test/src/schemas" includes="**/*.xsd"/>
      <srcfiles dir="build/ar" includes="xbean.jar"/>
    </uptodate>
  </target>

  <target name="schemas.jar" depends="schemas.check, dirs, xbean" unless="schemas.notRequired">
    <java classname="${schema_compiler}" classpathref="scomp.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="-out build/private/lib/schemas.jar test/src/schemas"/>
    </java>
  </target>

  <!-- ericschema (for testing) target ================================ -->

  <target name="ericschema.check">
    <uptodate property="ericschema.notRequired" targetfile="build/private/lib/ericschema.jar">
      <srcfiles dir="test/src/ericschema" includes="**/*.xsd"/>
      <srcfiles dir="build/ar" includes="xbean.jar"/>
    </uptodate>
  </target>

  <target name="ericschema.jar" depends="ericschema.check, dirs, xbean" unless="ericschema.notRequired">
    <java classname="${schema_compiler}" classpathref="scomp.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="-src build/private/src -out build/private/lib/ericschema.jar test/src/ericschema"/>
    </java>
  </target>

  <!-- enumtest (for testing) target ================================= -->

  <target name="enumtest.check">
    <uptodate property="enumtest.notRequired" targetfile="build/private/lib/enumtest.jar">
      <srcfiles dir="test/cases/schema/simple" includes="**/*.xsd"/>
      <srcfiles dir="build/ar" includes="xbean.jar"/>
    </uptodate>
  </target>

  <target name="enumtest.jar" depends="enumtest.check, dirs, xbean" unless="enumtest.notRequired">
    <java classname="${schema_compiler}" classpathref="scomp.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="-out build/private/lib/enumtest.jar test/src/enumtest"/>
    </java>
  </target>

  <!-- xstypes (for testing) target ================================= -->

  <target name="xstypes.check">
    <uptodate property="xstypes.notRequired" targetfile="build/private/lib/xstypes.jar">
      <srcfiles dir="test/cases/schema/simple" includes="**/*.xsd"/>
      <srcfiles dir="build/ar" includes="xbean.jar"/>
    </uptodate>
  </target>

  <target name="xstypes.jar" depends="xstypes.check, dirs, xbean" unless="xstypes.notRequired">
    <java classname="${schema_compiler}" classpathref="scomp.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="-out build/private/lib/xstypes.jar test/src/xstypes"/>
    </java>
  </target>

  <!-- javadocs ====================================================== -->

  <!-- All docs to build/docs, including guide and javadocs. -->

  <target name="docs" depends="xbean">
    <property name="docs.dir" value="build/docs"/>
    <delete dir="${docs.dir}"/>
    <mkdir dir="${docs.dir}"/>
    <javadoc packagenames="*" sourcepath="src/xmlpublic" classpath="${javadoc.path}" destdir="${docs.dir}/reference" windowtitle="XMLBeans Documentation" source="1.4" stylesheetfile="docs/stylesheet.css">
      <link href="http://e-docs.bea.com/wls/docs81/javadocs/"/>
      <link href="http://java.sun.com/j2se/1.4.2/docs/api/"/>
      <link href="http://java.sun.com/j2ee/1.4/docs/api/"/>
      <link href="http://xml.apache.org/xerces-j/apiDocs/"/>
      <classpath>
        <pathelement location="build/ar/xbean.jar"/>
      </classpath>
    </javadoc>
    <copy file="docs/xmlbeans.css" tofile="${docs.dir}/xmlbeans.css" />
    <copy todir="${docs.dir}/guide">
      <fileset dir="docs/guide"/>
    </copy>
    <copy todir="${docs.dir}/images">
      <fileset dir="docs/images"/>
    </copy>
  </target>

  <!-- stream conformance tests ======================================= -->

  <target name="streamtest.classes" depends="dirs">
    <mkdir dir="build/private/classes/streamtest"/>
    <javac
      srcdir="test/src/streamtest"
      destdir="build/private/classes/streamtest"
      classpathref="test.compile.path"
      source="1.4"
      debug="on"/>
  </target>

  <target name="streamtest.jar" depends="streamtest.classes">
    <jar jarfile="build/private/lib/streamtest.jar" basedir="build/private/classes/streamtest"/>
  </target>

  <path id="run.streamconf.path">
    <path refid="test.run.path"/>
    <pathelement location="build/private/classes/streamtest/"/>
  </path>

  <target name="streamconf" depends="streamtest.jar">
    <java classname="streamtest.XmlStreamConformance"
          classpathref="run.streamconf.path"
          fork="true">
      <jvmarg value="-ea"/>
      <!--arg line="test/cases/streamconf/small.xml" /-->
      <arg line="test/cases/streamconf/dtd.xml" />
    </java>
  </target>


  <target name="dist" depends="dist-src, dist-bin">
  </target>

  <target name="dist-bin" depends="xbean, docs">
     <delete dir="build/private/xmlbeans-${product.version}"/>
     <delete file="build/private/incubating-xmlbeans-${product.version}.zip"/>
     <delete file="build/private/incubating-xmlbeans-${product.version}.tgz"/>

     <mkdir dir="build/private/xmlbeans-${product.version}"/>
     <copy todir="build/private/xmlbeans-${product.version}">
        <fileset dir="xkit"/>
     </copy>

     <mkdir dir="build/private/xmlbeans-${product.version}/lib"/>
     <copy todir="build/private/xmlbeans-${product.version}/lib" file="build/ar/xbean.jar"/>

     <mkdir dir="build/private/xmlbeans-${product.version}/src/schema"/>
     <copy todir="build/private/xmlbeans-${product.version}/src/schema">
        <fileset dir="src/toolschema"/>
     </copy>

     <mkdir dir="build/private/xmlbeans-${product.version}/docs"/>
     <copy todir="build/private/xmlbeans-${product.version}/docs">
        <fileset dir="build/docs"/>
     </copy>

     <zip destfile="build/private/incubating-xmlbeans-${product.version}.zip"
          basedir="build/private"
          includes="xmlbeans-${product.version}/**"/>
     <tar destfile="build/private/incubating-xmlbeans-${product.version}.tgz"
          basedir="build/private"
          includes="xmlbeans-${product.version}/**"
          compression="gzip"/>
  </target>

  <target name="dist-src" depends="clean, dirs">
     <delete file="build/private/incubating-xmlbeans-${product.version}-src.zip"/>
	 <delete file="build/private/incubating-xmlbeans-${product.version}-src.tgz"/>

	 <zip destfile="build/private/incubating-xmlbeans-${product.version}-src.zip">
     	<zipfileset
     		dir="."
       		includes="**"
       		excludes="build/**"
       		prefix="xmlbeans-${product.version}"/>
     </zip>
	 <tar destfile="build/private/incubating-xmlbeans-${product.version}-src.tgz"
	 	  compression="gzip">
     	<tarfileset
     		dir="."
       		includes="**"
       		excludes="build/**"
       		prefix="xmlbeans-${product.version}"/>
     </tar>
  </target>

  <!-- previously in xbean.xml -->

  <target name="xbean.jar"
        depends="dirs, xmlpublic.classes, typestore.classes,
                 common.classes, typeimpl.classes, xmlcomp.classes,
                 xmlstore.classes,
                 oldxbean.jar, xsdschema.classes,
                 xmlinputstream.classes">
    <jar jarfile="build/lib/xbean.jar" index="true">
      <fileset dir="build/classes/xmlpublic"/>
      <fileset dir="build/classes/typestore"/>
      <fileset dir="build/classes/common"/>
      <fileset dir="build/classes/typeimpl"/>
      <fileset dir="build/classes/xmlcomp"/>
      <fileset dir="build/classes/configschema"/>
      <fileset dir="build/classes/toolschema"/>
      <fileset dir="build/classes/xsdschema"/>
      <fileset dir="build/classes/xmlschema"/>
      <fileset dir="build/classes/xmlstore"/>
      <fileset dir="build/classes/xmlinputstream"/>
      <fileset dir="build/classes/repackage"/>
      <fileset dir="src/license"/>
    </jar>
  </target>

  <!-- jaxb target =================================================== -->

  <path id="jaxb.compile.path">
    <pathelement location="external/lib/jaxb-1.0/jaxb-api.jar"/>
    <pathelement location="build/classes/xmlpublic"/>
    <pathelement location="build/classes/typeimpl"/>
    <pathelement location="build/classes/common"/>
    <pathelement location="build/classes/typestore"/>
    <pathelement location="build/classes/xmlinputstream"/>
    <pathelement location="build/classes/jaxbschema"/>
  </path>

    <target name="jaxbschema.check">
        <condition property="jaxbschema.notRequired">
            <uptodate property="jaxbschema.notRequired" targetfile="build/classes/jaxbschema/schema/system/JAXBCONFIG/index.xsb">
                <srcfiles dir="src/jaxb/schema" includes="**/*.xsd;**/*.xsdconfig"/>
            </uptodate>
        </condition>
    </target>

    <target name="jaxbschema.classes" depends="jaxbschema.check, xmlpublic.classes, typeimpl.classes, common.classes, typestore.classes, xmlinputstream.classes" unless="jaxbschema.notRequired">
        <delete dir="build/classes/jaxbschema"/>
        <delete dir="build/src/jaxbschema"/>
        <java classname="${bootstrap_schema_compiler}" classpathref="bootstrap.run.path" fork="true" failonerror="true">
            <jvmarg value="-ea"/>
            <arg line="${repackage_arg} -name JAXBCONFIG -cp ${bootstrap.compile.path} -srconly -d build/classes/jaxbschema -src build/src/jaxbschema src/jaxb/schema"/>
        </java>
    </target>

    <target name="jaxb.classes" depends="dirs, jaxbschema.classes, xmlpublic.classes, typeimpl.classes, common.classes, typestore.classes, xmlinputstream.classes">
        <mkdir dir="build/src/jaxb"/>
        <mkdir dir="build/classes/jaxb"/>

        <javac destdir="build/classes/jaxb" classpathref="jaxb.compile.path" source="1.4" debug="on">
            <src path="src/jaxb"/>
            <src path="build/src/jaxbschema"/>
        </javac>
    </target>

  <!-- build XMLInputStream interface ============================================= -->

  <target name="xmlinputstream.classes" depends="dirs">
    <mkdir dir="build/classes/xmlinputstream"/>
    <javac srcdir="src/xmlinputstream"
        destdir="build/classes/xmlinputstream"
        debug="on"/>
  </target>

  <!-- xmlpublic target ============================================== -->

  <target name="xmlpublic.classes" depends="dirs, xmlinputstream.classes">
    <mkdir dir="build/classes/xmlpublic"/>
    <javac srcdir="src/xmlpublic" destdir="build/classes/xmlpublic" source="1.4" debug="on">
      <classpath>
        <pathelement location="build/classes/xmlinputstream"/>
      </classpath>
    </javac>

  </target>

  <target name="xmlpublic.jar" depends="dirs, xmlinputstream.classes, xmlpublic.classes, xmlschema.classes, xsdschema.classes">
    <jar jarfile="build/lib/xmlpublic.jar"  index="true">
      <fileset dir="build/classes/xmlpublic"/>
      <fileset dir="build/classes/xmlschema"/>
      <fileset dir="build/classes/xsdschema"/>
    </jar>
  </target>

  <!-- typestore target ============================================== -->

  <target name="typestore.classes" depends="dirs, xmlpublic.classes, common.classes, xmlinputstream.classes">
    <mkdir dir="build/classes/typestore"/>
    <javac srcdir="src/typestore" destdir="build/classes/typestore" source="1.4" debug="on">
      <classpath>
        <pathelement location="build/classes/xmlinputstream"/>
        <pathelement location="build/classes/xmlpublic"/>
        <pathelement location="build/classes/common"/>
      </classpath>
    </javac>

  </target>

  <!-- common target ============================================= -->

  <target name="common.classes" depends="dirs, xmlpublic.jar, xmlinputstream.classes">
    <mkdir dir="build/classes/common"/>
    <javac srcdir="src/common" destdir="build/classes/common" source="1.4" debug="on">
      <classpath>
        <pathelement location="build/classes/xmlinputstream"/>
        <pathelement location="build/lib/xmlpublic.jar"/>
      </classpath>
    </javac>

  </target>

  <!-- typeimpl target ============================================== -->

  <target name="typeimpl.classes" depends="dirs, repackage.classes, xmlpublic.classes, typestore.classes, xsdschema.classes, configschema.classes, toolschema.classes">
    <mkdir dir="build/classes/typeimpl"/>
    <javac destdir="build/classes/typeimpl" source="1.4" debug="on">
      <classpath>
        <pathelement location="build/classes/xmlinputstream"/>
        <pathelement location="build/classes/common"/>
        <pathelement location="build/classes/repackage"/>
        <pathelement location="build/classes/typestore"/>
        <pathelement location="build/classes/xmlpublic"/>
        <pathelement location="build/classes/xmlconfig"/>
        <pathelement location="build/classes/configschema"/>
        <pathelement location="build/classes/xsdschema"/>
      </classpath>

        <src path="src/typeimpl"/>
        <src path="build/src/xmlschema"/>
        <src path="build/src/xsdschema"/>
        <src path="build/src/configschema"/>
        <src path="build/src/toolschema"/>
        <src path="src/xmlconfig"/>
    </javac>

    <!-- Need properties files for regex -->
    <copy
      todir="build/classes/typeimpl">
      <fileset dir="src/typeimpl">
        <exclude name="**/*.java"/>
      </fileset>
    </copy>
  </target>

  <!-- xmlcomp target =============================================== -->

  <target name="xmlcomp.classes" depends="dirs, repackage.classes, typeimpl.classes, xmlpublic.classes, typestore.classes">
    <mkdir dir="build/classes/xmlcomp"/>
    <javac srcdir="src/xmlcomp" destdir="build/classes/xmlcomp" source="1.4" debug="on">
      <classpath>
        <pathelement location="build/classes/xmlinputstream"/>
        <pathelement location="build/classes/xmlpublic"/>
        <pathelement location="build/classes/common"/>
        <pathelement location="build/classes/repackage"/>
        <pathelement location="build/classes/typeimpl"/>
        <pathelement location="build/classes/xmlconfig"/>
        <pathelement location="build/classes/configschema"/>
        <pathelement location="build/classes/toolschema"/>
        <pathelement location="build/classes/xsdschema"/>
      </classpath>
    </javac>

  </target>

  <!-- xmlstore target ============================================== -->

  <target name="xmlstore.classes"
        depends="dirs, common.classes, typestore.classes, xmlpublic.classes">
    <mkdir dir="build/classes/xmlstore"/>
    <javac srcdir="src/xmlstore" destdir="build/classes/xmlstore" source="1.4" debug="on">
      <classpath id="xmlstore.compile.path">
        <pathelement location="build/classes/xmlinputstream"/>
        <pathelement location="build/classes/typestore"/>
        <pathelement location="build/classes/xmlpublic"/>
        <pathelement location="build/classes/common"/>
      </classpath>
    </javac>

  </target>

  <!-- bootstrap schema target support ================================ -->


  <!-- xsdschema target =============================================== -->

  <!-- Note that this is a tricky target because it bootstraps xbeans on itself. -->
  <!-- The basic strategy is to rely on the oldxbeans.jar checked into external/lib -->

  <path id="bootstrap.run.path">
    <pathelement location="build/private/lib/oldxbean.jar"/>
  </path>

  <path id="bootstrap.compile.path">
    <pathelement location="build/classes/xmlpublic"/>
  </path>

  <property name="bootstrap.compile.path" refid="bootstrap.compile.path"/>

  <path id="xsdschema.compile.path">
    <pathelement location="build/classes/xmlschema"/>
    <pathelement location="build/classes/xmlpublic"/>
  </path>

  <property name="xsdschema.compile.path" refid="xsdschema.compile.path"/>

  <target name="xsdschema.check">
    <condition property="xsdschema.notRequired">
        <uptodate property="xsdschema.notRequired" targetfile="build/classes/xsdschema/schema/system/sXMLSCHEMA/index.xsb">
          <srcfiles dir="src/xsdschema" includes="**/*.xsd"/>
        </uptodate>
    </condition>
  </target>

  <target name="xsdschema.classes" depends="xsdschema.check, xmlschema.classes, xmlpublic.classes, oldxbean.jar" unless="xsdschema.notRequired">
    <delete dir="build/classes/xsdschema"/>
    <delete dir="build/src/xsdschema"/>
    <java classname="${bootstrap_schema_compiler}" classpathref="bootstrap.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="${repackage_arg} -name sXMLSCHEMA -cp ${xsdschema.compile.path} -srconly -d build/classes/xsdschema -src build/src/xsdschema src/xsdschema/schema"/>
    </java>
  </target>

  <!-- xmlschema target ============================================= -->

  <!-- Note that this is a tricky target because it bootstraps xbeans on itself. -->
  <!-- The basic strategy is to rely on the oldxbeans.jar checked into external/lib -->

  <target name="xmlschema.check">
    <condition property="xmlschema.notRequired">
        <uptodate property="xmlschema.notRequired" targetfile="build/classes/xmlschema/schema/system/sXMLLANG/index.xsb">
          <srcfiles dir="src/xmlschema" includes="**/*.xsd"/>
        </uptodate>
    </condition>
  </target>

  <target name="xmlschema.classes" depends="xmlschema.check, xmlpublic.classes, oldxbean.jar" unless="xmlschema.notRequired">
    <delete dir="build/classes/xmlschema"/>
    <delete dir="build/src/xmlschema"/>
    <java classname="${bootstrap_schema_compiler}" classpathref="bootstrap.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="${repackage_arg} -name sXMLLANG -d build/classes/xmlschema -src build/src/xmlschema -srconly src/xmlschema/schema"/>
    </java>
  </target>

  <!-- xmlconfig target =============================================== -->

  <target name="xmlconfig.classes" depends="dirs, xmlpublic.jar, configschema.classes">
    <mkdir dir="build/classes/xmlconfig"/>
    <javac srcdir="src/xmlconfig" destdir="build/classes/xmlconfig" source="1.4" debug="on">
      <classpath>
        <pathelement location="build/lib/xmlpublic.jar"/>
        <pathelement location="build/classes/configschema"/>
      </classpath>
    </javac>

  </target>

  <!-- configschema target ============================================= -->

  <!-- Note that this is a tricky target because it bootstraps xbeans on itself. -->
  <!-- The basic strategy is to rely on the oldxbeans.jar checked into external/lib -->

  <property name="bootstrap.compile.path" refid="bootstrap.compile.path"/>

  <target name="configschema.check">
    <uptodate property="configschema.notRequired" targetfile="build/classes/configschema/schema/system/sXMLCONFIG/index.xsb">
      <srcfiles dir="src/configschema" includes="**/*.xsd"/>
    </uptodate>
  </target>

  <target name="configschema.classes" depends="configschema.check, xmlpublic.classes, oldxbean.jar" unless="configschema.notRequired">
    <delete dir="build/classes/configschema"/>
    <java classname="${bootstrap_schema_compiler}" classpathref="bootstrap.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="${repackage_arg} -name sXMLCONFIG -srconly -src build/src/configschema -d build/classes/configschema src/configschema/schema"/>
    </java>
  </target>

  <!-- toolschema target ============================================= -->

  <!-- Note that this is a tricky target because it bootstraps xbeans on itself. -->
  <!-- The basic strategy is to rely on the oldxbeans.jar checked into external/lib -->

  <property name="bootstrap.compile.path" refid="bootstrap.compile.path"/>

  <target name="toolschema.check">
    <uptodate property="toolschema.notRequired" targetfile="build/classes/toolschema/schema/system/sXMLTOOLS/index.xsb">
      <srcfiles dir="src/toolschema" includes="**/*.xsd"/>
    </uptodate>
  </target>

  <target name="toolschema.classes" depends="toolschema.check, xmlpublic.classes, oldxbean.jar" unless="toolschema.notRequired">
    <delete dir="build/classes/toolschema"/>
    <mkdir dir="build/src/toolschema"/>
    <java classname="${bootstrap_schema_compiler}" classpathref="bootstrap.run.path" fork="true" failonerror="true">
      <jvmarg value="-ea"/>
      <arg line="${repackage_arg} -name sXMLTOOLS -srconly -src build/src/toolschema -d build/classes/toolschema src/toolschema"/>
    </java>
  </target>


    <!-- =========================== -->
    <!-- =====   Repackaging  ====== -->
    <!-- =========================== -->

    <target name="edit_build_script">
        <echo message="editing repackage build file: ${token} -->${replacement}"/>

        <java classname="repackage.EditBuildScript" failonerror="true">
            <arg value="${basedir}/build/repackage/build.xml"/>
            <arg value="${token}"/>
            <arg value="${replacement}"/>
            <classpath>
                <pathelement location="build/classes/repackage"/>
            </classpath>
        </java>
    </target>

    <property name="repackage_arg" value=""/>
    <property name="schema_compiler" value="org.apache.xmlbeans.impl.tool.SchemaCompiler"/>
    <property name="bootstrap_schema_compiler" value="org.apache.xmlbeans.impl.tool.SchemaCompiler"/>

    <!--
        Params to repackage are:

            repackage_spec:

                Of the form from_pkg_1:to_pkg_1;from_pkg_2:to_pkg_2 which specifies which packages
                are to be converted which which which other packages.  Right now, there are two.
                org.apache.xmlbeans and apache.xmlbeans.impl, the public and implementation
                packages.

            new_schema_compiler

                The name of the class which will new the new schema compiler.  Will replace
                ${schema_compiler} during the bootstrap process.
    -->

    <target name="repackage" depends="repackage.classes">

        <echo message="Re-packaging XMlBeans"/>

        <property
            name="new_repackage_arg"
            value="-repackage ${repackage_spec}"/>

        <java classname="repackage.Repackage" fork="true" failonerror="true">
            <classpath>
                <pathelement location="build/classes/repackage"/>
            </classpath>
            <arg line="${new_repackage_arg}"/>
        </java>

        <antcall target="edit_build_script">
            <param name="token"       value="repackage_arg"/>
            <param name="replacement" value="${new_repackage_arg}"/>
        </antcall>

        <antcall target="edit_build_script">
            <param name="token"       value="schema_compiler"/>
            <param name="replacement" value="${new_schema_compiler}"/>
        </antcall>

        <ant dir="build/repackage" target="xbean" inheritAll="false"/>

        <antcall target="edit_build_script">
            <param name="token"       value="bootstrap_schema_compiler"/>
            <param name="replacement" value="${new_schema_compiler}"/>
        </antcall>

        <ant dir="build/repackage" target="bootstrap" inheritAll="false"/>

    </target>

    <target name="repackage.classes">
        <mkdir dir="build/classes/repackage"/>
        <javac srcdir="src/repackage" destdir="build/classes/repackage" source="1.4" debug="on"/>
    </target>

</project>