community/jruby: fix jruby script to handle ruby args with whitespaces

This commit is contained in:
Jakub Jirutka 2016-08-25 12:46:51 +02:00
parent d1063e281e
commit d2017f7e32
2 changed files with 24 additions and 16 deletions

View File

@ -4,7 +4,7 @@
# so it's probably not much usable for regular users.
pkgname=jruby
pkgver=9.1.2.0
pkgrel=0
pkgrel=1
pkgdesc="An implementation of Ruby on the JVM"
url="http://jruby.org"
# openjdk8 is currently built only for x86*
@ -146,8 +146,8 @@ _mvgem() {
}
md5sums="749bb917dde9666e365e12bbe776a5c2 jruby-bin-9.1.2.0.tar.gz
7e6d8f6168f4a69109ea9d14e3e9f874 jruby"
88df7ddd5bcd2ecec3ad526c6efd884d jruby"
sha256sums="60598a465883ab4c933f805de4a7f280052bddc793b95735465619c03ca43f35 jruby-bin-9.1.2.0.tar.gz
51794ecefb0d8fd3084ffb10867e2feffc9ccfadb45021af68520cf75fe58590 jruby"
0585f49f8712c3fea68ab3dca2b3939f6fe9a1a940cbdd3fc8462e25fd312cb1 jruby"
sha512sums="cc6b1e1a2907c128dd04edf9da11933a54bbed5e861ab6f0208505bca5aa2aa9d9acdd04bfde65824346fbb435584081fc8ec2e2e9a3aeea1bef8047915e0c61 jruby-bin-9.1.2.0.tar.gz
d0f19f791274f00f5b35a5e9a5dfe885d58330ebd3fd959f7325e545357497609403b5646988651265d08ac7a08cfec8b88ec260da558bcb0db623d9b8ce5a20 jruby"
f2906a0136f437eaa119eae26d93b1a8e3411bc4ccee9453debf7a5d57bce767100b36a660db42184fd8398ff258455c3f2a8ef1082c907285b48d1b9b218bc2 jruby"

View File

@ -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