Class: Glimmer::Launcher
- Inherits:
-
Object
- Object
- Glimmer::Launcher
- Defined in:
- lib/glimmer/launcher.rb
Overview
Launcher of glimmer applications and main entry point for the ‘glimmer` command.
Constant Summary collapse
- OPERATING_SYSTEMS_SUPPORTED =
["mac", "windows", "linux"]
- TEXT_USAGE =
TODO convert to a bash script to achieve faster startup time
"Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v\#{File.read(File.expand_path('../../../VERSION', __FILE__))}\nUsage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]\n\nRuns Glimmer applications and tasks.\n\nWhen applications are specified, they are run using JRuby,\nautomatically preloading the glimmer Ruby gem and SWT jar dependency.\n\nOptionally, extra Glimmer options, JRuby options, and/or environment variables may be passed in.\n\nGlimmer options:\n- \"--bundler=GROUP\" : Activates gems in Bundler default group in Gemfile\n- \"--pd=BOOLEAN\" : Requires puts_debuggerer to enable pd method\n- \"--quiet=BOOLEAN\" : Does not announce file path of Glimmer application being launched\n- \"--debug\" : Displays extra debugging information, passes \"--debug\" to JRuby, and enables debug logging\n- \"--log-level=VALUE\" : Sets Glimmer's Ruby logger level (\"ERROR\" / \"WARN\" / \"INFO\" / \"DEBUG\"; default is none)\n\nTasks are run via rake. Some tasks take arguments in square brackets.\n\nAvailable tasks are below (if you do not see any, please add `require 'glimmer/rake_task'` to Rakefile and rerun or run rake -T):\n \n"- GLIMMER_LIB_LOCAL =
File.(File.join('lib', 'glimmer-dsl-swt.rb'))
- GLIMMER_LIB_GEM =
'glimmer-dsl-swt'- GLIMMER_OPTIONS =
%w[--log-level --quiet --bundler --pd]- GLIMMER_OPTION_ENV_VAR_MAPPING =
{ '--log-level' => 'GLIMMER_LOGGER_LEVEL' , '--bundler' => 'GLIMMER_BUNDLER_SETUP' , '--pd' => 'PD' , }
- REGEX_RAKE_TASK_WITH_ARGS =
/^([^\[]+)\[?([^\]]*)\]?$/- @@mutex =
Mutex.new
Instance Attribute Summary collapse
-
#application_paths ⇒ Object
readonly
Returns the value of attribute application_paths.
-
#env_vars ⇒ Object
readonly
Returns the value of attribute env_vars.
-
#glimmer_options ⇒ Object
readonly
Returns the value of attribute glimmer_options.
-
#jruby_options ⇒ Object
readonly
Returns the value of attribute jruby_options.
Class Method Summary collapse
- .dev_mode? ⇒ Boolean
- .glimmer_lib ⇒ Object
- .glimmer_option_env_vars(glimmer_options) ⇒ Object
- .jruby_os_specific_options ⇒ Object
- .launch(application, jruby_options: [], env_vars: {}, glimmer_options: {}) ⇒ Object
- .load_env_vars(env_vars) ⇒ Object
- .platform_os ⇒ Object
- .swt_jar_file ⇒ Object
Instance Method Summary collapse
-
#initialize(raw_options) ⇒ Launcher
constructor
A new instance of Launcher.
- #launch ⇒ Object
Constructor Details
#initialize(raw_options) ⇒ Launcher
Returns a new instance of Launcher.
168 169 170 171 172 173 174 175 |
# File 'lib/glimmer/launcher.rb', line 168 def initialize() << '--quiet' if !caller.join("\n").include?('/bin/glimmer:') && !.join.include?('--quiet=') << '--log-level=DEBUG' if .join.include?('--debug') && !.join.include?('--log-level=') @application_paths = extract_application_paths() @env_vars = extract_env_vars() = () = end |
Instance Attribute Details
#application_paths ⇒ Object (readonly)
Returns the value of attribute application_paths.
163 164 165 |
# File 'lib/glimmer/launcher.rb', line 163 def application_paths @application_paths end |
#env_vars ⇒ Object (readonly)
Returns the value of attribute env_vars.
164 165 166 |
# File 'lib/glimmer/launcher.rb', line 164 def env_vars @env_vars end |
#glimmer_options ⇒ Object (readonly)
Returns the value of attribute glimmer_options.
165 166 167 |
# File 'lib/glimmer/launcher.rb', line 165 def end |
#jruby_options ⇒ Object (readonly)
Returns the value of attribute jruby_options.
166 167 168 |
# File 'lib/glimmer/launcher.rb', line 166 def end |
Class Method Details
.dev_mode? ⇒ Boolean
99 100 101 |
# File 'lib/glimmer/launcher.rb', line 99 def dev_mode? glimmer_lib == GLIMMER_LIB_LOCAL end |
.glimmer_lib ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/glimmer/launcher.rb', line 85 def glimmer_lib @@mutex.synchronize do unless @glimmer_lib @glimmer_lib = GLIMMER_LIB_GEM glimmer_gem_listing = `jgem list #{GLIMMER_LIB_GEM}`.split("\n").map {|l| l.split.first} if !glimmer_gem_listing.include?(GLIMMER_LIB_GEM) && File.exists?(GLIMMER_LIB_LOCAL) @glimmer_lib = GLIMMER_LIB_LOCAL puts "[DEVELOPMENT MODE] (detected #{@glimmer_lib})" end end end @glimmer_lib end |
.glimmer_option_env_vars(glimmer_options) ⇒ Object
103 104 105 106 107 |
# File 'lib/glimmer/launcher.rb', line 103 def glimmer_option_env_vars() GLIMMER_OPTION_ENV_VAR_MAPPING.reduce({}) do |hash, pair| [pair.first] ? hash.merge(GLIMMER_OPTION_ENV_VAR_MAPPING[pair.first] => [pair.first]) : hash end end |
.jruby_os_specific_options ⇒ Object
81 82 83 |
# File 'lib/glimmer/launcher.rb', line 81 def OS.mac? ? "-J-XstartOnFirstThread" : "" end |
.launch(application, jruby_options: [], env_vars: {}, glimmer_options: {}) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/glimmer/launcher.rb', line 115 def launch(application, jruby_options: [], env_vars: {}, glimmer_options: {}) = .join(' ') + ' ' if .any? env_vars = env_vars.merge(glimmer_option_env_vars()) env_vars_string = env_vars.map do |k,v| if OS.windows? && ENV['PROMPT'] # detect command prompt (or powershell) "set #{k}=#{v} && " else "export #{k}=#{v} && " end end.join the_glimmer_lib = glimmer_lib devmode_require = nil if the_glimmer_lib == GLIMMER_LIB_LOCAL devmode_require = '-r puts_debuggerer ' end require_relative 'rake_task' rake_tasks = Rake.application.tasks.map(&:to_s).map {|t| t.sub('glimmer:', '')} # handle a bash quirk with calling package[msi] while there is a "packages" directory locally (it passes package[msi] as packages) application = 'package[msi]' if application == 'packages' potential_rake_task_parts = application.match(REGEX_RAKE_TASK_WITH_ARGS) application = potential_rake_task_parts[1] rake_task_args = potential_rake_task_parts[2].split(',') if rake_tasks.include?(application) load_env_vars(glimmer_option_env_vars()) rake_task = "glimmer:#{application}" puts "Running Glimmer rake task: #{rake_task}" if .to_s.include?('--debug') Rake::Task[rake_task].invoke(*rake_task_args) else @@mutex.synchronize do puts "Launching Glimmer Application: #{application}" if .to_s.include?('--debug') || ['--quiet'].to_s.downcase != 'true' end command = "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}" if !env_vars_string.empty? && OS.windows? command = "bash -c \"#{command}\"" if ENV['SHELL'] # do in Windows Git Bash only command = "cmd /C \"#{command}\"" if ENV['PROMPT'] # do in Windows Command Prompt only (or Powershell) end puts command if .to_s.include?('--debug') if command.include?(' irb ') exec command else system command end end end |
.load_env_vars(env_vars) ⇒ Object
109 110 111 112 113 |
# File 'lib/glimmer/launcher.rb', line 109 def load_env_vars(env_vars) env_vars.each do |key, value| ENV[key] = value end end |
.platform_os ⇒ Object
73 74 75 |
# File 'lib/glimmer/launcher.rb', line 73 def platform_os OPERATING_SYSTEMS_SUPPORTED.detect {|os| OS.send("#{os}?")} end |
.swt_jar_file ⇒ Object
77 78 79 |
# File 'lib/glimmer/launcher.rb', line 77 def swt_jar_file @swt_jar_file ||= File.(File.join(__FILE__, '..', '..', '..', 'vendor', 'swt', platform_os, 'swt.jar')) end |
Instance Method Details
#launch ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/glimmer/launcher.rb', line 177 def launch if @application_paths.empty? display_usage else launch_application end end |