File indexing completed on 2022-11-29 15:38:19

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 Mingw, 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 ##########################################################################################
0204 # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
0205 # This allows using the maven wrapper in projects that prohibit checking in binary data.
0206 ##########################################################################################
0207 if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
0208     if [ "$MVNW_VERBOSE" = true ]; then
0209       echo "Found .mvn/wrapper/maven-wrapper.jar"
0210     fi
0211 else
0212     if [ "$MVNW_VERBOSE" = true ]; then
0213       echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
0214     fi
0215     jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
0216     while IFS="=" read key value; do
0217       case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
0218       esac
0219     done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
0220     if [ "$MVNW_VERBOSE" = true ]; then
0221       echo "Downloading from: $jarUrl"
0222     fi
0223     wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
0224 
0225     if command -v wget > /dev/null; then
0226         if [ "$MVNW_VERBOSE" = true ]; then
0227           echo "Found wget ... using wget"
0228         fi
0229         wget "$jarUrl" -O "$wrapperJarPath"
0230     elif command -v curl > /dev/null; then
0231         if [ "$MVNW_VERBOSE" = true ]; then
0232           echo "Found curl ... using curl"
0233         fi
0234         curl -o "$wrapperJarPath" "$jarUrl"
0235     else
0236         if [ "$MVNW_VERBOSE" = true ]; then
0237           echo "Falling back to using Java to download"
0238         fi
0239         javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
0240         if [ -e "$javaClass" ]; then
0241             if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
0242                 if [ "$MVNW_VERBOSE" = true ]; then
0243                   echo " - Compiling MavenWrapperDownloader.java ..."
0244                 fi
0245                 # Compiling the Java class
0246                 ("$JAVA_HOME/bin/javac" "$javaClass")
0247             fi
0248             if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
0249                 # Running the downloader
0250                 if [ "$MVNW_VERBOSE" = true ]; then
0251                   echo " - Running MavenWrapperDownloader.java ..."
0252                 fi
0253                 ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
0254             fi
0255         fi
0256     fi
0257 fi
0258 ##########################################################################################
0259 # End of extension
0260 ##########################################################################################
0261 
0262 export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
0263 if [ "$MVNW_VERBOSE" = true ]; then
0264   echo $MAVEN_PROJECTBASEDIR
0265 fi
0266 MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
0267 
0268 # For Cygwin, switch paths to Windows format before running java
0269 if $cygwin; then
0270   [ -n "$M2_HOME" ] &&
0271     M2_HOME=`cygpath --path --windows "$M2_HOME"`
0272   [ -n "$JAVA_HOME" ] &&
0273     JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
0274   [ -n "$CLASSPATH" ] &&
0275     CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
0276   [ -n "$MAVEN_PROJECTBASEDIR" ] &&
0277     MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
0278 fi
0279 
0280 WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
0281 
0282 exec "$JAVACMD" \
0283   $MAVEN_OPTS \
0284   -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
0285   "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
0286   ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"