<?xml version="1.0"?>
<!-- Copyright 2002-2007, 2009-2013, 2018-2022 Elliotte Rusty Harold

This library is free software; you can redistribute 
it and/or modify it under the terms of version 2.1 of 
the GNU Lesser General Public License as published by  
the Free Software Foundation.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General 
Public License along with this library; if not, write to the 
Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
Boston, MA  02111-1307  USA

You can contact Elliotte Rusty Harold by sending e-mail to
elharo@ibiblio.org. Please include the word "XOM" in the
subject line. The XOM home page is http://www.xom.nu/
-->
<project name="XOM" default="help" basedir=".">

    <description>
      Build XOM
    </description>
   
  <!-- set global properties for this build -->
  <target name="init">
    <tstamp/>
    <property name="Name"    value="XOM"/>
    <property name="name"    value="xom"/>
    <property name="majorversion" value="1"/>
    <property name="minorversion" value="3"/>
    <property name="microversion" value="8"/>
    <!-- put a1, b2 etc. here in non-releases -->
    <property name="versionqualifier" value=""/>
    <property name="version" value="${majorversion}.${minorversion}.${microversion}${versionqualifier}"/>
    <!-- OSGI wants a period before the a1/b2/d3 qualifier -->
    
    <!-- Can I have an if statement here to check if ${microversion} is an empty string before adding a period? 
         Problem is release version doesn't get a version qualifier. -->
    <property name="bundleversion" value="${majorversion}.${minorversion}.${microversion}.osgi"/>
    <property name="jaxenversion" value="1.1.6"/>
    <!-- <property name="bundleversion" value="${majorversion}.${minorversion}.${microversion}.${versionqualifier}.osgi"/> -->
    <property name="year"    value="2022"/>

    <echo message="----------- ${Name} ${version} ------------"/>

    <property name="debug"       value="off"/>
    <property name="optimize"    value="on"/>
    <property name="deprecation" value="off"/>

    <property name="src.dir"    value="./src"/>
    <property name="fat.src"    value="./fatsrc"/>
    <property name="lib.dir"    value="./lib"/>
    <property name="lib2.dir"   value="./lib2"/>
    <property name="packages"   value="nu.xom.*"/>

    <property name="build.dir"       value="./build"/>
    <property name="build.src"       value="./build/src"/>
    <property name="build.dest"      value="./build/classes"/>
    <property name="build.javadocs"  value="./build/apidocs"/>
    <property name="testoutput.dir"  value="./testresults"/>
    <property name="dist.dir"        value="./dist"/>    
    <property name="clover.dir"      value="./clover"/>
    <property name="testreports.dir" value="./testreports" />
    <property name="jaxen.dir"       value="${build.dir}/jaxen-classes"/>

    <property name="parser.jar"     value="${lib.dir}/dtd-xercesImpl.jar"/>
    <property name="xslt.jar"       value="${lib.dir}/xalan.jar"/>
    <property name="serializer.jar" value="${lib.dir}/serializer.jar"/>
    <property name="tagsoup.jar"    value="${lib2.dir}/tagsoup-1.2.1.jar"/>
    <property name="junit.jar"      value="${lib.dir}/junit.jar"/>
    <property name="xom.jar"        value="${build.dir}/${name}-${version}.jar"/>
    <property name="xom-core"       value="${build.dest}"/>
    
    <property name="saxon6.jar"     value="${lib2.dir}/saxon.jar"/>
    <property name="saxon7.jar"     value="${lib2.dir}/saxon-aelfred.jar"/>
    <property name="gnujaxp.jar"    value="${lib2.dir}/gnujaxp.jar"/>
    <property name="resolver.jar"   value="${lib2.dir}/resolver.jar"/>
    <property name="dom4j.jar"      value="${lib2.dir}/dom4j-1.6.1.jar"/>

    <property name="excludes"       value=".clover, .DS_Store, **/.DS_Store, **/.AppleFileInfo, **/*.zip, **/.thumbnails/**, clover_html/**, clover/**, xom.gif, data/XInclude-Test-Suite/**, data/xmlconf/**, data/canonical/xmlconf/**, data/oasis*/**, **/testresults/**, **/pantry/**, **/workspace/**, **/junit*properties, **/.nautilus-metafile.xml, website/**, **/.project, **/.classpath, build/**, dist/**, .settings/**, lib2/**, xom.fb, jester*, trademark*"/>

    <property name="test.outputFormat" value="xml"/>   
    <property name="binary.jar" location="${dist.dir}/maven2/xom-${version}.jar" />
    <property name="sources.jar" location="${dist.dir}/maven2/xom-${version}-sources.jar" />
    <property name="javadoc.jar" location="${dist.dir}/maven2/xom-${version}-javadoc.jar" />
    
    <property name="ossrh-snapshots-repository-url" value="https://oss.sonatype.org/content/repositories/snapshots/" />
    <property name="ossrh-staging-repository-url" value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />
    <property name="ossrh-server-id" value="ossrh" /> <!-- the server ID in the Maven settings.xml -->
    
    <path id="compile.class.path">
      <pathelement location="${parser.jar}"/>
      <pathelement location="${junit.jar}"/>
      <pathelement location="${jaxen.dir}"/>
      <pathelement location="${servlet.jar}"/>
    </path>

    <path id="run.class.path">
      <pathelement location="${parser.jar}"/>
      <pathelement location="${xom-core}"/>
      <pathelement location="${jaxen.dir}"/>
      <pathelement location="${xslt.jar}"/>
      <pathelement location="${serializer.jar}"/>
    </path>
    
    <path id="test.class.path">
      <path refid="run.class.path"/>
      <pathelement location="${junit.jar}"/>
      <pathelement location="${saxon6.jar}"/>
      <pathelement location="${saxon7.jar}"/>
      <pathelement location="${gnujaxp.jar}"/>
      <pathelement location="${resolver.jar}"/>
      <pathelement location="${dom4j.jar}"/>
    </path>
    
    <path id="doc.class.path">
      <path refid="test.class.path"/>
      <pathelement location="${build.dest}"/>
      <pathelement location="${tagsoup.jar}"/>
    </path>

    <!-- set these properties for debugging -->
    <property name="compile.classpath" refid="compile.class.path"/>
    <property name="test.classpath" refid="test.class.path"/>
    <property name="run.classpath" refid="run.class.path"/>
    <property name="doc.classpath" refid="doc.class.path"/>


    <available property="tagsoup.installed" classname="org.ccil.cowan.tagsoup.Parser">
      <classpath>
        <pathelement location="${tagsoup.jar}" />
      </classpath>
    </available>
    
    <available property="clover.installed" 
               file="clover.jar" filepath="${ant-home}/lib/clover.jar" />
    
  </target>
  
  <target name="help">
    <echo>
