/
jruby
executable file
·148 lines (125 loc) · 3.66 KB
/
jruby
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
#!/bin/bash
# -----------------------------------------------------------------------------
# jruby.sh - Start Script for the JRuby interpreter
#
# Environment Variable Prequisites
#
# JRUBY_OPTS (Optional) Default JRuby command line args
# JRUBY_SHELL Where/What is system shell
#
# JAVA_HOME Must point at your Java Development Kit installation.
#
# -----------------------------------------------------------------------------
cygwin=false
# ----- Identify OS we are running under --------------------------------------
case "`uname`" in
CYGWIN*) cygwin=true
esac
# ----- Verify and Set Required Environment Variables -------------------------
## resolve links - $0 may be a link to home
PRG=$0
progname=`basename "$0"`
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
JRUBY_HOME_1=`dirname "$PRG"` # the ./bin dir
JRUBY_HOME=`dirname "$JRUBY_HOME_1"` # the . dir
if [ -z "$JRUBY_OPTS" ] ; then
JRUBY_OPTS=""
fi
if [ -z "$JAVA_HOME" ] ; then
JAVA_CMD='java'
else
if $cygwin; then
JAVA_HOME=`cygpath -u "$JAVA_HOME"`
fi
JAVA_CMD="$JAVA_HOME/bin/java"
fi
JRUBY_SHELL=/bin/sh
# ----- Set Up The System Classpath -------------------------------------------
if [ "$JRUBY_PARENT_CLASSPATH" != "" ]; then
# Use same classpath propagated from parent jruby
CP=$JRUBY_PARENT_CLASSPATH
else
if [ "$CLASSPATH" != "" ]; then
CP="$CLASSPATH"
if $cygwin; then
CP=`cygpath -p -u "$CP"`
fi
else
CP=""
fi
CP_DELIMETER=":"
# add necessary jars for command-line execution
for j in "$JRUBY_HOME"/lib/*.jar; do
if [ "$CP" ]; then
CP="$CP$CP_DELIMETER$j"
else
CP="$j"
fi
done
if $cygwin; then
CP=`cygpath -p -w "$CP"`
fi
fi
# ----- Execute The Requested Command -----------------------------------------
JAVA_MEM=-Xmx378m
JAVA_STACK=-Xss1024k
# Split out any -J argument for passing to the JVM.
# Scanning for args is aborted by '--'.
declare -a java_args
declare -a ruby_args
while [ $# -gt 0 ]
do
case "$1" in
# Stuff after '-J' in this argument goes to JVM
-J*)
val=${1:2}
if [ "${val:0:4}" = "-Xmx" ]; then
JAVA_MEM=$val
elif [ "${val:0:4}" = "-Xss" ]; then
JAVA_STACK=$val
else
java_args=("${java_args[@]}" "${1:2}")
fi
;;
# Match switches that take an argument
-e|-I|-S) ruby_args=("${ruby_args[@]}" "$1" "$2"); shift ;;
# Match same switches with argument stuck together
-e*|-I*|-S*) ruby_args=("${ruby_args[@]}" "$1" ) ;;
# Abort processing on the double dash
--) break ;;
# Other opts go to ruby
-*) ruby_args=("${ruby_args[@]}" "$1") ;;
# Abort processing on first non-opt arg
*) break ;;
esac
shift
done
# Append the rest of the arguments
ruby_args=("${ruby_args[@]}" "$@")
# Put the ruby_args back into the position arguments $1, $2 etc
set -- "${ruby_args[@]}"
JAVA_OPTS="$JAVA_OPTS ${java_args[@]} $JAVA_MEM $JAVA_STACK"
if $cygwin; then
JAVA_HOME=`cygpath --mixed "$JAVA_HOME"`
JRUBY_HOME=`cygpath --mixed "$JRUBY_HOME"`
JRUBY_SHELL=`cygpath --mixed "$JRUBY_SHELL"`
if [[ ( "${1:0:1}" = "/" ) && ( ( -f "$1" ) || ( -d "$1" )) ]]; then
win_arg=`cygpath -w "$1"`
shift
win_args=("$win_arg" "$@")
set -- "${win_args[@]}"
fi
fi
exec "$JAVA_CMD" $JAVA_OPTS -classpath "$CP" \
"-Djruby.home=$JRUBY_HOME" \
"-Djruby.lib=$JRUBY_HOME/lib" -Djruby.script=jruby \
"-Djruby.shell=$JRUBY_SHELL" \
org.jruby.Main $JRUBY_OPTS "$@"