|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +# ----------------------------------------------------------------------------- |
| 21 | +# Apache Maven Startup Script |
| 22 | +# |
| 23 | +# Environment Variable Prerequisites |
| 24 | +# |
| 25 | +# JAVA_HOME (Optional) Points to a Java installation. |
| 26 | +# MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments. |
| 27 | +# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed. |
| 28 | +# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files. |
| 29 | +# ----------------------------------------------------------------------------- |
| 30 | + |
| 31 | +if [ -z "$MAVEN_SKIP_RC" ] ; then |
| 32 | + |
| 33 | + if [ -f /usr/local/etc/mavenrc ] ; then |
| 34 | + . /usr/local/etc/mavenrc |
| 35 | + fi |
| 36 | + |
| 37 | + if [ -f /etc/mavenrc ] ; then |
| 38 | + . /etc/mavenrc |
| 39 | + fi |
| 40 | + |
| 41 | + if [ -f "$HOME/.mavenrc" ] ; then |
| 42 | + . "$HOME/.mavenrc" |
| 43 | + fi |
| 44 | + |
| 45 | +fi |
| 46 | + |
| 47 | +# OS specific support. $var _must_ be set to either true or false. |
| 48 | +cygwin=false; |
| 49 | +mingw=false; |
| 50 | +case "`uname`" in |
| 51 | + CYGWIN*) cygwin=true;; |
| 52 | + MINGW*) mingw=true;; |
| 53 | +esac |
| 54 | + |
| 55 | +## resolve links - $0 may be a link to Maven's home |
| 56 | +PRG="$0" |
| 57 | + |
| 58 | +# need this for relative symlinks |
| 59 | +while [ -h "$PRG" ] ; do |
| 60 | + ls=`ls -ld "$PRG"` |
| 61 | + link=`expr "$ls" : '.*-> \(.*\)$'` |
| 62 | + if expr "$link" : '/.*' > /dev/null; then |
| 63 | + PRG="$link" |
| 64 | + else |
| 65 | + PRG="`dirname "$PRG"`/$link" |
| 66 | + fi |
| 67 | +done |
| 68 | + |
| 69 | +saveddir=`pwd` |
| 70 | + |
| 71 | +MAVEN_HOME=`dirname "$PRG"`/.. |
| 72 | + |
| 73 | +# make it fully qualified |
| 74 | +MAVEN_HOME=`cd "$MAVEN_HOME" && pwd` |
| 75 | + |
| 76 | +cd "$saveddir" |
| 77 | + |
| 78 | +CLASSWORLDS_CONF="$MAVEN_HOME/bin/m2.conf" |
| 79 | + |
| 80 | +# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched |
| 81 | +if $cygwin || $mingw ; then |
| 82 | + [ -n "$JAVA_HOME" ] && |
| 83 | + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` |
| 84 | +fi |
| 85 | + |
| 86 | +if [ -n "$JAVA_HOME" ] ; then |
| 87 | + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then |
| 88 | + # IBM's JDK on AIX uses strange locations for the executables |
| 89 | + JAVACMD="$JAVA_HOME/jre/sh/java" |
| 90 | + else |
| 91 | + JAVACMD="$JAVA_HOME/bin/java" |
| 92 | + |
| 93 | + if [ ! -x "$JAVACMD" ] ; then |
| 94 | + echo "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started." >&2 |
| 95 | + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" does not exist." >&2 |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + fi |
| 99 | +else |
| 100 | + JAVACMD="`\\unset -f command; \\command -v java`" |
| 101 | + |
| 102 | + if [ ! -x "$JAVACMD" ] ; then |
| 103 | + echo "The java(1) command does not exist in PATH nor is JAVA_HOME set, so Apache Maven cannot be started." >&2 |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | +fi |
| 107 | + |
| 108 | +# traverses directory structure from process work directory to filesystem root |
| 109 | +# first directory with .mvn subdirectory is considered project base directory |
| 110 | +find_maven_basedir() { |
| 111 | +( |
| 112 | + basedir=`find_file_argument_basedir "$@"` |
| 113 | + wdir="$basedir" |
| 114 | + while : |
| 115 | + do |
| 116 | + if [ -d "$wdir"/.mvn ] ; then |
| 117 | + basedir=$wdir |
| 118 | + break |
| 119 | + fi |
| 120 | + if [ "$wdir" = '/' ] ; then |
| 121 | + break |
| 122 | + fi |
| 123 | + wdir=`cd "$wdir/.."; pwd` |
| 124 | + done |
| 125 | + echo "$basedir" |
| 126 | +) |
| 127 | +} |
| 128 | + |
| 129 | +find_file_argument_basedir() { |
| 130 | +( |
| 131 | + basedir=`pwd` |
| 132 | + |
| 133 | + found_file_switch=0 |
| 134 | + for arg in "$@"; do |
| 135 | + if [ ${found_file_switch} -eq 1 ]; then |
| 136 | + if [ -d "${arg}" ]; then |
| 137 | + basedir=`cd "${arg}" && pwd -P` |
| 138 | + elif [ -f "${arg}" ]; then |
| 139 | + basedir=`dirname "${arg}"` |
| 140 | + basedir=`cd "$basedir" && pwd -P` |
| 141 | + if [ ! -d "$basedir" ]; then |
| 142 | + echo "Directory $basedir extracted from the -f/--file command-line argument ${arg} does not exist" >&2 |
| 143 | + exit 1 |
| 144 | + fi |
| 145 | + else |
| 146 | + echo "POM file ${arg} specified with the -f/--file command line argument does not exist" >&2 |
| 147 | + exit 1 |
| 148 | + fi |
| 149 | + break |
| 150 | + fi |
| 151 | + if [ "$arg" = "-f" -o "$arg" = "--file" ]; then |
| 152 | + found_file_switch=1 |
| 153 | + fi |
| 154 | + done |
| 155 | + echo "$basedir" |
| 156 | +) |
| 157 | +} |
| 158 | + |
| 159 | +# concatenates all lines of a file |
| 160 | +concat_lines() { |
| 161 | + if [ -f "$1" ]; then |
| 162 | + echo "`tr -s '\r\n' ' ' < "$1"`" |
| 163 | + fi |
| 164 | +} |
| 165 | + |
| 166 | +MAVEN_PROJECTBASEDIR="`find_maven_basedir "$@"`" |
| 167 | +MAVEN_OPTS="$MAVEN_OPTS `concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"`" |
| 168 | +LAUNCHER_JAR=`echo "$MAVEN_HOME"/boot/plexus-classworlds-*.jar` |
| 169 | +LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher |
| 170 | + |
| 171 | +# For Cygwin and MinGW, switch paths to Windows format before running java(1) command |
| 172 | +if $cygwin || $mingw ; then |
| 173 | + [ -n "$JAVA_HOME" ] && |
| 174 | + JAVA_HOME=`cygpath --windows "$JAVA_HOME"` |
| 175 | + LAUNCHER_JAR=`cygpath --windows "$LAUNCHER_JAR"` |
| 176 | + CLASSWORLDS_CONF=`cygpath --windows "$CLASSWORLDS_CONF"` |
| 177 | + MAVEN_HOME=`cygpath --windows "$MAVEN_HOME"` |
| 178 | + MAVEN_PROJECTBASEDIR=`cygpath --windows "$MAVEN_PROJECTBASEDIR"` |
| 179 | +fi |
| 180 | + |
| 181 | +exec "$JAVACMD" \ |
| 182 | + $MAVEN_OPTS \ |
| 183 | + $MAVEN_DEBUG_OPTS \ |
| 184 | + --enable-native-access=ALL-UNNAMED \ |
| 185 | + -classpath "$LAUNCHER_JAR" \ |
| 186 | + "-Dclassworlds.conf=$CLASSWORLDS_CONF" \ |
| 187 | + "-Dmaven.home=$MAVEN_HOME" \ |
| 188 | + "-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \ |
| 189 | + "-Dmaven.multiModuleProjectDirectory=$MAVEN_PROJECTBASEDIR" \ |
| 190 | + $LAUNCHER_CLASS \ |
| 191 | + $MAVEN_ARGS \ |
| 192 | + "$@" |
0 commit comments