This repository has been archived by the owner on May 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
grainw
115 lines (97 loc) · 2.57 KB
/
grainw
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
#!/usr/bin/env bash
cygwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
esac
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Determine command to run java
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Determine java options
if [ -n "$GRAIN_OPTS" ]
then
GRAIN_OPTS="$GRAIN_OPTS"
else
GRAIN_OPTS="-server -Xmx256M -Xms32M -XX:PermSize=32m -XX:MaxPermSize=128m"
fi
JAVA_OPTS="$GRAIN_OPTS $JAVA_OPTS"
# Get target Grain version
APP_PROPS="application.properties"
if [ ! -f $APP_PROPS ]; then
echo "Error: $APP_PROPS not found";
exit 1;
fi
while read line; do
case "$line" in
*grain.version*)
TMP_VERSION="${line#*=}";
read -r GRAIN_VERSION << eof
$TMP_VERSION
eof
;;
esac
done < $APP_PROPS
if [ -z "$GRAIN_VERSION" ]; then
echo "Error: unable to determine Grain version from $APP_PROPS";
exit 1;
fi
# Check if site deps exists for current Grain version
SITE_DEPS=".site-${GRAIN_VERSION}.dep"
if [ ! -f $SITE_DEPS ]; then
# Site deps don't exist - generate them
./gradlew gendeps
if [ $? -ne 0 ]; then
exit 1;
fi
fi
function validateAndLaunch() {
# Get Grain JAR from site deps
read -r GRAIN_JAR < $SITE_DEPS
if $cygwin ; then
GRAIN_JAR=`cygpath --unix "$GRAIN_JAR"`
fi
if [ ! -f $GRAIN_JAR ]; then
# Grain Jar doesn't exist - regenerate site deps and recompute Grain Jar
./gradlew gendeps
if [ $? -ne 0 ]; then
exit 1;
fi
read -r GRAIN_JAR < $SITE_DEPS
fi
if $cygwin ; then
GRAIN_JAR=`cygpath --path --mixed "$GRAIN_JAR"`
fi
# Check if site deps are valid
"$JAVACMD" $JAVA_OPTS -cp $GRAIN_JAR com.sysgears.grain.SiteLauncher $GRAIN_VERSION -- "$@"
return $?
}
validateAndLaunch "$@"
STATUS=$?
if [ $STATUS -eq 2 ]; then
./gradlew gendeps
if [ $? -ne 0 ]; then
exit 1;
fi
validateAndLaunch "$@"
STATUS=$?
fi
exit $STATUS