mvnw 9.6 KB

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. # Apache Maven Wrapper startup batch script, version 3.1.1
  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" ] &&
  79. JAVA_HOME="`(cd "$JAVA_HOME"; 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; \\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/.."; pwd`
  138. fi
  139. # end of workaround
  140. done
  141. printf '%s' "$(cd "$basedir"; pwd)"
  142. }
  143. # concatenates all lines of a file
  144. concat_lines() {
  145. if [ -f "$1" ]; then
  146. echo "$(tr -s '\n' ' ' < "$1")"
  147. fi
  148. }
  149. BASE_DIR=$(find_maven_basedir "$(dirname $0)")
  150. if [ -z "$BASE_DIR" ]; then
  151. exit 1;
  152. fi
  153. MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
  154. if [ "$MVNW_VERBOSE" = true ]; then
  155. echo $MAVEN_PROJECTBASEDIR
  156. fi
  157. ##########################################################################################
  158. # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
  159. # This allows using the maven wrapper in projects that prohibit checking in binary data.
  160. ##########################################################################################
  161. if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
  162. if [ "$MVNW_VERBOSE" = true ]; then
  163. echo "Found .mvn/wrapper/maven-wrapper.jar"
  164. fi
  165. else
  166. if [ "$MVNW_VERBOSE" = true ]; then
  167. echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
  168. fi
  169. if [ -n "$MVNW_REPOURL" ]; then
  170. wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
  171. else
  172. wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
  173. fi
  174. while IFS="=" read key value; do
  175. case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;;
  176. esac
  177. done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
  178. if [ "$MVNW_VERBOSE" = true ]; then
  179. echo "Downloading from: $wrapperUrl"
  180. fi
  181. wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
  182. if $cygwin; then
  183. wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
  184. fi
  185. if command -v wget > /dev/null; then
  186. QUIET="--quiet"
  187. if [ "$MVNW_VERBOSE" = true ]; then
  188. echo "Found wget ... using wget"
  189. QUIET=""
  190. fi
  191. if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
  192. wget $QUIET "$wrapperUrl" -O "$wrapperJarPath"
  193. else
  194. wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath"
  195. fi
  196. [ $? -eq 0 ] || rm -f "$wrapperJarPath"
  197. elif command -v curl > /dev/null; then
  198. QUIET="--silent"
  199. if [ "$MVNW_VERBOSE" = true ]; then
  200. echo "Found curl ... using curl"
  201. QUIET=""
  202. fi
  203. if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
  204. curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L
  205. else
  206. curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L
  207. fi
  208. [ $? -eq 0 ] || rm -f "$wrapperJarPath"
  209. else
  210. if [ "$MVNW_VERBOSE" = true ]; then
  211. echo "Falling back to using Java to download"
  212. fi
  213. javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
  214. javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class"
  215. # For Cygwin, switch paths to Windows format before running javac
  216. if $cygwin; then
  217. javaSource=`cygpath --path --windows "$javaSource"`
  218. javaClass=`cygpath --path --windows "$javaClass"`
  219. fi
  220. if [ -e "$javaSource" ]; then
  221. if [ ! -e "$javaClass" ]; then
  222. if [ "$MVNW_VERBOSE" = true ]; then
  223. echo " - Compiling MavenWrapperDownloader.java ..."
  224. fi
  225. # Compiling the Java class
  226. ("$JAVA_HOME/bin/javac" "$javaSource")
  227. fi
  228. if [ -e "$javaClass" ]; then
  229. # Running the downloader
  230. if [ "$MVNW_VERBOSE" = true ]; then
  231. echo " - Running MavenWrapperDownloader.java ..."
  232. fi
  233. ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
  234. fi
  235. fi
  236. fi
  237. fi
  238. ##########################################################################################
  239. # End of extension
  240. ##########################################################################################
  241. MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
  242. # For Cygwin, switch paths to Windows format before running java
  243. if $cygwin; then
  244. [ -n "$JAVA_HOME" ] &&
  245. JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  246. [ -n "$CLASSPATH" ] &&
  247. CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  248. [ -n "$MAVEN_PROJECTBASEDIR" ] &&
  249. MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
  250. fi
  251. # Provide a "standardized" way to retrieve the CLI args that will
  252. # work with both Windows and non-Windows executions.
  253. MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
  254. export MAVEN_CMD_LINE_ARGS
  255. WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
  256. exec "$JAVACMD" \
  257. $MAVEN_OPTS \
  258. $MAVEN_DEBUG_OPTS \
  259. -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
  260. "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
  261. ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"