propane 2.4.0.pre-java → 2.5.0-java
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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG.md +11 -1
- data/Gemfile +1 -0
- data/README.md +16 -6
- data/Rakefile +2 -2
- data/lib/propane.rb +2 -2
- data/lib/propane/app.rb +24 -18
- data/lib/propane/creators/sketch_class.rb +6 -4
- data/lib/propane/library_loader.rb +82 -27
- data/lib/propane/runner.rb +10 -0
- data/lib/propane/version.rb +1 -1
- data/library/control_panel/control_panel.rb +15 -11
- data/library/library_proxy/README.md +2 -2
- data/library/library_proxy/library_proxy.rb +11 -9
- data/pom.rb +4 -4
- data/pom.xml +4 -4
- data/propane.gemspec +5 -3
- data/src/monkstone/core/LibraryProxy.java +109 -91
- data/test/sketches/key_event.rb +37 -0
- data/test/sketches/library/my_library/my_library.rb +32 -0
- data/vendors/Rakefile +1 -1
- metadata +39 -11
- data/lib/propane/java_library.rb +0 -54
- data/lib/propane/native_folder.rb +0 -33
- data/lib/propane/native_loader.rb +0 -26
- data/lib/propane/ruby_library.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9533ddd2e6f1573ce40817c97356676069e9e2a4
|
4
|
+
data.tar.gz: 7b2b891d044c4f98c85b5b1f286a60d1b77f5281
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e9fec391db8b365247028e0a298329342e39fa716027a031402768cecb33c5e764fcd0fae5d96ed31dafa578bdbfa9d762cf1c6cb8549baeae01a345a7db623
|
7
|
+
data.tar.gz: 0d251e46ec1a06f2bed2357a2ae178c6af0a67efe0cd5f869aea38287e9bc7232585018dd553a4041b971ee82e3e76b8299598c509a936d726bf04e61fda03d3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
**v2.
|
1
|
+
**v2.5.0** No need for `$app` we can replace with `Propane.app`
|
2
|
+
|
3
|
+
**v2.4.1** Add post_initialize hoop to app.rb.
|
4
|
+
|
5
|
+
**v2.4.0** Extend LibraryProxy to include mouseEvent and keyEvent.
|
6
|
+
|
7
|
+
**v2.3.4** Simplify control_panel library (replacing `c.title = 'PaneTitle'` with `c.title('PaneTitle')`) also enable use of `block` with `button's`.
|
8
|
+
|
9
|
+
**v2.3.3** Update to processing-3.3.4, and upgrade jruby-9.1.12.0 last in 9.1 series?
|
10
|
+
|
11
|
+
**v2.3.3** Update to processing-3.3.2
|
2
12
|
|
3
13
|
**v2.3.1** Update to processing-3.3.1, Update samples which now include `#!/usr/bin/env jruby` to assist running sketches from atom, add Rakefile for automatic sketch running for many samples, expected upgrade to final jruby-9.1.x.x
|
4
14
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
# Propane
|
2
|
-
[](https://badge.fury.io/rb/propane)
|
2
|
+
[](https://badge.fury.io/rb/propane) [](https://travis-ci.org/ruby-processing/propane)
|
3
3
|
|
4
|
-
A slim layer to communicate with Processing from JRuby, features a polyglot maven build. We have created a configuration free version of ruby processing, for processing-3.3.
|
4
|
+
A slim layer to communicate with Processing from JRuby, features a polyglot maven build. We have created a configuration free version of ruby processing, for processing-3.3.5, where we include processing core (from a local maven repository and opengl etc from maven central). These jars are small enough to include in a gem distribution, and hence we do not require configuration. This has created a scriptable version, ie files get run direct from jruby, but you could use jruby-complete if you used the propane script (avoids need to give the absolute data path for the data folder, but would also be needed for a watch mode). See guide to [building ruby-processing projects][building].
|
5
|
+
|
6
|
+
NB: The main reason for build failing is when the `core.jar` is not available from maven central, to install a local jar (_example for linux mint_):-
|
7
|
+
```bash
|
8
|
+
|
9
|
+
mvn install:install-file /home/tux/processing-3.3.5/core/library/core.jar -DgroupId=org.processing -DartifactId=core -Dversion=3.3.5
|
10
|
+
```
|
11
|
+
adjust above for your OS/distro setup.
|
5
12
|
|
6
13
|
## Requirements
|
7
14
|
|
8
15
|
- jdk8+
|
9
|
-
- jruby-9.1.
|
10
|
-
- mvn-3.
|
11
|
-
- core.jar processing-3.3.
|
16
|
+
- jruby-9.1.12.0
|
17
|
+
- mvn-3.5.0+
|
18
|
+
- core.jar processing-3.3.5 (_build only_)
|
12
19
|
|
13
20
|
## Building and testing
|
14
21
|
|
@@ -21,7 +28,7 @@ rake javadoc
|
|
21
28
|
## Installation
|
22
29
|
```bash
|
23
30
|
jgem install propane # from rubygems
|
24
|
-
jgem install propane-2.
|
31
|
+
jgem install propane-2.5.0-java.gem # for local install
|
25
32
|
```
|
26
33
|
|
27
34
|
## Usage
|
@@ -70,4 +77,7 @@ propane --install video
|
|
70
77
|
```
|
71
78
|
Other java libraries can be manually installed to the same folder (no need for processing ide)
|
72
79
|
|
80
|
+
See [gh-pages][gh-pages] for more detailed instructions and much more.
|
81
|
+
|
73
82
|
[building]:http://ruby-processing.github.io/building/building/
|
83
|
+
[gh-pages]:https://ruby-processing.github.io/propane/
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ def create_manifest
|
|
7
7
|
File.open('MANIFEST.MF', 'w') do |f|
|
8
8
|
f.puts(title)
|
9
9
|
f.puts(version)
|
10
|
-
f.puts('Class-Path: core-3.3.
|
10
|
+
f.puts('Class-Path: core-3.3.5.jar gluegen-rt-2.3.2.jar jog-all-2.3.2.jar')
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -47,7 +47,7 @@ end
|
|
47
47
|
desc 'Test'
|
48
48
|
task :test do
|
49
49
|
sh 'jruby test/helper_methods_test.rb'
|
50
|
-
sh 'jruby test/respond_to_test.rb'
|
50
|
+
# sh 'jruby test/respond_to_test.rb' Skip test on Travis to avoid Headless fail
|
51
51
|
sh 'jruby test/create_test.rb'
|
52
52
|
sh 'jruby test/math_tool_test.rb'
|
53
53
|
sh 'jruby test/deglut_spec_test.rb'
|
data/lib/propane.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: false
|
2
2
|
require 'java'
|
3
3
|
unless defined? PROPANE_ROOT
|
4
4
|
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
|
5
|
-
PROPANE_ROOT = File.
|
5
|
+
PROPANE_ROOT = File.expand_path(File.dirname(__FILE__) + '/../')
|
6
6
|
end
|
7
7
|
Dir["#{PROPANE_ROOT}/lib/*.jar"].each do |jar|
|
8
8
|
require jar
|
data/lib/propane/app.rb
CHANGED
@@ -43,6 +43,10 @@ module Propane
|
|
43
43
|
key_typed: :keyTyped
|
44
44
|
}.freeze
|
45
45
|
|
46
|
+
class << self
|
47
|
+
attr_accessor :app
|
48
|
+
end
|
49
|
+
|
46
50
|
# All sketches extend this class
|
47
51
|
class App < PApplet
|
48
52
|
include Math, MathTool, HelperMethods, Render
|
@@ -110,7 +114,8 @@ module Propane
|
|
110
114
|
raise TypeError unless arguments.is_a? Array
|
111
115
|
# Set up the sketch.
|
112
116
|
super()
|
113
|
-
|
117
|
+
post_initialize(options)
|
118
|
+
Propane.app = self
|
114
119
|
@arguments = arguments
|
115
120
|
@options = options
|
116
121
|
run_sketch
|
@@ -125,6 +130,9 @@ module Propane
|
|
125
130
|
super(*args)
|
126
131
|
end
|
127
132
|
|
133
|
+
def post_initialize(_args)
|
134
|
+
end
|
135
|
+
|
128
136
|
def sketch_title(title)
|
129
137
|
surface.set_title(title)
|
130
138
|
end
|
@@ -139,15 +147,15 @@ module Propane
|
|
139
147
|
|
140
148
|
def import_opengl
|
141
149
|
# Include processing opengl classes that we'd like to use:
|
142
|
-
%w
|
150
|
+
%w[FontTexture FrameBuffer LinePath LineStroker PGL
|
143
151
|
PGraphics2D PGraphics3D PGraphicsOpenGL PShader
|
144
|
-
PShapeOpenGL Texture
|
152
|
+
PShapeOpenGL Texture].each do |klass|
|
145
153
|
java_import "processing.opengl.#{klass}"
|
146
154
|
end
|
147
155
|
end
|
148
156
|
|
149
157
|
def proxy_java_fields
|
150
|
-
fields = %w
|
158
|
+
fields = %w[sketchPath key frameRate mousePressed keyPressed]
|
151
159
|
methods = fields.map { |field| java_class.declared_field(field) }
|
152
160
|
@declared_fields = Hash[fields.zip(methods)]
|
153
161
|
end
|
@@ -160,22 +168,20 @@ module Propane
|
|
160
168
|
end
|
161
169
|
end
|
162
170
|
|
163
|
-
#
|
164
|
-
#
|
165
|
-
# `include Math etc because we expect to use them`
|
166
|
-
# Using :method_missing to mimic inner class methods
|
167
|
-
# @HACK you should consider using 'forwardable' to avoid this
|
168
|
-
# egregious hack...
|
171
|
+
# @HACK purists may prefer 'forwardable' to the use of Proxy
|
172
|
+
# Importing PConstants here to access the processing constants
|
169
173
|
module Proxy
|
170
|
-
|
171
|
-
include
|
172
|
-
|
173
|
-
|
174
|
+
include Math
|
175
|
+
include HelperMethods
|
176
|
+
include Java::ProcessingCore::PConstants
|
177
|
+
|
178
|
+
def respond_to_missing?(symbol, include_priv = false)
|
179
|
+
Propane.app.respond_to?(symbol, include_priv) || super
|
174
180
|
end
|
175
181
|
|
176
|
-
def method_missing(name, *args)
|
177
|
-
return
|
182
|
+
def method_missing(name, *args, &block)
|
183
|
+
return Propane.app.send(name, *args) if Propane.app.respond_to? name
|
178
184
|
super
|
179
185
|
end
|
180
|
-
end
|
181
|
-
end
|
186
|
+
end # Processing::Proxy
|
187
|
+
end # Propane
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#frozen_string_literal: false
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
2
3
|
# the sketch class
|
3
4
|
class SketchClass
|
4
5
|
attr_reader :name, :width, :height, :mode
|
@@ -24,7 +25,7 @@ class SketchClass
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def size
|
27
|
-
return format(' size %d, %d', width.to_i, height.to_i)
|
28
|
+
return format(' size %d, %d', width.to_i, height.to_i) unless mode
|
28
29
|
format(' size %d, %d, %s', width.to_i, height.to_i, mode.upcase)
|
29
30
|
end
|
30
31
|
|
@@ -33,8 +34,8 @@ class SketchClass
|
|
33
34
|
format(" sketch_title '%s'", human)
|
34
35
|
end
|
35
36
|
|
36
|
-
def method_lines(name, content =
|
37
|
-
return [format(' def %s', name),
|
37
|
+
def method_lines(name, content = nil)
|
38
|
+
return [format(' def %s', name), '', ' end'] unless content
|
38
39
|
[format(' def %s', name), content, ' end', '']
|
39
40
|
end
|
40
41
|
|
@@ -50,6 +51,7 @@ class SketchClass
|
|
50
51
|
lines.concat method_lines('setup', sketch_title)
|
51
52
|
lines.concat method_lines('draw')
|
52
53
|
lines << 'end'
|
54
|
+
lines << ''
|
53
55
|
lines << sketch_new
|
54
56
|
end
|
55
57
|
end
|
@@ -1,13 +1,8 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
# The processing wrapper module
|
3
3
|
module Propane
|
4
|
-
require_relative 'ruby_library'
|
5
|
-
require_relative 'java_library'
|
6
|
-
|
7
4
|
# Encapsulate library loader functionality as a class
|
8
5
|
class LibraryLoader
|
9
|
-
attr_reader :library
|
10
|
-
|
11
6
|
def initialize
|
12
7
|
@loaded_libraries = Hash.new(false)
|
13
8
|
end
|
@@ -18,43 +13,103 @@ module Propane
|
|
18
13
|
end
|
19
14
|
|
20
15
|
# Load a list of Ruby or Java libraries (in that order)
|
21
|
-
# Usage: load_libraries :
|
16
|
+
# Usage: load_libraries :opengl, :boids
|
22
17
|
#
|
23
18
|
# If a library is put into a 'library' folder next to the sketch it will
|
24
19
|
# be used instead of the library that ships with Propane.
|
25
20
|
def load_libraries(*args)
|
26
21
|
message = 'no such file to load -- %s'
|
27
22
|
args.each do |lib|
|
28
|
-
loaded =
|
29
|
-
|
23
|
+
loaded = load_ruby_library(lib) || load_java_library(lib)
|
24
|
+
fail(LoadError.new, format(message, lib)) unless loaded
|
30
25
|
end
|
31
26
|
end
|
32
|
-
|
27
|
+
alias_method :load_library, :load_libraries
|
28
|
+
|
29
|
+
# For pure ruby libraries.
|
30
|
+
# The library should have an initialization ruby file
|
31
|
+
# of the same name as the library folder.
|
32
|
+
def load_ruby_library(library_name)
|
33
|
+
library_name = library_name.to_sym
|
34
|
+
return true if @loaded_libraries.include?(library_name)
|
35
|
+
path = get_library_paths(library_name, 'rb').first
|
36
|
+
return false unless path
|
37
|
+
@loaded_libraries[library_name] = (require path)
|
38
|
+
end
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
# HACK: For pure java libraries, such as the ones that are available
|
41
|
+
# on this page: http://processing.org/reference/libraries/index.html
|
42
|
+
# that include native code, we mess with the 'Java ClassLoader', so that
|
43
|
+
# you don't have to futz with your PATH. But it's probably bad juju.
|
44
|
+
def load_java_library(library_name)
|
45
|
+
library_name = library_name.to_sym
|
46
|
+
return true if @loaded_libraries.include?(library_name)
|
47
|
+
jpath = get_library_directory_path(library_name, 'jar')
|
48
|
+
jars = get_library_paths(library_name, 'jar')
|
49
|
+
return false if jars.empty?
|
50
|
+
jars.each { |jar| require jar }
|
51
|
+
platform_specific_library_paths = get_platform_specific_library_paths(jpath)
|
52
|
+
platform_specific_library_paths = platform_specific_library_paths.select do |ppath|
|
53
|
+
FileTest.directory?(ppath) && !Dir.glob(File.join(ppath, '*.{so,dll,jnilib}')).empty?
|
39
54
|
end
|
40
|
-
|
41
|
-
|
55
|
+
unless platform_specific_library_paths.empty?
|
56
|
+
platform_specific_library_paths << java.lang.System.getProperty('java.library.path')
|
57
|
+
new_library_path = platform_specific_library_paths.join(java.io.File.pathSeparator)
|
58
|
+
java.lang.System.setProperty('java.library.path', new_library_path)
|
59
|
+
field = java.lang.Class.for_name('java.lang.ClassLoader').get_declared_field('sys_paths')
|
60
|
+
if field
|
61
|
+
field.accessible = true
|
62
|
+
field.set(java.lang.Class.for_name('java.lang.System').get_class_loader, nil)
|
63
|
+
end
|
42
64
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
65
|
+
@loaded_libraries[library_name] = true
|
66
|
+
end
|
67
|
+
|
68
|
+
def platform
|
69
|
+
match = %w(mac linux windows).find do |os|
|
70
|
+
java.lang.System.getProperty('os.name').downcase.index(os)
|
47
71
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
72
|
+
return 'other' unless match
|
73
|
+
return match unless match =~ /mac/
|
74
|
+
'macosx'
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_platform_specific_library_paths(basename)
|
78
|
+
# for MacOSX, but does this even work, or does Mac return '64'?
|
79
|
+
bits = 'universal'
|
80
|
+
if java.lang.System.getProperty('sun.arch.data.model') == '32' ||
|
81
|
+
java.lang.System.getProperty('java.vm.name').index('32')
|
82
|
+
bits = '32'
|
83
|
+
elsif java.lang.System.getProperty('sun.arch.data.model') == '64' ||
|
84
|
+
java.lang.System.getProperty('java.vm.name').index('64')
|
85
|
+
bits = '64' unless platform =~ /macosx/
|
52
86
|
end
|
53
|
-
|
87
|
+
[platform, platform + bits].map { |p| File.join(basename, p) }
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_library_paths(library_name, extension = nil)
|
91
|
+
dir = get_library_directory_path(library_name, extension)
|
92
|
+
Dir.glob("#{dir}/*.{rb,jar}")
|
54
93
|
end
|
55
94
|
|
56
|
-
|
57
|
-
|
95
|
+
protected
|
96
|
+
|
97
|
+
def get_library_directory_path(library_name, extension = nil)
|
98
|
+
extensions = extension ? [extension] : %w(jar rb)
|
99
|
+
extensions.each do |ext|
|
100
|
+
[
|
101
|
+
"#{SKETCH_ROOT}/library/#{library_name}",
|
102
|
+
"#{PROPANE_ROOT}/library/#{library_name}",
|
103
|
+
"#{PROPANE_ROOT}/library/#{library_name}/library",
|
104
|
+
"#{PROPANE_ROOT}/library/#{library_name}",
|
105
|
+
"#{ENV['HOME']}/.propane/libraries/#{library_name}/library"
|
106
|
+
].each do |jpath|
|
107
|
+
if File.exist?(jpath) && !Dir.glob(format('%s/*.%s', jpath, ext)).empty?
|
108
|
+
return jpath
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
nil
|
58
113
|
end
|
59
114
|
end
|
60
115
|
end
|
data/lib/propane/runner.rb
CHANGED
@@ -50,6 +50,11 @@ module Propane
|
|
50
50
|
options[:create] = true
|
51
51
|
end
|
52
52
|
|
53
|
+
options[:example] = false
|
54
|
+
opts.on('-e', '--example', 'Create new sketch outline') do
|
55
|
+
options[:example] = true
|
56
|
+
end
|
57
|
+
|
53
58
|
# This displays the help screen, all programs are
|
54
59
|
# assumed to have this option.
|
55
60
|
opts.on('-h', '--help', 'Display this screen') do
|
@@ -63,6 +68,11 @@ module Propane
|
|
63
68
|
|
64
69
|
def create
|
65
70
|
require_relative 'creators/sketch_writer'
|
71
|
+
SketchFactory.new(argc).write
|
72
|
+
end
|
73
|
+
|
74
|
+
def examples
|
75
|
+
require_relative 'creators/sketch_factory'
|
66
76
|
SketchWriter.new(File.basename(filename, '.rb'), argc).write
|
67
77
|
end
|
68
78
|
|
data/lib/propane/version.rb
CHANGED
@@ -21,7 +21,7 @@ module ControlPanel
|
|
21
21
|
label = control_panel.add_element(self, name)
|
22
22
|
add_change_listener do
|
23
23
|
update_label(label, name, value)
|
24
|
-
|
24
|
+
Propane.app.instance_variable_set("@#{name}", value) unless value.nil?
|
25
25
|
proc.call(value) if proc
|
26
26
|
end
|
27
27
|
set_value(initial_value ? initial_value * 100 : min)
|
@@ -46,7 +46,7 @@ module ControlPanel
|
|
46
46
|
set_preferred_size(java.awt.Dimension.new(190, 30))
|
47
47
|
control_panel.add_element(self, name)
|
48
48
|
add_action_listener do
|
49
|
-
|
49
|
+
Propane.app.instance_variable_set("@#{name}", value) unless value.nil?
|
50
50
|
proc.call(value) if proc
|
51
51
|
end
|
52
52
|
set_selected_index(initial_value ? elements.index(initial_value) : 0)
|
@@ -66,11 +66,11 @@ module ControlPanel
|
|
66
66
|
set_horizontal_alignment javax.swing.SwingConstants::CENTER
|
67
67
|
control_panel.add_element(self, name, false)
|
68
68
|
add_action_listener do
|
69
|
-
|
69
|
+
Propane.app.instance_variable_set("@#{name}", value)
|
70
70
|
proc.call(value) if proc
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
# define value as checkbox state
|
74
74
|
def value
|
75
75
|
is_selected
|
76
76
|
end
|
@@ -83,7 +83,7 @@ module ControlPanel
|
|
83
83
|
set_preferred_size(java.awt.Dimension.new(170, 64))
|
84
84
|
control_panel.add_element(self, name, false, true)
|
85
85
|
add_action_listener do
|
86
|
-
|
86
|
+
Propane.app.send(name)
|
87
87
|
proc.call(value) if proc
|
88
88
|
end
|
89
89
|
end
|
@@ -107,7 +107,7 @@ module ControlPanel
|
|
107
107
|
set_size 200, 30 + (64 * elements.size)
|
108
108
|
set_default_close_operation javax.swing.JFrame::HIDE_ON_CLOSE
|
109
109
|
set_resizable false
|
110
|
-
set_location(
|
110
|
+
set_location(Propane.app.width + 10, 0) unless Propane.app.width + 10 > Propane.app.displayWidth
|
111
111
|
panel.visible = true
|
112
112
|
end
|
113
113
|
|
@@ -126,6 +126,10 @@ module ControlPanel
|
|
126
126
|
dispose
|
127
127
|
end
|
128
128
|
|
129
|
+
def title(name)
|
130
|
+
set_title(name)
|
131
|
+
end
|
132
|
+
|
129
133
|
def slider(name, range = 0..100, initial_value = nil, &block)
|
130
134
|
Slider.new(self, name, range, initial_value, block || nil)
|
131
135
|
end
|
@@ -134,7 +138,7 @@ module ControlPanel
|
|
134
138
|
Menu.new(self, name, elements, initial_value, block || nil)
|
135
139
|
end
|
136
140
|
|
137
|
-
def checkbox(name, initial_value =
|
141
|
+
def checkbox(name, initial_value = false, &block)
|
138
142
|
checkbox = Checkbox.new(self, name, block || nil)
|
139
143
|
checkbox.do_click if initial_value == true
|
140
144
|
end
|
@@ -151,10 +155,10 @@ module ControlPanel
|
|
151
155
|
|
152
156
|
def set_feel(lf = 'metal')
|
153
157
|
lafinfo = javax.swing.UIManager.getInstalledLookAndFeels
|
154
|
-
laf = lafinfo.select do |info|
|
155
|
-
info.
|
158
|
+
laf = lafinfo.to_ary.select do |info|
|
159
|
+
info.name =~ Regexp.new(Regexp.escape(lf), Regexp::IGNORECASE)
|
156
160
|
end
|
157
|
-
javax.swing.UIManager.setLookAndFeel(laf[0].
|
161
|
+
javax.swing.UIManager.setLookAndFeel(laf[0].class_name)
|
158
162
|
end
|
159
163
|
end
|
160
164
|
|
@@ -169,4 +173,4 @@ module ControlPanel
|
|
169
173
|
end
|
170
174
|
end
|
171
175
|
|
172
|
-
Propane::App.
|
176
|
+
Propane::App.include(ControlPanel::InstanceMethods)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
### Using the LibraryProxy in your sketches
|
2
2
|
LibraryProxy is a [abstract java class](https://github.com/ruby-processing/JRubyArt/blob/master/src/monkstone/core/LibraryProxy.java) so that you can acccess vanilla processing library reflection methods in your sketches using ruby.
|
3
3
|
|
4
|
-
In the sketch you should `load_library :library_proxy` and your library class should inherit
|
5
|
-
from LibraryProxy and implement
|
4
|
+
In the sketch you should `load_library :library_proxy` and your library class should inherit
|
5
|
+
from LibraryProxy and implement the draw() method (can be empty method if not
|
6
6
|
required). For simplicity initialize your `processing library` in the sketch `setup`.
|
7
7
|
|
8
8
|
### Example library
|
@@ -1,12 +1,14 @@
|
|
1
1
|
java_import Java::MonkstoneCore::LibraryProxy
|
2
|
+
java_import Java::ProcessingEvent::KeyEvent
|
3
|
+
java_import Java::ProcessingEvent::MouseEvent
|
2
4
|
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# def
|
8
|
-
# def
|
9
|
-
# def
|
10
|
-
# def
|
11
|
-
# NOOP
|
5
|
+
# classes that inherit from LibraryProxy are expected to implement
|
6
|
+
# the abstract draw method of monkstone.core.LibraryProxy the other methods are
|
7
|
+
# registered with PApplet instance in constructor ImplementingClass.new(app)
|
8
|
+
#
|
9
|
+
# def pre... NOOP can be overridden
|
10
|
+
# def draw... Abstract Method should be implemented NOOP is OK
|
11
|
+
# def post... NOOP can be overridden
|
12
|
+
# def keyEvent(e)... NOOP can be overridden
|
13
|
+
# def mouseEvent(e)... NOOP can be overridden
|
12
14
|
# `app` can be called to get PApplet instance
|
data/pom.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
project 'rp5extras', 'https://github.com/monkstone/propane' do
|
3
3
|
model_version '4.0.0'
|
4
|
-
id 'propane:propane', '2.
|
4
|
+
id 'propane:propane', '2.5.0'
|
5
5
|
packaging 'jar'
|
6
6
|
description 'rp5extras for propane'
|
7
7
|
organization 'ruby-processing', 'https://ruby-processing.github.io'
|
@@ -32,8 +32,8 @@ project 'rp5extras', 'https://github.com/monkstone/propane' do
|
|
32
32
|
'jogl.version' => '2.3.2'
|
33
33
|
)
|
34
34
|
|
35
|
-
pom 'org.jruby:jruby:9.1.
|
36
|
-
jar 'org.processing:core:3.3.
|
35
|
+
pom 'org.jruby:jruby:9.1.12.0'
|
36
|
+
jar 'org.processing:core:3.3.5'
|
37
37
|
jar 'org.processing:video:3.0.2'
|
38
38
|
jar('org.jogamp.jogl:jogl-all:${jogl.version}')
|
39
39
|
jar('org.jogamp.gluegen:gluegen-rt-main:${jogl.version}')
|
@@ -44,7 +44,7 @@ project 'rp5extras', 'https://github.com/monkstone/propane' do
|
|
44
44
|
execute_goals( id: 'default-cli',
|
45
45
|
artifactItems: [ { groupId: 'org.processing',
|
46
46
|
artifactId: 'core',
|
47
|
-
version: '3.3.
|
47
|
+
version: '3.3.5',
|
48
48
|
type: 'jar',
|
49
49
|
outputDirectory: '${propane.basedir}/lib'
|
50
50
|
},
|
data/pom.xml
CHANGED
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
|
|
11
11
|
<modelVersion>4.0.0</modelVersion>
|
12
12
|
<groupId>propane</groupId>
|
13
13
|
<artifactId>propane</artifactId>
|
14
|
-
<version>2.
|
14
|
+
<version>2.5.0</version>
|
15
15
|
<name>rp5extras</name>
|
16
16
|
<description>rp5extras for propane</description>
|
17
17
|
<url>https://github.com/monkstone/propane</url>
|
@@ -58,13 +58,13 @@ DO NOT MODIFIY - GENERATED CODE
|
|
58
58
|
<dependency>
|
59
59
|
<groupId>org.jruby</groupId>
|
60
60
|
<artifactId>jruby</artifactId>
|
61
|
-
<version>9.1.
|
61
|
+
<version>9.1.12.0</version>
|
62
62
|
<type>pom</type>
|
63
63
|
</dependency>
|
64
64
|
<dependency>
|
65
65
|
<groupId>org.processing</groupId>
|
66
66
|
<artifactId>core</artifactId>
|
67
|
-
<version>3.3.
|
67
|
+
<version>3.3.5</version>
|
68
68
|
</dependency>
|
69
69
|
<dependency>
|
70
70
|
<groupId>org.processing</groupId>
|
@@ -103,7 +103,7 @@ DO NOT MODIFIY - GENERATED CODE
|
|
103
103
|
<artifactItem>
|
104
104
|
<groupId>org.processing</groupId>
|
105
105
|
<artifactId>core</artifactId>
|
106
|
-
<version>3.3.
|
106
|
+
<version>3.3.5</version>
|
107
107
|
<type>jar</type>
|
108
108
|
<outputDirectory>${propane.basedir}/lib</outputDirectory>
|
109
109
|
</artifactItem>
|
data/propane.gemspec
CHANGED
@@ -10,11 +10,11 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ['mamba2928@yahoo.co.uk']
|
11
11
|
gem.licenses = %w(GPL-3.0 LGPL-2.0)
|
12
12
|
gem.description = %q{A batteries included version of processing in ruby, MacOS and linux64}
|
13
|
-
gem.summary = %q{ruby wrapper for processing-3.3.
|
13
|
+
gem.summary = %q{ruby wrapper for processing-3.3.5 on MacOS and linux64 bit only for opengl}
|
14
14
|
gem.homepage = 'https://ruby-processing.github.io/propane/'
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.files << 'lib/propane.jar'
|
17
|
-
gem.files << 'lib/core-3.3.
|
17
|
+
gem.files << 'lib/core-3.3.5.jar'
|
18
18
|
gem.files << 'lib/gluegen-rt-2.3.2.jar'
|
19
19
|
gem.files << 'lib/jogl-all-2.3.2.jar'
|
20
20
|
gem.files << 'lib/gluegen-rt-2.3.2-natives-linux-amd64.jar'
|
@@ -23,7 +23,9 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.files << 'lib/jogl-all-2.3.2-natives-macosx-universal.jar'
|
24
24
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
25
25
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
26
|
-
gem.
|
26
|
+
gem.add_development_dependency 'rake', '~> 12'
|
27
|
+
gem.add_development_dependency 'minitest', '~> 5.10'
|
28
|
+
gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.0'
|
27
29
|
gem.require_paths = ['lib']
|
28
30
|
gem.platform = 'java'
|
29
31
|
end
|
@@ -2,106 +2,124 @@ package monkstone.core;
|
|
2
2
|
|
3
3
|
import processing.core.PApplet;
|
4
4
|
import static processing.core.PConstants.*;
|
5
|
+
import processing.event.MouseEvent;
|
6
|
+
import processing.event.KeyEvent;
|
5
7
|
|
6
8
|
/**
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
* The purpose of this class is to enable
|
10
|
+
* access to processing pre, draw and post loops in
|
11
|
+
* ruby-processing as a regular java library class.
|
12
|
+
* Also included background, fill and stroke methods.
|
13
|
+
* PConstants should also be available from static import
|
14
|
+
* @author Martin Prout
|
15
|
+
*/
|
14
16
|
public abstract class LibraryProxy {
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
/**
|
19
|
-
* Useful accessors
|
20
|
-
*/
|
21
|
-
public int width, height;
|
22
|
-
|
23
|
-
/**
|
24
|
-
*
|
25
|
-
* @param app PApplet
|
26
|
-
*/
|
27
|
-
public LibraryProxy(PApplet app) {
|
28
|
-
this.app = app;
|
29
|
-
this.width = app.width;
|
30
|
-
this.height = app.height;
|
31
|
-
setActive(true);
|
32
|
-
}
|
18
|
+
private final PApplet app;
|
33
19
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
public abstract void pre();
|
39
|
-
|
40
|
-
/**
|
41
|
-
* Extending classes must implement this gives access to processing PApplet
|
42
|
-
* draw loop
|
43
|
-
*/
|
44
|
-
public abstract void draw();
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Extending classes must implement this gives access to, by reflection,
|
48
|
-
* processing PApplet post loop (called after draw)
|
49
|
-
*/
|
50
|
-
public abstract void post();
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Register or unregister reflection methods
|
54
|
-
* @param active
|
55
|
-
*/
|
56
|
-
final void setActive(boolean active) {
|
57
|
-
if (active) {
|
58
|
-
this.app.registerMethod("pre", this);
|
59
|
-
this.app.registerMethod("draw", this);
|
60
|
-
this.app.registerMethod("post", this);
|
61
|
-
this.app.registerMethod("dispose", this);
|
62
|
-
} else {
|
63
|
-
this.app.unregisterMethod("pre", this);
|
64
|
-
this.app.unregisterMethod("draw", this);
|
65
|
-
this.app.unregisterMethod("post", this);
|
66
|
-
}
|
67
|
-
}
|
20
|
+
/**
|
21
|
+
* Useful accessors
|
22
|
+
*/
|
23
|
+
public int width, height;
|
68
24
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
25
|
+
/**
|
26
|
+
*
|
27
|
+
* @param app PApplet
|
28
|
+
*/
|
29
|
+
public LibraryProxy(PApplet app) {
|
30
|
+
this.app = app;
|
31
|
+
this.width = app.width;
|
32
|
+
this.height = app.height;
|
33
|
+
setActive(true);
|
34
|
+
}
|
76
35
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
this.app.fill(col);
|
83
|
-
}
|
36
|
+
/**
|
37
|
+
* Extending classes can override this, gives access to, by reflection,
|
38
|
+
* processing PApplet pre loop (called before draw)
|
39
|
+
*/
|
40
|
+
public void pre(){}
|
84
41
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
this.app.stroke(col);
|
91
|
-
}
|
42
|
+
/**
|
43
|
+
* Extending classes must implement this gives access to processing PApplet
|
44
|
+
* draw loop
|
45
|
+
*/
|
46
|
+
public abstract void draw();
|
92
47
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
48
|
+
/**
|
49
|
+
* Extending classes can override this, gives access to, by reflection,
|
50
|
+
* processing PApplet post loop (called after draw)
|
51
|
+
*/
|
52
|
+
public void post(){}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Extending classes can override this, gives access to, by reflection,
|
56
|
+
* processing PApplet post loop (called after draw)
|
57
|
+
*/
|
58
|
+
public void keyEvent(KeyEvent e){}
|
100
59
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
60
|
+
/**
|
61
|
+
* Extending classes can override this, gives access to, by reflection,
|
62
|
+
* processing PApplet post loop (called after draw)
|
63
|
+
*/
|
64
|
+
public void mouseEvent(MouseEvent e){}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Register or unregister reflection methods
|
68
|
+
* @param active
|
69
|
+
*/
|
70
|
+
final void setActive(boolean active) {
|
71
|
+
if (active) {
|
72
|
+
this.app.registerMethod("pre", this);
|
73
|
+
this.app.registerMethod("draw", this);
|
74
|
+
this.app.registerMethod("post", this);
|
75
|
+
this.app.registerMethod("mouseEvent", this);
|
76
|
+
this.app.registerMethod("keyEvent", this);
|
77
|
+
this.app.registerMethod("dispose", this);
|
78
|
+
} else {
|
79
|
+
this.app.unregisterMethod("pre", this);
|
80
|
+
this.app.unregisterMethod("draw", this);
|
81
|
+
this.app.unregisterMethod("post", this);
|
82
|
+
this.app.unregisterMethod("mouseEvent", this);
|
83
|
+
this.app.unregisterMethod("keyEvent", this);
|
106
84
|
}
|
85
|
+
}
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Simple signature for background hides need to call app
|
89
|
+
* @param col int
|
90
|
+
*/
|
91
|
+
public void background(int col) {
|
92
|
+
this.app.background(col);
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Simple signature for fill hides need to call app
|
97
|
+
* @param col int
|
98
|
+
*/
|
99
|
+
public void fill(int col) {
|
100
|
+
this.app.fill(col);
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Simple signature for stroke hides need to call app
|
105
|
+
* @param col int
|
106
|
+
*/
|
107
|
+
public void stroke(int col) {
|
108
|
+
this.app.stroke(col);
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Access applet if we must
|
113
|
+
* @return applet PApplet
|
114
|
+
*/
|
115
|
+
public PApplet app() {
|
116
|
+
return this.app;
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* required for processing
|
121
|
+
*/
|
122
|
+
public void dispose() {
|
123
|
+
setActive(false);
|
124
|
+
}
|
107
125
|
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
require 'propane'
|
3
|
+
|
4
|
+
|
5
|
+
class CustomProxySketch < Propane::App
|
6
|
+
|
7
|
+
# A simple demonstration of vanilla processing 'reflection' methods using
|
8
|
+
# propane :library_proxy. See my_library.rb code for the guts.
|
9
|
+
load_libraries :library_proxy, :my_library
|
10
|
+
|
11
|
+
attr_reader :visible
|
12
|
+
|
13
|
+
def settings
|
14
|
+
size 300, 200
|
15
|
+
@visible = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
sketch_title 'Reflection Voodoo Proxy'
|
20
|
+
MyLibrary.new self
|
21
|
+
end
|
22
|
+
|
23
|
+
def hide(val)
|
24
|
+
@visible = !val
|
25
|
+
end
|
26
|
+
|
27
|
+
def draw
|
28
|
+
if visible
|
29
|
+
fill(0, 0, 200)
|
30
|
+
ellipse(170, 115, 70, 100)
|
31
|
+
else
|
32
|
+
background 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
CustomProxySketch.new
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This class demonstrates how by inheriting from the abstract class LibraryProxy
|
2
|
+
# we can access 'keyEvent' and 'draw' (Note we need a draw method even
|
3
|
+
# though can be empty)
|
4
|
+
class MyLibrary < LibraryProxy
|
5
|
+
java_import 'processing.event.KeyEvent'
|
6
|
+
|
7
|
+
attr_reader :app
|
8
|
+
|
9
|
+
def initialize(parent)
|
10
|
+
@app = parent
|
11
|
+
end
|
12
|
+
|
13
|
+
def draw # optional
|
14
|
+
fill app.color(200, 0, 0, 100)
|
15
|
+
app.rect 100, 100, 60, 90
|
16
|
+
end
|
17
|
+
|
18
|
+
# favor guard clause no_op unless key pressed
|
19
|
+
# and no_op unless ascii key
|
20
|
+
def keyEvent(e) # NB: need camel case for reflection to work
|
21
|
+
return unless e.get_action == KeyEvent::PRESS
|
22
|
+
return if e.get_key > 122 # else we can't use :chr
|
23
|
+
case e.get_key.chr.upcase
|
24
|
+
when 'S'
|
25
|
+
app.send :hide, false
|
26
|
+
when 'H'
|
27
|
+
app.send :hide, true
|
28
|
+
else
|
29
|
+
puts e.get_key.chr
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/vendors/Rakefile
CHANGED
@@ -9,7 +9,7 @@ SOUND = 'sound.zip'.freeze
|
|
9
9
|
SOUND_VERSION = 'v1.3.2' # version 1.3.2
|
10
10
|
VIDEO = 'video-2.zip'
|
11
11
|
VIDEO_VERSION = '2' # version 1.0.1
|
12
|
-
EXAMPLES = '1.
|
12
|
+
EXAMPLES = '1.5'.freeze
|
13
13
|
HOME_DIR = ENV['HOME']
|
14
14
|
MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
|
15
15
|
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: propane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- monkstone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.10'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: arcball
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,7 +79,7 @@ files:
|
|
51
79
|
- Rakefile
|
52
80
|
- bin/propane
|
53
81
|
- lib/PROCESSING_LICENSE.txt
|
54
|
-
- lib/core-3.3.
|
82
|
+
- lib/core-3.3.5.jar
|
55
83
|
- lib/export.txt
|
56
84
|
- lib/gluegen-rt-2.3.2-natives-linux-amd64.jar
|
57
85
|
- lib/gluegen-rt-2.3.2-natives-macosx-universal.jar
|
@@ -66,11 +94,7 @@ files:
|
|
66
94
|
- lib/propane/creators/sketch_writer.rb
|
67
95
|
- lib/propane/helper_methods.rb
|
68
96
|
- lib/propane/helpers/numeric.rb
|
69
|
-
- lib/propane/java_library.rb
|
70
97
|
- lib/propane/library_loader.rb
|
71
|
-
- lib/propane/native_folder.rb
|
72
|
-
- lib/propane/native_loader.rb
|
73
|
-
- lib/propane/ruby_library.rb
|
74
98
|
- lib/propane/runner.rb
|
75
99
|
- lib/propane/version.rb
|
76
100
|
- library/boids/boids.rb
|
@@ -117,6 +141,8 @@ files:
|
|
117
141
|
- test/helper_methods_test.rb
|
118
142
|
- test/math_tool_test.rb
|
119
143
|
- test/respond_to_test.rb
|
144
|
+
- test/sketches/key_event.rb
|
145
|
+
- test/sketches/library/my_library/my_library.rb
|
120
146
|
- test/test_helper.rb
|
121
147
|
- test/vecmath_spec_test.rb
|
122
148
|
- vendors/Rakefile
|
@@ -136,20 +162,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
162
|
version: '0'
|
137
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
164
|
requirements:
|
139
|
-
- - "
|
165
|
+
- - ">="
|
140
166
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
167
|
+
version: '0'
|
142
168
|
requirements: []
|
143
169
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.5.1
|
145
171
|
signing_key:
|
146
172
|
specification_version: 4
|
147
|
-
summary: ruby wrapper for processing-3.3.
|
173
|
+
summary: ruby wrapper for processing-3.3.5 on MacOS and linux64 bit only for opengl
|
148
174
|
test_files:
|
149
175
|
- test/create_test.rb
|
150
176
|
- test/deglut_spec_test.rb
|
151
177
|
- test/helper_methods_test.rb
|
152
178
|
- test/math_tool_test.rb
|
153
179
|
- test/respond_to_test.rb
|
180
|
+
- test/sketches/key_event.rb
|
181
|
+
- test/sketches/library/my_library/my_library.rb
|
154
182
|
- test/test_helper.rb
|
155
183
|
- test/vecmath_spec_test.rb
|
data/lib/propane/java_library.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require_relative 'native_folder'
|
2
|
-
require_relative 'native_loader'
|
3
|
-
|
4
|
-
# The JavaLibrary class
|
5
|
-
class JavaLibrary
|
6
|
-
attr_reader :dir, :path, :name, :ppath
|
7
|
-
|
8
|
-
def initialize(name)
|
9
|
-
@name = name
|
10
|
-
@dir = '.'
|
11
|
-
@path = File.join(dir, "#{name}.jar")
|
12
|
-
end
|
13
|
-
|
14
|
-
def exist?
|
15
|
-
File.exist? path
|
16
|
-
end
|
17
|
-
|
18
|
-
def load_jars
|
19
|
-
Dir["#{dir}/*.jar"].each do |jar|
|
20
|
-
require jar
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def native_binaries?
|
25
|
-
native_folder = NativeFolder.new
|
26
|
-
native = native_folder.name
|
27
|
-
@ppath = File.join(dir, native)
|
28
|
-
File.directory?(ppath) &&
|
29
|
-
!Dir.glob(File.join(ppath, native_folder.extension)).empty?
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_binaries_to_classpath
|
33
|
-
native_loader = NativeLoader.new
|
34
|
-
native_loader.add_native_path(ppath)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# The LocalJavaLibrary class
|
39
|
-
class LocalJavaLibrary < JavaLibrary
|
40
|
-
def initialize(name)
|
41
|
-
super
|
42
|
-
@dir = File.join(Propane::SKETCH_ROOT, 'library', name)
|
43
|
-
@path = File.join(dir, "#{name}.jar")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# The InstalledJavaLibrary class
|
48
|
-
class InstalledJavaLibrary < JavaLibrary
|
49
|
-
def initialize(name)
|
50
|
-
super
|
51
|
-
@dir = File.join(ENV['HOME'], '.propane', 'libraries', name, 'library')
|
52
|
-
@path = File.join(dir, "#{name}.jar")
|
53
|
-
end
|
54
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
|
3
|
-
# Utility to load native binaries on Java CLASSPATH
|
4
|
-
class NativeFolder
|
5
|
-
attr_reader :os, :bit
|
6
|
-
|
7
|
-
WIN_FORMAT = 'windows%d'
|
8
|
-
LINUX_FORMAT = 'linux%d'
|
9
|
-
# WIN_PATTERNS = [
|
10
|
-
# /bccwin/i,
|
11
|
-
# /cygwin/i,
|
12
|
-
# /djgpp/i,
|
13
|
-
# /ming/i,
|
14
|
-
# /mswin/i,
|
15
|
-
# /wince/i
|
16
|
-
# ].freeze
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
@os = RbConfig::CONFIG['host_os'].downcase
|
20
|
-
@bit = java.lang.System.get_property('os.arch') =~ /64/ ? 64 : 32
|
21
|
-
end
|
22
|
-
|
23
|
-
def name
|
24
|
-
return 'macosx' if os =~ /darwin/ || os =~ /mac/
|
25
|
-
# return format(WIN_FORMAT, bit) if WIN_PATTERNS.include? os
|
26
|
-
return format(LINUX_FORMAT, bit) if os =~ /linux/
|
27
|
-
end
|
28
|
-
|
29
|
-
def extension
|
30
|
-
return '*.so' if os =~ /linux/
|
31
|
-
'*.dylib' # MacOS
|
32
|
-
end
|
33
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# This class knows how to dynamically set the 'java' native library path
|
2
|
-
# It might not work with java 9?
|
3
|
-
class NativeLoader
|
4
|
-
attr_reader :separator, :current_path
|
5
|
-
|
6
|
-
module JC
|
7
|
-
java_import 'java.lang.Class'
|
8
|
-
java_import 'java.lang.System'
|
9
|
-
java_import 'java.io.File'
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@separator = JC::File.pathSeparatorChar
|
14
|
-
@current_path = JC::System.getProperty('java.library.path')
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_native_path(pth)
|
18
|
-
current_path << separator << pth
|
19
|
-
JC::System.setProperty('java.library.path', current_path)
|
20
|
-
field = JC::Class.for_name('java.lang.ClassLoader')
|
21
|
-
.get_declared_field('sys_paths')
|
22
|
-
return unless field
|
23
|
-
field.accessible = true # some jruby magic
|
24
|
-
field.set(JC::Class.for_name('java.lang.System').get_class_loader, nil)
|
25
|
-
end
|
26
|
-
end
|
data/lib/propane/ruby_library.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# The abstract RubyLibrary class
|
2
|
-
class RubyLibrary
|
3
|
-
attr_reader :path, :name
|
4
|
-
|
5
|
-
def initialize(name)
|
6
|
-
@name = name
|
7
|
-
@path = nil
|
8
|
-
end
|
9
|
-
|
10
|
-
def exist?
|
11
|
-
File.exist? path
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# The LocalRubyLibrary class
|
16
|
-
class LocalRubyLibrary < RubyLibrary
|
17
|
-
def initialize(name)
|
18
|
-
super
|
19
|
-
@path = File.absolute_path(
|
20
|
-
File.join(Propane::SKETCH_ROOT, 'library', name, "#{name}.rb")
|
21
|
-
)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# The InstalledLibraryLoader class
|
26
|
-
class InstalledRubyLibrary < RubyLibrary
|
27
|
-
def initialize(name)
|
28
|
-
super
|
29
|
-
@path = File.join(PROPANE_ROOT, 'library', name, "#{name}.rb")
|
30
|
-
end
|
31
|
-
end
|