mvnw 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. fi
  103. if [ -z "$JAVA_HOME" ]; then
  104. javaExecutable="`which javac`"
  105. if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
  106. # readlink(1) is not available as standard on Solaris 10.
  107. readLink=`which readlink`
  108. if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
  109. if $darwin ; then
  110. javaHome="`dirname \"$javaExecutable\"`"
  111. javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
  112. else
  113. javaExecutable="`readlink -f \"$javaExecutable\"`"
  114. fi
  115. javaHome="`dirname \"$javaExecutable\"`"
  116. javaHome=`expr "$javaHome" : '\(.*\)/bin'`
  117. JAVA_HOME="$javaHome"
  118. export JAVA_HOME
  119. fi
  120. fi
  121. fi
  122. if [ -z "$JAVACMD" ] ; then
  123. if [ -n "$JAVA_HOME" ] ; then
  124. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  125. # IBM's JDK on AIX uses strange locations for the executables
  126. JAVACMD="$JAVA_HOME/jre/sh/java"
  127. else
  128. JAVACMD="$JAVA_HOME/bin/java"
  129. fi
  130. else
  131. JAVACMD="`which java`"
  132. fi
  133. fi
  134. if [ ! -x "$JAVACMD" ] ; then
  135. echo "Error: JAVA_HOME is not defined correctly." >&2
  136. echo " We cannot execute $JAVACMD" >&2
  137. exit 1
  138. fi
  139. if [ -z "$JAVA_HOME" ] ; then
  140. echo "Warning: JAVA_HOME environment variable is not set."
  141. fi
  142. CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
  143. # traverses directory structure from process work directory to filesystem root
  144. # first directory with .mvn subdirectory is considered project base directory
  145. find_maven_basedir() {
  146. if [ -z "$1" ]
  147. then
  148. echo "Path not specified to find_maven_basedir"
  149. return 1
  150. fi
  151. basedir="$1"
  152. wdir="$1"
  153. while [ "$wdir" != '/' ] ; do
  154. if [ -d "$wdir"/.mvn ] ; then
  155. basedir=$wdir
  156. break
  157. fi
  158. # workaround for JBEAP-8937 (on Solaris 10/Sparc)
  159. if [ -d "${wdir}" ]; then
  160. wdir=`cd "$wdir/.."; pwd`
  161. fi
  162. # end of workaround
  163. done
  164. echo "${basedir}"
  165. }
  166. # concatenates all lines of a file
  167. concat_lines() {
  168. if [ -f "$1" ]; then
  169. echo "$(tr -s '\n' ' ' < "$1")"
  170. fi
  171. }
  172. BASE_DIR=`find_maven_basedir "$(pwd)"`
  173. if [ -z "$BASE_DIR" ]; then
  174. exit 1;
  175. fi
  176. ##########################################################################################
  177. # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
  178. # This allows using the maven wrapper in projects that prohibit checking in binary data.
  179. ##########################################################################################
  180. if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
  181. if [ "$MVNW_VERBOSE" = true ]; then
  182. echo "Found .mvn/wrapper/maven-wrapper.jar"
  183. fi
  184. else
  185. if [ "$MVNW_VERBOSE" = true ]; then
  186. echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
  187. fi
  188. if [ -n "$MVNW_REPOURL" ]; then
  189. jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
  190. else
  191. jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
  192. fi
  193. while IFS="=" read key value; do
  194. case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
  195. esac
  196. done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
  197. if [ "$MVNW_VERBOSE" = true ]; then
  198. echo "Downloading from: $jarUrl"
  199. fi
  200. wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
  201. if $cygwin; then
  202. wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
  203. fi
  204. if command -v wget > /dev/null; then
  205. if [ "$MVNW_VERBOSE" = true ]; then
  206. echo "Found wget ... using wget"
  207. fi
  208. if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
  209. wget "$jarUrl" -O "$wrapperJarPath"
  210. else
  211. wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
  212. fi
  213. elif command -v curl > /dev/null; then
  214. if [ "$MVNW_VERBOSE" = true ]; then
  215. echo "Found curl ... using curl"
  216. fi
  217. if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
  218. curl -o "$wrapperJarPath" "$jarUrl" -f
  219. else
  220. curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
  221. fi
  222. else
  223. if [ "$MVNW_VERBOSE" = true ]; then
  224. echo "Falling back to using Java to download"
  225. fi
  226. javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
  227. # For Cygwin, switch paths to Windows format before running javac
  228. if $cygwin; then
  229. javaClass=`cygpath --path --windows "$javaClass"`
  230. fi
  231. if [ -e "$javaClass" ]; then
  232. if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
  233. if [ "$MVNW_VERBOSE" = true ]; then
  234. echo " - Compiling MavenWrapperDownloader.java ..."
  235. fi
  236. # Compiling the Java class
  237. ("$JAVA_HOME/bin/javac" "$javaClass")
  238. fi
  239. if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
  240. # Running the downloader
  241. if [ "$MVNW_VERBOSE" = true ]; then
  242. echo " - Running MavenWrapperDownloader.java ..."
  243. fi
  244. ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
  245. fi
  246. fi
  247. fi
  248. fi
  249. ##########################################################################################
  250. # End of extension
  251. ##########################################################################################
  252. export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
  253. if [ "$MVNW_VERBOSE" = true ]; then
  254. echo $MAVEN_PROJECTBASEDIR
  255. fi
  256. MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
  257. # For Cygwin, switch paths to Windows format before running java
  258. if $cygwin; then
  259. [ -n "$M2_HOME" ] &&
  260. M2_HOME=`cygpath --path --windows "$M2_HOME"`
  261. [ -n "$JAVA_HOME" ] &&
  262. JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  263. [ -n "$CLASSPATH" ] &&
  264. CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  265. [ -n "$MAVEN_PROJECTBASEDIR" ] &&
  266. MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
  267. fi
  268. # Provide a "standardized" way to retrieve the CLI args that will
  269. # work with both Windows and non-Windows executions.
  270. MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
  271. export MAVEN_CMD_LINE_ARGS
  272. WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
  273. exec "$JAVACMD" \
  274. $MAVEN_OPTS \
  275. -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
  276. "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
  277. ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"