-
Notifications
You must be signed in to change notification settings - Fork 1
/
gfbuild.sh
executable file
·170 lines (160 loc) · 5.65 KB
/
gfbuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash -e
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2010-2017 Oracle and/or its affiliates. All rights reserved.
#
# The contents of this file are subject to the terms of either the GNU
# General Public License Version 2 only ("GPL") or the Common Development
# and Distribution License("CDDL") (collectively, the "License"). You
# may not use this file except in compliance with the License. You can
# obtain a copy of the License at
# https://oss.oracle.com/licenses/CDDL+GPL-1.1
# or LICENSE.txt. See the License for the specific
# language governing permissions and limitations under the License.
#
# When distributing the software, include this License Header Notice in each
# file and include the License file at LICENSE.txt.
#
# GPL Classpath Exception:
# Oracle designates this particular file as subject to the "Classpath"
# exception as provided by Oracle in the GPL Version 2 section of the License
# file that accompanied this code.
#
# Modifications:
# If applicable, add the following below the License Header, with the fields
# enclosed by brackets [] replaced by your own identifying information:
# "Portions Copyright [year] [name of copyright owner]"
#
# Contributor(s):
# If you wish your version of this file to be governed by only the CDDL or
# only the GPL Version 2, indicate your decision by adding "[Contributor]
# elects to include this software in this distribution under the [CDDL or GPL
# Version 2] license." If you don't indicate a single choice of license, a
# recipient has the option to distribute your version of this file under
# either the CDDL, the GPL Version 2 or to extend the choice of license to
# its licensees as provided above. However, if you add GPL Version 2 code
# and therefore, elected the GPL Version 2 license, then the option applies
# only if the new code is made subject to such option by the copyright
# holder.
#
# check if maven is installed and in the path
set +e
which mvn 2>&1 > /dev/null
_status=${?}
set -e
if [ ${_status} -ne 0 ]; then
echo "Unable to find mvn in the path."
echo "Please install Maven version 3.0.3 or above. http://maven.apache.org/download.html"
exit "$_status"
fi
#mvn is available in the path. Now verify that it's the right version.
java_ver=`mvn -version 2>&1 | awk '/^Java version:/ {print substr($3,3,1)}'`
#verify JDK 1.7
echo "Java version: ${java_ver}"
if [ ${java_ver} -lt 7 ]; then
echo "Please use JDK 1.7"
exit 1
fi
# mvn -version returns "Maven version:..." in 2.0.9
# and in >= 2.2.0 and up returns "Apache Maven..." so need to
# apply awk with different string values.
mvn_ver=`mvn -version 2>&1 | awk '/^Maven version:/ {print $3}'`
if [ "${mvn_ver}" = "" ]; then
mvn_ver=`mvn -version 2>&1 | awk '/^Apache Maven/ {print $3}'`
fi
# convert to number since shell is unable to compare float"
# e.g. convert x.y.z to xyz
version=`echo $mvn_ver | sed 's/\.//g'`
#verify that maven version is >= 3.0.3
echo "Maven version: ${version}"
if [ ${version} -lt "303" ]; then
echo "Please do not use Maven version lower than 3.0.3."
exit 1
fi
is_scenario(){
case "$1" in
"build_re_dev" | \
"build_re_external_dev" | \
"binary_dev" | \
"build_re_nightly" | \
"build_re_weekly" | \
"promote_dev" | \
"promote_nightly" | \
"promote_weekly") echo 1;;
*) echo 0;;
esac
}
usage(){
cat << END_USAGE
Usage: $0 [OPTION]... [ [-Dkey=value]... MAVEN_PHASE... | SCENARIO ]
GlassFish build wrapper script.
Verifies that a suitable mvn version (>= 3.0.3) is available in the PATH.
Also verifies that JDK 1.7 is installed to compile GlassFish.
-r or -Dmaven.local.repo can be specified to supply the local maven repository location,
otherwise the default is used, which is user's home directory (~/.m2/repository).
The supplied directory will be created if needed.
The script saves the output in gfbuild.log.
-r LOCAL_REPO_PATH
path to a directory that will be used as a local maven
repository.
-U
forces update of SNAPSHOTs
-h
display this help and exit
MAVEN_PHASE
can be Maven phase, e.g.
clean
compile
package
install
SCENARIO
build_re_dev
build_re_nightly
build_re_weekly
promote_dev
promote_nightly
promote_weekly
END_USAGE
exit 0
}
build_args="$@"
build_arg1=`awk '{print $1}' <<< "$build_args"`
mvn_env=""
#get command options
while getopts r:D:U:h opt
do
case "$opt" in
r) maven_repo=$OPTARG;;
D) mvn_env="$mvn_env -D$OPTARG";;
U) update="-U"; build_args=`sed s@'-U '@@g <<< "$build_args"`;;
h | *) usage;;
esac
done
shift `expr $OPTIND - 1`
MAVEN_OPTS=${MAVEN_OPTS:='-Xmx1024m -Xms256m -XX:MaxPermSize=512m'}
export MAVEN_OPTS
if [ "$maven_repo" != "" ]; then
if [ -d "$maven_repo" ]; then
echo "$maven_repo exists. Continue with build."
else
echo "$maven_repo does not exist. Create $maven_repo."
mkdir "$maven_repo"
_status=$?
if [ "$_status" -ne 0 ]; then
echo "Unable to create maven repository at: $maven_repo."
exit "$_status"
fi
fi
fi
if [ ! -z $build_arg1 ] && [ $(is_scenario $build_arg1) -eq 1 ]
then
source `dirname $0`/common.sh
eval "$build_arg1" "$2"
else
if [ "$maven_repo" = "" ]; then
mvn $mvn_env $update $build_args | tee gfbuild.log
else
mvn -Dmaven.repo.local=$maven_repo $mvn_env $update $build_args | tee gfbuild.log
fi
fi