#!/bin/sh

#  Gant -- A Groovy way of scripting Ant tasks.
#
#  Copyright © 2006-8 Russel Winder
#
#  Licensed 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.
#
#  Author : Russel Winder <russel.winder@concertant.com>

#  Gant initiation script for Linux and UNIX

#  If GANT_HOME is not set, deduce a path.  Assume the executable is in $GANT_HOME/bin.

if [ -z "$GANT_HOME" ]
then
    if [ -h $0 ]
    then
        GANT_HOME=`readlink -f $0`
        GANT_HOME=`dirname $GANT_HOME`
    else
        GANT_HOME=`dirname $0`
    fi
    GANT_HOME=`dirname $GANT_HOME`
fi

#  If GROOVY_HOME is not set, deduce a path -- this is needed in order to discover the location of the
#  startGroovy script.  Assume the executable is in $GROOVY_HOME/bin.

if [ -z "$GROOVY_HOME" ]
then
    GROOVY_HOME=`which groovy`
    if [ -h $GROOVY_HOME ]
    then
        GROOVY_HOME=`readlink -f $GROOVY_HOME`
    fi
    GROOVY_HOME=`dirname "$GROOVY_HOME"`
    GROOVY_HOME=`dirname "$GROOVY_HOME"`
fi

#  If ANT_HOME is not set, deduce a path -- this is needed in order to discover the location of the jars
#  associated with the Ant installation.  Assume the executable is in $ANT_HOME/bin.

if [ -z "$ANT_HOME" ]
then
    ANT_HOME=`which ant`
    if [ -h $ANT_HOME ]
    then
        ANT_HOME=`readlink -f $ANT_HOME`
    fi
    ANT_HOME=`dirname "$ANT_HOME"`
    ANT_HOME=`dirname "$ANT_HOME"`
fi

GROOVY_APP_NAME=Gant
GROOVY_CONF="$GANT_HOME/conf/gant-starter.conf"

. "$GROOVY_HOME/bin/startGroovy"

if $cygwin
then
    GANT_HOME=`cygpath --mixed "$GANT_HOME"`
    ANT_HOME=`cygpath --mixed "$ANT_HOME"`
fi
JAVA_OPTS="$JAVA_OPTS -Dgant.home=$GANT_HOME -Dant.home=$ANT_HOME"

startGroovy gant.Gant "$@"
