123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. # Maven2 Start Up Batch script
  22. #
  23. # Required ENV vars:
  24. # ------------------
  25. # JAVA_HOME - location of a JDK home dir
  26. #
  27. # Optional ENV vars
  28. # -----------------
  29. # M2_HOME - location of maven2's installed home dir
  30. # MAVEN_OPTS - parameters passed to the Java VM when running Maven
  31. # e.g. to debug Maven itself, use
  32. # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
  33. # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
  34. # ----------------------------------------------------------------------------
  35. if [ -z "$MAVEN_SKIP_RC" ] ; then
  36. if [ -f /etc/mavenrc ] ; then
  37. . /etc/mavenrc
  38. fi
  39. if [ -f "$HOME/.mavenrc" ] ; then
  40. . "$HOME/.mavenrc"
  41. fi
  42. fi
  43. # OS specific support. $var _must_ be set to either true or false.
  44. cygwin=false;
  45. darwin=false;
  46. mingw=false
  47. case "`uname`" in
  48. CYGWIN*) cygwin=true ;;
  49. MINGW*) mingw=true;;
  50. Darwin*) darwin=true
  51. # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
  52. # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
  53. if [ -z "$JAVA_HOME" ]; then
  54. if [ -x "/usr/libexec/java_home" ]; then
  55. export JAVA_HOME="`/usr/libexec/java_home`"
  56. else
  57. export JAVA_HOME="/Library/Java/Home"
  58. fi
  59. fi
  60. ;;
  61. esac
  62. if [ -z "$JAVA_HOME" ] ; then
  63. if [ -r /etc/gentoo-release ] ; then
  64. JAVA_HOME=`java-config --jre-home`
  65. fi
  66. fi
  67. if [ -z "$M2_HOME" ] ; then
  68. ## resolve links - $0 may be a link to maven's home
  69. PRG="$0"
  70. # need this for relative symlinks
  71. while [ -h "$PRG" ] ; do
  72. ls=`ls -ld "$PRG"`
  73. link=`expr "$ls" : '.*-> \(.*\)$'`
  74. if expr "$link" : '/.*' > /dev/null; then
  75. PRG="$link"
  76. else
  77. PRG="`dirname "$PRG"`/$link"
  78. fi
  79. done
  80. saveddir=`pwd`
  81. M2_HOME=`dirname "$PRG"`/..
  82. # make it fully qualified
  83. M2_HOME=`cd "$M2_HOME" && pwd`
  84. cd "$saveddir"
  85. # echo Using m2 at $M2_HOME
  86. fi
  87. # For Cygwin, ensure paths are in UNIX format before anything is touched
  88. if $cygwin ; then
  89. [ -n "$M2_HOME" ] &&
  90. M2_HOME=`cygpath --unix "$M2_HOME"`
  91. [ -n "$JAVA_HOME" ] &&
  92. JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  93. [ -n "$CLASSPATH" ] &&
  94. CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  95. fi
  96. # For Mingw, ensure paths are in UNIX format before anything is touched
  97. if $mingw ; then
  98. [ -n "$M2_HOME" ] &&
  99. M2_HOME="`(cd "$M2_HOME"; pwd)`"
  100. [ -n "$JAVA_HOME" ] &&
  101. JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
  102. # TODO classpath?
  103. fi
  104. if [ -z "$JAVA_HOME" ]; then
  105. javaExecutable="`which javac`"
  106. if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
  107. # readlink(1) is not available as standard on Solaris 10.
  108. readLink=`which readlink`
  109. if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
  110. if $darwin ; then
  111. javaHome="`dirname \"$javaExecutable\"`"
  112. javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
  113. else
  114. javaExecutable="`readlink -f \"$javaExecutable\"`"
  115. fi
  116. javaHome="`dirname \"$javaExecutable\"`"
  117. javaHome=`expr "$javaHome" : '\(.*\)/bin'`
  118. JAVA_HOME="$javaHome"
  119. export JAVA_HOME
  120. fi
  121. fi
  122. fi
  123. if [ -z "$JAVACMD" ] ; then
  124. if [ -n "$JAVA_HOME" ] ; then
  125. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  126. # IBM's JDK on AIX uses strange locations for the executables
  127. JAVACMD="$JAVA_HOME/jre/sh/java"
  128. else
  129. JAVACMD="$JAVA_HOME/bin/java"
  130. fi
  131. else
  132. JAVACMD="`which java`"
  133. fi
  134. fi
  135. if [ ! -x "$JAVACMD" ] ; then
  136. echo "Error: JAVA_HOME is not defined correctly." >&2
  137. echo " We cannot execute $JAVACMD" >&2
  138. exit 1
  139. fi
  140. if [ -z "$JAVA_HOME" ] ; then
  141. echo "Warning: JAVA_HOME environment variable is not set."
  142. fi
  143. CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
  144. # traverses directory structure from process work directory to filesystem root
  145. # first directory with .mvn subdirectory is considered project base directory
  146. find_maven_basedir() {
  147. if [ -z "$1" ]
  148. then
  149. echo "Path not specified to find_maven_basedir"
  150. return 1
  151. fi
  152. basedir="$1"
  153. wdir="$1"
  154. while [ "$wdir" != '/' ] ; do
  155. if [ -d "$wdir"/.mvn ] ; then
  156. basedir=$wdir
  157. break
  158. fi
  159. # workaround for JBEAP-8937 (on Solaris 10/Sparc)
  160. if [ -d "${wdir}" ]; then
  161. wdir=`cd "$wdir/.."; pwd`
  162. fi
  163. # end of workaround
  164. done
  165. echo "${basedir}"
  166. }
  167. # concatenates all lines of a file
  168. concat_lines() {
  169. if [ -f "$1" ]; then
  170. echo "$(tr -s '\n' ' ' < "$1")"
  171. fi
  172. }
  173. BASE_DIR=`find_maven_basedir "$(pwd)"`
  174. if [ -z "$BASE_DIR" ]; then
  175. exit 1;
  176. fi
  177. ##########################################################################################
  178. # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
  179. # This allows using the maven wrapper in projects that prohibit checking in binary data.
  180. ##########################################################################################
  181. if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
  182. if [ "$MVNW_VERBOSE" = true ]; then
  183. echo "Found .mvn/wrapper/maven-wrapper.jar"
  184. fi
  185. else
  186. if [ "$MVNW_VERBOSE" = true ]; then
  187. echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
  188. fi
  189. jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
  190. while IFS="=" read key value; do
  191. case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
  192. esac
  193. done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
  194. if [ "$MVNW_VERBOSE" = true ]; then
  195. echo "Downloading from: $jarUrl"
  196. fi
  197. wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
  198. if command -v wget > /dev/null; then
  199. if [ "$MVNW_VERBOSE" = true ]; then
  200. echo "Found wget ... using wget"
  201. fi
  202. wget "$jarUrl" -O "$wrapperJarPath"
  203. elif command -v curl > /dev/null; then
  204. if [ "$MVNW_VERBOSE" = true ]; then
  205. echo "Found curl ... using curl"
  206. fi
  207. curl -o "$wrapperJarPath" "$jarUrl"
  208. else
  209. if [ "$MVNW_VERBOSE" = true ]; then
  210. echo "Falling back to using Java to download"
  211. fi
  212. javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
  213. if [ -e "$javaClass" ]; then
  214. if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
  215. if [ "$MVNW_VERBOSE" = true ]; then
  216. echo " - Compiling MavenWrapperDownloader.java ..."
  217. fi
  218. # Compiling the Java class
  219. ("$JAVA_HOME/bin/javac" "$javaClass")
  220. fi
  221. if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
  222. # Running the downloader
  223. if [ "$MVNW_VERBOSE" = true ]; then
  224. echo " - Running MavenWrapperDownloader.java ..."
  225. fi
  226. ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
  227. fi
  228. fi
  229. fi
  230. fi
  231. ##########################################################################################
  232. # End of extension
  233. ##########################################################################################
  234. export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
  235. if [ "$MVNW_VERBOSE" = true ]; then
  236. echo $MAVEN_PROJECTBASEDIR
  237. fi
  238. MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
  239. # For Cygwin, switch paths to Windows format before running java
  240. if $cygwin; then
  241. [ -n "$M2_HOME" ] &&
  242. M2_HOME=`cygpath --path --windows "$M2_HOME"`
  243. [ -n "$JAVA_HOME" ] &&
  244. JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  245. [ -n "$CLASSPATH" ] &&
  246. CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  247. [ -n "$MAVEN_PROJECTBASEDIR" ] &&
  248. MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
  249. fi
  250. WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
  251. exec "$JAVACMD" \
  252. $MAVEN_OPTS \
  253. -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
  254. "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
  255. ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"