aboutsummaryrefslogtreecommitdiffstats
path: root/community/jruby/jruby
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2016-08-25 12:46:51 +0200
committerJakub Jirutka <jakub@jirutka.cz>2016-08-25 12:48:12 +0200
commitd2017f7e321a4fa2c4a04cf157afc360eed7a403 (patch)
treec8ef73b2ecec9bcc0c9609abdf4de2ba5b729a94 /community/jruby/jruby
parentd1063e281e6d20c36a03455baa86b9eafd594510 (diff)
community/jruby: fix jruby script to handle ruby args with whitespaces
Diffstat (limited to 'community/jruby/jruby')
-rw-r--r--community/jruby/jruby32
1 files changed, 20 insertions, 12 deletions
diff --git a/community/jruby/jruby b/community/jruby/jruby
index 4b7fd77571a..aa404beb368 100644
--- a/community/jruby/jruby
+++ b/community/jruby/jruby
@@ -43,6 +43,12 @@ readonly JRUBY_SHELL="${JRUBY_SHELL:-"/bin/sh"}"
readonly NAILGUN_CMD="$JRUBY_HOME/tool/nailgun/ng"
readonly PROFILE_ARGS="${PROFILE_ARGS:-}"
+quote() {
+ local val; for val in "$@"; do
+ printf %s "$val" | sed "s/'/'\\\\''/g; 1s/^/'/; \$s/\$/' /"
+ done
+}
+
java_stack="${JAVA_STACK:-"-Xss2048k"}"
java_cmd="${JAVA_HOME:+"$JAVA_HOME/bin/"}java"
@@ -72,13 +78,13 @@ verify_jruby='no'
# Split out any -J argument for passing to the JVM.
# Scanning for args is aborted by '--'.
-set -- ${JRUBY_OPTS:-} $@
+set -- ${JRUBY_OPTS:-} "$@"
while [ $# -gt 0 ]; do
case "$1" in
# Stuff after "-J" goes to JVM.
-J | -J-X)
"$java_cmd" -help
- printf '\n(Prepend -J in front of these options when using "jruby" command)\n'
+ printf '\n%s\n' '(Prepend -J in front of these options when using "jruby" command)'
exit 1
;;
-J-classpath | -J-cp)
@@ -98,7 +104,7 @@ while [ $# -gt 0 ]; do
;;
# Match -Xa.b.c=d to translate to -Da.b.c=d as a Java option.
-X*)
- val=${1:2}
+ val="${1:2}"
if expr "$val" : '.*[.]' > /dev/null; then
java_opts="$java_opts -Djruby.$val"
else
@@ -107,12 +113,12 @@ while [ $# -gt 0 ]; do
;;
# Match switches that take an argument.
-C | -e | -I | -S)
- ruby_args="$ruby_args $1 $2"
+ ruby_args="$ruby_args $1 $(quote "$2")"
shift
;;
# Match same switches with argument stuck together.
-e* | -I* | -S*)
- ruby_args="$ruby_args $1"
+ ruby_args="$ruby_args $(quote "$1")"
;;
# Run with JMX management enabled.
--manage)
@@ -166,7 +172,7 @@ while [ $# -gt 0 ]; do
;;
# Other opts go to ruby.
-*)
- ruby_args="$ruby_args $1"
+ ruby_args="$ruby_args $(quote "$1")"
;;
# Abort processing on first non-opt arg.
*)
@@ -181,7 +187,7 @@ for opt in -Xmx -Xms -Xss; do
val=$(expr "$java_opts" : ".*$opt\([^ \t]*\).*" ||:) # gets the later one
if [ -n "$val" ]; then
# Remove all occurrences of $opt and append the last one to the end.
- java_opts=$(echo "$java_opts" | sed "s/$opt[^ \t]*//g")
+ java_opts=$(printf "%s\n" "$java_opts" | sed "s/$opt[^ \t]*//g")
java_opts="$java_opts ${opt}${val}"
fi
done
@@ -194,10 +200,12 @@ java_opts="$java_opts $java_vm
-Djruby.shell=$JRUBY_SHELL"
# Append the rest of the arguments.
-ruby_args="$ruby_args $@"
+ruby_args="$ruby_args $(quote "$@")"
# Put $ruby_args back into the position arguments $1, $2, ...
-set -- $ruby_args
+# We must use eval to unquote arguments that we have quoted in order to
+# preserve whitespaces.
+eval "set -- $ruby_args"
if [ "$nailgun_client" = 'yes' ]; then
@@ -205,14 +213,14 @@ if [ "$nailgun_client" = 'yes' ]; then
echo 'ERROR: ng executable not found' 1>&2
exit 1
fi
- exec "$NAILGUN_CMD" $MAIN_CLASS_NGCLIENT $@
+ exec "$NAILGUN_CMD" $MAIN_CLASS_NGCLIENT "$@"
elif [ "$verify_jruby" = 'yes' ]; then
[ -n "$PROFILE_ARGS" ] && echo 'Running with instrumented profiler'
set +e
"$java_cmd" $PROFILE_ARGS $java_opts \
- -classpath "$JRUBY_CP:$classpath" $main_class $@
+ -classpath "$JRUBY_CP:$classpath" $main_class "$@"
exit_code=$?
set -e
@@ -227,5 +235,5 @@ elif [ "$verify_jruby" = 'yes' ]; then
else
exec "$java_cmd" $java_opts -Xbootclasspath/a:"$JRUBY_CP" \
${classpath:+"-classpath $classpath"} \
- $main_class $@
+ $main_class "$@"
fi