mvnw 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. # Apache Maven Wrapper startup batch script, version 3.2.0
  22. #
  23. # Required ENV vars:
  24. # ------------------
  25. # JAVA_HOME - location of a JDK home dir
  26. #
  27. # Optional ENV vars
  28. # -----------------
  29. # MAVEN_OPTS - parameters passed to the Java VM when running Maven
  30. # e.g. to debug Maven itself, use
  31. # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
  32. # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
  33. # ----------------------------------------------------------------------------
  34. if [ -z "$MAVEN_SKIP_RC" ] ; then
  35. if [ -f /usr/local/etc/mavenrc ] ; then
  36. . /usr/local/etc/mavenrc
  37. fi
  38. if [ -f /etc/mavenrc ] ; then
  39. . /etc/mavenrc
  40. fi
  41. if [ -f "$HOME/.mavenrc" ] ; then
  42. . "$HOME/.mavenrc"
  43. fi
  44. fi
  45. # OS specific support. $var _must_ be set to either true or false.
  46. cygwin=false;
  47. darwin=false;
  48. mingw=false
  49. case "$(uname)" in
  50. CYGWIN*) cygwin=true ;;
  51. MINGW*) mingw=true;;
  52. Darwin*) darwin=true
  53. # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
  54. # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
  55. if [ -z "$JAVA_HOME" ]; then
  56. if [ -x "/usr/libexec/java_home" ]; then
  57. JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME
  58. else
  59. JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
  60. fi
  61. fi
  62. ;;
  63. esac
  64. if [ -z "$JAVA_HOME" ] ; then
  65. if [ -r /etc/gentoo-release ] ; then
  66. JAVA_HOME=$(java-config --jre-home)
  67. fi
  68. fi
  69. # For Cygwin, ensure paths are in UNIX format before anything is touched
  70. if $cygwin ; then
  71. [ -n "$JAVA_HOME" ] &&
  72. JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
  73. [ -n "$CLASSPATH" ] &&
  74. CLASSPATH=$(cygpath --path --unix "$CLASSPATH")
  75. fi
  76. # For Mingw, ensure paths are in UNIX format before anything is touched
  77. if $mingw ; then
  78. [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] &&
  79. JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)"
  80. fi
  81. if [ -z "$JAVA_HOME" ]; then
  82. javaExecutable="$(which javac)"
  83. if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then
  84. # readlink(1) is not available as standard on Solaris 10.
  85. readLink=$(which readlink)
  86. if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then
  87. if $darwin ; then
  88. javaHome="$(dirname "\"$javaExecutable\"")"
  89. javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac"
  90. else
  91. javaExecutable="$(readlink -f "\"$javaExecutable\"")"
  92. fi
  93. javaHome="$(dirname "\"$javaExecutable\"")"
  94. javaHome=$(expr "$javaHome" : '\(.*\)/bin')
  95. JAVA_HOME="$javaHome"
  96. export JAVA_HOME
  97. fi
  98. fi
  99. fi
  100. if [ -z "$JAVACMD" ] ; then
  101. if [ -n "$JAVA_HOME" ] ; then
  102. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  103. # IBM's JDK on AIX uses strange locations for the executables
  104. JAVACMD="$JAVA_HOME/jre/sh/java"
  105. else
  106. JAVACMD="$JAVA_HOME/bin/java"
  107. fi
  108. else
  109. JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)"
  110. fi
  111. fi
  112. if [ ! -x "$JAVACMD" ] ; then
  113. echo "Error: JAVA_HOME is not defined correctly." >&2
  114. echo " We cannot execute $JAVACMD" >&2
  115. exit 1
  116. fi
  117. if [ -z "$JAVA_HOME" ] ; then
  118. echo "Warning: JAVA_HOME environment variable is not set."
  119. fi
  120. # traverses directory structure from process work directory to filesystem root
  121. # first directory with .mvn subdirectory is considered project base directory
  122. find_maven_basedir() {
  123. if [ -z "$1" ]
  124. then
  125. echo "Path not specified to find_maven_basedir"
  126. return 1
  127. fi
  128. basedir="$1"
  129. wdir="$1"
  130. while [ "$wdir" != '/' ] ; do
  131. if [ -d "$wdir"/.mvn ] ; then
  132. basedir=$wdir
  133. break
  134. fi
  135. # workaround for JBEAP-8937 (on Solaris 10/Sparc)
  136. if [ -d "${wdir}" ]; then
  137. wdir=$(cd "$wdir/.." || exit 1; pwd)
  138. fi
  139. # end of workaround
  140. done
  141. printf '%s' "$(cd "$basedir" || exit 1; pwd)"
  142. }
  143. # concatenates all lines of a file
  144. concat_lines() {
  145. if [ -f "$1" ]; then
  146. # Remove \r in case we run on Windows within Git Bash
  147. # and check out the repository with auto CRLF management
  148. # enabled. Otherwise, we may read lines that are delimited with
  149. # \r\n and produce $'-Xarg\r' rather than -Xarg due to word
  150. # splitting rules.
  151. tr -s '\r\n' ' ' < "$1"
  152. fi
  153. }
  154. log() {
  155. if [ "$MVNW_VERBOSE" = true ]; then
  156. printf '%s\n' "$1"
  157. fi
  158. }
  159. BASE_DIR=$(find_maven_basedir "$(dirname "$0")")
  160. if [ -z "$BASE_DIR" ]; then
  161. exit 1;
  162. fi
  163. MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
  164. log "$MAVEN_PROJECTBASEDIR"
  165. ##########################################################################################
  166. # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
  167. # This allows using the maven wrapper in projects that prohibit checking in binary data.
  168. ##########################################################################################
  169. wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar"
  170. if [ -r "$wrapperJarPath" ]; then
  171. log "Found $wrapperJarPath"
  172. else
  173. log "Couldn't find $wrapperJarPath, downloading it ..."
  174. if [ -n "$MVNW_REPOURL" ]; then
  175. wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
  176. else
  177. wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
  178. fi
  179. while IFS="=" read -r key value; do
  180. # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' )
  181. safeValue=$(echo "$value" | tr -d '\r')
  182. case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;;
  183. esac
  184. done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
  185. log "Downloading from: $wrapperUrl"
  186. if $cygwin; then
  187. wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
  188. fi
  189. if command -v wget > /dev/null; then
  190. log "Found wget ... using wget"
  191. [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet"
  192. if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
  193. wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
  194. else
  195. wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
  196. fi
  197. elif command -v curl > /dev/null; then
  198. log "Found curl ... using curl"
  199. [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent"
  200. if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
  201. curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
  202. else
  203. curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
  204. fi
  205. else
  206. log "Falling back to using Java to download"
  207. javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java"
  208. javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class"
  209. # For Cygwin, switch paths to Windows format before running javac
  210. if $cygwin; then
  211. javaSource=$(cygpath --path --windows "$javaSource")
  212. javaClass=$(cygpath --path --windows "$javaClass")
  213. fi
  214. if [ -e "$javaSource" ]; then
  215. if [ ! -e "$javaClass" ]; then
  216. log " - Compiling MavenWrapperDownloader.java ..."
  217. ("$JAVA_HOME/bin/javac" "$javaSource")
  218. fi
  219. if [ -e "$javaClass" ]; then
  220. log " - Running MavenWrapperDownloader.java ..."
  221. ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath"
  222. fi
  223. fi
  224. fi
  225. fi
  226. ##########################################################################################
  227. # End of extension
  228. ##########################################################################################
  229. # If specified, validate the SHA-256 sum of the Maven wrapper jar file
  230. wrapperSha256Sum=""
  231. while IFS="=" read -r key value; do
  232. case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;;
  233. esac
  234. done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
  235. if [ -n "$wrapperSha256Sum" ]; then
  236. wrapperSha256Result=false
  237. if command -v sha256sum > /dev/null; then
  238. if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then
  239. wrapperSha256Result=true
  240. fi
  241. elif command -v shasum > /dev/null; then
  242. if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then
  243. wrapperSha256Result=true
  244. fi
  245. else
  246. echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available."
  247. echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties."
  248. exit 1
  249. fi
  250. if [ $wrapperSha256Result = false ]; then
  251. echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2
  252. echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2
  253. echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2
  254. exit 1
  255. fi
  256. fi
  257. MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
  258. # For Cygwin, switch paths to Windows format before running java
  259. if $cygwin; then
  260. [ -n "$JAVA_HOME" ] &&
  261. JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME")
  262. [ -n "$CLASSPATH" ] &&
  263. CLASSPATH=$(cygpath --path --windows "$CLASSPATH")
  264. [ -n "$MAVEN_PROJECTBASEDIR" ] &&
  265. MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR")
  266. fi
  267. # Provide a "standardized" way to retrieve the CLI args that will
  268. # work with both Windows and non-Windows executions.
  269. MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*"
  270. export MAVEN_CMD_LINE_ARGS
  271. WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
  272. # shellcheck disable=SC2086 # safe args
  273. exec "$JAVACMD" \
  274. $MAVEN_OPTS \
  275. $MAVEN_DEBUG_OPTS \
  276. -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
  277. "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
  278. ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"