jruby-launcher 1.1.19-java → 2.0.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1 -19
  3. data/Rakefile +1 -1
  4. data/exe/jruby.sh +990 -0
  5. data/inc/Makefile-conf.mk +11 -9
  6. data/jrubyexe.cpp +4 -5
  7. data/lib/jruby-launcher.rb +1 -1
  8. data/spec/launcher_spec.rb +1 -1
  9. data/unixlauncher.c +142 -0
  10. data/unixlauncher.h +9 -11
  11. data/version.h +1 -1
  12. metadata +5 -23
  13. data/lib/rubygems/defaults/jruby_native.rb +0 -4
  14. data/pkg/jruby-launcher-1.1.17-java/extconf.rb +0 -12
  15. data/pkg/jruby-launcher-1.1.17-java/lib/jruby-launcher.rb +0 -3
  16. data/pkg/jruby-launcher-1.1.17-java/lib/rubygems/defaults/jruby_native.rb +0 -4
  17. data/pkg/jruby-launcher-1.1.17-java/spec/launcher_spec.rb +0 -288
  18. data/pkg/jruby-launcher-1.1.17-java/spec/spec_helper.rb +0 -76
  19. data/pkg/jruby-launcher-1.1.18-java/extconf.rb +0 -12
  20. data/pkg/jruby-launcher-1.1.18-java/lib/jruby-launcher.rb +0 -3
  21. data/pkg/jruby-launcher-1.1.18-java/lib/rubygems/defaults/jruby_native.rb +0 -4
  22. data/pkg/jruby-launcher-1.1.18-java/pkg/jruby-launcher-1.1.17-java/extconf.rb +0 -12
  23. data/pkg/jruby-launcher-1.1.18-java/pkg/jruby-launcher-1.1.17-java/lib/jruby-launcher.rb +0 -3
  24. data/pkg/jruby-launcher-1.1.18-java/pkg/jruby-launcher-1.1.17-java/lib/rubygems/defaults/jruby_native.rb +0 -4
  25. data/pkg/jruby-launcher-1.1.18-java/pkg/jruby-launcher-1.1.17-java/spec/launcher_spec.rb +0 -288
  26. data/pkg/jruby-launcher-1.1.18-java/pkg/jruby-launcher-1.1.17-java/spec/spec_helper.rb +0 -76
  27. data/pkg/jruby-launcher-1.1.18-java/spec/launcher_spec.rb +0 -288
  28. data/pkg/jruby-launcher-1.1.18-java/spec/spec_helper.rb +0 -76
  29. data/unixlauncher.cpp +0 -131
