@@ -5,11 +5,13 @@ module Processing
55 # The command class check for configuration and options, before creating and
66 # executing the jruby (or java) command to run the sketch
77 class Launcher
8- attr_reader :runner , :args , :filename
8+ attr_reader :command
99 def initialize ( runner :, args :, filename :)
10- @runner = runner
11- @args = args
12- @filename = filename
10+ @command = if Processing ::RP_CONFIG . fetch ( 'JRUBY' , true )
11+ JRubyCommand . new ( runner , filename , args )
12+ else
13+ JavaCommand . new ( runner , filename , args )
14+ end
1315 end
1416
1517 # Trade in this Ruby instance for a JRuby instance, loading in a starter
@@ -18,23 +20,40 @@ def initialize(runner:, args:, filename:)
1820 # of our vendored one. Note the use of jruby-complete might make using
1921 # other gems in your sketches hard (but not impossible)....
2022 def cmd
21- cmda = jruby_command
23+ cmda = command . cmd
2224 begin
2325 exec ( *cmda )
2426 # exec replaces the Ruby process with the JRuby one.
2527 rescue Java ::JavaLang ::ClassNotFoundException
2628 end
2729 end
30+ end
31+ end
2832
29- private
33+ # Wrap creation of java command string as a class
34+ class JavaCommand
35+ MAIN = 'org.jruby.Main' . freeze
36+ attr_reader :runner , :args , :filename , :opts , :complete
37+ def initialize ( runner , args , filename )
38+ @runner , @args , @filename = runner , args , filename
39+ @complete = JRubyComplete . complete
40+ @opts = JavaOpts . new . opts
41+ end
3042
31- # avoiding multiline ternary etc
32- def jruby_command
33- installed = Processing ::RP_CONFIG . fetch ( 'JRUBY' , true )
34- opts = installed ? JRubyOpts . new . opts : JavaOpts . new . opts
35- return [ 'jruby' , opts , runner , filename , args ] . flatten if installed
36- complete = JRubyComplete . complete
37- [ 'java' , opts , '-cp' , complete , 'org.jruby.Main' , runner , filename , args ] . flatten
38- end
43+ def cmd
44+ [ 'java' , opts , '-cp' , complete , MAIN , runner , filename , args ] . flatten
45+ end
46+ end
47+
48+ # Wrap creation of jruby command string as a class
49+ class JRubyCommand
50+ attr_reader :runner , :args , :filename , :opts
51+ def initialize ( runner , args , filename )
52+ @runner , @args , @filename = runner , args , filename
53+ @opts = JRubyOpts . new . opts
54+ end
55+
56+ def cmd
57+ [ 'jruby' , opts , runner , filename , args ] . flatten if installed
3958 end
4059end
0 commit comments