forked from kindleit/heroku-buildpack-scala-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon
executable file
·132 lines (112 loc) · 2.79 KB
/
common
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
#!/usr/bin/env bash
## SBT 0.10 allows either *.sbt in the root dir, or project/*.scala or .sbt/*.scala
detect_sbt() {
local ctxDir=$1
if _has_sbtFile $ctxDir || \
_has_projectScalaFile $ctxDir || \
_has_hiddenSbtDir $ctxDir || \
_has_buildPropertiesFile $ctxDir ; then
return 0
else
return 1
fi
}
is_play() {
_has_playConfig $1
}
_has_sbtFile() {
local ctxDir=$1
test -n "$(find $ctxDir -maxdepth 1 -name '*.sbt' -print -quit)"
}
_has_projectScalaFile() {
local ctxDir=$1
test -d $ctxDir/project && test -n "$(find $ctxDir/project -maxdepth 1 -name '*.scala' -print -quit)"
}
_has_hiddenSbtDir() {
local ctxDir=$1
test -d $ctxDir/.sbt && test -n "$(find $ctxDir/.sbt -maxdepth 1 -name '*.scala' -print -quit)"
}
_has_buildPropertiesFile() {
local ctxDir=$1
test -e $ctxDir/project/build.properties
}
_has_playConfig() {
local ctxDir=$1
test -e $ctxDir/conf/application.conf
}
get_supported_sbt_version() {
local ctxDir=$1
if _has_buildPropertiesFile $ctxDir; then
sbtVersionLine="$(grep -P '[ \t]*sbt\.version[ \t]*=' "${ctxDir}"/project/build.properties | sed -E -e 's/[ \t\r\n]//g')"
sbtVersion=$(expr "$sbtVersionLine" : 'sbt\.version=\(0\.1[1-3]\.[0-9]\(-[a-zA-Z0-9_]*\)*\)$')
if [ "$sbtVersion" != 0 ] ; then
echo "$sbtVersion"
else
echo ""
fi
else
echo ""
fi
}
has_supported_sbt_version() {
local ctxDir=$1
local supportedVersion="$(get_supported_sbt_version ${ctxDir})"
if [ "$supportedVersion" != "" ] ; then
return 0
else
return 1
fi
}
count_files() {
local location=$1
local pattern=$2
if [ -d ${location} ]; then
find ${location} -name ${pattern} | wc -l | sed 's/ //g'
else
echo "0"
fi
}
detect_play_lang() {
local appDir=$1/app
local num_scala_files=$(count_files ${appDir} '*.scala')
local num_java_files=$(count_files ${appDir} '*.java')
if [ ${num_scala_files} -gt ${num_java_files} ] ; then
echo "Scala"
elif [ ${num_scala_files} -lt ${num_java_files} ] ; then
echo "Java"
else
echo ""
fi
}
uses_universal_packaging() {
local ctxDir=$1
test -d $ctxDir/target/universal/stage/bin
}
_universal_packaging_procs() {
local ctxDir=$1
(cd $ctxDir; find target/universal/stage/bin -type f -executable)
}
_universal_packaging_proc_count() {
local ctxDir=$1
_universal_packaging_procs $ctxDir | wc -l
}
universal_packaging_default_web_proc() {
local ctxDir=$1
if [ $(_universal_packaging_proc_count $ctxDir) -eq 1 ]; then
echo "web: $(_universal_packaging_procs $ctxDir) -Dhttp.port=\$PORT"
fi
}
error() {
echo " ! $1"
exit 1
}
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
}