jruby_art 2.2.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/bin/k9 +4 -3
  3. data/lib/gluegen-rt-natives-linux-amd64.jar +0 -0
  4. data/lib/gluegen-rt-natives-macosx-universal.jar +0 -0
  5. data/lib/gluegen-rt-natives-windows-amd64.jar +0 -0
  6. data/lib/gluegen-rt.jar +0 -0
  7. data/lib/jogl-all-natives-linux-amd64.jar +0 -0
  8. data/lib/jogl-all-natives-macosx-universal.jar +0 -0
  9. data/lib/jogl-all-natives-windows-amd64.jar +0 -0
  10. data/lib/jogl-all.jar +0 -0
  11. data/lib/jruby_art-2.4.1.jar +0 -0
  12. data/lib/jruby_art/app.rb +8 -7
  13. data/lib/jruby_art/config.rb +2 -0
  14. data/lib/jruby_art/creators/sketch_writer.rb +31 -13
  15. data/lib/jruby_art/default_config.rb +2 -0
  16. data/lib/jruby_art/helper_methods.rb +23 -23
  17. data/lib/jruby_art/helpers/aabb.rb +3 -0
  18. data/lib/jruby_art/helpers/numeric.rb +1 -0
  19. data/lib/jruby_art/installer.rb +10 -7
  20. data/lib/jruby_art/java_opts.rb +2 -0
  21. data/lib/jruby_art/jruby_complete.rb +2 -0
  22. data/lib/jruby_art/launcher.rb +8 -3
  23. data/lib/jruby_art/library.rb +14 -5
  24. data/lib/jruby_art/library_loader.rb +4 -1
  25. data/lib/jruby_art/native_folder.rb +16 -14
  26. data/lib/jruby_art/native_loader.rb +3 -0
  27. data/lib/jruby_art/processing_ide.rb +5 -1
  28. data/lib/jruby_art/runner.rb +65 -44
  29. data/lib/jruby_art/runners/base.rb +5 -4
  30. data/lib/jruby_art/runners/live.rb +10 -7
  31. data/lib/jruby_art/runners/run.rb +1 -0
  32. data/lib/jruby_art/runners/watch.rb +6 -4
  33. data/lib/jruby_art/version.rb +2 -1
  34. data/library/boids/boids.rb +19 -10
  35. data/library/chooser/chooser.rb +10 -9
  36. data/library/color_group/color_group.rb +2 -0
  37. data/library/control_panel/control_panel.rb +8 -5
  38. data/library/dxf/dxf.rb +2 -0
  39. data/library/library_proxy/library_proxy.rb +2 -0
  40. data/library/net/net.rb +2 -0
  41. data/library/slider/slider.rb +24 -23
  42. data/library/vector_utils/vector_utils.rb +5 -1
  43. data/library/video_event/video_event.rb +5 -1
  44. data/vendors/Rakefile +90 -37
  45. metadata +12 -12
  46. data/lib/jruby_art-2.2.0.jar +0 -0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'native_folder'
2
4
  require_relative 'native_loader'
3
5
 
@@ -35,10 +37,17 @@ class Library
35
37
  end
36
38
 
37
39
  def locate_installed_java
38
- prefix = library_path
39
- @dir = Pathname.new(
40
- File.join(prefix, "libraries/#{name}/library")
41
- )
40
+ return if dir.directory?
41
+
42
+ if Processing::RP_CONFIG.fetch('processing_ide', false)
43
+ prefix = library_path
44
+ @dir = Pathname.new(File.join(prefix, 'libraries', name, 'library'))
45
+ @path = dir.join(Pathname.new("#{name}.jar"))
46
+ else
47
+ @dir = Pathname.new(
48
+ File.join(ENV['HOME'], '.jruby_art', 'libraries', name, 'library')
49
+ )
50
+ end
42
51
  @path = dir.join(Pathname.new("#{name}.jar"))
43
52
  end
44
53
 
@@ -55,7 +64,7 @@ class Library
55
64
  end
56
65
 
57
66
  def load_jars
