Debian Codegraph @

apache-maven/src/bin/mvn

raw ◀ ▶
1 Debian patch touch this file
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 Startup Script
22 #
23 # Environment Variable Prerequisites
24 #
25 # JAVA_HOME Must point at your Java Development Kit installation.
26 # MAVEN_ARGS (Optional) Arguments passed to Maven before CLI arguments.
27 # MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
28 # MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
29 # -----------------------------------------------------------------------------
30
31 if [ -z "$MAVEN_SKIP_RC" ] ; then
32
33 if [ -f /usr/local/etc/mavenrc ] ; then
34 . /usr/local/etc/mavenrc
35 fi
36
37 if [ -f /etc/mavenrc ] ; then
38 . /etc/mavenrc
39 fi
40
41 if [ -f "$HOME/.mavenrc" ] ; then
42 . "$HOME/.mavenrc"
43 fi
44
45 fi
46
47 # OS specific support. $var _must_ be set to either true or false.
48 cygwin=false;
49 mingw=false;
50 case "`uname`" in
51 CYGWIN*) cygwin=true;;
52 MINGW*) mingw=true;;
53 esac
54
55 ## resolve links - $0 may be a link to Maven's home
56 PRG="$0"
57
58 # need this for relative symlinks
59 while [ -h "$PRG" ] ; do
60 ls=`ls -ld "$PRG"`
61 link=`expr "$ls" : '.*-> \(.*\)$'`
62 if expr "$link" : '/.*' > /dev/null; then
63 PRG="$link"
64 else
65 PRG="`dirname "$PRG"`/$link"
66 fi
67 done
68
69 saveddir=`pwd`
70
71 MAVEN_HOME=`dirname "$PRG"`/..
72
73 # make it fully qualified
74 MAVEN_HOME=`cd "$MAVEN_HOME" && pwd`
75
76 cd "$saveddir"
77
78 # For Cygwin, ensure paths are in Unix format before anything is touched
79 if $cygwin ; then
80 [ -n "$MAVEN_HOME" ] &&
81 MAVEN_HOME=`cygpath --unix "$MAVEN_HOME"`
82 [ -n "$JAVA_HOME" ] &&
83 JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
84 [ -n "$CLASSPATH" ] &&
85 CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
86 fi
87
88 # For MinGW, ensure paths are in Unix format before anything is touched
89 if $mingw ; then
90 [ -n "$MAVEN_HOME" ] &&
91 MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
92 [ -n "$JAVA_HOME" ] &&
93 JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
94 # TODO classpath?
95 fi
96
97 if [ -z "$JAVA_HOME" ] ; then
98 JAVACMD="`\\unset -f command; \\command -v java`"
99 else
100 JAVACMD="$JAVA_HOME/bin/java"
101 fi
102
103 if [ ! -x "$JAVACMD" ] ; then
104 echo "The JAVA_HOME environment variable is not defined correctly," >&2
105 echo "this environment variable is needed to run this program." >&2
106 exit 1
107 fi
108
109 CLASSWORLDS_JAR=`echo "${MAVEN_HOME}"/boot/plexus-classworlds-*.jar`
110 CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
111
112 # For Cygwin, switch paths to Windows format before running java
113 if $cygwin ; then
114 [ -n "$MAVEN_HOME" ] &&
115 MAVEN_HOME=`cygpath --path --windows "$MAVEN_HOME"`
116 [ -n "$JAVA_HOME" ] &&
117 JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
118 [ -n "$CLASSPATH" ] &&
119 CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
120 [ -n "$CLASSWORLDS_JAR" ] &&
121 CLASSWORLDS_JAR=`cygpath --path --windows "$CLASSWORLDS_JAR"`
122 fi
123
124 # traverses directory structure from process work directory to filesystem root
125 # first directory with .mvn subdirectory is considered project base directory
126 find_maven_basedir() {
127 (
128 basedir=`find_file_argument_basedir "$@"`
129 wdir="${basedir}"
130 while :
131 do
132 if [ -d "$wdir"/.mvn ] ; then
133 basedir=$wdir
134 break
135 fi
136 if [ "$wdir" = '/' ] ; then
137 break
138 fi
139 wdir=`cd "$wdir/.."; pwd`
140 done
141 echo "${basedir}"
142 )
143 }
144
145 find_file_argument_basedir() {
146 (
147 basedir=`pwd`
148
149 found_file_switch=0
150 for arg in "$@"; do
151 if [ ${found_file_switch} -eq 1 ]; then
152 if [ -d "${arg}" ]; then
153 basedir=`cd "${arg}" && pwd -P`
154 elif [ -f "${arg}" ]; then
155 basedir=`dirname "${arg}"`
156 basedir=`cd "${basedir}" && pwd -P`
157 if [ ! -d "${basedir}" ]; then
158 echo "Directory ${basedir} extracted from the -f/--file command-line argument ${arg} does not exist" >&2
159 exit 1
160 fi
161 else
162 echo "POM file ${arg} specified with the -f/--file command line argument does not exist" >&2
163 exit 1
164 fi
165 break
166 fi
167 if [ "$arg" = "-f" -o "$arg" = "--file" ]; then
168 found_file_switch=1
169 fi
170 done
171 echo "${basedir}"
172 )
173 }
174
175 # concatenates all lines of a file
176 concat_lines() {
177 if [ -f "$1" ]; then
178 echo "`tr -s '\r\n' ' ' < "$1"`"
179 fi
180 }
181
•182 jansi_mode_property() {
183 jansi_mode="-Djansi.mode=force"
184 for arg in "$@"; do
185 if [ "${arg}" = "--batch-mode" ] || [ "${arg}" = "-B" ]; then
186 jansi_mode="-Djansi.mode=strip"
187 break
188 fi
189 done
190 echo ${jansi_mode}
191 }
192 MAVEN_JANSI_PROPERTY="${MAVEN_JANSI_PROPERTY-$(jansi_mode_property "$@")}"
193
194 MAVEN_PROJECTBASEDIR="${MAVEN_BASEDIR:-`find_maven_basedir "$@"`}"
•195 MAVEN_OPTS="`concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"` $MAVEN_OPTS $MAVEN_JANSI_PROPERTY"
196
197 # For Cygwin, switch project base directory path to Windows format before
198 # executing Maven otherwise this will cause Maven not to consider it.
199 if $cygwin ; then
200 [ -n "$MAVEN_PROJECTBASEDIR" ] &&
201 MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
202 fi
203
204 export MAVEN_PROJECTBASEDIR
205
206 # Provide a "standardized" way to retrieve the CLI args that will
207 # work with both Windows and non-Windows executions.
208 MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
209 export MAVEN_CMD_LINE_ARGS
210
211 # MNG-8248
212 if "$JAVACMD" --enable-native-access=ALL-UNNAMED -version >/dev/null 2>&1; then
213 MAVEN_OPTS="--enable-native-access=ALL-UNNAMED $MAVEN_OPTS"
214 # MNG-8169
215 if $mingw ; then
216 MAVEN_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED $MAVEN_OPTS"
217 fi
218 fi
219
220 exec "$JAVACMD" \
221 $MAVEN_OPTS \
222 $MAVEN_DEBUG_OPTS \
223 -classpath "${CLASSWORLDS_JAR}" \
224 "-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
225 "-Dmaven.home=${MAVEN_HOME}" \
226 "-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \
227 "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
228 ${CLASSWORLDS_LAUNCHER} ${MAVEN_ARGS} "$@"