glimmer-dsl-swt 0.6.2 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -2
  3. data/VERSION +1 -1
  4. data/bin/girb +1 -1
  5. data/bin/glimmer +5 -1
  6. data/icons/scaffold_app.png +0 -0
  7. data/lib/ext/glimmer/config.rb +13 -1
  8. data/lib/glimmer-dsl-swt.rb +5 -9
  9. data/lib/glimmer/Rakefile +5 -0
  10. data/lib/glimmer/data_binding/table_items_binding.rb +4 -1
  11. data/lib/glimmer/dsl/swt/message_box_expression.rb +9 -1
  12. data/lib/glimmer/dsl/swt/widget_expression.rb +1 -7
  13. data/lib/glimmer/launcher.rb +59 -20
  14. data/lib/glimmer/package.rb +26 -9
  15. data/lib/glimmer/rake_task.rb +115 -5
  16. data/lib/glimmer/scaffold.rb +66 -33
  17. data/lib/glimmer/swt/display_proxy.rb +13 -2
  18. data/lib/glimmer/swt/message_box_proxy.rb +23 -5
  19. data/lib/glimmer/swt/shell_proxy.rb +0 -1
  20. data/lib/glimmer/swt/table_proxy.rb +60 -2
  21. data/lib/glimmer/swt/widget_proxy.rb +44 -19
  22. data/samples/elaborate/contact_manager.rb +121 -0
  23. data/samples/elaborate/contact_manager/contact.rb +11 -0
  24. data/samples/elaborate/contact_manager/contact_manager_presenter.rb +26 -0
  25. data/samples/elaborate/contact_manager/contact_repository.rb +244 -0
  26. data/samples/elaborate/login.rb +108 -0
  27. data/samples/elaborate/tic_tac_toe.rb +55 -0
  28. data/samples/elaborate/tic_tac_toe/board.rb +124 -0
  29. data/samples/elaborate/tic_tac_toe/cell.rb +27 -0
  30. data/samples/elaborate/user_profile.rb +55 -0
  31. data/samples/hello/hello_browser.rb +8 -0
  32. data/samples/hello/hello_combo.rb +38 -0
  33. data/samples/hello/hello_computed.rb +69 -0
  34. data/samples/hello/hello_computed/contact.rb +21 -0
  35. data/samples/hello/hello_drag_and_drop.rb +29 -0
  36. data/samples/hello/hello_list_multi_selection.rb +48 -0
  37. data/samples/hello/hello_list_single_selection.rb +37 -0
  38. data/samples/hello/hello_menu_bar.rb +64 -0
  39. data/samples/hello/hello_message_box.rb +15 -0
  40. data/samples/hello/hello_pop_up_context_menu.rb +36 -0
  41. data/samples/hello/hello_tab.rb +24 -0
  42. data/samples/hello/hello_world.rb +8 -0
  43. metadata +65 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d54a8793938853e74eb207e159ce6ab3f856ac57f737a3bd28990f5e52a745d
4
- data.tar.gz: a28121a29d1a123b056d121642bf70acd12891c428bdda8602caa2cf7157df35
3
+ metadata.gz: eb75003a6ed29f05d26a63307423121409b114157a50df69501310a93fcb27fe
4
+ data.tar.gz: 0e14fe3b080a81f4795a6a9703bd499aaa17e0e512034cf570560238bb5841ad
5
5
  SHA512:
6
- metadata.gz: 21a850f6805c1cc2f129bdc91c09c7a8b336ce81640311af63040c8168d535ab68fb91cb53bf0a8421ec38d1daab94b9a835eec209e2685e1702ca3e91b51af8
7
- data.tar.gz: 3044e95046bbda195c0ecd736ff30097ab6dadf660093d317d86d92c46f1bdf16dc669f944a9a62b398fa2f27697572290f4df9caffb8825c6b61a8f0ff2fea1
6
+ metadata.gz: ad51599c93c102b01c2a0756dbd030c705c85e7b4b2d2e2791d24a4281f01311fbddb155c08b13f6f58b3952d0340fd3403c3f47b7ec1348c86c95cf9a920fa0
7
+ data.tar.gz: a2f25a0ad0c9557dc41b4cf1bbbef162946d6cd112379f261cf9f862663924aed1af2006ff8ea41b13c910eed386a94c46c009d1e5727e66b1907c22e7373244
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 0.6.2 (Desktop GUI)
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 0.6.7 (JRuby Desktop GUI)
2
2
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
3
3
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-swt/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-swt?branch=master)
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/aaf1cba142dd351f84bd/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-swt/maintainability)
6
6
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7
7
 