58
- Dir.glob("#{dir}/*.jar").each do |jar|
67
+ Dir.glob("#{dir}/*.jar").sort.each do |jar|
59
68
  require jar
60
69
  end
61
70
  return unless native_binaries?
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  # The processing wrapper module
3
4
  module Processing
4
5
  require_relative 'library'
@@ -19,7 +20,7 @@ module Processing
19
20
  # Load a list of Ruby or Java libraries (in that order)
20
21
  # Usage: load_libraries :video, :video_event
21
22
  #
22
- # If a library is put into a 'library' folder next to the sketch it will be used
23
+ # If a library is put into a 'library' folder next to the sketch it will be used
23
24
  # instead of the library that ships with vanilla processing (or ide installed), or JRubyArt.
24
25
  def load_libraries(*args)
25
26
  message = 'no such file to load -- %s'
@@ -32,10 +33,12 @@ module Processing
32
33
 
33
34
  def loader(name)
34
35
  return true if @loaded_libraries.include?(name)
36
+
35
37
  fname = name.to_s
36
38
  library = Library.new(fname)
37
39
  library.locate
38
40
  return require_library(library, name) if library.ruby?
41
+
39
42
  warn("Not found library: #{fname}") unless library.exist?
40
43
  load_jars(library, name)
41
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rbconfig'
2
4
 
3
5
  # Utility to load native binaries on Java CLASSPATH
@@ -5,10 +7,9 @@ require 'rbconfig'
5
7
  class NativeFolder
6
8
  attr_reader :os, :bit
7
9
 
