mvnw 9.9 KB

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