#! /bin/sh

#   Copyright 2001-2004 The Apache Software Foundation
#
#   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.
#
#   Adapted for ALT Linux by Mikhail Zabaluev <mhz@altlinux.org>

# Source functions library
if [ -f /usr/share/java-common/java-functions ] ; then
  . /usr/share/java-common/java-functions
fi

# Save the real CLASSPATH that will end up in the -lib option.
# This means that any CLASSPATH modifications made in the configuration
# files included below will end up in the JRE classpath, not in
# the -lib option of ant. Use LIBCLASSPATH for the latter.
LIBCLASSPATH=$CLASSPATH
CLASSPATH=

# load system-wide ant configuration
if [ -f /etc/ant.conf ] ; then 
  . /etc/ant.conf
fi

# load user ant configuration
if [ -f "$HOME/.antrc" ] ; then 
  . "$HOME/.antrc"
fi

# provide default values for people who don't use RPMs
if [ -z "$usejikes" ] ; then
  usejikes=false;
fi

# set ANT_HOME and ANT_LIB locations
if [ -z "$ANT_HOME" ] ; then
  ANT_HOME=/usr/share/ant
fi
ANT_LIB="$ANT_HOME/lib"

JAVALIBDIR=/usr/share/java

AddToClasspath \
    "$JAVALIBDIR"/xml-commons-apis.jar \
    "$JAVALIBDIR"/jaxp_parser_impl.jar \
    "$JAVALIBDIR"/antlr.jar \
    "$JAVALIBDIR"/bcel.jar \
    "$JAVALIBDIR"/jai/jai_core.jar \
    "$JAVALIBDIR"/jai/jai_codec.jar \
    "$JAVALIBDIR"/jakarta-commons-logging.jar \
    "$JAVALIBDIR"/jakarta-commons-net.jar \
    "$JAVALIBDIR"/jakarta-oro.jar \
    "$JAVALIBDIR"/jakarta-regexp.jar \
    "$JAVALIBDIR"/javamail/mailapi.jar \
    "$JAVALIBDIR"/javamail/smtp.jar \
    "$JAVALIBDIR"/activation.jar \
    "$JAVALIBDIR"/jdepend.jar \
    "$JAVALIBDIR"/jsch.jar \
    "$JAVALIBDIR"/junit.jar \
    "$JAVALIBDIR"/log4j.jar \
    "$JAVALIBDIR"/stylebook.jar \
    "$JAVALIBDIR"/xalan-j.jar \
    "$JAVALIBDIR"/serializer.jar \
    "$JAVALIBDIR"/xml-commons-resolver.jar \
    "$ANT_LIB"/ant-launcher.jar

if [ -z "$JAVA_HOME" ] ; then
  if [ -d /usr/lib/jdk ] ; then
    JAVA_HOME=/usr/lib/jdk
    export JAVA_HOME
  fi
fi

if [ -n "$JAVA_HOME" ] ; then
  AddToClasspath "$JAVA_HOME"/lib/tools.jar
else
  echo "Error: JAVA_HOME is not defined correctly." >&2
  echo "  We cannot execute java"                   >&2
  exit 1
fi

# Allow Jikes support (off by default)
if $usejikes; then
  ANT_OPTS="$ANT_OPTS -Dbuild.compiler=jikes"
  if [ -n "$JIKESPATH" ]; then
    ANT_OPTS="$ANT_OPTS -Djikes.class.path=$JIKESPATH"
  fi
fi

FindJVM

if test -z "$JAVA_BIN"; then
	echo "$0: cannot find the Java VM executable" >&2
	exit 1
fi

exec "$JAVA_BIN"  -Dant.home="$ANT_HOME" $ANT_OPTS \
	org.apache.tools.ant.launch.Launcher $ANT_ARGS -lib "$LIBCLASSPATH" "$@"

