-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
134 lines (107 loc) · 4.07 KB
/
run.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
#!/bin/bash
# Copyright 2017, Oracle and/or its affiliates. All rights reserved.
echo "$(date +%H:%M:%S): Hello from the Maven Wercker Step"
echo "For information on how to use this step, please review the documentation in the Wercker Marketplace,"
echo "or visit https://github.com/wercker/step-maven"
# check that all of the required parameters were provided
# note that wercker does not enforce this for us, so we have to check
if [[ -z "$WERCKER_MAVEN_GOALS" ]]; then
echo "$(date +%H:%M:%S): All required parameters: goals MUST be specified"
exit 9
fi
#
# check if a specific version of maven was requested, otherwise use the latest one we have tested with
#
if [[ -z "$WERCKER_MAVEN_VERSION" ]]; then
WERCKER_MAVEN_VERSION="3.5.0"
fi
#
# check we have everything we need to run Maven
#
if [ -n "$JAVA_HOME" ] ; then
if [ ! -x "$JAVA_HOME/bin/java" ] ; then
echo "$(date +%H:%M:%S): ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME"
exit 1
fi
else
echo "$(date +%H:%M:%S): Maven requires java to work, please ensure Java is installed and JAVA_HOME set correctly"
exit 1
fi
# check that curl is installed
hash curl 2>/dev/null || { echo "$(date +%H:%M:%S): curl is required to install maven, install curl before this step."; exit 1; }
# check that tar is installed
hash tar 2>/dev/null || { echo "$(date +%H:%M:%S): tar is required, install tar before this step"; exit 1; }
# check that gzip is installed
hash gzip 2>/dev/null || { echo "$(date +%H:%M:%S): gzip is required, install gzip before this step"; exit 1; }
# check that md5sum installed
hash md5sum 2>/dev/null || { echo "$(date +%H:%M:%S): md5sum is required to validate the download, please install it before running this step"; exit 1; }
if [ ! -d "/maven" ]; then
mkdir /maven
echo "$(date +%H:%M:%S): Downloading Maven"
curl -O https://www.apache.org/dist/maven/maven-3/$WERCKER_MAVEN_VERSION/binaries/apache-maven-$WERCKER_MAVEN_VERSION-bin.tar.gz
curl -O https://www.apache.org/dist/maven/maven-3/$WERCKER_MAVEN_VERSION/binaries/apache-maven-$WERCKER_MAVEN_VERSION-bin.tar.gz.md5
CHECK1=$(cat apache-maven-$WERCKER_MAVEN_VERSION-bin.tar.gz.md5)
CHECK2=$(md5sum apache-maven-$WERCKER_MAVEN_VERSION-bin.tar.gz)
CHECK1="$CHECK1 apache-maven-$WERCKER_MAVEN_VERSION-bin.tar.gz"
if [ "$CHECK1" = "$CHECK2" ] ; then
echo "$(date +%H:%M:%S): checksum matches"
else
echo "$(date +%H:%M:%S): checksum does not match"
exit 1
fi
echo "$(date +%H:%M:%S): Extracting maven "
tar -C /maven -zxf apache-maven-$WERCKER_MAVEN_VERSION-bin.tar.gz
rm apache-maven-$WERCKER_MAVEN_VERSION-bin.tar.gz*
else
if [ ! -x "/maven/apache-maven-$WERCKER_MAVEN_VERSION/bin/mvn" ] ; then
echo "$(date +%H:%M:%S): ERROR: maven was not installed properly"
exit 1
fi
echo "$(date +%H:%M:%S): Maven already present"
fi
export PATH=$PATH:/maven/apache-maven-$WERCKER_MAVEN_VERSION/bin
#
# prepare maven command
#
if [ "$WERCKER_MAVEN_DEBUG" = "true" ]; then
DEBUG="-X -e"
else
DEBUG=""
fi
if [[ -z "$WERCKER_MAVEN_PROFILES" ]]; then
PROFILES=""
else
PROFILES="-p $WERCKER_MAVEN_PROFILES"
fi
if [[ -z "$WERCKER_MAVEN_MAVEN_OPTS" ]]; then
MAVEN_OPTS=""
else
MAVEN_OPTS="-p $WERCKER_MAVEN_MAVEN_OPTS"
fi
if [[ -z "$WERCKER_MAVEN_SETTINGS" ]]; then
SETTINGS=""
else
SETTINGS="-s $WERCKER_MAVEN_SETTINGS"
fi
# set the M2_HOME
# put security-settings.xml in the right place
export M2_HOME="/maven/apache-maven-$WERCKER_MAVEN_VERSION"
export MAVEN_OPTS="$WERCKER_MAVEN_MAVEN_OPTS"
if [[ -z "$WERCKER_MAVEN_SECURITY_SETTINGS" ]]; then
# do nothing
echo "" > /dev/null
else
cp $WERCKER_MAVEN_SECURITY_SETTINGS $M2_HOME/
fi
# put the local repository into the Wercker Cache directory, so that it
# would still be available on subsequent runs (unless cache is cleared)
# keeping this optional because of bug https://github.com/wercker/wercker/issues/139
if [ "$WERCKER_MAVEN_CACHE_REPO" = "true" ]; then
CAHCE_REPO="-Dmaven.repo.local=$WERCKER_CACHE_DIR/.m2"
else
CACHE_REPO=""
fi
#
# run the maven command
#
mvn $CACHE_REPO $DEBUG $SETTINGS $PROFILES $MAVEN_OPTS $WERCKER_MAVEN_GOALS