8
- LINUX_FORMAT = 'linux%s'.freeze
9
- ARM32 = '-armv6hf'.freeze
10
- # ARM64 = '-aarch64'.freeze
11
- WIN_FORMAT = 'windows%d'.freeze
10
+ LINUX_FORMAT = 'linux%<bit>d'
11
+ # ARM64 = '-aarch64'
12
+ WIN_FORMAT = 'windows%<bit>d'
12
13
  WIN_PATTERNS = [
13
14
  /bccwin/i,
14
15
  /cygwin/i,
@@ -20,25 +21,26 @@ class NativeFolder
20
21
 
21
22
  def initialize
22
23
  @os = RbConfig::CONFIG['host_os'].downcase
23
- @bit = java.lang.System.get_property('os.arch')
24
+ @bit = /64/.match?(java.lang.System.get_property('os.arch')) ? 64 : 32
24
25
  end
25
26
 
26
27
  def name
27
28
  return 'macosx' if /darwin|mac/.match?(os)
28
- if /linux/.match?(os)
29
- return format(LINUX_FORMAT, '64') if /amd64/.match?(bit)
30
- return format(LINUX_FORMAT, ARM32) if /arm/.match?(bit)
31
- end
32
- if WIN_PATTERNS.any? { |pat| pat =~ os }
33
- return format(WINDOWS_FORMAT, '64') if /64/.match?(bit)
34
- return format(WINDOWS_FORMAT, '32') if /32/.match?(bit)
29
+
30
+ return format(LINUX_FORMAT, bit: bit) if /linux/.match?(os)
31
+
32
+ unless WIN_PATTERNS.any? { |pat| pat.match?(os) }
33
+ raise StandardError, 'Unsupported Architecture'
35
34
  end
36
- raise 'Unsupported Architecture'
35
+
36
+ format(WIN_FORMAT, bit: bit)
37
37
  end
38
38
 
39
39
  def extension
40
40
  return '*.so' if /linux/.match?(os)
41
- return '*.dll' if WIN_PATTERNS.any? { |pat| pat =~ os }
41
+
42
+ return '*.dll' if WIN_PATTERNS.any? { |pat| pat.match?(os) }
43
+
42
44
  '*.dylib' # MacOS
43
45
  end
44
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This class knows how to dynamically set the 'java' native library path
2
4
  # It might not work with java 9?
3
5
  class NativeLoader
@@ -20,6 +22,7 @@ class NativeLoader
20
22
  field = JC::Class.for_name('java.lang.ClassLoader')
21
23
  .get_declared_field('sys_paths')
22
24
  return unless field
25
+
23
26
  field.accessible = true # some jruby magic
24
27
  field.set(JC::Class.for_name('java.lang.System').get_class_loader, nil)
25
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # detects processing preferences.txt, extracts sketchbook_path
2
4
  class ProcessingIde
3
5
  attr_reader :preferences
@@ -12,7 +14,9 @@ class ProcessingIde
12
14
  def sketchbook_path
13
15
  File.open(preferences, 'r') do |file|
14
16
  file.each_line do |line|
15
- return line.tap { |sli| sli.slice!('sketchbook.path.three=') }.chomp if line =~ /sketchbook/
17
+ if /sketchbook/.match?(line)
18
+ return line.tap { |sli| sli.slice!('sketchbook.path.three=') }.chomp
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -9,12 +9,12 @@ require_relative '../jruby_art/java_opts'
9
9
  require_relative '../jruby_art/launcher'
10
10
  # processing wrapper module
11
11
  module Processing
12
- # Utility class to handle the different commands that the 'k9' command
13
- # offers. Able to run, watch, live, create, app, and unpack
14
12
  unless defined? RP_CONFIG
15
13
  conf = Config.new.load_config
16
14
  RP_CONFIG = conf.config
17
15
  end
16
+ # Utility class to handle the different commands that the 'k9' command
17
+ # offers. Able to run, watch, live, create, app, and unpack
18
18
  class Runner
19
19
  WIN_PATTERNS = [
20
20
  /bccwin/i,
@@ -25,6 +25,11 @@ module Processing
25
25
  /wince/i
26
26
  ].freeze
27
27
 
28
+ INSTALL = <<~MSG.freeze
29
+ <Config|JRuby-Complete|Samples>
30
+ or <Sound|Video> library
31
+ MSG
32
+
28
33
  attr_reader :options, :argc, :filename, :os
29
34
 
30
35
  def initialize
@@ -35,19 +40,19 @@ module Processing
35
40
  def self.execute
36
41
  runner = new
37
42
  runner.parse_options(ARGV)
38
- runner.execute!
43
+ runner.execute
39
44
  end
40
45
 
41
46
  # Dispatch central.
42
- def execute!
43
- show_help if options.empty?
47
+ def execute
48
+ parse_options('-h') if options.empty?
44
49
  show_version if options[:version]
45
50
  run_sketch if options[:run]
46
51
  watch_sketch if options[:watch]
47
52
  live if options[:live]
48
53
  create if options[:create]
49
54
  check if options[:check]
50
- install if options[:install]
55
+ install(filename) if options[:install]
51
56
  end
52
57
 
53
58
  # Parse the command-line options.
@@ -57,49 +62,44 @@ module Processing
57
62
  # of the help screen.
58
63
  opts.banner = 'Usage: k9 [options] [<filename.rb>]'
59
64
  # Define the options, and what they do
60
- options[:version] = false
65
+
61
66
  opts.on('-v', '--version', 'JRubyArt Version') do
62
67
  options[:version] = true
63
68
  end
64
69
 
65
- options[:install] = false
66
- opts.on('-i', '--install', 'Installs jruby-complete and examples') do
67
- options[:install] = true
68
- end
69
-
70
- options[:check] = false
71
70
  opts.on('-?', '--check', 'Prints configuration') do
72
71
  options[:check] = true
73
72
  end
74
73
 
75
- options[:app] = false
76
- opts.on('-a', '--app', 'Export as app NOT IMPLEMENTED YET') do
77
- options[:export] = true
74
+ opts.on('-i', '--install', INSTALL) do
75
+ options[:install] = true
78
76
  end
79
77
 
80
- options[:watch] = false
81
- opts.on('-w', '--watch', 'Watch/run the sketch') do
82
- options[:watch] = true
78
+ opts.on('-f', '--force', 'Force removal of old Config') do
79
+ options[:force] = true
80
+ end
81
+
82
+ opts.on('-c', '--create', 'Create new outline sketch') do
83
+ options[:create] = true
83
84
  end
84
85
 
85
- options[:run] = false
86
86
  opts.on('-r', '--run', 'Run the sketch') do
87
87
  options[:run] = true
88
88
  end
89
89
 
90
- options[:live] = false
90
+ opts.on('-w', '--watch', 'Watch/run the sketch') do
91
+ options[:watch] = true
92
+ end
93
+
91
94
  opts.on('-l', '--live', 'As above, with pry console bound to Processing.app') do
92
95
  options[:live] = true
93
96
  end
94
97
 
95
- options[:create] = false
96
- opts.on('-c', '--create', 'Create new outline sketch') do
97
- options[:create] = true
98
+ opts.on('-a', '--app', 'Export as app NOT IMPLEMENTED YET') do
99
+ options[:export] = true
98
100
  end
99
101
 
100
- # This displays the help screen, all programs are
101
- # assumed to have this option.
102
- opts.on('-h', '--help', 'Display this screen') do
102
+ opts.on_tail('-h', '--help', 'Display this screen') do
103
103
  puts opts
104
104
  exit
105
105
  end
@@ -138,11 +138,26 @@ module Processing
138
138
  spin_up('watch.rb', filename, argc)
139
139
  end
140
140
 
141
- def install
141
+ def install(library = nil)
142
142
  require_relative 'installer'
143
- Installer.new.install
144
- JRubyCompleteInstall.new.install
145
- UnpackSamples.new.install
143
+ library ||= 'new'
144
+ case library.downcase
145
+ when /sound|video/
146
+ system "cd #{K9_ROOT}/vendors && rake download_and_copy_#{choice}"
147
+ when /samples/
148
+ system "cd #{K9_ROOT}/vendors && rake install_samples"
149
+ when /jruby/
150
+ system "cd #{K9_ROOT}/vendors && rake"
151
+ when /config/
152
+ remove_old_config if options[:force]
153
+ Installer.new.install
154
+ when /new/
155
+ # install samples and config JRubyArt
156
+ system "cd #{K9_ROOT}/vendors && rake"
157
+ Installer.new.install
158
+ else
159
+ warn format('No installer for %<library>s', library: library)
160
+ end
146
161
  end
147
162
 
148
163
  def check
@@ -152,19 +167,19 @@ module Processing
152
167
 
153
168
  # Show the standard help/usage message.
154
169
  def show_help
155
- puts HELP_MESSAGE
170
+ puts HELP_INSTALL
156
171
  end
157
172
 
158
173
  def show_version
159
174
  require 'erb'
160
- warning = 'WARNING: JDK11 is preferred'.freeze
175
+ warning = 'WARNING: JDK12 is preferred'.freeze
161
176
  if RUBY_PLATFORM == 'java'
162
- warn warning unless ENV_JAVA['java.specification.version'] == '11'
177
+ warn warning unless ENV_JAVA['java.specification.version'].to_i >= 11
163
178
  end
164
- template = ERB.new <<-EOF
165
- JRubyArt version <%= JRubyArt::VERSION %>
166
- Ruby version <%= RUBY_VERSION %>
167
- EOF
179
+ template = ERB.new <<-VERSION
180
+ JRubyArt version <%= JRubyArt::VERSION %>
181
+ Ruby version <%= RUBY_VERSION %>
182
+ VERSION
168
183
  puts template.result(binding)
169
184
  end
170
185
 
@@ -184,20 +199,26 @@ module Processing
184
199
  end
185
200
 
186
201
  # NB: We really do mean to use 'and' not '&&' for flow control purposes
187
-
188
202
  def ensure_exists(filename)
189
- puts("Couldn't find: #{filename}") and exit unless FileTest.exist?(filename)
203
+ return if FileTest.exist?(filename)
204
+
205
+ puts("Couldn't find: #{filename}") and exit
190
206
  end
191
207
 
192
208
  def jruby_complete
193
209
  rcomplete = File.join(K9_ROOT, 'lib/ruby/jruby-complete.jar')
194
210
  return [rcomplete] if FileTest.exist?(rcomplete)
211
+
195
212
  warn "#{rcomplete} does not exist\nTry running `k9 --install`"
196
213
  exit
197
214
  end
198
215
 
199
- def libraries
200
- %w(video sound).map { |library| Sketchbook.library(library) }.flatten
216
+ def remove_old_config
217
+ old_config = File.join((ENV['HOME']).to_s, '.jruby_art', 'config.yml')
218
+ puts "Removing #{old_config}"
219
+ system "rm #{old_config}"
201
220
  end
202
- end # class Runner
203
- end # module Processing
221
+ # class Runner
222
+ end
223
+ # module Processing
224
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  SKETCH_PATH ||= ARGV.shift
3
4
  SKETCH_ROOT ||= File.absolute_path(File.dirname(SKETCH_PATH))
4
5
 
@@ -8,13 +9,13 @@ require_relative '../app'
8
9
  # More processing module
9
10
  module Processing
10
11
  # For use with "bare" sketches that don't want to define a class or methods
11
- BARE_WRAP = <<-EOS.freeze
12
+ BARE_WRAP = <<-BARE
12
13
  class Sketch < Processing::App
13
14
  %s
14
15
  end
15
- EOS
16
+ BARE
16
17
 
17
- NAKED_WRAP = <<-EOS.freeze
18
+ NAKED_WRAP = <<-NAKED
18
19
  class Sketch < Processing::App
19
20
  def setup
20
21
  sketch_title '%s'
@@ -26,7 +27,7 @@ module Processing
26
27
  size(%d, %d)
27
28
  end
28
29
  end
29
- EOS
30
+ NAKED
30
31
 
31
32
  # This method is the common entry point to run a sketch, bare or complete.
32
33
  def self.load_and_run_sketch
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  # A pry shell for live coding.
3
4
  # Will start with your sketch.
4
5
  require_relative 'base'
5
6
  Processing.load_and_run_sketch
6
7
 
8
+ # Custom Exception
7
9
  class PryException < StandardError
10
+ MESSAGE = "You need to 'jruby -S gem install pry' for 'live' mode".freeze
11
+
12
+ def initialize(msg = MESSAGE)
13
+ super
14
+ end
8
15
  end
9
16
 
10
- MESSAGE = "You need to 'jruby -S gem install pry' for 'live' mode".freeze
17
+ raise PryException unless Gem::Specification.find_all_by_name('pry').any?
11
18
 
12
- if Gem::Specification.find_all_by_name('pry').any?
13
- require 'pry'
14
- Processing.app.pry
15
- else
16
- raise(PryException.new, MESSAGE)
17
- end
19
+ require 'pry'
20
+ Processing.app.pry
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative 'base'
3
4
 
4
5
  Processing.load_and_run_sketch
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  require_relative 'base'
3
4
  require_relative '../config'
4
5
 
@@ -21,9 +22,10 @@ module Processing
21
22
  EOS
22
23
  SLEEP_TIME = 0.2
23
24
  def initialize
24
- count = Dir["**.*rb"].length
25
+ count = Dir['**.*rb'].length
25
26
  max_watch = RP_CONFIG.fetch('MAX_WATCH', 20)
26
- return warn format(WATCH_MESSAGE, max_watch, count) if count > max_watch.to_i
27
+ abort format(WATCH_MESSAGE, max_watch, count) if count > max_watch.to_i
28
+
27
29
  reload_files_to_watch
28
30
  @time = Time.now
29
31
  start_watching
@@ -36,7 +38,7 @@ module Processing
36
38
  Kernel.loop do
37
39
  if @files.find { |file| FileTest.exist?(file) && File.stat(file).mtime > @time }
38
40
  puts 'reloading sketch...'
39
- Processing.app && Processing.app.close
41
+ Processing.app&.close
40
42
  java.lang.System.gc
41
43
  @time = Time.now
42
44
  start_runner
@@ -66,7 +68,7 @@ module Processing
66
68
  end
67
69
 
68
70
  def start_runner
69
- @runner.kill if @runner && @runner.alive?
71
+ @runner.kill if @runner&.alive?
70
72
  @runner.join
71
73
  @runner = nil
72
74
  start_original