@@ -170,6 +170,16 @@ is_newer() {
170170 [ -e " $master " ] && ! find " $@ " -newer " $master " 2> /dev/null | read -r _
171171}
172172
173+ # unquote STRING
174+ #
175+ # Remove single/double quotes from beginning and end of a string
176+ unquote () {
177+ REPLY=$1
178+ case $REPLY in
179+ (\" * \" | \' * \' ) REPLY=${REPLY# ?} ; REPLY=${REPLY% ?} ;;
180+ esac
181+ }
182+
173183# echo [STRING...]
174184#
175185# Dumb echo, i.e. print arguments joined by spaces with no further processing
@@ -179,7 +189,6 @@ echo() {
179189
180190# ----- Set variable defaults -------------------------------------------------
181191
182- java_class=org.jruby.Main
183192JRUBY_SHELL=/bin/sh
184193
185194# Detect cygwin and mingw environments
238247# Gather environment information as we go
239248readonly cr='
240249'
241- environment_log=" JRuby Environment $cr ================= "
250+ environment_log=" "
242251add_log () {
243252 environment_log=" ${environment_log}${cr}${* -} "
244253}
@@ -402,6 +411,15 @@ JRUBY_HOME="${SELF_PATH%/*/*}"
402411
403412# ----- File paths for various options and files we'll process later ----------
404413
414+ # Find HOME of current user if empty
415+ if [ -z " ${HOME-} " ]; then
416+ username=$( id -un)
417+ case $username in
418+ (* [!_[:alnum]]* ) ;;
419+ (* ) eval HOME=" ~$username " ; export HOME ;;
420+ esac
421+ fi
422+
405423# Module options to open up packages we need to reflect
406424readonly jruby_module_opts_file=" $JRUBY_HOME /bin/.jruby.module_opts"
407425
@@ -417,6 +435,9 @@ readonly pwd_jruby_java_opts_file="$PWD/.jruby.java_opts"
417435# Options from .dev_mode.java_opts for "--dev" mode, to reduce JRuby startup time
418436readonly dev_mode_opts_file=" $JRUBY_HOME /bin/.dev_mode.java_opts"
419437
438+ # Release file with version-specific values
439+ readonly jruby_release_file=" $JRUBY_HOME /bin/.jruby.release"
440+
420441# ----- Initialize environment log --------------------------------------------
421442
422443add_log
@@ -504,21 +525,39 @@ if $use_modules; then
504525fi
505526
506527# ----- Detect Java version and determine available features ------------------
528+
529+ # assume Java 8 if no release file
530+ java_version=1.8
531+ java_major=8
532+
507533# shellcheck source=/dev/null
508534if [ -f " $JAVA_HOME /release" ]; then
509- java_version=$( . " $JAVA_HOME /release" && echo " ${JAVA_VERSION-} " )
535+ # Get java version from JAVA_HOME/release file
536+ while IFS= read -r line; do
537+ case $line in
538+ (\# * ) continue ;;
539+ esac
540+
541+ name=${line%% =* }
542+ value=${line#* =}
543+
544+ case $name in
545+ (JAVA_VERSION) unquote " $value " && java_version=$REPLY ;;
546+ (JAVA_RELEASE_VERSION) unquote " $value " && java_runtime_version=$REPLY ;;
547+ esac
548+ done < " $JAVA_HOME " /release
549+ unset line name value
510550
511551 # convert version to major, considering 1.8 as 8
512552 case $java_version in
513553 1.8 | 1.8.* ) java_major=8 ;;
514554 * ) java_major=${java_version%% .* } ;;
515555 esac
516- else
517- # assume Java 8 if no release file
518- java_version=1.8
519- java_major=8
520556fi
521557
558+ # Default java_runtime_version to $java_version
559+ : " ${java_runtime_version:= $java_version } "
560+
522561# shellcheck source=/dev/null
523562if [ -f " $JRUBY_HOME /bin/.java-version" ] && . " $JRUBY_HOME /bin/.java-version" && [ " ${JRUBY_MINIMUM_JAVA_VERSION-} " ]; then
524563 minimum_java_version=$JRUBY_MINIMUM_JAVA_VERSION
527566 minimum_java_version=8
528567fi
529568add_log " Detected Java version: $java_version "
569+ add_log " Detected Java runtime version: $java_runtime_version "
530570
531571# Present a useful error if running a Java version lower than bin/.java-version
532572if [ " $java_major " -lt " $minimum_java_version " ]; then
@@ -605,6 +645,18 @@ JAVA_OPTS="$JAVA_OPTS_TEMP"
605645
606646CP_DELIMITER=" :"
607647
648+ # Get main class and version from .jruby.release
649+
650+ # shellcheck source=/dev/null
651+ # shellcheck disable=2153 # Assigned in sourced file
652+ if [ -f " $jruby_release_file " ] && . " $jruby_release_file " ; then
653+ java_class=$JRUBY_MAIN
654+ jruby_version=$JRUBY_VERSION
655+ else
656+ java_class=org.jruby.main
657+ jruby_version=unspecified
658+ fi
659+
608660# Find main jruby jar and add it to the classpath
609661jruby_jar=
610662for j in " $JRUBY_HOME " /lib/jruby.jar " $JRUBY_HOME " /lib/jruby-complete.jar; do
702754 -X* .* ) append java_args -Djruby." ${1# -X} " ;;
703755 # Match switches that take an argument
704756 -[CeIS])
757+ if [ " $# " -eq 1 ]; then
758+ echo " Error: Missing argument to $1 " >&2
759+ exit 2
760+ fi
705761 append ruby_args " $1 " " $2 "
706762 shift
707763 ;;
@@ -803,7 +859,7 @@ if $use_modules; then
803859fi
804860
805861# Default JVM Class Data Sharing Archive (jsa) file for JVMs that support it
806- readonly jruby_jsa_file=" $JRUBY_HOME /lib/jruby-java$java_version .jsa"
862+ readonly jruby_jsa_file=" $JRUBY_HOME /lib/jruby-java$java_runtime_version .jsa"
807863
808864# Find JSAs for all Java versions
809865assign jruby_jsa_files " $JRUBY_HOME " /lib/jruby-java* .jsa
@@ -955,7 +1011,9 @@ add_log
9551011add_log " Java command line:"
9561012add_log " $* "
9571013
1014+ # shellcheck source=/dev/null
9581015if $print_environment_log ; then
1016+ environment_log=" JRuby Environment${cr} =================${cr}${cr} JRuby version: ${jruby_version}${environment_log} "
9591017 echo " $environment_log "
9601018 exit 0
9611019fi
0 commit comments