<?xml version="1.0" encoding="utf-8" ?>
 <!--
 * 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.                                           *
 -->
<project name="installers" basedir="." default="help">
    <description>Installers, .zip and .tar.gz packages</description>
    <property name="Etch.basedir" location="${basedir}/.." />
    <import file="${Etch.basedir}/build-support/etch.includes.xml" />

    <!-- Static properties of the sub-project -->
    <property name="proj"                 location="${Etch.basedir}/installers" />
    <property name="target"               location="${proj}/target" />
    <property name="packageName"          value="${Etch.longname}" />

    <!-- INIT TARGET -->
    <!-- Modify this target to define project specific properties that can only be set at runtime -->
    <target name="do-init">
        <delete dir="${target}" failonerror="false" quiet="true" />
        <mkdir dir="${Etch.dist}" />
        <mkdir dir="${target}" />
    </target>

    <!-- CLEAN TARGET -->
    <target name="do-clean">
        <delete dir="${target}" />
    </target>

    <!-- BUILD TARGET -->

    <target name="do-txts">
        <copy file="${Etch.basedir}/LICENSE.txt" todir="${Etch.dist}" />
        <copy file="${Etch.basedir}/ChangeLog.txt" todir="${Etch.dist}" />
        <copy file="${Etch.basedir}/README.txt" tofile="${Etch.dist}/README.txt" />
        <copy file="${Etch.basedir}/RELEASE_NOTES.txt" tofile="${Etch.dist}/RELEASE_NOTES.txt" />
        <copy file="${Etch.basedir}/NOTICE.txt" tofile="${Etch.dist}/NOTICE.txt" />
        <copy file="${proj}/etch-maven-install.bat" todir="${Etch.dist}/maven" >
            <filterset refid="Etch.buildTokens" />
        </copy>
    </target>

    <target name="do-zips" >
        <!-- create zipped binary distribution -->
        <zip destfile="${target}/${packageName}.zip" >
            <zipfileset dir="${Etch.dist}" prefix="${packageName}/" >
                <exclude name="bin/etch" />
            </zipfileset>
            <zipfileset dir="${Etch.dist}" prefix="${packageName}/" filemode="755" >
                <include name="bin/etch" />
            </zipfileset>                
        </zip>

        <!-- create tar-gzip binary distribution -->
        <tar destfile="${target}/${packageName}.tar.gz" compression="gzip" >
            <tarfileset dir="${Etch.dist}" prefix="${packageName}/">
                <exclude name="bin/etch" />
            </tarfileset>
            <tarfileset dir="${Etch.dist}" prefix="${packageName}/" filemode="755" >
                <include name="bin/etch" />
            </tarfileset>
        </tar>
    </target>

    <target name="do-nsis" if="NSIS.enabled" >
        <makensis destfile="${target}/${packageName}-setup.exe" root="${Etch.basedir}" dir="installers" script="etch-full-installer" />        
    </target>

    <target name="do-build" depends="do-txts,do-nsis,do-zips" />

    <!-- TEST TARGET -->
    <target name="do-test">
		<available property="build.tests.fail" file="${Etch.runtime.tests.fail}"/>
    </target>

    <!-- POSTBUILD TARGET -->
    <target name="do-postbuild">
        <mkdir dir="${Etch.basedir}/target/Installers" />
        <copy todir="${Etch.basedir}/target/Installers/packages" >
            <fileset dir="${target}">
                <include name="**/*.zip" />
                <include name="**/*.exe" />
                <include name="**/*.tar.gz" />
            </fileset>
        </copy>
    </target>

    <target name="do-publish" if="build.tests.fail">
        <!-- Set flag file if any tests failed -->
        <touch file="${Etch.runtime.tests.fail}"/>
    </target>

</project>
