-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
124 lines (100 loc) · 3.3 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
#!/bin/bash
# Copyright 2017, Oracle and/or its affiliates. All rights reserved.
echo "$(date +%H:%M:%S): Hello from the Gradle 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-gradle"
# 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_GRADLE_TASK" ]]; then
echo "$(date +%H:%M:%S): All required parameters: task MUST be specified"
exit 9
fi
#
# check if a specific version of gradle was requested, otherwise use the latest one we have tested with
#
if [[ -z "$WERCKER_GRADLE_VERSION" ]]; then
WERCKER_GRADLE_VERSION="4.2"
fi
echo "$(date +%H:%M:%S): Gradle version is $WERCKER_GRADLE_VERSION"
#
# check if we have everything we need to run Gradle
#
if [ -n "$JAVA_HOME" ] ; then
if [ ! -x "$JAVA_HOME/bin/java" ] ; then
echo "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME"
exit 1
fi
else
echo "$(date +%H:%M:%S): Gradle 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 gradle, install curl before this step."; exit 1; }
# check unzip is installed
hash unzip 2>/dev/null || { echo "$(date +%H:%M:%S): unzip is required, install tar before this step"; exit 1; }
if [ ! -d "/gradle" ]; then
mkdir /gradle
echo "$(date +%H:%M:%S): Downloading Gradle"
curl -O -L https://services.gradle.org/distributions/gradle-$WERCKER_GRADLE_VERSION-bin.zip
echo "$(date +%H:%M:%S): Extracting gradle"
unzip -q gradle-$WERCKER_GRADLE_VERSION-bin.zip -d /gradle
rm gradle-$WERCKER_GRADLE_VERSION-bin.zip
else
if [ ! -x "/gradle/gradle-$WERCKER_GRADLE_VERSION-all/bin/gradle" ] ; then
echo "$(date +%H:%M:%S): ERROR: gradle was not installed properly"
exit 1
fi
echo "$(date +%H:%M:%S): Gradle already present"
fi
#
# prepare gradle command
#
if [ "$WERCKER_GRADLE_DEBUG" = "true" ]; then
DEBUG="--debug"
else
DEBUG=""
fi
if [[ -z "$WERCKER_GRADLE_BUILD_FILE" ]]; then
BUILD_FILE=""
else
BUILD_FILE="-b $WERCKER_GRADLE_BUILD_FILE"
fi
if [[ -z "$WERCKER_GRADLE_SETTINGS_FILE" ]]; then
SETTINGS_FILE=""
else
SETTINGS_FILE="-c $WERCKER_GRADLE_SETTINGS_FILE"
fi
if [[ -z "$WERCKER_GRADLE_SYSTEM_PROPS" ]]; then
SYSTEM_PROPS=""
else
SYSTEM_PROPS=""
for property in $WERCKER_GRADLE_SYSTEM_PROPS
do
SYSTEM_PROPS="$SYSTEM_PROPS -D$property"
done
fi
if [[ -z "$WERCKER_GRADLE_INIT_SCRIPT" ]]; then
INIT_SCRIPT=""
else
INIT_SCRIPT="-I $WERCKER_GRADLE_INIT_SCRIPT"
fi
if [[ -z "$WERCKER_GRADLE_PROFILES" ]]; then
PROFILES=""
else
PROFILES="-I $WERCKER_GRADLE_PROFILES"
fi
if [ "$WERCKER_GRADLE_CACHE_PROJECT_CACHE" = "true" ]; then
CACHE_DIR="--project-cache-dir=$WERCKER_CACHE_DIR/.gradle"
else
CACHE_DIR=""
fi
# set the GRADLE_OPTS
export GRADLE_OPTS="$WERCKER_GRADLE_GRADLE_OPTS"
#
# run gradle
#
export PATH=$PATH:/gradle/gradle-$WERCKER_GRADLE_VERSION/bin
GRADLE_CMD="gradle $BUILD_FILE $SETTINGS_FILE --console=plain $SYSTEM_PROPS $DEBUG $INIT_SCRIPT $CACHE_DIR --stacktrace --no-daemon $WERCKER_GRADLE_TASK"
echo "$(date +%H:%M:%S): Running Gradle with command:"
echo $GRADLE_CMD
$GRADLE_CMD