-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathcommon.sh
108 lines (93 loc) · 3.15 KB
/
common.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
#!/usr/bin/env bash
export BUILDPACK_STDLIB_URL="https://lang-common.s3.amazonaws.com/buildpack-stdlib/v7/stdlib.sh"
gradle_build_file() {
local buildDir=${1}
if [ -f ${buildDir}/build.gradle.kts ]; then
echo "${buildDir}/build.gradle.kts"
else
echo "${buildDir}/build.gradle"
fi
}
has_stage_task() {
local gradleFile="$(gradle_build_file ${1})"
test -f ${gradleFile} &&
test -n "$(grep "^ *task *stage" ${gradleFile})"
}
is_spring_boot() {
local gradleFile="$(gradle_build_file ${1})"
test -f ${gradleFile} &&
(
test -n "$(grep "^[^/].*org.springframework.boot:spring-boot" ${gradleFile})" ||
test -n "$(grep "^[^/].*spring-boot-gradle-plugin" ${gradleFile})" ||
test -n "$(grep "^[^/].*id.*org.springframework.boot" ${gradleFile})"
) &&
test -z "$(grep "org.grails:grails-" ${gradleFile})"
}
is_ratpack() {
local gradleFile="$(gradle_build_file ${1})"
test -f ${gradleFile} &&
test -n "$(grep "^[^/].*io.ratpack.ratpack" ${gradleFile})"
}
is_grails() {
local gradleFile="$(gradle_build_file ${1})"
test -f ${gradleFile} &&
test -n "$(grep "^[^/].*org.grails:grails-" ${gradleFile})"
}
is_webapp_runner() {
local gradleFile="$(gradle_build_file ${1})"
test -f ${gradleFile} &&
test -n "$(grep "^[^/].*io.ratpack.ratpack" ${gradleFile})"
}
create_build_log_file() {
local buildLogFile=".heroku/gradle-build.log"
echo "" > $buildLogFile
echo "$buildLogFile"
}
# By default gradle will write its cache in `$BUILD_DIR/.gradle`. Rather than
# using the --project-cache-dir option, which muddies up the command, we
# symlink this directory to the cache.
create_project_cache_symlink() {
local buildpackCacheDir="${1:?}/.gradle-project"
local projectCacheLink="${2:?}/.gradle"
if [ ! -d "$projectCacheLink" ]; then
mkdir -p "$buildpackCacheDir"
ln -s "$buildpackCacheDir" "$projectCacheLink"
trap "rm -f $projectCacheLink" EXIT
fi
}
# sed -l basically makes sed replace and buffer through stdin to stdout
# so you get updates while the command runs and dont wait for the end
# e.g. sbt stage | indent
output() {
local logfile="$1"
local c='s/^/ /'
case $(uname) in
Darwin) tee -a "$logfile" | sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) tee -a "$logfile" | sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
esac
}
cache_copy() {
rel_dir=$1
from_dir=$2
to_dir=$3
rm -rf $to_dir/$rel_dir
if [ -d $from_dir/$rel_dir ]; then
mkdir -p $to_dir/$rel_dir
cp -pr $from_dir/$rel_dir/. $to_dir/$rel_dir
fi
}
install_jdk() {
local install_dir=${1:?}
local cache_dir=${2:?}
let start=$(nowms)
JVM_COMMON_BUILDPACK=${JVM_COMMON_BUILDPACK:-https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/jvm.tgz}
mkdir -p /tmp/jvm-common
curl --retry 3 --silent --location $JVM_COMMON_BUILDPACK | tar xzm -C /tmp/jvm-common --strip-components=1
source /tmp/jvm-common/bin/util
source /tmp/jvm-common/bin/java
source /tmp/jvm-common/opt/jdbc.sh
mtime "jvm-common.install.time" "${start}"
let start=$(nowms)
install_java_with_overlay "${install_dir}" "${cache_dir}"
mtime "jvm.install.time" "${start}"
}