<!-- 
  ############################################################################
  # This is the Ant build file for writer2latex
  # Original: Sep 2004 (mgn)
  # version 1.2 (2010-11-20)
  ############################################################################
-->
<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/openoffice" />
	<property name="URE_CLASSES" location="/usr/share/java/openoffice" />

    <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="writer2latex11"/>
    <property name="distrofile" value="${basename}8alpha.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"/>
    <!-- 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"/>
        <!-- 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.5"
               debug="on">
            <classpath refid="main.class.path"/>
        </javac>
        <copy todir="${classes}">
            <fileset dir="${src}">
                <include name="**/*.xml"/>
            </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="**/*.class"/>
                    <!-- do not include OOo components in standalone library -->
                	<exclude name="org/openoffice/**/*"/>
                </patternset>
            </fileset>
            <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"/>
                    <exclude name="writer2latex/Application.class"/>
                    <exclude name="writer2latex/xhtml/**/*"/>
                	<exclude name="org/openoffice/da/comp/writer2xhtml/**/*"/>
                </patternset>
            </fileset>
            <!-- 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/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/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/util/HeadingMap.class"/>
                    <include name="writer2latex/latex/util/StyleMap.class"/>
                	<include name="writer2latex/latex/i18n/*.class"/>
                </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: writer4latex.oxt -->
    	
        <!-- Create jar with relevant files  -->
        <jar jarfile="${tmp}/writer4latex.jar">
            <fileset dir="${classes}">
                <patternset>
                	<include name="org/openoffice/da/comp/w2lcommon/helper/**/*"/>
                	<include name="org/openoffice/da/comp/writer4latex/**/*"/>
                	<include name="com/sun/star/lib/loader/**/*"/>
                </patternset>
            </fileset>
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <attribute name="Class-Path" value="jaxp.jar parser.jar"/>
                <!-- OOo needs this to register the filter: -->
                <attribute name="RegistrationClassName" value="org.openoffice.da.comp.writer4latex.W4LRegistration" />
            </manifest>
        </jar>
        
    	<!-- Pack extension -->
        <zip destfile="${target.lib}/writer4latex.oxt">
            <zipfileset dir="source/oxt/writer4latex" prefix="" />
            <zipfileset dir="${tmp}" includes="writer4latex.jar" />
        </zip>

    	<!-- delete the jar for this extension -->
        <delete file="${tmp}/writer4latex.jar" />
		
        <!-- 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,writer4latex.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>
