#!/bin/sh

#  Gant -- A Groovy build framework based on 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.

if [ -z "$GANT_HOME" ]
then
    GANT_HOME=`dirname $0`
    GANT_HOME=`dirname $GANT_HOME`
    export 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.

if [ -z "$GROOVY_HOME" ]
then
    GROOVY_HOME=`which groovy`
    GROOVY_HOME=`dirname "$GROOVY_HOME"`
    GROOVY_HOME=`dirname "$GROOVY_HOME"`
    export 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.

if [ -z "$ANT_HOME" ]
then
    ANT_HOME=`which ant`
    ANT_HOME=`dirname "$ANT_HOME"`
    ANT_HOME=`dirname "$ANT_HOME"`
    export 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 --path --mixed "$GANT_HOME"`
    ANT_HOME=`cygpath --path --mixed "$ANT_HOME"`
    STARTER_CLASSPATH="$STARTER_CLASSPATH;$GANT_HOME\\lib\\gant-@GANT_VERSION@.jar"
else
    STARTER_CLASSPATH="$STARTER_CLASSPATH:$GANT_HOME/lib/gant-@GANT_VERSION@.jar"
fi
JAVA_OPTS="$JAVA_OPTS -Dgant.home=$GANT_HOME -Dant.home=$ANT_HOME"

startGroovy gant.Gant "$@"
