Sha256: 1ed6538eaf3dccb1b501c04e1a9056647c5dc81c435ecb1e8d040bdd78c0af01

Contents?: true

Size: 1.88 KB

Versions: 28

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true
require_relative '../jruby_art/jruby_complete'
require_relative '../jruby_art/java_opts'
module Processing
  # The command class check for configuration and options, before creating and
  # executing the jruby (or java) command to run the sketch
  class Launcher
    attr_reader :command
    def initialize(runner:, args:, filename:)
      @command = if Processing::RP_CONFIG.fetch('JRUBY', true)
                   JRubyCommand.new(runner, filename, args)
                 else
                   JavaCommand.new(runner, filename, args)
                 end
    end

    # Trade in this Ruby instance for a JRuby instance, loading in a starter
    # script and passing it some arguments. Unless you set JRUBY: false in
    # ~/.jruby_art/config.yml, an installed version of jruby is used instead
    # of our vendored one. Note the use of jruby-complete might make using
    # other gems in your sketches hard (but not impossible)....
    def cmd
      cmda = command.cmd
      begin
        exec(*cmda)
        # exec replaces the Ruby process with the JRuby one.
      rescue Java::JavaLang::ClassNotFoundException
      end
    end
  end
end

# Wrap creation of java command string as a class
class JavaCommand
  MAIN = 'org.jruby.Main'.freeze
  attr_reader :runner, :args, :filename, :opts, :complete
  def initialize(runner, args, filename)
    @runner, @args, @filename = runner, args, filename
    @complete = JRubyComplete.complete
    @opts = JavaOpts.new.opts
  end

  def cmd
    ['java', opts, '-cp', complete, MAIN, runner, filename, args].flatten
  end
end

# Wrap creation of jruby command string as a class
class JRubyCommand
  attr_reader :runner, :args, :filename, :opts
  def initialize(runner, args, filename)
    @runner, @args, @filename = runner, args, filename
    @opts = JRubyOpts.new.opts
  end

  def cmd
    ['jruby', opts, runner, filename, args].flatten
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
jruby_art-2.2.2 lib/jruby_art/launcher.rb
jruby_art-2.2.1 lib/jruby_art/launcher.rb
jruby_art-2.2.0 lib/jruby_art/launcher.rb
jruby_art-1.7.0 lib/jruby_art/launcher.rb
jruby_art-2.1.0.pre lib/jruby_art/launcher.rb
jruby_art-2.0.0.pre lib/jruby_art/launcher.rb
jruby_art-1.6.4 lib/jruby_art/launcher.rb
jruby_art-1.6.3 lib/jruby_art/launcher.rb
jruby_art-1.6.2 lib/jruby_art/launcher.rb
jruby_art-1.6.1 lib/jruby_art/launcher.rb
jruby_art-1.6.0 lib/jruby_art/launcher.rb
jruby_art-1.5.2 lib/jruby_art/launcher.rb
jruby_art-1.5.1 lib/jruby_art/launcher.rb
jruby_art-1.5.0 lib/jruby_art/launcher.rb
jruby_art-1.4.9 lib/jruby_art/launcher.rb
jruby_art-1.4.8 lib/jruby_art/launcher.rb
jruby_art-1.4.7 lib/jruby_art/launcher.rb
jruby_art-1.4.6 lib/jruby_art/launcher.rb
jruby_art-1.4.5 lib/jruby_art/launcher.rb
jruby_art-1.4.4 lib/jruby_art/launcher.rb