data/exe/jruby.sh ADDED
@@ -0,0 +1,990 @@
1
+ #!/bin/sh
2
+ # shellcheck shell=dash # local variable support
3
+ # shellcheck disable=1007 # spurious warnings when initializing multiple vars
4
+
5
+ # -----------------------------------------------------------------------------
6
+ # jruby.sh - Start Script for the JRuby interpreter
7
+ #
8
+ # This script handles all Ruby and JRuby command-line arguments, detects the
9
+ # location of the `java` command and JRuby standard library, and launches JRuby
10
+ # using appropriate flags and configuration. A few flags provide additional
11
+ # information:
12
+ #
13
+ # * `jruby --help` for standard options, most based on Ruby flags.
14
+ # * `jruby --properties` to list all JRuby JVM properties for finer-grained
15
+ # configuration.
16
+ # * `jruby --environment` to show the `java` command line that will be run and
17
+ # log output explaining how we got there.
18
+ #
19
+ # This script is intended to be compatible with POSIX shell as much as possible
20
+ # modulo a few small features known to be nonstandard but present in nearly all
21
+ # POSIX shell implementations. We tell shellcheck to treat this source as dash,
22
+ # a version of ash that adds those features and which has been the standard
23
+ # Debian /bin/sh since 2011.
24
+ #
25
+ # See https://en.wikipedia.org/wiki/Almquist_shell#Adoption_in_Debian_and_Ubuntu
26
+ #
27
+ # There are a number of utility functions defined here to cope with the lack of
28
+ # arrays in shell. These functions simulate arrays through other mechanism and
29
+ # ensure we do not damage quoting during argument processing.
30
+ # -----------------------------------------------------------------------------
31
+
32
+ # Enable uninitialized variable warnings
33
+ set -u
34
+
35
+ # ----- Guarantee local variables are available -------------------------------
36
+ if command -v local >/dev/null; then
37
+ :
38
+ elif command -v typeset >/dev/null; then
39
+ # ksh93 and older have typeset but not local, and expand aliases at parse
40
+ # time so require re-sourcing the script
41
+ alias local=typeset
42
+ if [ -z "${KSH_VERSION-}" ] || (eval : '"${.sh.version}"' >/dev/null 2>&1); then
43
+ # shellcheck source=/dev/null
44
+ . "$0"
45
+ exit
46
+ fi
47
+ else
48
+ echo >&2 "Error: Your shell does not support local variables. Re-run this script with one that does (e.g. bash, ksh)"
49
+ exit 1
50
+ fi
51
+
52
+ # ----- Helper functions ------------------------------------------------------
53
+
54
+ # esceval [ARGUMENT...]
55
+ #
56
+ # Escape ARGUMENT for safe use with eval
57
+ # Returns escaped arguments via $REPLY
58
+ # Thanks to @mentalisttraceur for original implementation:
59
+ # https://github.com/mentalisttraceur/esceval
60
+ esceval()
61
+ {
62
+ local escaped= unescaped= output=
63
+ REPLY=
64
+
65
+ [ $# -gt 0 ] || return 0
66
+ while true; do
67
+ escaped=\'
68
+ unescaped=$1
69
+ while true; do
70
+ case $unescaped in
71
+ (*\'*)
72
+ escaped="$escaped${unescaped%%\'*}'\''"
73
+ unescaped=${unescaped#*\'}
74
+ ;;
75
+ (*) break ;;
76
+ esac
77
+ done
78
+ escaped=$escaped$unescaped\'
79
+ shift
80
+ [ $# -gt 0 ] || break
81
+ output="$output $escaped"
82
+ done
83
+ REPLY="$output $escaped"
84
+ }
85
+
86
+ # assign LISTNAME ELEMENT [ELEMENT...]
87
+ #
88
+ # Assign ELEMENT to the list named by LISTNAME.
89
+ assign() {
90
+ local listname="$1"
91
+ local REPLY=
92
+ shift
93
+
94
+ esceval "$@"
95
+ eval "$listname=\"\${REPLY}\""
96
+ }
97
+
98
+ # append LISTNAME ELEMENT [ELEMENT...]
99
+ #
100
+ # Append ELEMENT to the list named by LISTNAME.
101
+ append() {
102
+ local listname="$1"
103
+ local REPLY=
104
+ shift
105
+
106
+ esceval "$@"
107
+ eval "$listname=\"\${$listname} \${REPLY}\""
108
+ }
109
+
110
+ # prepend LISTNAME ELEMENT [ELEMENT...]
111
+ #
112
+ # Prepend ELEMENT to the list named by LISTNAME, preserving order.
113
+ prepend() {
114
+ local listname="$1"
115
+ local REPLY=
116
+ shift
117
+
118
+ esceval "$@"
119
+ eval "$listname=\"\${REPLY} \${$listname}\""
120
+ }
121
+
122
+ # extend LISTNAME1 LISTNAME2
123
+ #
124
+ # Append the elements stored in the list named by LISTNAME2
125
+ # to the list named by LISTNAME1.
126
+ extend() {
127
+ eval "$1=\"\${$1} \${$2}\""
128
+ }
129
+
130
+ # preextend LISTNAME1 LISTNAME2
131
+ #
132
+ # Prepend the elements stored in the list named by LISTNAME2
133
+ # to the named by LISTNAME1, preserving order.
134
+ preextend() {
135
+ eval "$1=\"\${$2} \${$1}\""
136
+ }
137
+
138
+ # a_isempty
139
+ #
140
+ # Return 0 if an array is empty, otherwise return 1
141
+ a_isempty() {
142
+ case $ruby_args in
143
+ (*[![:space:]]*) return 1 ;; # If any nonblank, not empty
144
+ esac
145
+ return 0
146
+ }
147
+
148
+ # exists [FILE...]
149
+ #
150
+ # Returns 0 if all FILEs exist or none provided, otherwise returns 1
151
+ exists() {
152
+ while [ "$#" -gt 0 ]; do
153
+ [ -e "$1" ] || return
154
+ shift
155
+ done
156
+
157
+ return 0
158
+ }
159
+
160
+ # is_newer FILE OTHER...
161
+ #
162
+ # Returns 0 if FILE is newer than all OTHER files. If FILE doesn't exist,
163
+ # return error. If OTHER files don't exist, pretend they're older than FILE.
164
+ is_newer() {
165
+ local output master
166
+ master="$1"
167
+ shift
168
+
169
+ # Find any other files that are newer, negate outside find in case any don't exist
170
+ [ -e "$master" ] && ! find "$@" -newer "$master" 2>/dev/null | read -r _
171
+ }
172
+
173
+ # echo [STRING...]
174
+ #
175
+ # Dumb echo, i.e. print arguments joined by spaces with no further processing
176
+ echo() {
177
+ printf "%s\n" "$*"
178
+ }
179
+
180
+ # ----- Set variable defaults -------------------------------------------------
181
+
182
+ java_class=org.jruby.Main
183
+ JRUBY_SHELL=/bin/sh
184
+
185
+ # Detect cygwin and mingw environments
186
+ cygwin=false
187
+ case "$(uname)" in
188
+ CYGWIN*) cygwin=true ;;
189
+ MINGW*)
190
+ release_id=$(awk -F= '$1=="ID" { print $2; }' /etc/os-release 2> /dev/null)
191
+ case $release_id in
192
+ "msys2") ;;
193
+ *)
194
+ jruby.exe "$@"
195
+ exit $?
196
+ ;;
197
+ esac
198
+ ;;
199
+ esac
200
+ readonly cygwin
201
+
202
+ use_exec=true
203
+ jdb=false
204
+
205
+ NO_BOOTCLASSPATH=false
206
+ VERIFY_JRUBY=false
207
+ print_environment_log=false
208
+ regenerate_jsa_file=false
209
+ remove_jsa_files=false
210
+ log_cds=false
211
+
212
+ if [ -z "${JRUBY_OPTS-}" ]; then
213
+ JRUBY_OPTS=""
214
+ fi
215
+
216
+ if [ -z "${JAVA_STACK-}" ]; then
217
+ JAVA_STACK=-Xss2048k
218
+ fi
219
+
220
+ java_args=""
221
+ ruby_args=""
222
+
223
+ # shellcheck disable=2034 # variable is only read in an eval
224
+ java_opts_from_files=""
225
+ # shellcheck disable=2034 # variable is only read in an eval
226
+ jdb_args=""
227
+
228
+ # Force OpenJDK-based JVMs to use /dev/urandom for random number generation
229
+ # See https://github.com/jruby/jruby/issues/4685 among others.
230
+ # OpenJDK tries really hard to prevent you from using urandom.
231
+ # See https://bugs.openjdk.java.net/browse/JDK-6202721
232
+ # Non-file URL causes fallback to slow threaded SeedGenerator.
233
+ # See https://bz.apache.org/bugzilla/show_bug.cgi?id=56139
234
+ if [ -r "/dev/urandom" ]; then
235
+ JAVA_SECURITY_EGD="file:/dev/urandom"
236
+ fi
237
+
238
+ # Gather environment information as we go
239
+ readonly cr='
240
+ '
241
+ environment_log="JRuby Environment$cr================="
242
+ add_log() {
243
+ environment_log="${environment_log}${cr}${*-}"
244
+ }
245
+
246
+ # Logic to process "arguments files" on both Java 8 and Java 9+
247
+ process_java_opts() {
248
+ local java_opts_file="$1"
249
+ if [ -r "$java_opts_file" ]; then
250
+ add_log
251
+ add_log "Adding Java options from: $java_opts_file"
252
+
253
+ # On Java 9+, add an @argument for the given file.
254
+ # On earlier versions the file contents will be read and expanded on the Java command line.
255
+ if $use_modules; then
256
+ append java_opts_from_files "@$java_opts_file"
257
+ else
258
+ local line=
259
+ while read -r line; do
260
+ if [ "$line" ]; then
261
+ # shellcheck disable=2086 # Split options on whitespace
262
+ append java_opts_from_files $line
263
+ add_log " $line"
264
+ fi
265
+ done < "$java_opts_file"
266
+ fi
267
+ fi
268
+ }
269
+
270
+ # Pure shell dirname/basename
271
+ dir_name() {
272
+ local filename="$1" trail=
273
+ case $filename in
274
+ */*[!/]*)
275
+ trail=${filename##*[!/]}
276
+ filename=${filename%%"$trail"}
277
+ REPLY=${filename%/*}
278
+ ;;
279
+ *[!/]*)
280
+ trail=${filename##*[!/]}
281
+ REPLY="."
282
+ ;;
283
+ *)
284
+ REPLY="/"
285
+ ;;
286
+ esac
287
+ }
288
+
289
+ base_name() {
290
+ local filename="$1" trail=
291
+ case $filename in
292
+ */*[!/]*)
293
+ trail=${filename##*[!/]}
294
+ filename=${filename%%"$trail"}
295
+ REPLY=${filename##*/}
296
+ ;;
297
+ *[!/]*)
298
+ trail=${filename##*[!/]}
299
+ REPLY=${filename%%"$trail"}
300
+ ;;
301
+ *)
302
+ REPLY="/"
303
+ ;;
304
+ esac
305
+ }
306
+
307
+ # Determine whether path is absolute and contains no relative segments or symlinks
308
+ path_is_canonical() {
309
+ local path=
310
+ for path; do
311
+ case $path in
312
+ ([!/]*) return 1 ;;
313
+ (./*|../*) return 1 ;;
314
+ (*/.|*/..) return 1 ;;
315
+ (*/./*|*/../*) return 1 ;;
316
+ esac
317
+ while [ "$path" ]; do
318
+ [ -h "$path" ] && return 1
319
+ path="${path%/*}"
320
+ done
321
+ done
322
+ return 0
323
+ }
324
+
325
+ # Resolve directory to its canonical value
326
+ resolve_dir() {
327
+ # Some shells (dash, ksh) resolve relative paths by default before cd'ing, i.e.
328
+ # cd /foo/bar/../baz = cd /foo/baz
329
+ # This is fine unless bar is a symlink, in which case the second form is
330
+ # invalid. Passing -P to cd fixes this behaviour.
331
+ REPLY="$(cd -P -- "$1" && pwd)"
332
+ }
333
+
334
+ # Resolve symlink until it's not a symlink
335
+ resolve_file() {
336
+ local current="$1" target=
337
+
338
+ while [ -h "$current" ]; do
339
+ target="$(readlink "$current")" || return
340
+ case $target in
341
+ (/*) current="$target" ;;
342
+ # handle relative symlinks
343
+ (*) dir_name "$current"; current="$REPLY/$target" ;;
344
+ esac
345
+ done
346
+ REPLY="$current"
347
+ }
348
+
349
+ # Resolve path to its canonical value
350
+ resolve() {
351
+ local target="$1" base=
352
+ REPLY=
353
+
354
+ # Verify target actually exists (and isn't too deep in symlinks)
355
+ if ! [ -e "$target" ]; then
356
+ echo >&2 "Error: No such file or directory: $target"
357
+ return 1
358
+ fi
359
+
360
+ # Realpath is way faster than repeatedly calling readlink, so use it if possible
361
+ if command -v realpath >/dev/null; then
362
+ REPLY="$(realpath "$target")" && return
363
+ fi
364
+
365
+ # Take shortcut for directories
366
+ if [ -d "$target" ]; then
367
+ resolve_dir "$target" && return
368
+ fi
369
+
370
+ # Ensure $target is not a symlink
371
+ resolve_file "$target" || return
372
+ target="$REPLY"
373
+
374
+ # Resolve parent directory if it's not absolute
375
+ if ! path_is_canonical "$target"; then
376
+ dir_name "$target"
377
+ resolve_dir "$REPLY" || return
378
+ base="$REPLY"
379
+
380
+ base_name "$target"
381
+ target="$base/$REPLY"
382
+ fi
383
+ REPLY="$target"
384
+ }
385
+
386
+ # ----- Determine JRUBY_HOME based on this executable's path ------------------
387
+
388
+ # get the absolute path of the executable
389
+ if [ "${BASH-}" ]; then
390
+ # shellcheck disable=2128,3028
391
+ script_src="${BASH_SOURCE-}"
392
+ else
393
+ script_src="$0"
394
+ fi
395
+ dir_name "$script_src"
396
+ BASE_DIR="$(cd -P -- "$REPLY" >/dev/null && pwd -P)"
397
+ base_name "$script_src"
398
+ resolve "$BASE_DIR/$REPLY"
399
+ SELF_PATH="$REPLY"
400
+
401
+ JRUBY_HOME="${SELF_PATH%/*/*}"
402
+
403
+ # ----- File paths for various options and files we'll process later ----------
404
+
405
+ # Module options to open up packages we need to reflect
406
+ readonly jruby_module_opts_file="$JRUBY_HOME/bin/.jruby.module_opts"
407
+
408
+ # Cascading .java_opts files for localized JVM flags
409
+ readonly installed_jruby_java_opts_file="$JRUBY_HOME/bin/.jruby.java_opts"
410
+ if [ -z "${HOME-}" ]; then
411
+ readonly home_jruby_java_opts_file=""
412
+ else
413
+ readonly home_jruby_java_opts_file="$HOME/.jruby.java_opts"
414
+ fi
415
+ readonly pwd_jruby_java_opts_file="$PWD/.jruby.java_opts"
416
+
417
+ # Options from .dev_mode.java_opts for "--dev" mode, to reduce JRuby startup time
418
+ readonly dev_mode_opts_file="$JRUBY_HOME/bin/.dev_mode.java_opts"
419
+
420
+ # ----- Initialize environment log --------------------------------------------
421
+
422
+ add_log
423
+ add_log "JRuby executable:"
424
+ add_log " $script_src"
425
+ add_log "JRuby command line options:"
426
+ add_log " $*"
427
+ add_log "Current directory:"
428
+ add_log " $PWD"
429
+
430
+ add_log
431
+ add_log "Environment:"
432
+ add_log " JRUBY_HOME: $JRUBY_HOME"
433
+ add_log " JRUBY_OPTS: $JRUBY_OPTS"
434
+ add_log " JAVA_OPTS: ${JAVA_OPTS-}"
435
+
436
+ # ----- Discover JVM and prep environment to run it ---------------------------
437
+
438
+ # Determine where the java command is and ensure we have a good JAVA_HOME
439
+ if [ -z "${JAVACMD-}" ]; then
440
+ if [ -z "${JAVA_HOME-}" ]; then
441
+ readonly java_home_command="/usr/libexec/java_home"
442
+ if [ -r "$java_home_command" ] \
443
+ && [ -x "$java_home_command" ] \
444
+ && [ ! -d "$java_home_command" ]
445
+ then
446
+ # use java_home command when none is set (on MacOS)
447
+ JAVA_HOME="$("$java_home_command")" &&
448
+ JAVACMD="$JAVA_HOME"/bin/java
449
+ else
450
+ # Linux and others have a chain of symlinks
451
+ JAVACMD="$(command -v java)" &&
452
+ resolve "$JAVACMD" &&
453
+ JAVACMD="$REPLY"
454
+ fi
455
+ elif $cygwin; then
456
+ JAVACMD="$(cygpath -u "$JAVA_HOME")/bin/java"
457
+ else
458
+ resolve "$JAVA_HOME/bin/java" &&
459
+ JAVACMD="$REPLY"
460
+ fi
461
+ else
462
+ JAVACMD="$(command -v "$JAVACMD")" &&
463
+ resolve "$JAVACMD" &&
464
+ JAVACMD="$REPLY"
465
+ fi || {
466
+ # Something went wrong when looking for java
467
+ echo >&2 "${0##*/}: Error: Java executable not found!"
468
+ exit 2
469
+ }
470
+
471
+ # export separately from command execution
472
+ dir_name "$JAVACMD"
473
+ dir_name "$REPLY"
474
+ JAVA_HOME="$REPLY"
475
+
476
+ # Detect modularized Java
477
+ java_is_modular() {
478
+ # check that modules file is present
479
+ if [ -f "$JAVA_HOME"/lib/modules ]; then
480
+ return 0
481
+ fi
482
+
483
+ # check if a MODULES line appears in release
484
+ if [ -f "$JAVA_HOME"/release ] && grep -q ^MODULES "$JAVA_HOME"/release; then
485
+ return 0
486
+ fi
487
+
488
+ return 1
489
+ }
490
+
491
+ if java_is_modular; then
492
+ use_modules=true
493
+ else
494
+ use_modules=false
495
+ fi
496
+ readonly use_modules
497
+
498
+ add_log " JAVACMD: $JAVACMD"
499
+ add_log " JAVA_HOME: $JAVA_HOME"
500
+
501
+ if $use_modules; then
502
+ add_log
503
+ add_log "Detected Java modules at $JAVA_HOME"
504
+ fi
505
+
506
+ # ----- Detect Java version and determine available features ------------------
507
+ # shellcheck source=/dev/null
508
+ if [ -f "$JAVA_HOME/release" ]; then
509
+ java_version=$(. "$JAVA_HOME/release" && echo "${JAVA_VERSION-}")
510
+
511
+ # convert version to major, considering 1.8 as 8
512
+ case $java_version in
513
+ 1.8 | 1.8.*) java_major=8 ;;
514
+ *) java_major=${java_version%%.*} ;;
515
+ esac
516
+ else
517
+ # assume Java 8 if no release file
518
+ java_version=1.8
519
+ java_major=8
520
+ fi
521
+
522
+ # shellcheck source=/dev/null
523
+ if [ -f "$JRUBY_HOME/bin/.java-version" ] && . "$JRUBY_HOME/bin/.java-version" && [ "${JRUBY_MINIMUM_JAVA_VERSION-}" ]; then
524
+ minimum_java_version=$JRUBY_MINIMUM_JAVA_VERSION
525
+ else
526
+ # Only 9.4.12.0 and earlier will have shipped without a .java-version file, so fall back on minimum of 8
527
+ minimum_java_version=8
528
+ fi
529
+ add_log "Detected Java version: $java_version"
530
+
531
+ # Present a useful error if running a Java version lower than bin/.java-version
532
+ if [ "$java_major" -lt "$minimum_java_version" ]; then
533
+ echo "This version of JRuby requires Java ${minimum_java_version}+."
534
+ echo "Make sure JAVA_HOME points at JDK ${minimum_java_version} or higher"
535
+ echo "Detected Java version: $java_version"
536
+ echo "Detected JAVA_HOME: $JAVA_HOME"
537
+ exit 1
538
+ fi
539
+
540
+ # AppCDS support
541
+ if [ "$java_major" -ge 13 ] && exists "$JAVA_HOME"/lib/server/*.jsa; then
542
+ java_has_appcds=true
543
+ else
544
+ java_has_appcds=false
545
+ fi
546
+ readonly java_has_appcds
547
+
548
+ # Default to using AppCDS if available
549
+ use_jsa_file="$java_has_appcds"
550
+
551
+ # AppCDS autogeneration
552
+ if [ "$java_major" -ge 19 ]; then
553
+ java_has_appcds_autogenerate=true
554
+ else
555
+ java_has_appcds_autogenerate=false
556
+ fi
557
+ readonly java_has_appcds_autogenerate
558
+
559
+ # Native access
560
+ if [ "$java_major" -ge 22 ]; then
561
+ enable_native_access=true
562
+ else
563
+ enable_native_access=false
564
+ fi
565
+ readonly enable_native_access
566
+
567
+ # Unsafe memory access
568
+ if [ "$java_major" -ge 23 ]; then
569
+ enable_unsafe_memory=true
570
+ else
571
+ enable_unsafe_memory=false
572
+ fi
573
+ readonly enable_unsafe_memory
574
+
575
+ # ----- Process .java_opts files ----------------------------------------------
576
+
577
+ # We include options on the java command line in the following order:
578
+ #
579
+ # * JRuby installed bin/.jruby.java_opts (empty by default)
580
+ # * user directory .jruby.java_opts
581
+ # * current directory .jruby.java_opts
582
+ # * dev mode options from bin/.dev_mode.java_opts, if --dev is specified
583
+ # * module options from bin/.jruby.module_opts if modules are detected
584
+ # * JAVA_OPTS environment variable
585
+ # * command line flags
586
+
587
+ # Add local and global .jruby.java_opts
588
+ process_java_opts "$installed_jruby_java_opts_file"
589
+ process_java_opts "$home_jruby_java_opts_file"
590
+ process_java_opts "$pwd_jruby_java_opts_file"
591
+
592
+ # Capture some Java options to be passed separately
593
+ JAVA_OPTS_TEMP=""
594
+ for opt in ${JAVA_OPTS-}; do
595
+ case $opt in
596
+ -Xmx*) JAVA_MEM="$opt" ;;
597
+ -Xss*) JAVA_STACK="$opt" ;;
598
+ *) JAVA_OPTS_TEMP="$JAVA_OPTS_TEMP $opt" ;;
599
+ esac
600
+ done
601
+
602
+ JAVA_OPTS="$JAVA_OPTS_TEMP"
603
+
604
+ # ----- Set up the JRuby class/module path ------------------------------------
605
+
606
+ CP_DELIMITER=":"
607
+
608
+ # Find main jruby jar and add it to the classpath
609
+ jruby_jar=
610
+ for j in "$JRUBY_HOME"/lib/jruby.jar "$JRUBY_HOME"/lib/jruby-complete.jar; do
611
+ if [ ! -e "$j" ]; then
612
+ continue
613
+ fi
614
+ if [ "${JRUBY_CP-}" ]; then
615
+ JRUBY_CP="$JRUBY_CP$CP_DELIMITER$j"
616
+ else
617
+ JRUBY_CP="$j"
618
+ fi
619
+ if [ -n "$jruby_jar" ]; then
620
+ echo "WARNING: more than one JRuby JAR found in lib directory" 1>&2
621
+ fi
622
+ jruby_jar="$j"
623
+ done
624
+ readonly jruby_jar
625
+
626
+ if $cygwin; then
627
+ JRUBY_CP="$(cygpath -p -w "$JRUBY_CP")"
628
+ fi
629
+
630
+ # ----- Add additional jars from lib to classpath -----------------------------
631
+
632
+ if [ "${JRUBY_PARENT_CLASSPATH-}" ]; then
633
+ # Use same classpath propagated from parent jruby
634
+ CP="$JRUBY_PARENT_CLASSPATH"
635
+ else
636
+ # add other jars in lib to CP for command-line execution
637
+ for j in "$JRUBY_HOME"/lib/*.jar; do
638
+ case "${j#"$JRUBY_HOME/lib/"}" in
639
+ jruby.jar|jruby-complete.jar) continue
640
+ esac
641
+ if [ -z "${CP-}" ]; then
642
+ CP="$j"
643
+ else
644
+ CP="$CP$CP_DELIMITER$j"
645
+ fi
646
+ done
647
+
648
+ if [ "${CP-}" ] && $cygwin; then
649
+ CP="$(cygpath -p -w "$CP")"
650
+ fi
651
+ fi
652
+
653
+ if $cygwin; then
654
+ # switch delimiter only after building Unix style classpaths
655
+ CP_DELIMITER=";"
656
+ fi
657
+
658
+ readonly CP_DELIMITER
659
+
660
+ # ----- Continue processing JRuby options into JVM options --------------------
661
+
662
+ # Split out any -J argument for passing to the JVM.
663
+ # Scanning for args is aborted by '--'.
664
+ # shellcheck disable=2086
665
+ set -- $JRUBY_OPTS "$@"
666
+ # increment pointer, permute arguments
667
+ while [ $# -gt 0 ]
668
+ do
669
+ case $1 in
670
+ # Stuff after '-J' in this argument goes to JVM
671
+ -J-Xmx*) JAVA_MEM="${1#-J}" ;;
672
+ -J-Xss*) JAVA_STACK="${1#-J}" ;;
673
+ -J)
674
+ "$JAVACMD" -help
675
+ echo "(Prepend -J in front of these options when using 'jruby' command)" 1>&2
676
+ exit
677
+ ;;
678
+ -J-X)
679
+ "$JAVACMD" -X
680
+ echo "(Prepend -J in front of these options when using 'jruby' command)" 1>&2
681
+ exit
682
+ ;;
683
+ -J-classpath|-J-cp)
684
+ if [ -z "${CP-}" ]; then
685
+ CP="$2"
686
+ else
687
+ CP="$CP$CP_DELIMITER$2"
688
+ fi
689
+ CLASSPATH=""
690
+ shift
691
+ ;;
692
+ -J-ea*)
693
+ VERIFY_JRUBY=true
694
+ append java_args "${1#-J}"
695
+ ;;
696
+ -J-Djava.security.egd=*) JAVA_SECURITY_EGD=${1#-J-Djava.security.egd=} ;;
697
+ # This must be the last check for -J
698
+ -J*) append java_args "${1#-J}" ;;
699
+ # Pass -X... and -X? search options through
700
+ -X*...|-X*\?) append ruby_args "$1" ;;
701
+ # Match -Xa.b.c=d to translate to -Da.b.c=d as a java option
702
+ -X*.*) append java_args -Djruby."${1#-X}" ;;
703
+ # Match switches that take an argument
704
+ -[CeIS])
705
+ append ruby_args "$1" "$2"
706
+ shift
707
+ ;;
708
+ # Run with JMX management enabled
709
+ --manage)
710
+ append java_args -Dcom.sun.management.jmxremote
711
+ append java_args -Djruby.management.enabled=true
712
+ ;;
713
+ # Don't launch a GUI window, no matter what
714
+ --headless) append java_args -Djava.awt.headless=true ;;
715
+ # Run under JDB
716
+ --jdb)
717
+ jdb=true
718
+ if [ -z "$JAVA_HOME" ]; then
719
+ JAVACMD='jdb'
720
+ else
721
+ if $cygwin; then
722
+ JAVACMD="$(cygpath -u "$JAVA_HOME")/bin/jdb"
723
+ else
724
+ JAVACMD="$JAVA_HOME/bin/jdb"
725
+ fi
726
+ fi
727
+ JDB_SOURCEPATH="${JRUBY_HOME}/core/src/main/java:${JRUBY_HOME}/lib/ruby/stdlib:."
728
+ append jdb_args -sourcepath "$JDB_SOURCEPATH"
729
+ append ruby_args -X+C
730
+ ;;
731
+ --client|--server|--noclient)
732
+ echo "Warning: the $1 flag is deprecated and has no effect most JVMs" 1>&2
733
+ ;;
734
+ --dev)
735
+ process_java_opts "$dev_mode_opts_file"
736
+ # For OpenJ9 use environment variable to enable quickstart and shareclasses
737
+ export OPENJ9_JAVA_OPTIONS="-Xquickstart -Xshareclasses"
738
+ ;;
739
+ --sample) append java_args -Xprof ;;
740
+ --record)
741
+ append java_args -XX:+FlightRecorder -XX:StartFlightRecording=dumponexit=true
742
+ ;;
743
+ --no-bootclasspath) NO_BOOTCLASSPATH=true ;;
744
+ --ng*)
745
+ echo "Error: Nailgun is no longer supported" 1>&2
746
+ exit 1
747
+ ;;
748
+ --environment) print_environment_log=true ;;
749
+ # warn but ignore
750
+ --1.8|--1.9|--2.0) echo "warning: $1 ignored" 1>&2 ;;
751
+ --checkpoint=*)
752
+ java_class=org.jruby.main.CheckpointMain
753
+ append java_args -XX:CRaCCheckpointTo="${1#--checkpoint=}" ;;
754
+ # capture a checkpoint to specified location
755
+ --checkpoint)
756
+ java_class=org.jruby.main.CheckpointMain
757
+ append java_args -XX:CRaCCheckpointTo=.jruby.checkpoint ;;
758
+ # restore from checkpoint
759
+ --restore=*) append java_args -XX:CRaCRestoreFrom="${1#--restore=}" ;;
760
+ --restore) append java_args -XX:CRaCRestoreFrom=.jruby.checkpoint ;;
761
+ --cache)
762
+ if ! $java_has_appcds; then
763
+ echo "Error: Java $java_major doesn't support automatic AppCDS" >&2
764
+ exit 2
765
+ fi
766
+ regenerate_jsa_file=true # Force regeneration of archive
767
+ ;;
768
+ --nocache) use_jsa_file=false ;;
769
+ --rmcache) remove_jsa_files=true ;;
770
+ --logcache) log_cds=true ;;
771
+ # Abort processing on the double dash
772
+ --) break ;;
773
+ # Other opts go to ruby
774
+ -*) append ruby_args "$1" ;;
775
+ # Abort processing on first non-opt arg
776
+ *) break ;;
777
+ esac
778
+ shift
779
+ done
780
+
781
+ # Force JDK to use specified java.security.egd rand source
782
+ if [ -n "${JAVA_SECURITY_EGD-}" ]; then
783
+ append java_args "-Djava.security.egd=$JAVA_SECURITY_EGD"
784
+ fi
785
+
786
+ # The rest of the arguments are for ruby
787
+ append ruby_args "$@"
788
+
789
+ JAVA_OPTS="$JAVA_OPTS ${JAVA_MEM-} ${JAVA_STACK-}"
790
+
791
+ JFFI_OPTS="-Djffi.boot.library.path=$JRUBY_HOME/lib/jni"
792
+
793
+ CLASSPATH="${CP-}${CP_DELIMITER}${CLASSPATH-}"
794
+
795
+ # ----- Module and Class Data Sharing flags for Java 9+ -----------------------
796
+
797
+ if $use_modules; then
798
+ # Switch to non-boot path since we can't use bootclasspath on 9+
799
+ NO_BOOTCLASSPATH=true
800
+
801
+ # Add base opens we need for Ruby compatibility
802
+ process_java_opts "$jruby_module_opts_file"
803
+ fi
804
+
805
+ # 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"
807
+
808
+ # Find JSAs for all Java versions
809
+ assign jruby_jsa_files "$JRUBY_HOME"/lib/jruby-java*.jsa
810
+ readonly jruby_jsa_files
811
+
812
+ # Allow overriding default JSA file location
813
+ if [ -n "${JRUBY_JSA-}" ]; then
814
+ jruby_jsa_file="$JRUBY_JSA"
815
+ fi
816
+
817
+ # Ensure the AppCDS parent directory is actually writable
818
+ if dir_name "$jruby_jsa_file" && ! [ -w "$REPLY" ]; then
819
+ if $use_jsa_file || $regenerate_jsa_file || $remove_jsa_files; then
820
+ echo "Warning: AppCDS archive directory is not writable, disabling AppCDS operations" >&2
821
+ fi
822
+ regenerate_jsa_file=false
823
+ remove_jsa_files=false
824
+ use_jsa_file=false
825
+ fi
826
+
827
+ # Initialize AppCDS
828
+ if $use_jsa_file; then
829
+ # Default to no-op script when explicitly generating
830
+ if $regenerate_jsa_file && a_isempty "$ruby_args"; then
831
+ append ruby_args -e 1
832
+ fi
833
+
834
+ # Archive should be regenerated manually if requested or it's outdated relative to JRuby
835
+ if ! $regenerate_jsa_file && is_newer "$jruby_jar" "$jruby_jsa_file"; then
836
+ regenerate_jsa_file=true
837
+ fi
838
+
839
+ # Defer generation to Java if flag is available
840
+ if $java_has_appcds_autogenerate; then
841
+ append java_args -XX:+AutoCreateSharedArchive
842
+
843
+ add_log
844
+ add_log "Automatically generating and using CDS archive at:"
845
+ add_log " $jruby_jsa_file"
846
+ fi
847
+
848
+ # Determine if we should read or explicitly write the archive
849
+ if $regenerate_jsa_file && ! $java_has_appcds_autogenerate; then
850
+ # Explicitly create archive if outdated
851
+ append java_args -XX:ArchiveClassesAtExit="$jruby_jsa_file"
852
+
853
+ add_log
854
+ add_log "Regenerating CDS archive at:"
855
+ add_log " $jruby_jsa_file"
856
+ else
857
+ # Read archive if not explicitly regenerating
858
+ append java_args -XX:SharedArchiveFile="$jruby_jsa_file"
859
+
860
+ if ! $java_has_appcds_autogenerate; then
861
+ add_log
862
+ add_log "Using CDS archive at:"
863
+ add_log " $jruby_jsa_file"
864
+ fi
865
+ fi
866
+
867
+ if $log_cds; then
868
+ add_log "Logging CDS output to:"
869
+ add_log " $jruby_jsa_file.log"
870
+ append java_args -Xlog:cds=info:file="$jruby_jsa_file".log
871
+ append java_args -Xlog:cds+dynamic=info:file="$jruby_jsa_file".log
872
+ else
873
+ append java_args -Xlog:cds=off -Xlog:cds+dynamic=off
874
+ fi
875
+ fi
876
+
877
+ # Enable access to native libraries
878
+ if $enable_native_access; then
879
+ append java_args --enable-native-access=org.jruby.dist
880
+ fi
881
+
882
+ # Enable access to Unsafe memory functions
883
+ if $enable_unsafe_memory; then
884
+ append java_args --sun-misc-unsafe-memory-access=allow
885
+ fi
886
+
887
+ # Enable access to Unsafe memory functions
888
+
889
+ # ----- Tweak console environment for cygwin ----------------------------------
890
+
891
+ if $cygwin; then
892
+ use_exec=false
893
+ JRUBY_HOME="$(cygpath --mixed "$JRUBY_HOME")"
894
+ JRUBY_SHELL="$(cygpath --mixed "$JRUBY_SHELL")"
895
+
896
+ eval set -- "$ruby_args"
897
+
898
+ case $1 in
899
+ /*)
900
+ if [ -f "$1" ] || [ -d "$1" ]; then
901
+ # replace first element of ruby_args with cygwin form
902
+ win_arg="$(cygpath -w "$1")"
903
+ shift
904
+ set -- "$win_arg" "$@"
905
+ assign ruby_args "$@"
906
+ fi
907
+ ;;
908
+ esac
909
+
910
+ # fix JLine to use UnixTerminal
911
+ if stty -icanon min 1 -echo > /dev/null 2>&1; then
912
+ JAVA_OPTS="$JAVA_OPTS -Djline.terminal=jline.UnixTerminal"
913
+ fi
914
+
915
+ fi
916
+
917
+ # ----- Final prepration of the Java command line -----------------------------
918
+
919
+ # Don't quote JAVA_OPTS; we want it to expand
920
+ # shellcheck disable=2086
921
+ prepend java_args $JAVA_OPTS "$JFFI_OPTS"
922
+
923
+ # Include all options from files at the beginning of the Java command line
924
+ preextend java_args java_opts_from_files
925
+
926
+ if $jdb; then
927
+ preextend java_args jdb_args
928
+ fi
929
+
930
+ prepend java_args "$JAVACMD"
931
+
932
+ if $NO_BOOTCLASSPATH || $VERIFY_JRUBY; then
933
+ if $use_modules; then
934
+ # Use module path instead of classpath for the jruby libs
935
+ append java_args --module-path "$JRUBY_CP" -classpath "$CLASSPATH"
936
+ else
937
+ append java_args -classpath "$JRUBY_CP$CP_DELIMITER$CLASSPATH"
938
+ fi
939
+ else
940
+ append java_args -Xbootclasspath/a:"$JRUBY_CP"
941
+ append java_args -classpath "$CLASSPATH"
942
+ append java_args -Djruby.home="$JRUBY_HOME"
943
+ fi
944
+
945
+ append java_args -Djruby.home="$JRUBY_HOME" \
946
+ -Djruby.lib="$JRUBY_HOME/lib" \
947
+ -Djruby.script=jruby \
948
+ -Djruby.shell="$JRUBY_SHELL" \
949
+ "$java_class"
950
+ extend java_args ruby_args
951
+
952
+ eval set -- "$java_args"
953
+
954
+ add_log
955
+ add_log "Java command line:"
956
+ add_log " $*"
957
+
958
+ if $print_environment_log; then
959
+ echo "$environment_log"
960
+ exit 0
961
+ fi
962
+
963
+ # ----- Perform final mutations after logging ---------------------------------
964
+ # Delete All AppCDS files and exit if requested
965
+ if $remove_jsa_files; then
966
+ eval rm -f -- "$jruby_jsa_files"
967
+ exit
968
+ fi
969
+
970
+ if $regenerate_jsa_file && [ -e "$jruby_jsa_file" ]; then
971
+ # Delete selected AppCDS file if requested or if it's outdated
972
+ rm -f -- "$jruby_jsa_file"
973
+ fi
974
+
975
+ # ----- Run JRuby! ------------------------------------------------------------
976
+
977
+ if $use_exec; then
978
+ exec "$@"
979
+ else
980
+ "$@"
981
+
982
+ # Record the exit status immediately, or it will be overridden.
983
+ JRUBY_STATUS=$?
984
+
985
+ if $cygwin; then
986
+ stty icanon echo > /dev/null 2>&1
987
+ fi
988
+
989
+ exit $JRUBY_STATUS
990
+ fi