XOM Build file
-------------------------------------------------------------
    
  available targets are:
    
    help           --> print this message
    jar            --> build the xom.jar file
    samples        --> build the xom-samples.jar file
    compile        --> compile the source code
    javadoc        --> generate the API documentation
    betterdoc      --> better formatted API documentation (requires Ant 1.6)
    test           --> run JUnit test suite
    integration    --> run JUnit integration test suite (broken)
    testui         --> run JUnit test suite in GUI 
    clean          --> clean up the build directory
    dist           --> the zip and .tar.gz files
    upload         --> upload archive files
      
  Use the option -Dfat=true to make Text objects bigger but faster.

-------------------------------------------------------------
    </echo>
  </target>

  <target name="prepare" depends="init, prepare-dirs, prepare-fat" />
  
  <target name="prepare-dirs" depends="init">
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${dist.dir}/maven2"/>
    <mkdir dir="${testoutput.dir}"/>
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dir}/jaxen"/>
    <mkdir dir="${build.dir}/jaxen-classes"/>
    <mkdir dir="${build.src}"/>
    <mkdir dir="${build.dest}"/>

    <delete file="${build.src}/nu/xom/Text.java" failonerror="false"/>

    <copy todir="${build.src}">
      <fileset dir="${src.dir}"/>
    </copy>
    
  </target>

  <!-- use Text.java that stores contents in String -->
  <target name="prepare-fat" depends="init" if="fat">
   <copy todir="${build.src}" overwrite="true">
      <fileset dir="${fat.src}"/>
   </copy>
  </target>


  <target name="compile-core" depends="prepare, compile-jaxen" 
          description="Compile the source code">
    <javac srcdir="${build.src}"
           destdir="${build.dest}"
           debug="${debug}"
           optimize="${optimize}"
           deprecation="${deprecation}"
           target="1.6"
           source="1.6"
           encoding="UTF-8"
           fork="true"
           includeAntRuntime="false"
           excludes="nu/xom/pantry/* nu/xom/tools/* nu/xom/samples/*Servlet.java">
       <classpath refid="compile.class.path"/>
    </javac>
    <copy file="${build.src}/nu/xom/characters.dat" tofile="${build.dest}/nu/xom/characters.dat"/>
    
    <!-- update version number -->
    <echo file="${build.dest}/nu/xom/version.txt">${version}</echo>

    <copy file="${build.src}/nu/xom/compositions.dat" tofile="${build.dest}/nu/xom/compositions.dat" />
  </target>


  <target name="compile" depends="compile-core, compile-servlets" 
          description="Compile the source code" />
  
  <target name="compile-servlets" depends="compile-core" if="servlet.jar.installed"
          description="Compile the source code including the servlet samples">
    <javac srcdir="${build.src}"
           sourcepath=""
           destdir="${build.dest}"
           debug="${debug}"
           optimize="${optimize}"
           deprecation="${deprecation}"
           target="1.6"
           source="1.6"
           encoding="UTF-8"
           includeAntRuntime="false">
       <classpath refid="compile.class.path"/>
       <include name="nu/xom/samples/*Servlet.java" />
    </javac>
  </target>

  <target name="minimal" depends="compile" description="Create xom-minimal.jar">
    <jar jarfile="${build.dir}/${name}-${version}-minimal.jar"
         basedir="${build.dest}"
         index="no"
         compress="yes"
         includes="nu/xom/* nu/xom/xslt/* nu/xom/xinclude/* nu/xom/converters/* nu/xom/canonical/* nu/xom/tests/XOMTestCase.class"
         excludes="nu/xom/samples/* nu/xom/benchmarks/* nu/xom/pantry/* nu/xom/tools/* nu/xom/integrationtests/*">
      <manifest>
        <attribute name="Sealed" value="true"/>
        <attribute name="Built-By" value="${user.name}"/>
        <attribute name="Specification-Title"    value="XOM"/>
        <attribute name="Specification-Version"  value="${version}"/>
        <attribute name="Specification-Vendor"   value="Elliotte Rusty Harold"/>
        <attribute name="Implementation-Title"   value="XOM"/>
        <attribute name="Implementation-Version" value="${version}"/>
        <attribute name="Implementation-Vendor"  value="Elliotte Rusty Harold"/>          
        <attribute name="Main-Class" value="nu.xom.Info"/>
        <attribute name="Automatic-Module-Name" value="nu.xom"/>
        <section name="nu/xom/">
          <attribute name="Specification-Title"   value="XOM core classes"/>
          <attribute name="Implementation-Title"  value="nu.xom"/>
        </section>
        <section name="nu/xom/xslt/">
          <attribute name="Specification-Title"   value="XOM XSLT interface"/>
          <attribute name="Implementation-Title"  value="nu.xom.xslt"/>
        </section>
        <section name="nu/xom/xinclude/">
          <attribute name="Specification-Title"   value="XOM XInclude engine"/>
          <attribute name="Implementation-Title"  value="nu.xom.xinclude"/>
        </section>
        <section name="nu/xom/converters/">
          <attribute name="Specification-Title"   value="XOM converters to other object models"/>
          <attribute name="Implementation-Title"  value="nu.xom.converters"/>
        </section>
        <section name="nu/xom/canonical/">
          <attribute name="Specification-Title"   value="XOM Canonical XML support"/>
          <attribute name="Implementation-Title"  value="nu.xom.canonical"/>
        </section>
      </manifest>
    </jar>
  </target>


  <target name="jar" depends="compile" description="Create xom.jar">
     <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask"
              classpath="${lib.dir}/jarjar-1.0.jar"/>
    <jarjar jarfile="${build.dir}/${name}-${version}.jar"
         basedir="${build.dest}"
         index="no"
         compress="yes"
         includes="nu/xom/* nu/xom/xslt/* nu/xom/xinclude/* nu/xom/converters/* nu/xom/canonical/* nu/xom/tests/XOMTestCase.class"
         excludes="nu/xom/samples/* nu/xom/benchmarks/* nu/xom/pantry/* nu/xom/tools/*  nu/xom/integrationtests/*">

      <fileset dir="${jaxen.dir}"
         excludes="**Demo.class **/package.html org/jaxen/xom/** org/jaxen/XPathTestBase.class org/jaxen/jdom/** org/jaxen/dom4j/** org/jaxen/javabean/** org/jaxen/dom/** org/jaxen/**Test.class org/jaxen/saxpath/base/**Test.class org/jaxen/saxpath/helpers/**Test.class org/jaxen/saxpath/helpers/**Test.class org/jaxen/pattern/** org/jaxen/saxpath/SAXPathParseException.class org/w3c/dom/UserDataHandler.class org/jaxen/pattern/PriorityTest.class">
      </fileset>
    
      <rule pattern="org.jaxen.**" result="nu.xom.jaxen.@1"/>

      <manifest>
        <attribute name="Built-By" value="${user.name}"/>
        <attribute name="Specification-Title"    value="XOM"/>
        <attribute name="Specification-Version"  value="${version}"/>
        <attribute name="Specification-Vendor"   value="Elliotte Rusty Harold"/>
        <attribute name="Implementation-Title"   value="XOM"/>
        <attribute name="Implementation-Version" value="${version}"/>
        <attribute name="Implementation-Vendor"  value="Elliotte Rusty Harold"/>          
        <attribute name="Main-Class" value="nu.xom.Info"/>
        <attribute name="Automatic-Module-Name" value="nu.xom"/>
        
        <!-- OSGI Information -->
        <attribute name="Manifest-Version" value="1.0"/>
        <attribute name="Bundle-ManifestVersion" value="2"/>
        <attribute name="Bundle-Name" value="${Name}"/>
        <attribute name="Bundle-SymbolicName" value="nu.xom"/>
        <attribute name="Bundle-Version" value="${bundleversion}"/>
        <attribute name="Bundle-Vendor" value="xom.nu"/>
        <attribute name="Bundle-RequiredExecutionEnvironment" value="JavaSE-1.6"/>
        <attribute name="Export-Package" value="nu.xom, nu.xom.canonical, nu.xom.converters, nu.xom.xinclude, nu.xom.xslt"/>
        <attribute name="Import-Package" value='javax.xml.transform.sax, javax.xml.transform, org.w3c.dom, org.xml.sax, org.xml.sax.helpers, org.xml.sax.ext,
          org.apache.xerces.parsers;resolution:=optional;version="2.8.0", org.apache.xerces.impl;resolution:=optional;version="2.8.0", 
          org.apache.xerces.jaxp;resolution:=optional;version="2.9.0", junit.framework;resolution:=optional;version="3.8.1",
          com.sun.org.apache.xerces.internal.jaxp;resolution:=optional, com.sun.org.apache.xerces.internal.parsers;resolution:=optional'/>

        <section name="nu/xom/">
          <attribute name="Sealed" value="true"/>
          <attribute name="Specification-Title"    value="XOM core classes"/>
          <attribute name="Implementation-Title"   value="nu.xom"/>
          <attribute name="Implementation-Version" value="${version}"/>
          <attribute name="Implementation-Vendor"  value="Elliotte Rusty Harold"/>          
       </section>
        <section name="nu/xom/jaxen/">
          <attribute name="Specification-Title"    value="Jaxen XPath engine"/>
          <attribute name="Implementation-Title"   value="org.jaxen"/>
          <attribute name="Implementation-Version" value="${jaxenversion}"/>
          <attribute name="Implementation-Vendor"  value="CodeHaus"/>
        </section>
        <section name="nu/xom/xslt/">
          <attribute name="Sealed" value="true"/>
          <attribute name="Specification-Title"   value="XOM XSLT interface"/>
          <attribute name="Implementation-Title"  value="nu.xom.xslt"/>
        </section>
        <section name="nu/xom/xinclude/">
          <attribute name="Sealed" value="true"/>
          <attribute name="Specification-Title"   value="XOM XInclude engine"/>
          <attribute name="Implementation-Title"  value="nu.xom.xinclude"/>
        </section>
        <section name="nu/xom/converters/">
          <attribute name="Sealed" value="true"/>
          <attribute name="Specification-Title"   value="XOM converters to other object models"/>
          <attribute name="Implementation-Title"  value="nu.xom.converters"/>
        </section>
        <section name="nu/xom/canonical/">
          <attribute name="Sealed" value="true"/>
          <attribute name="Specification-Title"   value="XOM Canonical XML support"/>
          <attribute name="Implementation-Title"  value="nu.xom.canonical"/>
        </section>
      </manifest>
    </jarjar>
    
    <!-- Put a copy in the dist dir too, because I never remember to upload 
         the jar from the build directory. -->
    <copy file="${build.dir}/${name}-${version}.jar" todir="${dist.dir}"/>
  </target>

  
  <target name="samples" depends="compile" description="Create xom-samples.jar">
    <jar jarfile="${build.dir}/${name}-samples.jar"
         basedir="${build.dest}"
         index="yes"
     compress="yes"
         includes="nu/xom/samples/* nu/xom/benchmarks/*"
         excludes="nu/xom/xslt/* nu/xom/xinclude/* nu/xom/tools/* nu/xom/converters/* nu/xom/canonical/* nu/xom/pantry/* nu/xom/integrationtests/*">
      <manifest>
        <attribute name="Built-By" value="${user.name}"/>
        <attribute name="Specification-Title"    value="XOM Samples"/>
        <attribute name="Specification-Version"  value="${version}"/>
        <attribute name="Specification-Vendor"   value="Elliotte Rusty Harold"/>
        <attribute name="Implementation-Title"   value="XOM Samples"/>
        <attribute name="Implementation-Version" value="${version}"/>
        <attribute name="Implementation-Vendor"  value="Elliotte Rusty Harold"/>          
