<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- $Id: dist-build.xml 1451136 2013-02-28 08:17:57Z ilgrosso $ -->
<project name="dist">

  <description>
    Distribution targets
  </description>

  <target name="dist" depends="init" description="[admin] Builds the distribution">

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

    <copy todir="${dist}/tools">
      <fileset dir="${tools}">
        <exclude name="anttasks/**"/>
        <exclude name="loader/**"/>
        <exclude name="lib/xalan*"/>
        <exclude name="lib/xerces*"/>
        <exclude name="lib/jtidy*"/>
        <exclude name="lib/xml-apis.jar"/>
      </fileset>
    </copy>

    <copy todir="${dist}/lib">
      <fileset dir="${lib}"/>
    </copy>

    <copy todir="${dist}/src">
      <fileset dir="${src}"/>
    </copy>

    <copy todir="${dist}/legal">
      <fileset dir="${legal}"/>
    </copy>

    <copy todir="${dist}" filtering="on">
     <fileset dir=".">
      <include name="*.txt"/>
      <include name="DESKTOP.INI"/>
      <include name="*.bat"/>
      <include name="*.sh"/>
      <include name="KEYS"/>
      <include name="*.xml"/>
      <include name="*.sample"/>
      <include name="*.properties"/>
      <include name="*.xconf"/>
      <exclude name="local.*"/>
      <exclude name="announcement.xml"/>
     </fileset>
    </copy>

    <chmod perm="+x" file="${dist}/cocoon.sh"/>
    <chmod perm="+x" file="${dist}/build.sh"/>
    <chmod perm="+x" file="${dist}/tools/bin/antRun"/>
    <fixcrlf srcdir="${dist}" includes="**.sh" eol="lf"/>
    <fixcrlf srcdir="${dist}" includes="antRun" eol="lf"/>
    <fixcrlf srcdir="${dist}" includes="**.bat" eol="crlf"/>

    <zip zipfile="${dist.target}/${dist.name}-src.zip"
         basedir="${dist.root}"
         includes="${dist.name}/**">
        <exclude name="${dist.name}/lib/**"/>
        <exclude name="${dist.name}/tools/lib/**"/>
        <exclude name="${dist.name}/tools/jetty/lib/**"/>
        <exclude name="${dist.name}/legal/**"/>
    </zip>
    <checksum file="${dist.target}/${dist.name}-src.zip" algorithm="md5"/>
    <checksum file="${dist.target}/${dist.name}-src.zip" algorithm="sha1"/>

    <tar tarfile="${dist.target}/${dist.name}-src.tar"
         longfile="gnu">
         <tarfileset dir="${dist.root}">
             <include name="${dist.name}/**"/>
             <exclude name="${dist.name}/cocoon.sh"/>
             <exclude name="${dist.name}/build.sh"/>
             <exclude name="${dist.name}/tools/bin/antRun"/>
             <exclude name="${dist.name}/lib/**"/>
             <exclude name="${dist.name}/tools/lib/**"/>
             <exclude name="${dist.name}/tools/jetty/lib/**"/>
             <exclude name="${dist.name}/legal/**"/>
         </tarfileset>
         <tarfileset dir="${dist.root}" mode="755">
             <include name="${dist.name}/cocoon.sh"/>
             <include name="${dist.name}/build.sh"/>
             <include name="${dist.name}/tools/bin/antRun"/>
         </tarfileset>
    </tar>
    <gzip zipfile="${dist.target}/${dist.name}-src.tar.gz" src="${dist.target}/${dist.name}-src.tar"/>
    <delete file="${dist.target}/${dist.name}-src.tar"/>
    <checksum file="${dist.target}/${dist.name}-src.tar.gz" algorithm="md5"/>
    <checksum file="${dist.target}/${dist.name}-src.tar.gz" algorithm="sha1"/>

    <zip zipfile="${dist.target}/${dist.name}-deps.zip">
    	<fileset dir="${dist.root}">
            <include name="${dist.name}/lib/**"/>
            <include name="${dist.name}/tools/lib/**"/>
            <include name="${dist.name}/tools/jetty/lib/**"/>
    	</fileset>
        <zipfileset dir="${dist.root}/${dist.name}/legal" prefix="${dist.name}/">
            <include name="NOTICE.txt"/>
            <include name="LICENSE.txt"/>
        </zipfileset>
    </zip>
    <checksum file="${dist.target}/${dist.name}-deps.zip" algorithm="md5"/>
    <checksum file="${dist.target}/${dist.name}-deps.zip" algorithm="sha1"/>

    <tar tarfile="${dist.target}/${dist.name}-deps.tar"
         longfile="gnu">
        <tarfileset dir="${dist.root}">
            <include name="${dist.name}/lib/**"/>
            <include name="${dist.name}/tools/lib/**"/>
            <include name="${dist.name}/tools/jetty/lib/**"/>
        </tarfileset>
        <tarfileset dir="${dist.root}/${dist.name}/legal" prefix="${dist.name}/">
            <include name="NOTICE.txt"/>
            <include name="LICENSE.txt"/>
        </tarfileset>
    </tar>
    <gzip zipfile="${dist.target}/${dist.name}-deps.tar.gz" src="${dist.target}/${dist.name}-deps.tar"/>
    <delete file="${dist.target}/${dist.name}-deps.tar"/>
    <checksum file="${dist.target}/${dist.name}-deps.tar.gz" algorithm="md5"/>
    <checksum file="${dist.target}/${dist.name}-deps.tar.gz" algorithm="sha1"/>
  </target>

  <target name="clean-dist" depends="clean" description="Cleans everything and brings back to original 'SVN checkout' state">
    <delete dir="${build.root}"/>
    <delete dir="${tools.tasks.dest}"/>
    <delete dir="${tools.loader.dest}"/>
    <delete file="${dist.target}/${dist.name}-src.tar.gz"/>
    <delete file="${dist.target}/${dist.name}-src.zip"/>
    <delete dir="${dist.root}"/>
  </target>

</project>
