<!-- 
  ############################################################################
  # This is the Ant build file for writer2latex
  # Original: Sep 2004 (mgn)
  # version 1.6.1 (2018-08-24)
  ############################################################################
-->
<project name="w2l" default="help" basedir=".">

    <!-- set this property to the location of your SO/OOo installation -->
	<property name="OFFICE_CLASSES" location="/usr/share/java" />
	<property name="URE_CLASSES" location="/usr/share/java" />

    <description>writer2latex - build file</description>

    <target name="help" description="Displays usage information">
        <echo>Usage: ant &lt;target&gt;
          The following targets are supported:
          all
              Build nearly everything
          compile
              Compile all file except the tests.        
          jar
              Create the standalone jar file.
          oxt
              Create extension packages for OOo
          distro
              Create the distribution packages
          javadoc
              Create the javadoc documentation in target/javadoc. 
          clean
        </echo>
    </target>

    <!-- configure the directories -->
    <property name="jarfile" value="writer2latex"/>
    <property name="basename" value="writer2latex16"/>
    <property name="distrofile" value="${basename}1.zip" />
    <!--<property name="sourcedistrofile" value="${basename}source.zip" />-->
    <property name="src" location="source/java"/>
    <property name="source.distro" location="source/distro" />
    <property name="classes" location="target/classes"/>
    <property name="javadoc" location="target/javadoc"/>
    <property name="tmp" location="target/tmp"/>
    <property name="target" location="target"/>
    <property name="target.lib" location="target/lib"/>
    <property name="source.idl" location="source/idl"/>
    <property name="source.lib" location="source/lib"/>
    <property name="org.json" value="json-20140107.jar"/>
    <property name="org.jbibtex" value="jbibtex-1.0.14.jar"/>
    <!-- classpath for the application; needs java-uno classes -->
    <path id="main.class.path"> 
        <!-- java uno classes -->
    	<filelist dir="${URE_CLASSES}"
	        files="jurt.jar,juh.jar,ridl.jar"/>
        <filelist dir="${OFFICE_CLASSES}"
    		files="unoil.jar"/>
    	<!-- third party jars -->
    	<filelist dir="${source.lib}"
	        files="${org.json},${org.jbibtex}"/>
        <!-- additional uno interfaces generated from idl -->
        <pathelement path="${source.idl}/writer2latex"/>
        <pathelement path="${source.idl}/writer2xhtml"/>
    </path> 

    <target name="all"
            description="Build nearly everything"
            depends="javadoc,jar,oxt,distro" />

    <target name="compile"
            description="Compile the Java files (without tests)">
        <!-- create empty output directory for classes if not present -->
        <mkdir dir="${classes}"/>
        <!-- compile the application code -->
        <javac srcdir="${src}" 
               destdir="${classes}"
               encoding="us-ascii"
        	   source="1.8"
        	   target="1.8"
	     	   classpath="${source.lib}/${org.json}:${source.lib}/${org.jbibtex}"
        	   includeantruntime="false"
               debug="on">
            <classpath refid="main.class.path"/>
        </javac>
        <copy todir="${classes}">
            <fileset dir="${src}">
                <include name="**/*.xml"/>
                <include name="**/*.properties"/>
            </fileset>
        </copy>
    </target>

    <target name="jar"
            depends="compile"
            description="Create writer2latex jar file containing all compiled classes except OOo components and test cases.">
	    <!-- make a jar from the classes not matching magic testcase identifiers-->
        <mkdir dir="${target.lib}"/>
        <jar jarfile="${target.lib}/${jarfile}.jar">
            <fileset dir="${classes}">
                <patternset>
                    <exclude name="**/*Test.class"/>
                    <exclude name="**/AllTests.class"/>
		    		<include name="**/*.xml"/>
		    		<include name="**/*.properties"/>
                	<include name="**/*.class"/>
                    <!-- do not include OOo components in standalone library -->
                	<exclude name="org/openoffice/**/*"/>
                </patternset>
            </fileset>
        	<!-- include third party libraries -->
        	<zipgroupfileset dir="${source.lib}" includes="${org.json}" />
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <attribute name="Main-Class" value="writer2latex.Application"/>
                <attribute name="Class-Path" value="jaxp.jar parser.jar"/>
            </manifest>
        </jar>
    </target>
	
    <!-- Create extension package for OOo 2.0.4+ -->
    <target name="oxt"
            depends="jar"
            description="Create extension package for installation with OOo 2.0.4+">
        <mkdir dir="${target.lib}"/>
        <mkdir dir="${tmp}"/>

        <!-- First extension: writer2latex.oxt -->
		
        <!-- Create jar with relevant files  -->
        <jar jarfile="${tmp}/writer2latex-filter.jar">
            <fileset dir="${classes}">
                <patternset>
                    <exclude name="**/*Test.class"/>
                    <exclude name="**/AllTests.class"/>
		    		<include name="**/*.xml"/>
                	<include name="**/*.class"/>
		    		<include name="**/*.properties"/>
                    <exclude name="writer2latex/Application.class"/>
                    <exclude name="writer2latex/xhtml/**/*"/>
                	<exclude name="org/openoffice/da/comp/writer2xhtml/**/*"/>
                </patternset>
            </fileset>
        	<!-- include third party libraries -->
        	<zipgroupfileset dir="${source.lib}" includes="${org.json},${org.jbibtex}" />
            <!-- also include uno interface as generated from idl -->
            <fileset dir="${source.idl}/writer2latex">
                <include name="org/**/*"/>
            </fileset>
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <!-- OOo needs this to register the filter: -->
                <attribute name="RegistrationClassName" value="org.openoffice.da.comp.writer2latex.W2LRegistration" />
                <attribute name="Class-Path" value="jaxp.jar parser.jar"/>
            </manifest>
        </jar>

        <!-- Pack extension -->
        <zip destfile="${target.lib}/writer2latex.oxt">
            <zipfileset dir="source/oxt/writer2latex" prefix="" />
            <zipfileset dir="${tmp}" includes="writer2latex-filter.jar" />
            <zipfileset dir="${source.idl}/writer2latex" includes="writer2latex.rdb"/>
        </zip>
		
        <!-- delete the jar for this extension -->
        <delete file="${tmp}/writer2latex-filter.jar" />
		
		
        <!-- Second extension: writer2xhtml.oxt -->

        <!-- Create jar with relevant files  -->
        <jar jarfile="${tmp}/writer2xhtml-filter.jar">
            <fileset dir="${classes}">
                <patternset>
                    <exclude name="**/*Test.class"/>
                    <exclude name="**/AllTests.class"/>
                	<include name="org/openoffice/da/comp/w2lcommon/**/*.class"/>
                	<include name="org/openoffice/da/comp/w2lcommon/**/*.properties"/>
                	<include name="org/openoffice/da/comp/writer2xhtml/**/*.class"/>
                	<include name="writer2latex/api/**/*.class"/>
                	<include name="writer2latex/base/**/*.class"/>
                	<include name="writer2latex/epub/**/*.class"/>
                	<include name="writer2latex/office/**/*.class"/>
                	<include name="writer2latex/util/**/*.class"/>
                	<include name="writer2latex/xhtml/**/*.class"/>
                	<include name="writer2latex/xhtml/**/*.xml"/>
                	<include name="writer2latex/xhtml/**/*.properties"/>
                	<include name="writer2latex/xmerge/**/*.class"/>
                	<!-- include the portions of w2l necessary to convert formulas -->
                	<include name="writer2latex/latex/StarMathConverter.class"/>
                	<include name="writer2latex/latex/CharClasses.class"/>
                	<include name="writer2latex/latex/Token.class"/>
                   	<include name="writer2latex/latex/TGroup.class"/>
                   	<include name="writer2latex/latex/SmTokenTableEntry.class"/>
                   	<include name="writer2latex/latex/SmTokenTable.class"/>
                   	<include name="writer2latex/latex/SmToken.class"/>
                	<include name="writer2latex/latex/LaTeXDocumentPortion.class"/>
                	<include name="writer2latex/latex/LaTeXConfig*.class"/>
                	<include name="writer2latex/latex/ContentHandlingOption.class"/>
                	<include name="writer2latex/latex/util/HeadingMap.class"/>
                    <include name="writer2latex/latex/util/StyleMap.class"/>
                	<include name="writer2latex/latex/i18n/*.class"/>
                	<include name="writer2latex/latex/i18n/symbols.xml"/>
                </patternset>
            </fileset>
            <!-- also include uno interface as generated from idl -->
            <fileset dir="${source.idl}/writer2xhtml">
                <include name="org/**/*"/>
            </fileset>
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <!-- OOo needs this to register the filter: -->
                <attribute name="RegistrationClassName" value="org.openoffice.da.comp.writer2xhtml.W2XRegistration" />
                <attribute name="Class-Path" value="jaxp.jar parser.jar"/>
            </manifest>
        </jar>

        <!-- Pack extension -->
        <zip destfile="${target.lib}/writer2xhtml.oxt">
            <zipfileset dir="source/oxt/writer2xhtml" prefix="" />
            <zipfileset dir="${tmp}" includes="writer2xhtml-filter.jar" />
            <zipfileset dir="${source.idl}/writer2xhtml" includes="writer2xhtml.rdb"/>
        </zip>
		
        <!-- delete the jar for this extension -->
        <delete file="${tmp}/writer2xhtml-filter.jar" />

        <!-- Third extension: w2lconfig.oxt -->
    	
    	<!-- Pack extension -->
        <zip destfile="${target.lib}/w2lconfig.oxt" basedir="source/oxt/w2lconfig"/>

        <!-- Fourth extension: xhtml-config-package.oxt (xhtml sample configuration package) -->

        <zip destfile="${target.lib}/xhtml-config-sample.oxt" basedir="source/oxt/xhtml-config-sample"/>
            
    </target>
	
    <!-- Create distribution packages -->
    <target name="distro" depends="jar,oxt"
            description="Create Writer2LaTeX distribution">
		
        <zip destfile="${target.lib}/${distrofile}">

            <!-- Add misc files (documentation, readmes, scripts etc.) -->
            <zipfileset dir="${source.distro}" prefix="${basename}"/>
		
            <!-- Add default configurations (copied from source tree) -->
            <zipfileset dir="${src}/writer2latex/latex/config"  prefix="${basename}/config" />
            <zipfileset dir="${src}/writer2latex/xhtml/config"  prefix="${basename}/config" />
		
            <!-- Add jar and oxt's -->
            <zipfileset dir="${target.lib}" prefix="${basename}"
             includes="${jarfile}.jar,writer2latex.oxt,writer2xhtml.oxt,w2lconfig.oxt,xhtml-config-sample.oxt"/>
        </zip>
		
        <!-- Pack the source distribution -->
        <!--<zip destfile="${target.lib}/${sourcedistrofile}">
            <zipfileset dir="." includes="source/**/*,build.xml" prefix="${basename}" /> 
        </zip>-->
			 
    </target>

    <target name="clean"
            description="Remove unneccesary files and directories.">
        <delete dir="${classes}"/>
        <delete dir="${javadoc}"/>
		<delete dir="${target.lib}" />
        <delete dir="${tmp}" />
        </target>

    <target name="javadoc"
            description="Create JavaDoc HTML pages.">
        <mkdir dir="${javadoc}" />
        <javadoc 
             encoding="us-ascii"
             destdir="${javadoc}"
             author="true"
             version="true"
             use="true"
			 breakiterator="true" 
             splitindex="true"
             notree="false"
             nonavbar="false"
             noindex="false"
             nodeprecatedlist="false"
             nodeprecated="false">
            <classpath refid="main.class.path"/>
            <packageset dir="${src}" defaultexcludes="yes" />
        </javadoc>
        <copy todir="${javadoc}">
            <fileset dir="${src}">
                <include name="**/*.gif"/>
                <include name="**/*.png"/>
            </fileset>
        </copy>
    </target>

</project>
