<!--
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="2002"/>
  <property name="version" value="1_0_5"/>
  <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_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_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"/>

  <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_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_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="dependencies" depends="prepare,check_junit"/>

  <!-- =================================================================== -->
  <!-- Compilation tasks                                                   -->
  <!-- =================================================================== -->

  <target name="api" depends="prepare">
    <javac debug="${debug}" deprecation="${deprecation}"
       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}"
      srcdir="${src_samples}" destdir="${build_samples}"
      classpath="${build_classes}"/>
    <javac debug="${debug}" deprecation="${deprecation}"
      srcdir="${src_samples}" destdir="${build_samples}"
      classpath="${build_classes}"/>
  </target>


  <target name="compile" depends="xmlpull,tests,samples"/>

  <target name="all" depends="clean,compile"/>

  <!-- =================================================================== -->
  <!-- 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>
  </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">
    <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" />

      <!--batchtest>
        <fileset dir="${build_tests}">
          <include name="**/PackageTest.class" />
        </fileset>
      </batchtest-->
    </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>

    <!-- 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="**/soap/**"/-->
        <exclude name="**/*_protocol/**"/>
      </fileset>
    </copy>

    <mkdir dir="${dist}/${src_tests}"/>
    <copy todir="${dist}/${src_tests}">
      <fileset dir="${src_tests}">
        <!--include name="**"/-->
        <!--exclude name="**/soap/**"/-->
        <exclude name="**/*_protocol/**"/>
      </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}/${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"/>
        </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="**/*jsse*/*.jar"/>
        </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="prepare">
    <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>



