forked from jamesladd/stc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stic
executable file
·320 lines (296 loc) · 9.22 KB
/
stic
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#! /bin/sh
#
# Redline Smalltalk, Copyright (c) James C. Ladd. All rights reserved. See LICENSE in the root of this distribution
#
# Extract launch and stic arguments, (see details below).
stic_exec_args=
no_config=false
use_jikes_default=false
redline_exec_debug=false
show_help=false
for arg in "$@" ; do
if [ "$arg" = "--noconfig" ] ; then
no_config=true
elif [ "$arg" = "--usejikes" ] ; then
use_jikes_default=true
elif [ "$arg" = "--execdebug" ] ; then
redline_exec_debug=true
elif [ my"$arg" = my"--?" -o my"$arg" = my"--help" ] ; then
show_help=true
redline_exec_args="$redline_exec_args -?"
else
if [ my"$arg" = my"-?" -o my"$arg" = my"-help" ] ; then
show_help=true
redline_exec_args="$redline_exec_args -?"
fi
redline_exec_args="$redline_exec_args \"$arg\""
fi
done
# Source/default stic configuration
if $no_config ; then
rpm_mode=false
usejikes=$use_jikes_default
else
# load system-wide Redline configuration (ONLY if REDLINE_HOME has NOT been set)
if [ -z "$REDLINE_HOME" -o "$REDLINE_HOME" = "/usr/share/redline" ]; then
if [ -f "/etc/redline.conf" ] ; then
. /etc/redline.conf
fi
fi
# load user redline configuration
if [ -f "$HOME/.redline/redline.conf" ] ; then
. $HOME/.redline/redline.conf
fi
if [ -f "$HOME/.redlinerc" ] ; then
. "$HOME/.redlinerc"
fi
# provide default configuration values
if [ -z "$rpm_mode" ] ; then
rpm_mode=false
fi
if [ -z "$usejikes" ] ; then
usejikes=$use_jikes_default
fi
fi
# Setup Java environment in rpm mode
if $rpm_mode ; then
if [ -f /usr/share/java-utils/java-functions ] ; then
. /usr/share/java-utils/java-functions
set_jvm
set_javacmd
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
case "`uname`" in
CYGWIN*) cygwin=true ;;
Darwin*) darwin=true
if [ -z "$JAVA_HOME" ] ; then
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
fi
;;
esac
if [ -z "$REDLINE_HOME" -o ! -d "$REDLINE_HOME" ] ; then
## resolve links - $0 may be a link to redline's home
PRG="$0"
progname=`basename "$0"`
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
REDLINE_HOME=`dirname "$PRG"`/..
# make it fully qualified
REDLINE_HOME=`cd "$REDLINE_HOME" > /dev/null && pwd`
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$REDLINE_HOME" ] &&
REDLINE_HOME=`cygpath --unix "$REDLINE_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# set REDLINE_LIB location
REDLINE_LIB="${REDLINE_HOME}/lib"
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
JAVACMD="$JAVA_HOME/jre/sh/java"
elif [ -x "$JAVA_HOME/jre/bin/java" ] ; then
JAVACMD="$JAVA_HOME/jre/bin/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD=`which java 2> /dev/null `
if [ -z "$JAVACMD" ] ; then
JAVACMD=java
fi
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi
# Build local classpath using just the launcher in non-rpm mode or
# use the Jpackage helper in rpm mode with basic and default jars
# specified in the redline.conf configuration. Because the launcher is
# used, libraries linked in REDLINE_HOME/lib will also be included, but this
# is discouraged as it is not java-version safe. A user should
# request optional jars and their dependencies via the OPT_JAR_LIST
# variable
if $rpm_mode && [ -x /usr/bin/build-classpath ] ; then
LOCALCLASSPATH="$(/usr/bin/build-classpath redline-0.6-SNAPSHOT)"
# If no optional jars have been specified then build the default list
if [ -z "$OPT_JAR_LIST" ] ; then
for file in /etc/redline.d/*; do
if [ -f "$file" ]; then
case "$file" in
*~) ;;
*#*) ;;
*.rpmsave) ;;
*.rpmnew) ;;
*)
for dep in `cat "$file"`; do
case "$OPT_JAR_LIST" in
*"$dep"*) ;;
*) OPT_JAR_LIST="$OPT_JAR_LIST${OPT_JAR_LIST:+ }$dep"
esac
done
esac
fi
done
fi
# If the user requested to try to add some other jars to the classpath
if [ -n "$OPT_JAR_LIST" ] ; then
_OPTCLASSPATH="$(/usr/bin/build-classpath $OPT_JAR_LIST 2> /dev/null)"
if [ -n "$_OPTCLASSPATH" ] ; then
LOCALCLASSPATH="$LOCALCLASSPATH:$_OPTCLASSPATH"
fi
fi
# Explicitly add javac path to classpath, assume JAVA_HOME set
# properly in rpm mode
if [ -f "$JAVA_HOME/lib/tools.jar" ] ; then
LOCALCLASSPATH="$LOCALCLASSPATH:$JAVA_HOME/lib/tools.jar"
fi
if [ -f "$JAVA_HOME/lib/classes.zip" ] ; then
LOCALCLASSPATH="$LOCALCLASSPATH:$JAVA_HOME/lib/classes.zip"
fi
# if CLASSPATH_OVERRIDE env var is set, LOCALCLASSPATH will be
# user CLASSPATH first and ant-found jars after.
# In that case, the user CLASSPATH will override redline-found jars
#
# if CLASSPATH_OVERRIDE is not set, we'll have the normal behaviour
# with redline-found jars first and user CLASSPATH after
if [ -n "$CLASSPATH" ] ; then
# merge local and specified classpath
if [ -z "$LOCALCLASSPATH" ] ; then
LOCALCLASSPATH="$CLASSPATH"
elif [ -n "$CLASSPATH_OVERRIDE" ] ; then
LOCALCLASSPATH="$CLASSPATH:$LOCALCLASSPATH"
else
LOCALCLASSPATH="$LOCALCLASSPATH:$CLASSPATH"
fi
# remove class path from launcher -cp option
CLASSPATH=""
fi
else
# not using rpm_mode; use lib slurp to determine classpaths
for jar in $REDLINE_LIB/*.jar
do
the_redline_classpath=$the_redline_classpath:$jar
done
if [ -z "$LOCALCLASSPATH" ] ; then
LOCALCLASSPATH=$the_redline_classpath
else
LOCALCLASSPATH=$the_redline_classpath:$LOCALCLASSPATH
fi
fi
if [ -n "$JAVA_HOME" ] ; then
# OSX hack to make stic work with jikes
if $darwin ; then
OSXHACK="${JAVA_HOME}/../Classes"
if [ -d "${OSXHACK}" ] ; then
for i in "${OSXHACK}"/*.jar
do
JIKESPATH="$JIKESPATH:$i"
done
fi
fi
fi
# Allow Jikes support (off by default)
if $usejikes; then
REDLINE_OPTS="$REDLINE_OPTS -Dbuild.compiler=jikes"
fi
# For Cygwin, switch paths to appropriate format before running java
# For PATHs convert to unix format first, then to windows format to ensure
# both formats are supported. Probably this will fail on directories with ;
# in the name in the path. Let's assume that paths containing ; are more
# rare than windows style paths on cygwin.
if $cygwin; then
if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
format=mixed
else
format=windows
fi
REDLINE_HOME=`cygpath --$format "$REDLINE_HOME"`
REDLINE_LIB=`cygpath --$format "$REDLINE_LIB"`
JAVA_HOME=`cygpath --$format "$JAVA_HOME"`
LCP_TEMP=`cygpath --path --unix "$LOCALCLASSPATH"`
LOCALCLASSPATH=`cygpath --path --$format "$LCP_TEMP"`
if [ -n "$CLASSPATH" ] ; then
CP_TEMP=`cygpath --path --unix "$CLASSPATH"`
CLASSPATH=`cygpath --path --$format "$CP_TEMP"`
fi
CYGHOME=`cygpath --$format "$HOME"`
fi
# Show script help if requested
if $show_help ; then
echo $0 '[script options] [options] [target [target2 [target3] ..]]'
echo 'Script Options:'
echo ' --help, --h print this message and stic help'
echo ' --noconfig suppress sourcing of /etc/redline.conf,'
echo ' $HOME/.redline/redline.conf, and $HOME/.redlinerc'
echo ' configuration files'
echo ' --usejikes enable use of jikes by default, unless'
echo ' set explicitly in configuration files'
echo ' --execdebug print ant exec line generated by this'
echo ' launch script'
echo ' '
fi
# add a second backslash to variables terminated by a backslash under cygwin
if $cygwin; then
case "$REDLINE_HOME" in
*\\ )
REDLINE_HOME="$REDLINE_HOME\\"
;;
esac
case "$CYGHOME" in
*\\ )
CYGHOME="$CYGHOME\\"
;;
esac
case "$JIKESPATH" in
*\\ )
JIKESPATH="$JIKESPATH\\"
;;
esac
case "$LOCALCLASSPATH" in
*\\ )
LOCALCLASSPATH="$LOCALCLASSPATH\\"
;;
esac
case "$CLASSPATH" in
*\\ )
CLASSPATH="$CLASSPATH\\"
;;
esac
fi
# Execute stic using eval/exec to preserve spaces in paths,
# java options, and stic args
redline_sys_opts=
if [ -n "$CYGHOME" ]; then
if [ -n "$JIKESPATH" ]; then
redline_sys_opts="-Djikes.class.path=\"$JIKESPATH\" -Dcygwin.user.home=\"$CYGHOME\""
else
redline_sys_opts="-Dcygwin.user.home=\"$CYGHOME\""
fi
else
if [ -n "$JIKESPATH" ]; then
redline_sys_opts="-Djikes.class.path=\"$JIKESPATH\""
fi
fi
redline_exec_command="exec \"$JAVACMD\" $REDLINE_OPTS -classpath \"$LOCALCLASSPATH\" -Dredline.home=\"$REDLINE_HOME\" -Dredline.library.dir=\"$REDLINE_LIB\" $redline_sys_opts st.redline.Stic $REDLINE_ARGS $redline_exec_args"
if $redline_exec_debug ; then
echo $redline_exec_command
fi
echo $redline_exec_command
eval $redline_exec_command