|
2 | 2 | require_relative '../jruby_art/jruby_complete' |
3 | 3 | require_relative '../jruby_art/java_opts' |
4 | 4 | module Processing |
5 | | - # This is class wrapper for building the command |
| 5 | + # The command class check for configuration and options, before creating and |
| 6 | + # executing the jruby (or java) command to run the sketch |
6 | 7 | class Command |
7 | | - attr_reader :executable, :runner, :args, :filename |
8 | | - def initialize(executable:, runner:, args:, filename:) |
9 | | - @executable = executable |
| 8 | + attr_reader :runner, :args, :filename |
| 9 | + def initialize(runner:, args:, filename:) |
10 | 10 | @runner = runner |
11 | 11 | @args = args |
12 | 12 | @filename = filename |
13 | 13 | end |
14 | 14 |
|
| 15 | + # Trade in this Ruby instance for a JRuby instance, loading in a starter |
| 16 | + # script and passing it some arguments. Unless you set JRUBY: false in |
| 17 | + # ~/.jruby_art/config.yml, an installed version of jruby is used instead |
| 18 | + # of our vendored one. Note the use of jruby-complete might make using |
| 19 | + # other gems in your sketches hard (but not impossible).... |
15 | 20 | def cmd(root) |
16 | | - if executable =~ /jruby/ |
17 | | - cmda = [executable, JRubyOpts.new(root).opts, runner, filename, args].flatten |
18 | | - else |
19 | | - cmda = [executable, JavaOpts.new(root).opts, '-cp', JRubyComplete.complete, 'org.jruby.Main', runner, filename, args].flatten |
20 | | - end |
| 21 | + cmda = jruby_command(Processing::RP_CONFIG.fetch('JRUBY', true), root) |
21 | 22 | begin |
22 | | - # exec(*command) |
23 | 23 | exec(*cmda) |
24 | 24 | # exec replaces the Ruby process with the JRuby one. |
25 | 25 | rescue Java::JavaLang::ClassNotFoundException |
26 | 26 | end |
27 | 27 | end |
| 28 | + |
| 29 | + private |
| 30 | + |
| 31 | + # avoiding multiline ternary etc |
| 32 | + def jruby_command(installed, root) |
| 33 | + opts = JRubyOpts.new(root).opts |
| 34 | + return ['jruby', opts, runner, filename, args].flatten if installed |
| 35 | + ['java', opts, '-cp', JRubyComplete.complete, 'org.jruby.Main', runner, filename, args].flatten |
| 36 | + end |
28 | 37 | end |
29 | 38 | end |
0 commit comments