8
- [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [SWT](https://www.eclipse.org/swt/) enables desktop development with [Glimmer](https://github.com/AndyObtiva/glimmer).
8
+ [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [SWT](https://www.eclipse.org/swt/) enables desktop development with [Glimmer](https://github.com/AndyObtiva/glimmer) in [JRuby](https://www.jruby.org/).
9
9
 
10
10
  [Glimmer](https://github.com/AndyObtiva/glimmer) is a native-GUI cross-platform desktop development library written in Ruby. Glimmer's main innovation is a JRuby DSL that enables productive and efficient authoring of desktop application user-interfaces while relying on the robust Eclipse SWT library. Glimmer additionally innovates by having built-in data-binding support to greatly facilitate synchronizing the GUI with domain models. As a result, that achieves true decoupling of object oriented components, enabling developers to solve business problems without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models test-first afterwards.
11
11
 
@@ -15,6 +15,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
15
15
  - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps)
16
16
  - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
17
17
  - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
18
+ - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (MRI Ruby Desktop GUI)
18
19
 
19
20
  ## Example
20
21
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.7
data/bin/girb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env jruby
2
2
 
3
3
  trap "SIGINT" do
4
4
  # No Op for irb
@@ -1,5 +1,9 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env jruby
2
2
 
3
+ if ARGV.empty?
4
+ require 'rake-tui'
5
+ require 'tty-screen'
6
+ end
3
7
  require_relative '../lib/glimmer/launcher'
4
8
 
5
9
  Glimmer::Launcher.new(ARGV).launch
Binary file
@@ -48,6 +48,10 @@ module Glimmer
48
48
 
49
49
  def logging_appender_options
50
50
  @@logging_appender_options = {async: true, auto_flushing: 500, write_size: 500, flush_period: 60, immediate_at: [:error, :fatal], layout: logging_layout} unless defined? @@logging_appender_options
51
+ # TODO make this a glimmer command option
52
+ if ENV['GLIMMER_LOGGER_ASYNC'].to_s.downcase == 'false'
53
+ @@logging_appender_options.merge!(async: false, auto_flushing: 1, immediate_at: [:debug, :info, :warn, :error, :fatal])
54
+ end
51
55
  @@logging_appender_options
52
56
  end
53
57
 
@@ -90,9 +94,13 @@ module Glimmer
90
94
  end
91
95
  logger.appenders = appenders
92
96
  end
97
+
93
98
  end
99
+
94
100
  end
101
+
95
102
  end
103
+
96
104
  end
97
105
 
98
106
  Glimmer::Config.reset_logger!
@@ -100,7 +108,11 @@ if ENV['GLIMMER_LOGGER_LEVEL']
100
108
  # if glimmer log level is being overridden for debugging purposes, then disable async logging making logging immediate
101
109
  Glimmer::Config.logging_appender_options = Glimmer::Config.logging_appender_options.merge(async: false, auto_flushing: 1)
102
110
  Glimmer::Config.logging_devices = [:stdout]
103
- Glimmer::Config.logger.level = ENV['GLIMMER_LOGGER_LEVEL']
111
+ begin
112
+ Glimmer::Config.logger.level = ENV['GLIMMER_LOGGER_LEVEL'].strip
113
+ rescue => e
114
+ puts e.message
115
+ end
104
116
  end
105
117
  Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
106
118
  method = method_symbol.to_s
@@ -2,15 +2,11 @@ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
2
2
 
3
3
  # External requires
4
4
  require 'java'
5
- if ENV['BUNDLER_REQUIRE'].to_s.downcase == 'true'
6
- require 'bundler'
7
- Bundler.require
8
- else
9
- require 'glimmer'
10
- require 'logging'
11
- require 'nested_inherited_jruby_include_package'
12
- require 'super_module'
13
- end
5
+ require 'puts_debuggerer' if ("#{ENV['pd']}#{ENV['PD']}").to_s.downcase.include?('true')
6
+ require 'glimmer'
7
+ require 'logging'
8
+ require 'nested_inherited_jruby_include_package'
9
+ require 'super_module'
14
10
 
15
11
  # Internal requires
16
12
  require 'ext/glimmer/config'
@@ -0,0 +1,5 @@
1
+ # This Rakefile gets used from Glimmer::Launcher when the current directory for running the `glimmer` command
2
+ # does not have a Rakefile (e.g. during scaffolding).
3
+ # It is not needed when running from inside a scaffolded app or gem, or an app with a Rakefile that has
4
+ # `require 'glimmer/rake_task'`
5
+ require 'glimmer/rake_task'
@@ -30,7 +30,10 @@ module Glimmer
30
30
  end
31
31
 
32
32
  def call(new_model_collection=nil)
33
- new_model_collection = @model_binding.evaluate_property # this ensures applying converters (e.g. :on_read)
33
+ new_model_collection = @model_binding.evaluate_property # this ensures applying converters (e.g. :on_read)
34
+ table_cells = @table.swt_widget.items.map {|item| @table.column_properties.size.times.map {|i| item.get_text(i)} }
35
+ model_cells = new_model_collection.to_a.map {|m| @table.cells_for(m)}
36
+ return if table_cells == model_cells
34
37
  if new_model_collection and new_model_collection.is_a?(Array)
35
38
  @table_items_observer_registration&.unobserve
36
39
  @table_items_observer_registration = observe(new_model_collection, @column_properties)
@@ -16,7 +16,15 @@ module Glimmer
16
16
 
17
17
  def interpret(parent, keyword, *args, &block)
18
18
  potential_parent = args.first
19
- parent = args.shift if potential_parent.is_a?(Shell) || (potential_parent.respond_to?(:swt_widget) && potential_parent.swt_widget.is_a?(Shell))
19
+ potential_parent = potential_parent.swt_widget if potential_parent.respond_to?(:swt_widget)
20
+ parent = nil
21
+ if potential_parent.is_a?(Shell)
22
+ args.shift
23
+ parent = potential_parent
24
+ elsif potential_parent.is_a?(Widget)
25
+ args.shift
26
+ parent = potential_parent.shell
27
+ end
20
28
  Glimmer::SWT::MessageBoxProxy.new(parent, Glimmer::SWT::SWTProxy[args])
21
29
  end
22
30
  end
@@ -17,13 +17,7 @@ module Glimmer
17
17
  end
18
18
 
19
19
  def interpret(parent, keyword, *args, &block)
20
- begin
21
- class_name = "#{keyword.camelcase(:upper)}Proxy".to_sym
22
- widget_class = Glimmer::SWT.const_get(class_name)
23
- rescue
24
- widget_class = Glimmer::SWT::WidgetProxy
25
- end
26
- widget_class.new(keyword, parent, args)
20
+ Glimmer::SWT::WidgetProxy.create(keyword, parent, args)
27
21
  end
28
22
 
29
23
  def add_content(parent, &block)
@@ -1,36 +1,31 @@
1
+ require 'fileutils'
2
+
1
3
  require_relative 'rake_task'
2
4
 
3
5
  module Glimmer
4
6
  class Launcher
5
7
  OPERATING_SYSTEMS_SUPPORTED = ["mac", "windows", "linux"]
6
8
 
7
- TEXT_USAGE_PREFIX = <<~MULTI_LINE_STRING
9
+ TEXT_USAGE = <<~MULTI_LINE_STRING
10
+ Glimmer (Ruby Desktop Development GUI Library) - JRuby Gem: glimmer-dsl-swt v#{File.read(File.expand_path('../../../VERSION', __FILE__))}
8
11
  Usage: glimmer [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
9
12
 
10
- Runs Glimmer applications/tasks.
11
-
12
- Either a single task or one or more applications may be specified.
13
-
14
- When a task is specified, it runs via rake. Some tasks take arguments in square brackets.
15
-
16
- Available tasks are below (you may also lookup by adding `require 'glimmer/rake_task'` in Rakefile and running rake -T):
17
- MULTI_LINE_STRING
18
-
19
- TEXT_USAGE_SUFFIX = <<~MULTI_LINE_STRING
13
+ Runs Glimmer applications and tasks.
20
14
 
21
15
  When applications are specified, they are run using JRuby,
22
16
  automatically preloading the glimmer Ruby gem and SWT jar dependency.
23
17
 
24
- Optionally, extra Glimmer options, JRuby options and environment variables may be passed in.
18
+ Optionally, extra Glimmer options, JRuby options, and/or environment variables may be passed in.
25
19
 
26
20
  Glimmer options:
27
21
  - "--quiet" : Does not announce file path of Glimmer application being launched
28
22
  - "--debug" : Displays extra debugging information, passes "--debug" to JRuby, and enables debug logging
29
23
  - "--log-level=VALUE" : Sets Glimmer's Ruby logger level ("ERROR" / "WARN" / "INFO" / "DEBUG"; default is none)
30
24
 
31
- Example: glimmer samples/hello_world.rb
25
+ Tasks are run via rake. Some tasks take arguments in square brackets.
32
26
 
33
- This runs the Glimmer application samples/hello_world.rb
27
+ Available tasks are below (if you do not see any, please add `require 'glimmer/rake_task'` to Rakefile and rerun or run rake -T):
28
+
34
29
  MULTI_LINE_STRING
35
30
 
36
31
  GLIMMER_LIB_LOCAL = File.expand_path(File.join('lib', 'glimmer-dsl-swt.rb'))
@@ -73,6 +68,10 @@ module Glimmer
73
68
  end
74
69
  @glimmer_lib
75
70
  end
71
+
72
+ def dev_mode?
73
+ glimmer_lib == GLIMMER_LIB_LOCAL
74
+ end
76
75
 
77
76
  def glimmer_option_env_vars(glimmer_options)
78
77
  GLIMMER_OPTION_ENV_VAR_MAPPING.reduce({}) do |hash, pair|
@@ -89,13 +88,23 @@ module Glimmer
89
88
  def launch(application, jruby_options: [], env_vars: {}, glimmer_options: {})
90
89
  jruby_options_string = jruby_options.join(' ') + ' ' if jruby_options.any?
91
90
  env_vars = env_vars.merge(glimmer_option_env_vars(glimmer_options))
92
- env_vars_string = env_vars.map {|k,v| "#{k}=#{v}"}.join(' ')
91
+ env_vars_string = env_vars.map do |k,v|
92
+ if OS.windows? && ENV['PROMPT'] # detect command prompt (or powershell)
93
+ "set #{k}=#{v} && "
94
+ else
95
+ "export #{k}=#{v} && "
96
+ end
97
+ end.join
93
98
  the_glimmer_lib = glimmer_lib
94
99
  devmode_require = nil
95
100
  if the_glimmer_lib == GLIMMER_LIB_LOCAL
96
101
  devmode_require = '-r puts_debuggerer '
97
102
  end
98
103
  rake_tasks = Rake.application.tasks.map(&:to_s).map {|t| t.sub('glimmer:', '')}
104
+
105
+ # handle a bash quirk with calling package[msi] while there is a "packages" directory locally (it passes package[msi] as packages)
106
+ application = 'package[msi]' if application == 'packages'
107
+
99
108
  potential_rake_task_parts = application.match(REGEX_RAKE_TASK_WITH_ARGS)
100
109
  application = potential_rake_task_parts[1]
101
110
  rake_task_args = potential_rake_task_parts[2].split(',')
@@ -109,8 +118,16 @@ module Glimmer
109
118
  puts "Launching Glimmer Application: #{application}" if jruby_options_string.to_s.include?('--debug') || glimmer_options['--quiet'].to_s.downcase != 'true'
110
119
  end
111
120
  command = "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}"
121
+ if !env_vars_string.empty? && OS.windows?
122
+ command = "bash -c \"#{command}\"" if ENV['SHELL'] # do in Windows Git Bash only
123
+ command = "cmd /C \"#{command}\"" if ENV['PROMPT'] # do in Windows Command Prompt only (or Powershell)
124
+ end
112
125
  puts command if jruby_options_string.to_s.include?('--debug')
113
- exec command
126
+ if command.include?(' irb ')
127
+ exec command
128
+ else
129
+ system command
130
+ end
114
131
  end
115
132
  end
116
133
  end
@@ -155,10 +172,32 @@ module Glimmer
155
172
  end
156
173
 
157
174
  def display_usage
158
- rake_tasks = `rake -T`.gsub('rake glimmer:', 'glimmer ').split("\n").select {|l| l.start_with?('glimmer ')}
159
- puts TEXT_USAGE_PREFIX
160
- puts rake_tasks.join("\n")
161
- puts TEXT_USAGE_SUFFIX
175
+ puts TEXT_USAGE
176
+ display_tasks
177
+ end
178
+
179
+ def display_tasks
180
+ if OS.windows?
181
+ tasks = Rake.application.tasks
182
+ task_lines = tasks.reject do |task|
183
+ task.comment.nil?
184
+ end.map do |task|
185
+ max_task_size = tasks.map(&:name_with_args).map(&:size).max + 1
186
+ task_name = task.name_with_args.sub('glimmer:', '')
187
+ line = "glimmer #{task_name.ljust(max_task_size)} # #{task.comment}"
188
+ bound = TTY::Screen.width - 6
189
+ line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
190
+ end
191
+ puts task_lines.to_a
192
+ else
193
+ Rake::TUI.run(branding_header: nil, prompt_question: 'Select a Glimmer task to run:') do |task, tasks|
194
+ max_task_size = tasks.map(&:name_with_args).map(&:size).max + 1
195
+ task_name = task.name_with_args.sub('glimmer:', '')
196
+ line = "glimmer #{task_name.ljust(max_task_size)} # #{task.comment}"
197
+ bound = TTY::Screen.width - 6
198
+ line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
199
+ end
200
+ end
162
201
  end
163
202
 
164
203
  def extract_application_paths(options)
@@ -6,6 +6,7 @@ module Glimmer
6
6
  module Package
7
7
  class << self
8
8
  attr_accessor :javapackager_extra_args
9
+ alias jpackage_extra_args :javapackager_extra_args
9
10
 
10
11
  def clean
11
12
  require 'fileutils'
@@ -42,14 +43,15 @@ module Glimmer
42
43
  end
43
44
 
44
45
  def lock_jars
45
- puts 'Locking JARs with jar-dependencies...'
46
- command = "lock_jars --vendor-dir vendor"
46
+ puts 'Locking gem jar-dependencies by downloading & storing in vendor/jars...'
47
+ FileUtils.mkdir_p('vendor/jars')
48
+ command = "lock_jars --vendor-dir vendor/jars"
47
49
  puts command
48
50
  system command
49
51
  end
50
52
 
51
- def native(native_type=nil)
52
- puts "Generating native executable with javapackager..."
53
+ def native(native_type=nil, native_extra_args)
54
+ puts "Generating native executable with javapackager/jpackage..."
53
55
  require 'facets/string/titlecase'
54
56
  require 'facets/string/underscore'
55
57
  project_name = File.basename(File.expand_path('.'))
@@ -59,13 +61,28 @@ module Glimmer
59
61
  license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
60
62
  copyright = license.split("\n").first
61
63
  human_name = project_name.underscore.titlecase
62
- command = "javapackager -deploy -native #{native_type} -outdir packages -outfile \"#{project_name}\" -srcfiles \"dist/#{project_name}.jar\" -appclass JarMain -name \"#{human_name}\" -title \"#{human_name}\" -Bmac.CFBundleName=\"#{human_name}\" -Bmac.CFBundleIdentifier=\"org.#{project_name}.application.#{project_name}\" -Bmac.category=\"public.app-category.business\" -BinstalldirChooser=true -Bvendor=\"#{human_name}\" -Bwin.menuGroup=\"#{human_name}\" -BsystemWide=#{OS.mac?} "
63
- command += " -BjvmOptions=-XstartOnFirstThread " if OS.mac?
64
- command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
65
- command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
66
- command += " -Bcopyright=\"#{copyright}\" " if copyright
64
+ icon = "package/#{OS.mac? ? 'macosx' : 'windows'}/#{human_name}.#{OS.mac? ? 'icns' : 'ico'}"
65
+ if (`javapackager`.to_s.include?('Usage: javapackager') rescue nil)
66
+ command = "javapackager -deploy -native #{native_type} -outdir packages -outfile \"#{project_name}\" -srcfiles \"dist/#{project_name}.jar\" -appclass JarMain -name \"#{human_name}\" -title \"#{human_name}\" -Bmac.CFBundleName=\"#{human_name}\" -Bmac.CFBundleIdentifier=\"org.#{project_name}.application.#{project_name}\" -Bmac.category=\"public.app-category.business\" -BinstalldirChooser=true -Bvendor=\"#{human_name}\" -Bwin.menuGroup=\"#{human_name}\" "
67
+ command += " -BsystemWide=false " if OS.windows?
68
+ command += " -BjvmOptions=-XstartOnFirstThread " if OS.mac?
69
+ command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
70
+ command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
71
+ command += " -Bcopyright=\"#{copyright}\" " if copyright
72
+ elsif (`jpackage`.to_s.include?('Usage: jpackage') rescue nil)
73
+ command = "jpackage --type #{native_type} --dest 'packages/bundles' --input 'dist' --main-class JarMain --main-jar '#{project_name}.jar' --name '#{human_name}' --vendor '#{human_name}' --icon '#{icon}' "
74
+ command += " --win-per-user-install --win-dir-chooser --win-menu --win-menu-group '#{human_name}' " if OS.windows?
75
+ command += " --java-options '-XstartOnFirstThread' --mac-package-name '#{human_name}' --mac-package-identifier 'org.#{project_name}.application.#{project_name}' " if OS.mac?
76
+ command += " --app-version \"#{version}\" " if version
77
+ command += " --license-file LICENSE.txt " if license
78
+ command += " --copyright \"#{copyright}\" " if copyright
79
+ else
80
+ puts "Neither javapackager nor jpackage exist in your Java installation. Please ensure javapackager or jpackage is available in PATH environment variable."
81
+ return
82
+ end
67
83
  command += " #{javapackager_extra_args} " if javapackager_extra_args
68
84
  command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
85
+ command += " #{native_extra_args} " if native_extra_args
69
86
  puts command
70
87
  system command
71
88
  end
@@ -3,6 +3,116 @@ require 'rake'
3
3
  require_relative 'package'
4
4
 
5
5
  namespace :glimmer do
6
+ namespace :sample do
7
+ desc 'Runs a Glimmer internal sample [included in gem]. If no name is supplied, it runs all samples.'
8
+ task :run, [:name] => :requires do |t, args|
9
+ name = args[:name]
10
+ name = name.underscore.downcase unless name.nil?
11
+ samples = (Dir.glob(File.expand_path('../../../samples/hello/*.rb', __FILE__)) + Dir.glob(File.expand_path('../../../samples/elaborate/*.rb', __FILE__))).sort
12
+ samples = samples.select {|path| path.include?("#{name}.rb")} unless name.nil?
13
+ Rake::Task['glimmer:sample:code'].invoke(name) if samples.size == 1
14
+ Glimmer::Launcher.new(samples << '--quiet=false').launch
15
+ end
16
+
17
+ namespace :run do
18
+ task :hello do
19
+ samples = Dir.glob(File.expand_path('../../../samples/hello/*.rb', __FILE__)).sort
20
+ Glimmer::Launcher.new(samples << '--quiet=false').launch
21
+ end
22
+
23
+ task :elaborate do
24
+ samples = Dir.glob(File.expand_path('../../../samples/elaborate/*.rb', __FILE__)).sort
25
+ Glimmer::Launcher.new(samples << '--quiet=false').launch
26
+ end
27
+ end
28
+
29
+ desc 'Lists Glimmer internal samples [included in gem]. Filters by query if specified (query is optional)'
30
+ task :list, [:query] do |t, args|
31
+ Rake::Task['glimmer:sample:list:hello'].invoke(args[:query])
32
+ Rake::Task['glimmer:sample:list:elaborate'].invoke(args[:query])
33
+ end
34
+
35
+ namespace :list do
36
+ task :hello, [:query] => :requires do |t, args|
37
+ array_of_arrays = Dir.glob(File.expand_path('../../../samples/hello/*.rb', __FILE__)).map do |path|
38
+ File.basename(path, '.rb')
39
+ end.select do |path|
40
+ args[:query].nil? || path.include?(args[:query])
41
+ end.map do |path|
42
+ [path, path.underscore.titlecase, "#{'bin/' if Glimmer::Launcher.dev_mode?}glimmer sample:run[#{path}]"]
43
+ end.sort
44
+ if array_of_arrays.empty?
45
+ puts "No Glimmer Hello Samples match the query."
46
+ else
47
+ puts
48
+ puts " Glimmer Hello Samples (run all via: #{'bin/' if Glimmer::Launcher.dev_mode?}glimmer sample:run:hello):"
49
+ puts Text::Table.new(
50
+ :head => %w[Name Description Run],
51
+ :rows => array_of_arrays,
52
+ :horizontal_padding => 1,
53
+ :vertical_boundary => ' ',
54
+ :horizontal_boundary => ' ',
55
+ :boundary_intersection => ' '
56
+ )
57
+ end
58
+ end
59
+
60
+ task :elaborate, [:query] => :requires do |t, args|
61
+ array_of_arrays = Dir.glob(File.expand_path('../../../samples/elaborate/*.rb', __FILE__)).map do |path|
62
+ File.basename(path, '.rb')
63
+ end.select do |path|
64
+ args[:query].nil? || path.include?(args[:query])
65
+ end.map do |path|
66
+ [path, path.underscore.titlecase, "#{'bin/' if Glimmer::Launcher.dev_mode?}glimmer sample:run[#{path}]"]
67
+ end.sort
68
+ if array_of_arrays.empty?
69
+ puts "No Glimmer Elaborate Samples match the query."
70
+ else
71
+ puts
72
+ puts " Glimmer Elaborate Samples (run all via: #{'bin/' if Glimmer::Launcher.dev_mode?}glimmer sample:run:elaborate):"
73
+ puts Text::Table.new(
74
+ :head => %w[Name Description Run],
75
+ :rows => array_of_arrays,
76
+ :horizontal_padding => 1,
77
+ :vertical_boundary => ' ',
78
+ :horizontal_boundary => ' ',
79
+ :boundary_intersection => ' '
80
+ )
81
+ end
82
+ end
83
+ end
84
+
85
+ desc 'Outputs code for a Glimmer internal sample [included in gem] (name is required)'
86
+ task :code, [:name] => :requires do |t, args|
87
+ require 'tty-markdown' unless OS.windows?
88
+ samples = (Dir.glob(File.expand_path('../../../samples/hello/*.rb', __FILE__)) + Dir.glob(File.expand_path('../../../samples/elaborate/*.rb', __FILE__))).sort
89
+ sample = samples.detect {|path| path.include?("#{args[:name].to_s.underscore.downcase}.rb")}
90
+ sample_additional_files = Dir.glob(File.join(sample.sub('.rb', ''), '**', '*.rb'))
91
+ code = ([sample] + sample_additional_files).map do |file|
92
+ <<~RUBY
93
+
94
+ # #{file}
95
+
96
+ #{File.read(file)}
97
+
98
+ # # #
99
+
100
+ RUBY
101
+ end.join("\n")
102
+ code = TTY::Markdown.parse("```ruby\n#{code}\n```") unless OS.windows?
103
+ puts code
104
+ end
105
+
106
+ task :requires do
107
+ require 'text-table'
108
+ require 'facets/string/titlecase'
109
+ require 'facets/string/underscore'
110
+
111
+ require_relative 'launcher'
112
+ end
113
+
114
+ end
115
+
6
116
  namespace :package do
7
117
  desc 'Clean by removing "dist" and "packages" directories'
8
118
  task :clean do
@@ -24,22 +134,22 @@ namespace :glimmer do
24
134
  Glimmer::Package.lock_jars
25
135
  end
26
136
 
27
- desc 'Generate Native files (DMG/PKG/APP on the Mac, MSI/EXE/IMAGE on Windows, RPM/DEB on Linux) (type is optional)'
137
+ desc 'Generate Native files. type can be dmg/pkg on the Mac, msi/exe on Windows, and rpm/deb on Linux (type is optional)'
28
138
  task :native, [:type] do |t, args|
29
- Glimmer::Package.native(args[:type])
139
+ extra_args = ARGV.partition {|arg| arg.include?('package:native')}.last.to_a.join(' ')
140
+ Glimmer::Package.native(args[:type], extra_args)
30
141
  end
31
142
  end
32
143
 
33
144
  desc 'Package app for distribution (generating config, jar, and native files) (type is optional)'
34
145
  task :package, [:type] do |t, args|
146
+ Rake::Task['gemspec:generate'].execute
147
+ Rake::Task['glimmer:package:lock_jars'].execute
35
148
  Rake::Task['glimmer:package:config'].execute
36
149
  Rake::Task['glimmer:package:jar'].execute
37
- Rake::Task['glimmer:package:lock_jars'].execute
38
- Rake::Task['gemspec:generate'].execute
39
150
  Rake::Task['glimmer:package:native'].execute(args)
40
151
  end
41
152
 
42
-
43
153
  desc 'Scaffold Glimmer application directory structure to build a new app'
44
154
  task :scaffold, [:app_name] do |t, args|
45
155
  require_relative 'scaffold'