Class: Glimmer::Launcher

Inherits:
Object
  • Object
show all
Defined in:
lib/glimmer/launcher.rb

Constant Summary collapse

OPERATING_SYSTEMS_SUPPORTED =
["mac", "windows", "linux"]
TEXT_USAGE =
<<-MULTILINE
  Usage: glimmer application.rb

  Runs a Glimmer application using JRuby, automatically preloading
  the glimmer ruby gem and SWT jar dependency.

  Example: glimmer hello_world.rb
  This runs the Glimmer application hello_world.rb
MULTILINE
GLIMMER_LIB_LOCAL =
File.expand_path(File.join(__FILE__, '..', '..', 'glimmer.rb'))
GLIMMER_LIB_GEM =
'glimmer'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Launcher

Returns a new instance of Launcher.



50
51
52
53
54
# File 'lib/glimmer/launcher.rb', line 50

def initialize(options)
  @dev_mode = !!options.delete('--dev')
  @debug_mode = !!options.delete('--debug')
  @application_path = options.first
end

Class Method Details

.jruby_os_specific_optionsObject



27
28
29
# File 'lib/glimmer/launcher.rb', line 27

def jruby_os_specific_options
  OS.mac? ? "-J-XstartOnFirstThread" : ""
end

.jruby_swt_optionsObject



31
32
33
# File 'lib/glimmer/launcher.rb', line 31

def jruby_swt_options
  "#{jruby_os_specific_options} -J-classpath \"#{swt_jar_file}\""
end

.launch(application, dev_mode = false, debug_mode = false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/glimmer/launcher.rb', line 35

def launch(application, dev_mode = false, debug_mode = false)
  glimmer_lib = GLIMMER_LIB_GEM
  if dev_mode
    glimmer_lib = GLIMMER_LIB_LOCAL
    puts "[DEVELOPMENT MODE] (#{glimmer_lib})"
  end
  debug_option = ''
  if debug_mode
    debug_option = '--debug '
    puts "[DEBUG MODE]"
  end
  system "jruby #{debug_option}#{jruby_swt_options} -r #{glimmer_lib} -S #{application}"
end

.platform_osObject



19
20
21
# File 'lib/glimmer/launcher.rb', line 19

def platform_os
  OPERATING_SYSTEMS_SUPPORTED.detect {|os| OS.send("#{os}?")}
end

.swt_jar_fileObject



23
24
25
# File 'lib/glimmer/launcher.rb', line 23

def swt_jar_file
  @swt_jar_file ||= File.expand_path(File.join(__FILE__, '..', '..', '..', 'vendor', 'swt', platform_os, 'swt.jar'))
end

Instance Method Details

#launchObject



56
57
58
59
60
61
62
# File 'lib/glimmer/launcher.rb', line 56

def launch
  if @application_path
    launch_application
  else
    display_usage
  end
end