<!--
This is an ant build file compatible with ant version 1.3.

All generated files are created under ${build} directory

-->

<project name="XmlPull_V1" default="compile" basedir=".">

  <!-- set global properties for this build -->

  <property name="name" value="XmlPull"/>
  <property name="year" value="2006"/>
  <property name="version" value="1_1_3_4c"/>
  <property name="xmlpull_version" value="xmlpull_${version}"/>
  <property name="xmlpull_tag" value="XMLPULL_${version}"/>
  <property name="copyright"
    value="This XmlPull V1 API is free, enjoy! &lt;a href='http://www.xmlpull.org/'>http://www.xmlpull.org/&lt;/a>" />

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

  <property name="doc" value="doc"/>

  <property name="src" value="src/java"/>

  <property name="src_api" value="${src}/api"/>
  <property name="src_tests" value="${src}/tests"/>
  <property name="src_tests_xml" value="src/xml/tests"/>
  <property name="src_samples" value="${src}/samples"/>

  <property name="build" value="build"/>
  <property name="build_dist" value="${build}/dist"/>
  <property name="build_lib" value="${build}/lib"/>
  <property name="build_classes" value="${build}/classes"/>
  <property name="build_tests" value="${build}/tests"/>
  <property name="build_tests_xml" value="${build_tests}/org/xmlpull/v1/tests/xml"/>  
  <property name="build_samples" value="${build}/samples"/>
  <property name="build_apidoc" value="${doc}/api"/>
  <property name="build_javadoc" value="${doc}/api_impl"/>
  <property name="apidoc_packages" value="org.xmlpull.v1.*"/>
  <property name="api_sourcepath" value="${src_api}"/>
  <property name="javadoc_packages" value="org.xmlpull.v1.*"/>
  <property name="dist" value="${build}/dist/${xmlpull_version}"/>
  <property name="lite_suffix" value="src"/>
  <property name="full_suffix" value="all"/>
  <property name="dist_lite" value="${build}/dist/${xmlpull_version}_${lite_suffix}"/>
  <property name="dist_full" value="${build}/dist/${xmlpull_version}_${full_suffix}"/>
  <property name="dist_lite_zip" value="${dist_lite}.zip"/>
  <property name="dist_full_zip" value="${dist_full}.zip"/>
  <property name="dist_lite_tar" value="${dist_lite}.tar"/>
  <property name="dist_full_tar" value="${dist_full}.tar"/>
  <property name="dist_lite_tgz" value="${dist_lite}.tgz"/>
  <property name="dist_full_tgz" value="${dist_full}.tgz"/>
  <property name="jar"  value="${build_lib}/${xmlpull_version}.jar"/>
  <property name="tests_jar"  value="${build_lib}/xmlpull-tests_${version}.jar"/>

  <!-- ======================================== -->
  <!-- ADDONS -->
  <property name="build_addons" value="${build}/addons"/>
  <property name="build_addons_tests" value="${build_addons}/tests"/>

  <property name="src_addons" value="addons/java"/>

  <property name="build_dom2_builder" value="${build_addons}/dom2_builder"/>
  <property name="src_dom2_builder" value="${src_addons}/dom2_builder/src"/>
  <property name="jar_dom2_builder"  value="${build_lib}/${xmlpull_version}-dom2_builder.jar"/>

  <property name="build_sax2" value="${build_addons}/sax2_driver"/>
  <property name="lib_sax2" value="${src_addons}/sax2_driver/lib"/>
  <property name="jar_sax2"  value="${build_lib}/${xmlpull_version}-sax2.jar"/>
  <property name="src_sax2" value="${src_addons}/sax2_driver/src"/>

  <property name="build_parser_pool" value="${build_addons}/parser_pool"/>
  <property name="src_parser_pool" value="${src_addons}/parser_pool/src"/>
  <property name="jar_parser_pool"  value="${build_lib}/${xmlpull_version}-parser_pool.jar"/>

  <property name="build_util" value="${build_addons}/util"/>
  <property name="src_util" value="${src_addons}/util/src"/>
  <property name="jar_util"  value="${build_lib}/${xmlpull_version}-util.jar"/>

  <property name="build_wrapper" value="${build_addons}/wrapper"/>
  <property name="src_wrapper" value="${src_addons}/wrapper/src"/>
  <property name="src_wrapper_tests" value="${src_addons}/wrapper/tests"/>
  <property name="jar_wrapper"  value="${build_lib}/${xmlpull_version}-wrapper.jar"/>

  <property name="build_xmlrpc" value="${build_addons}/xmlrpc"/>
  <property name="src_xmlrpc" value="${src_addons}/xmlrpc/src"/>
  <property name="jar_xmlrpc"  value="${build_lib}/${xmlpull_version}-xmlrpc.jar"/>

  <property name="website"      value="../xmlpull-website/v1"/>

  <patternset id="all_source_files">
        <exclude name="**/*-"/>
        <exclude name="**/*~"/>
        <exclude name="**/*.mcp"/>
        <exclude name="**/*_Data/**"/>
  </patternset>

  <!-- =================================================================== -->
  <!-- Preparing build environment                                         -->
  <!-- =================================================================== -->
  <target name="clean">
    <delete dir="${build_addons}"/>
    <delete dir="${build_classes}"/>
    <delete dir="${build_lib}"/>
    <delete dir="${build_tests}"/>
    <delete dir="${build_samples}"/>
    <delete file="${dist_zip}"/>
    <delete file="${dist_tgz}"/>
  </target>

  <target name="prepare">
    <mkdir dir="${build}"/>
    <mkdir dir="${build_dist}"/>
    <mkdir dir="${build_lib}"/>
    <mkdir dir="${build_tests}"/>
    <mkdir dir="${build_classes}"/>
    <touch file="${build_classes}/${xmlpull_tag}_VERSION"/>
    <touch file="${build_tests}/${xmlpull_tag}_VERSION_TESTS"/>
    <available property="junit_present" classname="junit.framework.TestCase" />
    <uptodate property="build_notRequired" targetfile="${jar}">
      <srcfiles dir="${src_api}" includes="**/*.java"/>
    </uptodate>
    <uptodate property="build_tests_jar_notRequired" targetfile="${tests_jar}">
      <srcfiles dir="${src_tests}" includes="**/*.java"/>
    </uptodate>
  </target>

  <target name="check_junit" unless="junit_present" depends="prepare">
    <echo message="Warning: JUnit dependencies were not resolved."/>
  </target>

  <target name="require_junit" unless="junit_present" depends="prepare">
    <fail message="ERROR: JUnit library must be present to compile this target (see http://www.junit.org)."/>
  </target>

  <target name="dependencies" depends="prepare,check_junit"/>

  <!-- =================================================================== -->
  <!-- Compilation tasks                                                   -->
  <!-- =================================================================== -->

  <target name="api" depends="prepare">
    <javac debug="${debug}" deprecation="${deprecation}" source="1.2" target="1.1"
       srcdir="${src_api}" destdir="${build_classes}" classpath="${build_classes}"/>
  </target>

  <target name="jar" unless="build_notRequired" depends="api">
    <mkdir dir="${build_lib}"/>
    <jar jarfile="${jar}">
      <fileset dir="${build_classes}"/>
    </jar>
  </target>

  <target name="xmlpull" depends="jar"/>

  <target name="samples" depends="xmlpull">
    <mkdir dir="${build_samples}"/>
    <javac debug="${debug}" deprecation="${deprecation}" source="1.2" target="1.1"
      srcdir="${src_samples}" destdir="${build_samples}"
      classpath="${build_classes}"/>
  </target>


  <target name="compile" depends="xmlpull,tests,samples"/>

  <target name="all" depends="clean,compile"/>

  <!-- =================================================================== -->
  <!-- ADDONS                                                              -->
  <!-- =================================================================== -->


  <target name="dom2_builder" depends="api">
    <mkdir dir="${build_dom2_builder}"/>
    <javac debug="${debug}" deprecation="${deprecation}" source="1.2" target="1.1"
       srcdir="${src_dom2_builder}" destdir="${build_dom2_builder}" 
       classpath="${build_classes}"/>
    <jar jarfile="${jar_dom2_builder}">
      <fileset dir="${build_dom2_builder}"/>
    </jar>       
  </target>

  <target name="parser_pool" depends="api">
    <mkdir dir="${build_parser_pool}"/>
    <javac debug="${debug}" deprecation="${deprecation}" source="1.2" target="1.1"
       srcdir="${src_parser_pool}" destdir="${build_parser_pool}" 
       classpath="${build_classes}"/>
    <jar jarfile="${jar_parser_pool}">
      <fileset dir="${build_parser_pool}"/>
    </jar>       
  </target>

  <target name="sax2" depends="api">
    <mkdir dir="${build_sax2}"/>
    <javac debug="${debug}" deprecation="${deprecation}" source="1.2" target="1.1"
       srcdir="${src_sax2}" destdir="${build_sax2}">
       <classpath>
        <pathelement location="${build_classes}" />
        <fileset dir="${lib_sax2}">
          <include name="*.jar"/>
        </fileset>
      </classpath>
    </javac>    
    <jar jarfile="${jar_sax2}">
      <fileset dir="${build_sax2}"/>
    </jar>       
  </target>

  <target name="util" depends="api">
    <mkdir dir="${build_util}"/>
    <javac debug="${debug}" deprecation="${deprecation}" source="1.2" target="1.1"
       srcdir="${src_util}" destdir="${build_util}" classpath="${build_classes}"/>
    <jar jarfile="${jar_util}">
      <fileset dir="${build_util}"/>
    </jar>       
  </target>

  <target name="wrapper" depends="require_junit,util">
    <mkdir dir="${build_wrapper}"/>
    <javac debug="${debug}" deprecation="${deprecation}" source="1.2" target="1.1"
       srcdir="${src_wrapper}" destdir="${build_wrapper}" classpath="${build_classes}:${build_util}"/>
    <jar jarfile="${jar_wrapper}">
      <fileset dir="${build_wrapper}"/>
    </jar>       
  </target>

  <target name="wrapper_tests" depends="require_junit,wrapper">
    <mkdir dir="${build_addons_tests}"/>
    <javac debug="${debug}" deprecation="${deprecation}" source="1.2" target="1.1"
       srcdir="${src_wrapper_tests}" destdir="${build_wrapper}" 
       classpath="${build_classes}:${build_util}:${build_wrapper}"/>
  </target>

  <target name="xmlrpc" depends="api">
    <mkdir dir="${build_xmlrpc}"/>
    <javac debug="${debug}" deprecation="${deprecation}" source="1.2" target="1.1"
       srcdir="${src_xmlrpc}" destdir="${build_xmlrpc}" classpath="${build_classes}"/>
    <jar jarfile="${jar_xmlrpc}">
      <fileset dir="${build_xmlrpc}"/>
    </jar>       
  </target>
      
  <target name="addons" depends="prepare,sax2,util,wrapper,xmlrpc,parser_pool,dom2_builder"/>

  <target name="addons_tests" depends="addons,wrapper_tests"/>

  <!-- =================================================================== -->
  <!-- JUnit automatic tests                                               -->
  <!-- =================================================================== -->

  <path id="test-classpath">
    <pathelement location="${build_classes}" />
    <pathelement path="${java.class.path}" />
  </path>

  <target name="tests_junit" if="junit_present" depends="xmlpull,check_junit">
    <mkdir dir="${build_tests}"/>
    <javac debug="${debug}" deprecation="${deprecation}"
      srcdir="${src_tests}"
      destdir="${build_tests}">
        <classpath refid="test-classpath" />
    </javac>
    <mkdir dir="${build_tests_xml}"/>
    <copy todir="${build_tests_xml}">
      <fileset dir="${src_tests_xml}">
        <include name="**/*.xml"/>
      </fileset>
    </copy>
  </target>

  <target name="tests_jar" unless="build_tests_jar_notRequired" depends="tests_junit">
    <mkdir dir="${build_lib}"/>
    <jar jarfile="${tests_jar}">
      <fileset dir="${build_tests}"/>
    </jar>
  </target>

  <target name="tests" depends="tests_jar"/>

  <target name="junit" if="junit_present" depends="tests">

    <java classname="org.xmlpull.v1.tests.PackageTests" fork="yes">
      <!--arg value="foo_argument_1" /-->
      <!--arg value="samples/list.xml" /-->
      <classpath>
        <path refid="test-classpath" />
        <pathelement location="${build_tests}" />
      </classpath>
    </java>


    <!--junit haltonfailure="yes" fork="yes">
      <classpath>
        <path refid="test-classpath" />
        <pathelement location="${build_tests}" />
      </classpath>
      <formatter type="plain" usefile="false" />
      <test name="org.xmlpull.v1.tests.PackageTests" />

    </junit-->

  </target>

  <!-- =================================================================== -->
  <!-- Creates the API documentation                                       -->
  <!-- =================================================================== -->
  <target name="apidoc" depends="xmlpull">
    <delete dir="${build_apidoc}"/>
    <mkdir dir="${build_apidoc}"/>
    <javadoc packagenames="${apidoc_packages}"
             public="yes"
             sourcepath="${api_sourcepath}"
             destdir="${build_apidoc}"
             author="true"
             version="true"
             use="true"
             windowtitle="${name} ${version} API"
             doctitle="${name}"
             bottom="${copyright}"
             stylesheetfile="${doc}/javadoc_stylesheet.css"
    />
  </target>

  <!-- =================================================================== -->
  <!-- Creates the JAVADOC documentation                                   -->
  <!-- =================================================================== -->
  <target name="javadoc" depends="xmlpull">
    <delete dir="${build_javadoc}"/>
    <mkdir dir="${build_javadoc}"/>
    <javadoc packagenames="${javadoc_packages}"
             sourcepath="${api_sourcepath}"
             destdir="${build_javadoc}"
             author="true"
             version="true"
             use="true"
             windowtitle="${name} ${version} Implementation API"
             doctitle="Implementation ${name}"
             bottom="${copyright}"
             stylesheetfile="${doc}/javadoc_stylesheet.css"
    />
  </target>


  <!-- =================================================================== -->
  <!-- Creates the XMLPULL distribution                                    -->
  <!-- =================================================================== -->
  <target name="dist_lite" depends="compile, apidoc">
    <delete dir="${dist}"/>
    <delete file="${dist_lite_zip}"/>

    <mkdir dir="${dist}"/>

    <mkdir dir="${dist}/build"/>
    <copy todir="${dist}/build">
      <fileset dir="${build}">
        <include name="lib/${xmlpull_version}*.jar"/>
        <include name="lib/xmlpull-tests_${version}*.jar"/>
        <include name="classes/**"/>
        <include name="samples/**"/>
        <include name="tests/**"/>
      </fileset>
    </copy>
    <copy todir="${dist}">
      <fileset dir="${build}/lib">
        <include name="${xmlpull_version}*.jar"/>
      </fileset>
    </copy>

    <!-- sources should be copied after build to make it newer -->
    <mkdir dir="${dist}/src"/>

    <mkdir dir="${dist}/${src_samples}"/>
    <copy todir="${dist}/${src_samples}">
      <fileset dir="${src_samples}">
        <!--include name="**"/-->
        <!--exclude name="**/stuff/**"/-->
      </fileset>
    </copy>

    <mkdir dir="${dist}/${src_tests}"/>
    <copy todir="${dist}/${src_tests}">
      <fileset dir="${src_tests}">
        <!--include name="**"/-->
        <!--exclude name="**/stuff/**"/-->
      </fileset>
    </copy>

    <mkdir dir="${dist}/${src_tests_xml}"/>
    <copy todir="${dist}/${src_tests_xml}">
      <fileset dir="${src_tests_xml}">
        <!--include name="**"/-->
        <!--exclude name="**/stuff/**"/-->
      </fileset>
    </copy>

    <mkdir dir="${dist}/${src_api}"/>
    <copy todir="${dist}/${src_api}">
      <fileset dir="${src_api}">
         <patternset refid="all_source_files"/>
      </fileset>
    </copy>

    <mkdir dir="${dist}/${src_addons}"/>
    <copy todir="${dist}/${src_addons}">
      <fileset dir="${src_addons}">
         <patternset refid="all_source_files"/>
      </fileset>
    </copy>

    <mkdir dir="${dist}/${doc}"/>
    <copy todir="${dist}/${doc}">
      <fileset dir="${doc}">
        <exclude name="**/*impl*/**"/>
      </fileset>
    </copy>

    <copy file="LICENSE.txt" tofile="${dist}/LICENSE.txt"/>
    <copy file="LICENSE_TESTS.txt" tofile="${dist}/LICENSE_TESTS.txt"/>
    <copy file="README.html" tofile="${dist}/README.html"/>
    <!--copy file="README.txt" tofile="${dist}/README.txt"/-->
    <copy file="build.xml" tofile="${dist}/build.xml"/>

    <copy todir="${dist}">
      <fileset dir=".">
        <include name="*.sh"/>
        <include name="*.bat"/>
      </fileset>
    </copy>


    <fixcrlf srcdir="${dist}"
       eol="lf" eof="remove"
       includes="**/*.html,**/*.txt,**/*.sh"
     />

    <fixcrlf srcdir="${dist}"
       eol="crlf"
       includes="**/*.bat"
     />



      <mkdir dir="${dist}/lib"/>
      <copy todir="${dist}/lib">
        <fileset dir="lib">
          <exclude name="**/*.jar"/>
          <exclude name="**/impl_*/**"/>
        </fileset>
        <fileset dir="lib">
          <include name="**/README.txt"/>
        </fileset>          
      </copy>

     <chmod perm="a+x" dir="${dist}"
       includes="**/*.sh" />

    <zip zipfile="${dist_lite_zip}" basedir="${build}/dist"
      includes="${xmlpull_version}/**"
      excludes="${xmlpull_version}/build/**,${xmlpull_version}/doc/api/**"/>

     <tar tarfile="${dist_lite_tar}"
         longfile="gnu">

          <tarfileset dir="${build}/dist" mode="755" username="aslom" group="ewww">
              <include name="${xmlpull_version}/**/*.sh"/>
              <exclude name="${xmlpull_version}/build/**"/>
              <exclude name="${xmlpull_version}/doc/api/**"/>
         </tarfileset>
         <tarfileset dir="${build}/dist" username="aslom" group="ewww">
             <include name="${xmlpull_version}/**"/>
             <exclude name="${xmlpull_version}/**/*.sh"/>
              <exclude name="${xmlpull_version}/build/**"/>
              <exclude name="${xmlpull_version}/doc/api/**"/>
         </tarfileset>

     </tar>


     <gzip zipfile="${dist_lite_tgz}" src="${dist_lite_tar}" />
    <delete file="${dist_lite_tar}"/>

  </target>

  <target name="dist_lib" depends="dist_lite">
      <mkdir dir="${dist}/lib"/>
      <copy todir="${dist}/lib">
        <fileset dir="lib">
          <exclude name="**/*impl_*/*"/>
        </fileset>
      </copy>

    <delete file="${dist_full_zip}"/>
    <zip zipfile="${dist_full_zip}" basedir="${build}/dist"
      includes="${xmlpull_version}/**"/>

     <!--tar tarfile="${dist_full_tar}" basedir="${build}/dist"
         longfile="gnu"
         includes="${xmlpull_version}/**" /-->

     <tar tarfile="${dist_full_tar}"
         longfile="gnu">

          <tarfileset dir="${build}/dist" mode="755" username="aslom" group="ewww">
              <include name="${xmlpull_version}/**/*.sh"/>
         </tarfileset>
         <tarfileset dir="${build}/dist" username="aslom" group="ewww">
             <include name="${xmlpull_version}/**"/>
             <exclude name="${xmlpull_version}/**/*.sh"/>
         </tarfileset>

     </tar>

     <gzip zipfile="${dist_full_tgz}" src="${dist_full_tar}" />
    <delete file="${dist_full_tar}"/>

  </target>

  <target name="dist" depends="dist_lib"/>



  <!-- =================================================================== -->
  <!-- Copy docs and downloads to XMLPULL website                          -->
  <!-- =================================================================== -->

  <target name="website_doc" depends="apidoc">
    <mkdir dir="${website}"/>

    <delete dir="${website}/${doc}"/>
    <mkdir dir="${website}/${doc}"/>
    <copy todir="${website}/${doc}">
      <fileset dir="${doc}">
        <exclude name="**/*impl*/**"/>
      </fileset>
    </copy>
  </target>

  <target name="website_download" depends="dist,website_doc">

    <delete dir="${website}/download"/>
    <mkdir dir="${website}/download"/>

    <copy file="${doc}/README_DOWNLOAD.html" tofile="${website}/download/README.html"/>


    <!-- get JAR files for easy download by people -->
    <copy todir="${website}/download">
      <fileset dir="${build}/lib">
        <include name="${xmlpull_version}*.jar"/>
        <include name="xmlpull-tests_${version}*.jar"/>
      </fileset>
    </copy>

    <copy todir="${website}/download">
      <fileset dir="${build}/dist">
        <include name="${xmlpull_version}_*.*"/>
      </fileset>
    </copy>


    <!--gunzip src="${dist_full_tgz}" dest="${website}/download/unpacked.tar"/>
    <untar src="${website}/download/unpacked.tar" dest="${website}/download"/>
    <delete file="${website}/unpacked.tar"/>
    <move file="${website}/download/${xmlpull_version}" todir="${website}/download/unpacked"/-->

    <mkdir dir="${website}/download/unpacked"/>
    <copy todir="${website}/download/unpacked">
      <fileset dir="${dist}"/>
    </copy>


  </target>

  <target name="website" depends="website_download"/>

  <target name="run" depends="samples">
    <java classname="SampleToRunFromANT" fork="yes">
      <arg value="foo_argument_1" />
      <!--arg value="samples/list.xml" /-->
      <classpath>
        <path refid="test-classpath" />
        <pathelement location="${build_samples}" />
      </classpath>
    </java>
  </target>


</project>


