#! /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 # and Igor Vlasenko rpm_mode=true # Extract launch and ant arguments, (see details below). ant_exec_args= no_config=false use_jikes_default=false ant_exec_debug=false show_help=false for arg in "$@" ; do if [ "$arg" = "--noconfig" ] ; then no_config=true elif [ "$arg" = "--usejikes" ] ; then use_jikes_default=true elif [ "$arg" = "--execdebug" ] ; then ant_exec_debug=true elif [ my"$arg" = my"--h" -o my"$arg" = my"--help" ] ; then show_help=true ant_exec_args="$ant_exec_args -h" else if [ my"$arg" = my"-h" -o my"$arg" = my"-help" ] ; then show_help=true fi ant_exec_args="$ant_exec_args \"$arg\"" fi done # Source/default ant configuration if $no_config ; then rpm_mode=false usejikes=$use_jikes_default else # load system-wide ant configuration (ONLY if ANT_HOME has NOT been set) if [ -z "$ANT_HOME" -o "$ANT_HOME" = "/usr/share/ant" ]; then if [ -f "/etc/ant.conf" ] ; then . /etc/ant.conf fi fi # load user ant configuration if [ -f "$HOME/.ant/ant.conf" ] ; then . $HOME/.ant/ant.conf fi if [ -f "$HOME/.antrc" ] ; then . "$HOME/.antrc" fi # provide default configuration values if [ -z "$rpm_mode" ] ; then rpm_mode=false fi if [ -z "$usejikes" ] ; then usejikes=$use_jikes_default fi fi # Setup Java environment in rpm mode if $rpm_mode ; then if [ -f /usr/share/java-utils/java-functions ] ; then . /usr/share/java-utils/java-functions set_jvm set_javacmd fi fi # set ANT_HOME and ANT_LIB locations if [ -z "$ANT_HOME" ] ; then ANT_HOME=/usr/share/ant fi ANT_LIB="$ANT_HOME/lib" if [ -z "$JAVA_HOME" ] ; then if [ -d /usr/lib/jvm/java ] ; then JAVA_HOME=/usr/lib/jvm/java export JAVA_HOME fi fi if [ -z "$JAVACMD" ] ; then if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/bin/java" ] ; then JAVACMD="$JAVA_HOME/jre/bin/java" else JAVACMD="$JAVA_HOME/bin/java" fi else JAVACMD=`which java 2> /dev/null ` if [ -z "$JAVACMD" ] ; then JAVACMD=java fi fi fi if test -z "$JAVACMD"; then echo "$0: cannot find the Java VM executable" >&2 exit 1 fi if [ ! -x "$JAVACMD" ] ; then echo "Error: JAVA_HOME is not defined correctly." echo " We cannot execute $JAVACMD" exit 1 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 ################################# # TODO: rewrite the stuff below # # using build-classpath # ################################# LOCALCLASSPATH= ## AddToLocalClasspath # Adds the list of specified names # to the LOCALCLASSPATH environment variable. # Names can be absolute or relative; if a relative name is specified, it is # prefixed with the system Java library directory. # Only the names that exist as files or directories will # be added. # AddToLocalClasspath() { local javalibdir=/usr/share/java local p for p in "$@"; do case "$p" in /*) ;; *) p=$javalibdir/$p ;; esac if [ ! -e "$p" ]; then continue fi if [ -n "$LOCALCLASSPATH" ]; then LOCALCLASSPATH=$LOCALCLASSPATH:$p else LOCALCLASSPATH=$p export LOCALCLASSPATH fi done } JAVALIBDIR=/usr/share/java AddToLocalClasspath \ "$ANT_LIB"/ant.jar \ "$ANT_LIB"/ant-launcher.jar \ "$JAVALIBDIR"/jaxp_parser_impl.jar \ "$JAVALIBDIR"/xml-commons-apis.jar \ "$JAVALIBDIR"/sun-mail/mailapi.jar \ "$JAVALIBDIR"/sun-mail/smtp.jar \ "$JAVALIBDIR"/junit.jar if [ -n "$JAVA_HOME" ] ; then AddToLocalClasspath "$JAVA_HOME"/lib/tools.jar else echo "Error: JAVA_HOME is not defined correctly." >&2 echo " We cannot execute java" >&2 exit 1 fi # Build local classpath using just the launcher in non-rpm mode or # use the Jpackage helper in rpm mode with basic and default jars # specified in the ant.conf configuration. Because the launcher is # used, libraries linked in ANT_HOME/lib will also be included, but this # is discouraged as it is not java-version safe. A user should # request optional jars and their dependencies via the OPT_JAR_LIST # variable if $rpm_mode && [ -x /usr/bin/build-classpath ] ; then # hack above; already set # LOCALCLASSPATH="$(/usr/bin/build-classpath ant ant-launcher jaxp_parser_impl xml-commons-apis)" # If no optional jars have been specified then build the default list if [ -z "$OPT_JAR_LIST" ] ; then for file in /etc/ant.d/*; do if [ -f "$file" ]; then case "$file" in *~) ;; *#*) ;; *.rpmsave) ;; *.rpmnew) ;; *) for dep in `cat "$file"`; do case "$OPT_JAR_LIST" in *"$dep"*) ;; *) OPT_JAR_LIST="$OPT_JAR_LIST${OPT_JAR_LIST:+ }$dep" esac done esac fi done fi # If the user requested to try to add some other jars to the classpath if [ -n "$OPT_JAR_LIST" ] ; then _OPTCLASSPATH="$(/usr/bin/build-classpath $OPT_JAR_LIST 2> /dev/null)" if [ -n "$_OPTCLASSPATH" ] ; then LOCALCLASSPATH="$LOCALCLASSPATH:$_OPTCLASSPATH" fi fi # Explicitly add javac path to classpath, assume JAVA_HOME set # properly in rpm mode if [ -f "$JAVA_HOME/lib/tools.jar" ] ; then LOCALCLASSPATH="$LOCALCLASSPATH:$JAVA_HOME/lib/tools.jar" fi if [ -f "$JAVA_HOME/lib/classes.zip" ] ; then LOCALCLASSPATH="$LOCALCLASSPATH:$JAVA_HOME/lib/classes.zip" fi # if CLASSPATH_OVERRIDE env var is set, LOCALCLASSPATH will be # user CLASSPATH first and ant-found jars after. # In that case, the user CLASSPATH will override ant-found jars # # if CLASSPATH_OVERRIDE is not set, we'll have the normal behaviour # with ant-found jars first and user CLASSPATH after if [ -n "$CLASSPATH" ] ; then # merge local and specified classpath if [ -z "$LOCALCLASSPATH" ] ; then LOCALCLASSPATH="$CLASSPATH" elif [ -n "$CLASSPATH_OVERRIDE" ] ; then LOCALCLASSPATH="$CLASSPATH:$LOCALCLASSPATH" else LOCALCLASSPATH="$LOCALCLASSPATH:$CLASSPATH" fi # remove class path from launcher -cp option CLASSPATH="" fi else # not using rpm_mode; use launcher to determine classpaths if [ -z "$LOCALCLASSPATH" ] ; then LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar else LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar:$LOCALCLASSPATH fi 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 # Show script help if requested if $show_help ; then echo $0 '[script options] [options] [target [target2 [target3] ..]]' echo 'Script Options:' echo ' --help, --h print this message and ant help' echo ' --noconfig suppress sourcing of /etc/ant.conf,' echo ' $HOME/.ant/ant.conf, and $HOME/.antrc' echo ' configuration files' echo ' --usejikes enable use of jikes by default, unless' echo ' set explicitly in configuration files' echo ' --execdebug print ant exec line generated by this' echo ' launch script' echo ' ' fi # Execute ant using eval/exec to preserve spaces in paths, # java options, and ant args ant_sys_opts= ant_exec_command="exec \"$JAVACMD\" $ANT_OPTS -classpath \"$LOCALCLASSPATH\" -Dant.home=\"$ANT_HOME\" -Dant.library.dir=\"$ANT_LIB\" $ant_sys_opts org.apache.tools.ant.launch.Launcher $ANT_ARGS -cp \"$CLASSPATH\" $ant_exec_args" if $ant_exec_debug ; then echo $ant_exec_command fi #eval $ant_exec_command # let us use Misha Zabaluev variant below before we will be sure export CLASSPATH="$LOCALCLASSPATH"; exec "$JAVACMD" -Dant.home="$ANT_HOME" $ANT_OPTS \ org.apache.tools.ant.launch.Launcher $ANT_ARGS -lib "$LIBCLASSPATH" "$@"