File indexing completed on 2023-09-24 06:16:23

0001 #!/bin/sh
0002 # ----------------------------------------------------------------------------
0003 # Licensed to the Apache Software Foundation (ASF) under one
0004 # or more contributor license agreements.  See the NOTICE file
0005 # distributed with this work for additional information
0006 # regarding copyright ownership.  The ASF licenses this file
0007 # to you under the Apache License, Version 2.0 (the
0008 # "License"); you may not use this file except in compliance
0009 # with the License.  You may obtain a copy of the License at
0010 #
0011 #    http://www.apache.org/licenses/LICENSE-2.0
0012 #
0013 # Unless required by applicable law or agreed to in writing,
0014 # software distributed under the License is distributed on an
0015 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0016 # KIND, either express or implied.  See the License for the
0017 # specific language governing permissions and limitations
0018 # under the License.
0019 # ----------------------------------------------------------------------------
0020 
0021 # ----------------------------------------------------------------------------
0022 # Maven2 Start Up Batch script
0023 #
0024 # Required ENV vars:
0025 # ------------------
0026 #   JAVA_HOME - location of a JDK home dir
0027 #
0028 # Optional ENV vars
0029 # -----------------
0030 #   M2_HOME - location of maven2's installed home dir
0031 #   MAVEN_OPTS - parameters passed to the Java VM when running Maven
0032 #     e.g. to debug Maven itself, use
0033 #       set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
0034 #   MAVEN_SKIP_RC - flag to disable loading of mavenrc files
0035 # ----------------------------------------------------------------------------
0036 
0037 if [ -z "$MAVEN_SKIP_RC" ] ; then
0038 
0039   if [ -f /etc/mavenrc ] ; then
0040     . /etc/mavenrc
0041   fi
0042 
0043   if [ -f "$HOME/.mavenrc" ] ; then
0044     . "$HOME/.mavenrc"
0045   fi
0046 
0047 fi
0048 
0049 # OS specific support.  $var _must_ be set to either true or false.
0050 cygwin=false;
0051 darwin=false;
0052 mingw=false
0053 case "`uname`" in
0054   CYGWIN*) cygwin=true ;;
0055   MINGW*) mingw=true;;
0056   Darwin*) darwin=true
0057     # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
0058     # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
0059     if [ -z "$JAVA_HOME" ]; then
0060       if [ -x "/usr/libexec/java_home" ]; then
0061         export JAVA_HOME="`/usr/libexec/java_home`"
0062       else
0063         export JAVA_HOME="/Library/Java/Home"
0064       fi
0065     fi
0066     ;;
0067 esac
0068 
0069 if [ -z "$JAVA_HOME" ] ; then
0070   if [ -r /etc/gentoo-release ] ; then
0071     JAVA_HOME=`java-config --jre-home`
0072   fi
0073 fi
0074 
0075 if [ -z "$M2_HOME" ] ; then
0076   ## resolve links - $0 may be a link to maven's home
0077   PRG="$0"
0078 
0079   # need this for relative symlinks
0080   while [ -h "$PRG" ] ; do
0081     ls=`ls -ld "$PRG"`
0082     link=`expr "$ls" : '.*-> \(.*\)$'`
0083     if expr "$link" : '/.*' > /dev/null; then
0084       PRG="$link"
0085     else
0086       PRG="`dirname "$PRG"`/$link"
0087     fi
0088   done
0089 
0090   saveddir=`pwd`
0091 
0092   M2_HOME=`dirname "$PRG"`/..
0093 
0094   # make it fully qualified
0095   M2_HOME=`cd "$M2_HOME" && pwd`
0096 
0097   cd "$saveddir"
0098   # echo Using m2 at $M2_HOME
0099 fi
0100 
0101 # For Cygwin, ensure paths are in UNIX format before anything is touched
0102 if $cygwin ; then
0103   [ -n "$M2_HOME" ] &&
0104     M2_HOME=`cygpath --unix "$M2_HOME"`
0105   [ -n "$JAVA_HOME" ] &&
0106     JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
0107   [ -n "$CLASSPATH" ] &&
0108     CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
0109 fi
0110 
0111 # For Migwn, ensure paths are in UNIX format before anything is touched
0112 if $mingw ; then
0113   [ -n "$M2_HOME" ] &&
0114     M2_HOME="`(cd "$M2_HOME"; pwd)`"
0115   [ -n "$JAVA_HOME" ] &&
0116     JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
0117   # TODO classpath?
0118 fi
0119 
0120 if [ -z "$JAVA_HOME" ]; then
0121   javaExecutable="`which javac`"
0122   if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
0123     # readlink(1) is not available as standard on Solaris 10.
0124     readLink=`which readlink`
0125     if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
0126       if $darwin ; then
0127         javaHome="`dirname \"$javaExecutable\"`"
0128         javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
0129       else
0130         javaExecutable="`readlink -f \"$javaExecutable\"`"
0131       fi
0132       javaHome="`dirname \"$javaExecutable\"`"
0133       javaHome=`expr "$javaHome" : '\(.*\)/bin'`
0134       JAVA_HOME="$javaHome"
0135       export JAVA_HOME
0136     fi
0137   fi
0138 fi
0139 
0140 if [ -z "$JAVACMD" ] ; then
0141   if [ -n "$JAVA_HOME"  ] ; then
0142     if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
0143       # IBM's JDK on AIX uses strange locations for the executables
0144       JAVACMD="$JAVA_HOME/jre/sh/java"
0145     else
0146       JAVACMD="$JAVA_HOME/bin/java"
0147     fi
0148   else
0149     JAVACMD="`which java`"
0150   fi
0151 fi
0152 
0153 if [ ! -x "$JAVACMD" ] ; then
0154   echo "Error: JAVA_HOME is not defined correctly." >&2
0155   echo "  We cannot execute $JAVACMD" >&2
0156   exit 1
0157 fi
0158 
0159 if [ -z "$JAVA_HOME" ] ; then
0160   echo "Warning: JAVA_HOME environment variable is not set."
0161 fi
0162 
0163 CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
0164 
0165 # traverses directory structure from process work directory to filesystem root
0166 # first directory with .mvn subdirectory is considered project base directory
0167 find_maven_basedir() {
0168 
0169   if [ -z "$1" ]
0170   then
0171     echo "Path not specified to find_maven_basedir"
0172     return 1
0173   fi
0174 
0175   basedir="$1"
0176   wdir="$1"
0177   while [ "$wdir" != '/' ] ; do
0178     if [ -d "$wdir"/.mvn ] ; then
0179       basedir=$wdir
0180       break
0181     fi
0182     # workaround for JBEAP-8937 (on Solaris 10/Sparc)
0183     if [ -d "${wdir}" ]; then
0184       wdir=`cd "$wdir/.."; pwd`
0185     fi
0186     # end of workaround
0187   done
0188   echo "${basedir}"
0189 }
0190 
0191 # concatenates all lines of a file
0192 concat_lines() {
0193   if [ -f "$1" ]; then
0194     echo "$(tr -s '\n' ' ' < "$1")"
0195   fi
0196 }
0197 
0198 BASE_DIR=`find_maven_basedir "$(pwd)"`
0199 if [ -z "$BASE_DIR" ]; then
0200   exit 1;
0201 fi
0202 
0203 export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
0204 echo $MAVEN_PROJECTBASEDIR
0205 MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
0206 
0207 # For Cygwin, switch paths to Windows format before running java
0208 if $cygwin; then
0209   [ -n "$M2_HOME" ] &&
0210     M2_HOME=`cygpath --path --windows "$M2_HOME"`
0211   [ -n "$JAVA_HOME" ] &&
0212     JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
0213   [ -n "$CLASSPATH" ] &&
0214     CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
0215   [ -n "$MAVEN_PROJECTBASEDIR" ] &&
0216     MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
0217 fi
0218 
0219 WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
0220 
0221 exec "$JAVACMD" \
0222   $MAVEN_OPTS \
0223   -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
0224   "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
0225   ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"