<!-- I can't get this to work yet
        <attribute name="Main-Class" value="nu.xom.samples.XMLPrinter"/>
        <attribute name="Class-Path" value="${name}-${version}.jar"/> -->
      </manifest>
    </jar>
  </target>

  
  <target name="javadoc" depends="prepare"
          description="Generate the API documentation">
          
    <mkdir dir="${build.javadocs}"/>
    
    <javadoc packagenames="nu.xom.xslt, nu.xom.canonical, nu.xom.xinclude, nu.xom, nu.xom.converters"
             sourcepath="${build.src}"
             destdir="${build.javadocs}"
             author="true"
             version="true"
             overview="overview.html"
             use="true"
             splitindex="true"
             noindex="false"
             windowtitle="${Name} ${version}  API"
             docencoding="UTF-8"
             charset="UTF-8"
             link="http://www.junit.org/junit/javadoc/3.8.1"
             doctitle="${Name} ${version}"
             bottom="Copyright 2002-${year} &lt;a href='http://www.elharo.com/'&gt;Elliotte Rusty Harold&lt;/a&gt;
       &lt;br /&gt; &lt;a href='&#109;&#97;&#105;&#108;&#116;&#111;&#58;elharo%40ibiblio%2Eorg?Subject=XOM'&gt;elharo&#64;ibiblio&#46;org&lt;/a&gt;">
      <classpath refid="test.class.path"/>
      
    <fileset dir="${build.src}" defaultexcludes="yes">
      <include name="nu/xom/tests/XOMTestCase.java" />
    </fileset>
      
    </javadoc>
  </target>
  
  
  <!-- I can never remember the exact target name -->
  <target name="javadocs"   depends="javadoc" />
  <target name="apidocs"    depends="javadoc"/>
  <target name="apidoc"     depends="javadoc"/>
  <target name="betterdocs" depends="betterdoc"/>

  <target name="-checkForClover" unless="clover.installed">
    <echo>
    The task you are trying to run requires Clover to be installed 
    in the $ANT_HOME/lib directory. You can purchase Clover from
    http://www.cenqua.com/clover/
    </echo>
  </target>

  <!-- This task requires Ant 1.6 and TagSoup -->
  <target name="betterdoc" depends="compile"
          description="Generate the API documentation">
    <mkdir dir="${build.javadocs}"/>
    <javadoc packagenames="nu.xom.xslt, nu.xom.canonical, nu.xom.xinclude, nu.xom, nu.xom.converters"
             sourcepath="${build.src}"
             destdir="${build.javadocs}"
             author="true"
             version="true"
             overview="overview.html"
             use="true"
             splitindex="true"
             noindex="false"
             windowtitle="${Name} ${version}  API"
             docencoding="UTF-8"
             charset="UTF-8"
             noqualifier="java.lang:java.io"
             link="http://www.junit.org/junit/javadoc/3.8.1"
             doctitle="${Name} ${version}"
             bottom="Copyright 2002-${year} &lt;a href='http://www.elharo.com/'&gt;Elliotte Rusty Harold&lt;/a&gt;
       &lt;br/&gt; &lt;a href='mailto:elharo%40ibiblio%2Eorg?Subject=XOM'&gt;elharo&#64;ibiblio&#46;org&lt;/a&gt;">
      <classpath refid="test.class.path"/>
      
    <fileset dir="${build.src}" defaultexcludes="yes">
      <include name="nu/xom/tests/XOMTestCase.java" />
    </fileset>
    </javadoc>
    
    <javac srcdir="${build.src}"
           destdir="${build.dest}"
           debug="${debug}"
           optimize="${optimize}"
           deprecation="${deprecation}"
           target="1.6"
           source="1.6"
           encoding="UTF-8"
           includeAntRuntime="false"
           includes="nu/xom/tools/*">
      <classpath>
        <pathelement path="${compile.class.path}"/>
        <pathelement path="${tagsoup.jar}"/> 
      </classpath>
    </javac>
    
    <java classname="nu.xom.tools.XHTMLJavaDoc" fork="yes"> 
      <jvmarg value="-Xbootclasspath/p:lib/dtd-xercesImpl.jar:lib/xalan.jar"/> 
      <classpath refid="doc.class.path" />
      <arg value="build/apidocs"/> 
    </java>
  </target>

  <property name="prefix" value="${name}-${version}" />
  
  <target name="dist" depends="zip, tar.gz, maven, website" />

  <!-- invoke as
      ant -Dpassword=secret upload -->
  <property name="password" value="" />
  
  <!-- This task depends on Jsch library not included in the Ant distribution. -->
  <target name="upload" depends="dist">

    <scp password="${password}" 
        todir="elharo:${password}@login.ibiblio.org:/export/sunsite/users/elharo/xml/XOM">
        <fileset file="${dist.dir}/${name}-${version}-src.zip" />
        <fileset file="${dist.dir}/${name}-${version}.zip" />
        <fileset file="${dist.dir}/${name}-${version}.tar.gz" />
        <fileset file="${dist.dir}/${name}-${version}-src.tar.gz" />
        <fileset file="${dist.dir}/${name}-${version}.jar" />
        <fileset file="${dist.dir}/maven2/xom-maven-${version}.jar" />
    </scp>
  </target>
    
  <target name="zip" depends="jar, betterdoc, samples" 
          description="Build zip file for distro">

    <zip destfile="${dist.dir}/${name}-${version}-src.zip">
      <zipfileset prefix="XOM" dir="." excludes="${excludes}"/> 
    </zip>

    <zip destfile="${dist.dir}/${name}-${version}.zip">
      <zipfileset prefix="XOM" dir="." excludes="${excludes}"/>   
      <zipfileset prefix="XOM/apidocs" dir="./${build.dir}/apidocs" 
        excludes="**/.thumbnails/**, **/.nautilus-metafile.xml, website/**, **/.project, **/.classpath, **/.DS_Store"/>   
      <zipfileset fullpath="XOM/${name}-${version}.jar" dir="./${build.dir}" includes="${name}-${version}.jar"/> 
      <zipfileset fullpath="XOM/${name}-samples.jar" dir="./${build.dir}" includes="${name}-samples.jar"/>
    </zip>

  </target>
  
  
  <target name="tar" depends="jar, betterdoc, samples" 
          description="Build tar file for distro">

    <tar destfile="${dist.dir}/${name}-${version}-src.tar">
      <tarfileset prefix="XOM" dir="." 
        excludes="${excludes}"/> 
    </tar>

    <tar destfile="${dist.dir}/${name}-${version}.tar">
      <tarfileset prefix="XOM" dir="." 
        excludes="${excludes}"/>   
      <tarfileset prefix="XOM/apidocs" dir="./${build.dir}/apidocs" 
        excludes="**/.thumbnails/**, **/.nautilus-metafile.xml, website/**, **/.project, **/.classpath, **/.DS_Store"/>   
      <tarfileset fullpath="XOM/${name}-${version}.jar" dir="./${build.dir}" includes="${name}-${version}.jar"/> 
      <tarfileset fullpath="XOM/${name}-samples.jar" dir="./${build.dir}" includes="${name}-samples.jar"/>   
    </tar>

  </target>
  
  
  <target name="tar.gz" depends="tar" description="Build tar.gz file for distro">
     <gzip src="${dist.dir}/${name}-${version}.tar" zipfile="${dist.dir}/${name}-${version}.tar.gz"/>
     <gzip src="${dist.dir}/${name}-${version}-src.tar" zipfile="${dist.dir}/${name}-${version}-src.tar.gz"/>
  </target>

 
  <!-- This task requires the ANT optional.jar -->
  <target name="test" depends="compile" description="Run JUnit tests using command line user interface">

    <junit fork="yes" failureproperty="testsfailed">
       <classpath refid="test.class.path" />
       <formatter type="${test.outputFormat}" />
       <batchtest fork="yes" todir="${testoutput.dir}">
         <fileset dir="${build.src}">
           <include name="**/*Test.java" />
           <exclude name="**/pantry/*" />
           <exclude name="**/MegaTest.java" />
            <exclude name="**/benchmarks/*.java" />
            <exclude name="**/integrationtests/*.java" />
           <exclude name="**/EBCDICTest.java" />
         </fileset>
      </batchtest>
    </junit>

    <junitreport todir="${testoutput.dir}">
      <fileset dir="${testoutput.dir}">
        <include name="TEST-*.xml" />
      </fileset>
      <report todir="${testoutput.dir}" />
    </junitreport>

    <fail message="tests failed">
      <condition>
        <and>
          <isset property="testsfailed"/>
          <isset property="test.haltonfailure"/>
        </and>
      </condition>
    </fail>

  </target>
 
 
  <target name="testjar" depends="jar" description="Run JUnit tests using jar file">
    <junit printsummary="on" fork="no">
       <classpath>
          <pathelement location="${xom.jar}"/>
          <pathelement location="${junit.jar}"/>
       </classpath>
       <classpath refid="run.class.path" />
       <formatter type="${test.outputFormat}" />
       <batchtest fork="yes" todir="${testoutput.dir}">
         <fileset dir="${build.src}">
           <include name="**/*Test.java" />
           <exclude name="**/pantry/*" />
           <exclude name="**/MegaTest.java" />
           <exclude name="**/benchmarks/*.java" />
           <exclude name="**/EBCDICTest.java" />
         </fileset>
      </batchtest>
    </junit>
  </target>
 

  <target name="testui" depends="compile" description="Run JUnit tests using GUI interface">
    <java classname="junit.swingui.TestRunner" fork="yes" maxmemory="99m">
      <sysproperty key="org.xml.sax.driver" value="org.apache.xerces.parsers.SAXParser"/> 
      <classpath refid="test.class.path" />
      <arg value="nu.xom.tests.XOMTests"/> 
    </java>
  </target>
    
      
  <target name="clean" depends="init" description="Remove build files">
    <delete dir="${build.dir}"/>
    <delete dir="${dist.dir}"/>
    <delete dir="${testoutput.dir}"/>
    <delete dir=".clover"/>
    <delete dir="clover"/>
    <delete dir="clover_html"/>
    <delete>
      <fileset dir="." includes="junit*properties"/>
    </delete>
    <ant antfile="build.xml" dir="website" target="clean"/>
  </target>

  
  <!-- These tasks require Clover -->
  <taskdef resource="clovertasks"/>
  
  <target name="with.clover" depends="init, -checkForClover">
    <mkdir dir="${clover.dir}"/>
    <clover-setup initString="${clover.dir}/xom_coverage.db">
      <files>
        <include name="nu/xom/**"/> <!-- work around Ant 1.6.3 bug  #34722 -->
        <exclude name="nu/xom/UnicodeUtil.java"/>
        <exclude name="nu/xom/Latin6Writer.java"/>
        <exclude name="nu/xom/Latin8Writer.java"/>
        <exclude name="nu/xom/Latin10Writer.java"/>
        <exclude name="nu/xom/tests/FastTests.java"/>
        <exclude name="nu/xom/tests/XOMTests.java"/>
        <exclude name="nu/xom/samples/**"/>
        <exclude name="nu/xom/pantry/**"/>
        <exclude name="nu/xom/benchmarks/**"/>
        <exclude name="nu/xom/tools/**" />
      </files>
    </clover-setup>
  </target>

  
  <property name="ant-home" value="/opt/ant"/>

  <target name="clover.html" depends="with.clover">
    <clover-report>
       <current outfile="clover_html" title="Clover results for ${Name} ${version}">
       <format type="html"/>
       </current>   
    </clover-report>
  </target>
  
 
  <!-- This task requires the ANT optional.jar. clover.jar, and junit.jar to be installed in ANT_HOME/lib -->
  <target name="clovertest" depends="compile, -checkForClover" description="Run JUnit tests with clover.jar in classpath">
    <junit printsummary="on" fork="no">
      <classpath refid="test.class.path" />
      <classpath>
        <pathelement path="${ant-home}/lib/clover.jar"/>
      </classpath>
      <formatter type="${test.outputFormat}" />
      <batchtest fork="yes" todir="${testoutput.dir}">
        <fileset dir="${build.src}">
          <include name="**/*Test.java" />
          <exclude name="**/pantry/*.java" />
          <exclude name="**/MegaTest.java" />
          <exclude name="**/benchmarks/*.java" />
          <exclude name="**/tools/*.java" />
          <exclude name="**/EBCDICTest.java" />
          <exclude name="nu/xom/tests/FastTests.java"/>
          <exclude name="nu/xom/tests/XOMTests.java"/>
        </fileset>
      </batchtest>
    </junit>
  </target> 

  <!-- This task requires the ANT optional.jar. clover.jar, and junit.jar to be installed in ANT_HOME/lib -->
  <target name="fastclover" depends="compile, -checkForClover" description="Run JUnit tests with clover.jar in classpath">
    <junit printsummary="on" fork="no" failureproperty="testsfailed">
      <classpath refid="test.class.path" />
      <classpath>
        <pathelement path="${ant-home}/lib/clover.jar"/>
      </classpath>
      <formatter type="${test.outputFormat}" />
      <batchtest fork="yes" todir="${testoutput.dir}">
        <fileset dir="${build.src}">
          <include name="**/*Test.java" />
          <exclude name="**/pantry/*.java" />
          <exclude name="**/EncodingTest.java" />
          <exclude name="**/XIncludeTest.java" />
          <exclude name="**/MegaTest.java" />
          <exclude name="**/benchmarks/*.java" />
          <exclude name="**/tools/*.java" />
          <exclude name="**/EBCDICTest.java" />
          <exclude name="nu/xom/tests/FastTests.java"/>
          <exclude name="nu/xom/tests/XOMTests.java"/>
        </fileset>
      </batchtest>
    </junit>

  </target> 

  <target name="maven" depends="maven2" />

  <target name="sources.jar" depends="init, compile">
    <jar jarfile="${sources.jar}" basedir="${build.dir}/src">
      <exclude name= "nu/xom/benchmarks/**" />
      <exclude name= "nu/xom/tools/**" />
      <exclude name= "nu/xom/tests/**" />
      <exclude name= "nu/xom/pantry/**" />
      <exclude name= "nu/xom/samples/**" />
    </jar>
  </target>
  
  <target name="javadoc.jar" depends="init, compile, betterdoc">
    <jar jarfile="${javadoc.jar}" basedir="${build.dir}/apidocs">
    </jar>
  </target>
    
  <!-- Generate a Maven JAR for uploading to OSRRH and hence placement onto ibiblio and mirrors. 
      See http://maven.apache.org/guides/mini/guide-central-repository-upload.html -->
  <target name="maven2" depends="jar, sources.jar, javadoc.jar" >
      <property name="pom2.template" location="project2.xml" />
      <property name="pom2.file" location="${build.dir}/maven2/project.xml" />
      <property name="package.jar" location="${build.dir}/${name}-${version}.jar"/>
      <property name="license" location="LICENSE.txt" />
      <copy file="${pom2.template}" tofile="${pom2.file}">
        <filterset>
         <filter token="VERSION" value="${version}"/>
       </filterset>
      </copy>
      <copy file="${pom2.file}" tofile="${dist.dir}/maven2/xom-${version}.pom">
        <filterset>
         <filter token="VERSION" value="${version}"/>
       </filterset>
      </copy>
      <copy file="${package.jar}" tofile="${dist.dir}/maven2/${name}-${version}.jar">
      </copy>
  </target>


  <target name="compile-jaxen" description="Compile Jaxen" depends="get-jaxen">
    <javac srcdir="${build.dir}/jaxen-${jaxenversion}/src/java/main"
           destdir="${build.dir}/jaxen-classes"
           debug="${debug}"
           optimize="${optimize}"
           deprecation="${deprecation}"
           target="1.6"
           source="1.6"
           encoding="UTF-8"
           includeAntRuntime="false"
           excludes="org/jaxen/dom/** 
                     org/jaxen/jdom/** 
                     org/jaxen/dom4j/** 
                     org/jaxen/pattern/** 
                     org/jaxen/javabean/** 
                     org/jaxen/xom/**
                     org/jaxen/function/xslt/**
                     org/jaxen/function/ext/**
                     org/w3c/dom/**
                     org/jaxen/saxpath/expr/DefaultPredicated.java
                     org/jaxen/saxpath/helpers/DefaultXPathHandler.java
                     org/jaxen/util/StackedIterator.java
                     org/jaxen/util/XPath2XMLVisitor.java
                     org/jaxen/util/LinkedIterator.java
                     org/jaxen/util/SelfAxisIterator.java
                     ">
       <classpath refid="compile.class.path"/>
    </javac>  
  </target>
  
  <target name="get-jaxen" description="Download Jaxen source code" depends="prepare">
      <unzip src="jaxen-${jaxenversion}-src.zip" dest="${build.dir}" />
  </target>

  <target name="debug" depends="init" description="Print various Ant properties">
    <echoproperties/>
    <java classname="org.apache.xalan.Version" fork="yes">
      <classpath refid="test.class.path" />
    </java>
  </target>
  
  <target name="website" depends="samples, betterdoc" description="Generate the website">
    <ant antfile="build.xml" dir="website" target="dist"/>
    <copy todir="${dist.dir}/website/apidocs">  
      <fileset dir="${build.javadocs}" includes="**"/>  
    </copy>
  </target>

  <target name="integration" description="Run conformance test suites">
    <echo>
      Placeholder for a target to run various conformance test suites.
    </echo>
  </target>
  
</project>
