<!-- Copyright (c) 2010 DeltaXML Ltd.  All rights reserved. -->
<!-- This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License version 3 only,
    as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License version 3 for more details
    (a copy is included in the LICENSE-LGPL.txt file that accompanied this code).

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/> -->
<!-- $Id: build.xml 6839 2010-07-30 14:47:55Z nigelw $ -->
<project name="change-tracking" default="jar" basedir=".">
  
  <property file="build.properties"/>
  
  <property name="src.dir" value="src"/>
  <property name="class.dir" value="class"/>
  <property name="xsl.dir" value="xsl"/>
  <property name="rng.dir" value="grammar"/>
  <property name="testng.report.dir" value="report"/>
  
  <property name="jar.name" value="track-changes-checker.jar"/>
  
  <property name="ULJ" value="/usr/local/java"/>
  
  <property name="saxon.dir" value="${ULJ}/saxonb9-1-0-7j"/>
  <property name="saxon.jar.name" value="saxon9.jar"/>
  <property name="saxon.jar" value="${saxon.dir}/${saxon.jar.name}"/>
  <property name="s9api.jar.name" value="saxon9-s9api.jar"/>
  <property name="s9api.jar" value="${saxon.dir}/${s9api.jar.name}"/>
    
  <property name="xerces.dir" value="${ULJ}/xerces-2_9_0"/>
  <property name="xerces.jar.name" value="xercesImpl.jar"/>
  <property name="xerces.jar" value="${xerces.dir}/${xerces.jar.name}"/>
  
  <property name="msv.dir" value="${ULJ}/msv-20090415"/>
  <property name="msv.jar.name" value="msv.jar"/>
  <property name="msv.jar" value="${msv.dir}/${msv.jar.name}"/>
  <property name="isorelax.jar.name" value="isorelax.jar"/>
  <property name="isorelax.jar" value="${msv.dir}/${isorelax.jar.name}"/>
  <property name="relaxngdatatype.jar.name" value="relaxngDatatype.jar"/>
  <property name="relaxngdatatype.jar" value="${msv.dir}/${relaxngdatatype.jar.name}"/>
  <property name="xsdlib.jar.name" value="xsdlib.jar"/>
  <property name="xsdlib.jar" value="${msv.dir}/${xsdlib.jar.name}"/>
  
  <property name="schematron.dir" value="${ULJ}/schematron-iso-2010-04-14"/>
  
  <property name="testng.dir" value="${ULJ}/testng-5.11" />
  <property name="testng.jar.name" value="testng-5.11-jdk15.jar" />
  <property name="testng.jar" value="${testng.dir}/${testng.jar.name}" />
  
  <taskdef resource="testngtasks" classpath="${testng.jar}" />
  
  <target name="compile">
    <mkdir dir="${class.dir}"/>
    <javac srcdir="${src.dir}" destdir="${class.dir}" target="1.5" debug="true" includes="**/*.java">
      <classpath>
        <!-- <pathelement location="${core.jar}"/> -->
        <pathelement location="${testng.jar}"/>
        <pathelement location="${saxon.jar}"/>
        <pathelement location="${s9api.jar}"/>
        <pathelement location="${msv.jar}"/>
        <pathelement location="${isorelax.jar}"/>
      </classpath>
    </javac>
  </target>
    
  <target name="compile-schematron">
    <!-- expand inclusions -->
    <xslt style="${schematron.dir}/iso_dsdl_include.xsl" in="grammar/delta-constraints.sch"  out="grammar/delta-constraints1.sch"> 
      <classpath>
        <pathelement location="${saxon.jar}"/>
      </classpath>
    </xslt>
    <!-- expand abstract patterns -->
    <xslt style="${schematron.dir}/iso_abstract_expand.xsl" in="grammar/delta-constraints1.sch"  out="grammar/delta-constraints2.sch"> 
      <classpath>
        <pathelement location="${saxon.jar}"/>
      </classpath>
    </xslt>
    <!-- compile it -->
    <xslt style="${schematron.dir}/iso_svrl_for_xslt2.xsl" in="grammar/delta-constraints2.sch"  out="xsl/delta-constraints.xsl"> 
      <classpath>
        <pathelement location="${saxon.jar}"/>
      </classpath>
    </xslt>
  </target>
    
  <target name="jar" depends="compile, compile-schematron">
    <jar jarfile="${jar.name}">
      <fileset dir="${class.dir}" includes="**/*.class"/>
      <zipfileset prefix="xsl" dir="${xsl.dir}" includes="*.xsl"/>
      <zipfileset prefix="schema" dir="${rng.dir}" includes="*.rng"/>
      <manifest>
        <attribute name="Main-Class" value="com.deltaxml.odf.ct.ChangeTrackingVerifier"/>
        <!-- <attribute name="Class-Path" value="${saxon.jar.name} ${core.jar.name} ${xerces.jar.name}"/> -->
        <attribute name="Class-Path" value="${saxon.jar.name} ${xerces.jar.name} ${s9api.jar.name} ${msv.jar.name}"/>
      </manifest>
    </jar>
  </target>

  <target name="test" depends="jar, link">
    <property name="verbose" value="false"/>
    <property name="rng" value="true"/>
    <property name="schematron" value="true"/>
    <property name="includes" value="test/**/testng.xml"/>
    <property name="excludes" value=""/>
    
    <testng sourcedir="${src.dir}" outputdir="${testng.report.dir}" failureproperty="failures">
      <jvmarg line="-Xmx1g"/>
      <sysproperty key="verbose" value="${verbose}"/>
      <sysproperty key="rng" value="${rng}"/>
      <sysproperty key="schematron" value="${schematron}"/>
      <xmlfileset dir="." includes="${includes}" excludes="${excludes}"/>
      <classpath>
        <pathelement location="${jar.name}"/>
      </classpath>
    </testng>
    
    <!--
      NOTE: Used for internal development - removed for distribution
    <xslt force="true"
          style="${xsl.dir}/schematron-coverage.xsl" 
          in="grammar/delta-constraints.sch" 
          out="schematron-coverage-report.xml">
      <classpath>
        <pathelement location="${saxon.jar}"/>
      </classpath>
    </xslt>
    -->
    
    <fail if="failures" message="Test(s) failed, see ${testng.report.dir}/index.html"/>
  </target>
  
  <target name="link">
    <exec executable="ln">
      <arg line="-s ${saxon.jar}"/>
    </exec>
    <exec executable="ln">
      <arg line="-s ${xerces.jar}"/>
    </exec>
   <!--  <exec executable="ln">
      <arg line="-s ${core.jar}"/>
    </exec> -->
    <exec executable="ln">
      <arg line="-s ${s9api.jar}"/>
    </exec>
    <exec executable="ln">
      <arg line="-s ${msv.jar}"/>
    </exec>
    <exec executable="ln">
      <arg line="-s ${isorelax.jar}"/>
    </exec>
    <exec executable="ln">
      <arg line="-s ${relaxngdatatype.jar}"/>
    </exec>
    <exec executable="ln">
      <arg line="-s ${xsdlib.jar}"/>
    </exec>
