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