StudentsSpring
/
mvnw
259 строк · 10.4 Кб
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# ----------------------------------------------------------------------------
22# Apache Maven Wrapper startup batch script, version 3.3.2
23#
24# Optional ENV vars
25# -----------------
26# JAVA_HOME - location of a JDK home dir, required when download maven via java source
27# MVNW_REPOURL - repo url base for downloading maven distribution
28# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
29# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
30# ----------------------------------------------------------------------------
31
32set -euf33[ "${MVNW_VERBOSE-}" != debug ] || set -x34
35# OS specific support.
36native_path() { printf %s\\n "$1"; }37case "$(uname)" in38CYGWIN* | MINGW*)39[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"40native_path() { cygpath --path --windows "$1"; }41;;42esac
43
44# set JAVACMD and JAVACCMD
45set_java_home() {46# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched47if [ -n "${JAVA_HOME-}" ]; then48if [ -x "$JAVA_HOME/jre/sh/java" ]; then49# IBM's JDK on AIX uses strange locations for the executables50JAVACMD="$JAVA_HOME/jre/sh/java"51JAVACCMD="$JAVA_HOME/jre/sh/javac"52else53JAVACMD="$JAVA_HOME/bin/java"54JAVACCMD="$JAVA_HOME/bin/javac"55
56if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then57echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&258echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&259return 160fi61fi62else63JAVACMD="$(64'set' +e65'unset' -f command 2>/dev/null66'command' -v java67)" || :68JAVACCMD="$(69'set' +e70'unset' -f command 2>/dev/null71'command' -v javac72)" || :73
74if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then75echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&276return 177fi78fi79}
80
81# hash string like Java String::hashCode
82hash_string() {83str="${1:-}" h=084while [ -n "$str" ]; do85char="${str%"${str#?}"}"86h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))87str="${str#?}"88done89printf %x\\n $h90}
91
92verbose() { :; }93[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }94
95die() {96printf %s\\n "$1" >&297exit 198}
99
100trim() {101# MWRAPPER-139:102# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.103# Needed for removing poorly interpreted newline sequences when running in more104# exotic environments such as mingw bash on Windows.105printf "%s" "${1}" | tr -d '[:space:]'106}
107
108# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
109while IFS="=" read -r key value; do110case "${key-}" in111distributionUrl) distributionUrl=$(trim "${value-}") ;;112distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;113esac114done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"115[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"116
117case "${distributionUrl##*/}" in118maven-mvnd-*bin.*)119MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/120case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in121*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;122:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;123:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;124:Linux*x86_64*) distributionPlatform=linux-amd64 ;;125*)126echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2127distributionPlatform=linux-amd64128;;129esac130distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"131;;132maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;133*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;134esac
135
136# apply MVNW_REPOURL and calculate MAVEN_HOME
137# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
138[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"139distributionUrlName="${distributionUrl##*/}"140distributionUrlNameMain="${distributionUrlName%.*}"141distributionUrlNameMain="${distributionUrlNameMain%-bin}"142MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"143MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"144
145exec_maven() {146unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :147exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"148}
149
150if [ -d "$MAVEN_HOME" ]; then151verbose "found existing MAVEN_HOME at $MAVEN_HOME"152exec_maven "$@"153fi
154
155case "${distributionUrl-}" in156*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;157*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;158esac
159
160# prepare tmp dir
161if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then162clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }163trap clean HUP INT TERM EXIT164else
165die "cannot create temp dir"166fi
167
168mkdir -p -- "${MAVEN_HOME%/*}"169
170# Download and Install Apache Maven
171verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."172verbose "Downloading from: $distributionUrl"173verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"174
175# select .zip or .tar.gz
176if ! command -v unzip >/dev/null; then177distributionUrl="${distributionUrl%.zip}.tar.gz"178distributionUrlName="${distributionUrl##*/}"179fi
180
181# verbose opt
182__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''183[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v184
185# normalize http auth
186case "${MVNW_PASSWORD:+has-password}" in187'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;188has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;189esac
190
191if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then192verbose "Found wget ... using wget"193wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"194elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then195verbose "Found curl ... using curl"196curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"197elif set_java_home; then198verbose "Falling back to use Java to download"199javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"200targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"201cat >"$javaSource" <<-END202public class Downloader extends java.net.Authenticator
203{204protected java.net.PasswordAuthentication getPasswordAuthentication()205{206return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );207}208public static void main( String[] args ) throws Exception209{210setDefault( new Downloader() );211java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );212}213}214END
215# For Cygwin/MinGW, switch paths to Windows format before running javac and java216verbose " - Compiling Downloader.java ..."217"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"218verbose " - Running Downloader.java ..."219"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"220fi
221
222# If specified, validate the SHA-256 sum of the Maven distribution zip file
223if [ -n "${distributionSha256Sum-}" ]; then224distributionSha256Result=false225if [ "$MVN_CMD" = mvnd.sh ]; then226echo "Checksum validation is not supported for maven-mvnd." >&2227echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2228exit 1229elif command -v sha256sum >/dev/null; then230if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then231distributionSha256Result=true232fi233elif command -v shasum >/dev/null; then234if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then235distributionSha256Result=true236fi237else238echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2239echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2240exit 1241fi242if [ $distributionSha256Result = false ]; then243echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2244echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2245exit 1246fi247fi
248
249# unzip and move
250if command -v unzip >/dev/null; then251unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"252else
253tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"254fi
255printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"256mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"257
258clean || :259exec_maven "$@"260