</target>
  
  <target name="clean">
    <delete dir="${class.dir}"/>
    <delete>
      <fileset dir="." includes="*.jar, *version-*.odt, **/TEST-OUTPUT*, **/*.svrl"/>
      <!-- intermediate schematron files and final checker as per '4 stage pipeline' -->
      <fileset dir="grammar" includes="delta-constraints1.sch, delta-constraints2.sch"/>
      <fileset dir="xsl" includes="delta-constraints.xsl"/>
    </delete>
  </target>
  
  <target name="dist">
    <property name="zip-prefix" value="DeltaXML-TC4"/>
    <tar destfile="${zip-prefix}.tar.gz" compression="gzip">
      <tarfileset prefix="${zip-prefix}/src" dir="${src.dir}" 
                  includes="com/deltaxml/odf/ct/*.java"
                  excludes="com/deltaxml/odf/ct/ApplyJavaConversionFilter.java,
                            com/deltaxml/odf/ct/ConvertTestInsertions.java"/>
      <tarfileset fullpath="${zip-prefix}/doc/odf-track-changes.odt" file="doc/xml-track-changes.odt"/>
      <tarfileset fullpath="${zip-prefix}/README.odt" file="doc/README.odt"/>
      <tarfileset prefix="${zip-prefix}/grammar" dir="grammar" includes="**"/>
      <tarfileset prefix="${zip-prefix}/test" dir="test" includes="**"/>
      <tarfileset prefix="${zip-prefix}/xsl" dir="xsl" includes="**" 
                  excludes="convert-text-insertions.xsl, unindent.xsl"/>
      <tarfileset prefix="${zip-prefix}" dir="." includes="build.xml, LICENSE-LGPL.txt"/>
      <tarfileset fullpath="${zip-prefix}/build.properties" file="dist.build.properties"/>
      
      <!-- dependencies -->
      <tarfileset prefix="${zip-prefix}/saxon" dir="${saxon.dir}" includes="${saxon.jar.name}, ${s9api.jar.name}"/>
      <tarfileset prefix="${zip-prefix}/notices/saxon" dir="${saxon.dir}/notices" includes="**"/>
      
      <tarfileset prefix="${zip-prefix}/xerces" dir="${xerces.dir}" includes="${xerces.jar.name}"/>
      <tarfileset prefix="${zip-prefix}/notices/xerces" dir="${xerces.dir}" includes="LICENSE*, NOTICE*"/>
      
      <tarfileset prefix="${zip-prefix}/msv" dir="${msv.dir}" 
                  includes="${msv.jar.name},
                            ${isorelax.jar.name},
                            ${relaxngdatatype.jar.name},
                            ${xsdlib.jar.name}"/>
      <tarfileset prefix="${zip-prefix}/notices/msv" dir="${msv.dir}" includes="license.txt, Apache-LICENSE-1.1.txt"/>
      
      <tarfileset prefix="${zip-prefix}/schematron" dir="${schematron.dir}" includes="**"/>
      
      <tarfileset prefix="${zip-prefix}/testng" dir="${testng.dir}" includes="${testng.jar.name}"/>
      <tarfileset prefix="${zip-prefix}/notices/testng" dir="${testng.dir}" includes="LICENSE.txt"/>
    </tar>
  </target>
</project>