Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
4aa0a09
parallel exist
monkstone Apr 27, 2017
8207dda
local ruby
monkstone Apr 27, 2017
a654a2a
now e are smoking
monkstone May 4, 2017
b78ea35
not so fast
monkstone May 4, 2017
d9a6845
tick ruby local and ruby installed
monkstone May 4, 2017
b23204d
inheritance
monkstone May 4, 2017
3b18ee5
working ruby loader
monkstone May 4, 2017
a72560d
tidy
monkstone May 4, 2017
d1b52ce
progress on installed java library
monkstone May 4, 2017
ca04c79
tidy
monkstone May 4, 2017
3a44a92
complete 1st stage of refactoring
monkstone May 4, 2017
d2e53bc
apparently working?git add lib!
monkstone May 4, 2017
182a3f2
merge java loaders?
monkstone May 4, 2017
2af7850
was it really that easy?
monkstone May 4, 2017
41f7ca0
cosmetic stuff
monkstone May 4, 2017
80dfced
pre-release version
monkstone May 4, 2017
5f55393
tidy up
monkstone May 5, 2017
fdc4c6a
more refinement
monkstone May 5, 2017
bd3416e
remove useless return
monkstone May 5, 2017
278705b
add post_initialize
monkstone Aug 10, 2017
1e68549
@jtoy we could probably live without
monkstone Aug 12, 2017
b6939ca
fix
monkstone Aug 13, 2017
f098b93
bump examples
monkstone Aug 15, 2017
762c64e
Merge pull request #13 from ruby-processing/post_initialize
monkstone Aug 15, 2017
be751c6
Merge branch 'new-loader' into master
monkstone Aug 15, 2017
ef20a2e
Merge pull request #14 from ruby-processing/master
monkstone Aug 15, 2017
8c396a6
at last refactored library loader working
monkstone Aug 15, 2017
922e8fe
cosmetic tidy ups
monkstone Aug 16, 2017
62db9d0
passing smell test, like never before!
monkstone Aug 16, 2017
cf20182
Merge pull request #15 from ruby-processing/new-loader
monkstone Aug 16, 2017
90ff666
create intermediate refactor as a possible release candidate
monkstone Aug 19, 2017
6f9add6
looking OK
monkstone Aug 19, 2017
adcf9f4
use Pathname
monkstone Aug 20, 2017
017ee11
Merge branch 'master' into ruby-library
monkstone Aug 20, 2017
58a77d1
Merge pull request #16 from ruby-processing/ruby-library
monkstone Aug 20, 2017
1edc5ea
bump version
monkstone Aug 20, 2017
c19e080
update README and CHANGELOG
monkstone Aug 20, 2017
ebd3013
glvideo
monkstone Aug 23, 2017
8f266e6
newer examples and CHANGELOG
monkstone Aug 26, 2017
54605c0
Bump processing version
monkstone Sep 5, 2017
becd6cd
update copyright date
monkstone Sep 6, 2017
cf84d51
recommend latest jruby
monkstone Sep 7, 2017
3945b43
self promoting release
monkstone Sep 23, 2017
54f2116
get ready for release
monkstone Oct 10, 2017
8da2afd
add .yardopts
monkstone Oct 15, 2017
9af7201
bump compiler plugin
monkstone Oct 30, 2017
054ce00
Bump recommended jruby
monkstone Nov 9, 2017
7e2353d
Bump actual version
monkstone Nov 9, 2017
e372ead
Bump Jruby Version
monkstone Dec 8, 2017
fe74f50
correct CHANGELOG
monkstone Dec 9, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<extension>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-ruby</artifactId>
<version>0.1.19</version>
<version>0.2.1</version>
</extension>
</extensions>
5 changes: 5 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--markup markdown
-
CHANGELOG.md
LICENSE.md
README.md
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
**v2.6.3** Bump recommended upgrade to jruby-9.1.15.0, possibly the last in 9.1 series?

**v2.6.2** Features example sketches using the PixelFlow library by Thomas Diewald

**v2.6.1** Bump processing version, bump recommended jruby version.

**v2.6.0** Refactored `LibraryLoader` knows less about `Library` class. The library class _knows_ about paths, and checks that they exist. Currently has ability to load `GLVideo` library, that will eventually become the new video libary (supports gstreamer-1.0 instead of gstreamer-0.1.0 that has already been dropped by some linux distros).

**v2.5.5** Intermediate `refactored_library` loader, can be release if required but still not there as regards refactor goals.

**v2.5.0** No need for `$app` we can replace with `Propane.app`

**v2.4.1** Add `post_initialize` hook to `app.rb`.

**v2.4.0** Extend LibraryProxy to include mouseEvent and keyEvent.

**v2.3.4** Simplify control_panel library (replacing `c.title = 'PaneTitle'` with `c.title('PaneTitle')`) also enable use of `block` with `button's`.
**v2.3.4** Simplify `control_panel` library (replacing `c.title = 'PaneTitle'` with `c.title('PaneTitle')`) also enable use of `block` with `button's`.

**v2.3.3** Update to processing-3.3.4, and upgrade jruby-9.1.12.0 last in 9.1 series?

Expand Down Expand Up @@ -40,4 +54,4 @@

**v0.4.0.pre** Inclusion of jogl-all.jar should fix 3D if install fails try getting rid of previous versions of gem (especially if you had done local installs, foxed me first) 3D still only for linux64 and macosx, any Windows developers are welcome to extend to windows (should be easy).

**v0.3.0.pre** First pre-release of propane.gem turns out 3D was not working because of missing jar in gem (3D was only going to work on macosx and linux64 OS anyways.
**v0.3.0.pre** First pre-release of propane.gem turns out 3D was not working because of missing jar in gem (3D was only going to work on macosx and linux64 OS anyways).
File renamed without changes.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Propane
[![Gem Version](https://badge.fury.io/rb/propane.svg)](https://badge.fury.io/rb/propane) [![Travis CI](https://travis-ci.org/ruby-processing/propane.svg)](https://travis-ci.org/ruby-processing/propane)

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].
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.6, 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].

NB: The main reason for build failing is when the `core.jar` is not available from maven central, to install a local jar:-
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_):-
```bash

mvn install:install-file /home/tux/processing-3.3.5/core/library/core.jar -DgroupId=org.processing -DartifactId=core -Dversion=3.3.5
mvn install:install-file /home/tux/processing-3.3.6/core/library/core.jar -DgroupId=org.processing -DartifactId=core -Dversion=3.3.6
```
adjust above for your OS/distro setup.

## Requirements

- jdk8+
- jruby-9.1.12.0
- jruby-9.1.15.0
- mvn-3.5.0+
- core.jar processing-3.3.5 (_build only_)
- core.jar processing-3.3.6 (_build only_)

## Building and testing

Expand All @@ -28,7 +28,7 @@ rake javadoc
## Installation
```bash
jgem install propane # from rubygems
jgem install propane-2.3.4-java.gem # for local install
jgem install propane-2.6.0-java.gem # for local install
```

## Usage
Expand All @@ -54,10 +54,7 @@ end
FlashingLightsSketch.new
```

To install the samples. The samples get copied to `~/propane_samples`. Depends on wget.
```bash
propane --install samples
```

There is a handy sketch creator tool
```bash
propane -c my_sketch 200 200 # for default renderer
Expand All @@ -68,7 +65,7 @@ propane -c my_sketch 200 200 p3d # for opengl 3D renderer
To run sketches

```bash
jruby -S propane --run my_sketch.rb # belt and braces version
jruby my_sketch.rb # or use script to run sketches from atom
```
To install the sound and video libraries `~/.propane/libraries`. Depends on wget.
```bash
Expand All @@ -79,5 +76,13 @@ Other java libraries can be manually installed to the same folder (no need for p

See [gh-pages][gh-pages] for more detailed instructions and much more.

## Examples

[Worked Examples](https://github.com/ruby-processing/propane-examples) more to follow, feel free to add your own, especially ruby-2.2+ syntax now we can. To install the samples. The samples get copied to `~/propane_samples`. Depends on wget.
```bash
propane --install samples
```
please move existing `propane_samples` if you wish to keep them. The current release features several PixelFlow glsl library examples, including a few shadertoy demos as sketches.

[building]:http://ruby-processing.github.io/building/building/
[gh-pages]:https://ruby-processing.github.io/propane/
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def create_manifest
File.open('MANIFEST.MF', 'w') do |f|
f.puts(title)
f.puts(version)
f.puts('Class-Path: core-3.3.5.jar gluegen-rt-2.3.2.jar jog-all-2.3.2.jar')
f.puts('Class-Path: core-3.3.6.jar gluegen-rt-2.3.2.jar jog-all-2.3.2.jar')
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/propane.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'java'
unless defined? PROPANE_ROOT
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
PROPANE_ROOT = File.expand_path(File.dirname(__FILE__) + '/../')
PROPANE_ROOT = File.absolute_path(File.dirname(__dir__))
end
Dir["#{PROPANE_ROOT}/lib/*.jar"].each do |jar|
require jar
Expand Down
14 changes: 11 additions & 3 deletions lib/propane/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ module Render
key_typed: :keyTyped
}.freeze

class << self
attr_accessor :app
end

# All sketches extend this class
class App < PApplet
include Math, MathTool, HelperMethods, Render
Expand Down Expand Up @@ -110,7 +114,8 @@ def initialize(options = {}, arguments = [])
raise TypeError unless arguments.is_a? Array
# Set up the sketch.
super()
$app = self
post_initialize(options)
Propane.app = self
@arguments = arguments
@options = options
run_sketch
Expand All @@ -125,6 +130,9 @@ def size(*args)
super(*args)
end

def post_initialize(_args)
end

def sketch_title(title)
surface.set_title(title)
end
Expand Down Expand Up @@ -168,11 +176,11 @@ module Proxy
include Java::ProcessingCore::PConstants

def respond_to_missing?(symbol, include_priv = false)
$app.respond_to?(symbol, include_priv) || super
Propane.app.respond_to?(symbol, include_priv) || super
end

def method_missing(name, *args, &block)
return $app.send(name, *args) if $app.respond_to? name
return Propane.app.send(name, *args) if Propane.app.respond_to? name
super
end
end # Processing::Proxy
Expand Down
12 changes: 12 additions & 0 deletions lib/propane/creators/sketch_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require_relative 'sketch_writer'

class SketchFactory
NAMES = %w[One Two Three]
def initialize(argc)
NAMES.each do |name|
SketchWriter.new(File.basename(name, '.rb'), width: 300, height: 300).write
end
end
end

SketchFactory.new(File.join(ENV['HOME'], 'test'))
69 changes: 69 additions & 0 deletions lib/propane/library.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require_relative 'native_folder'
require_relative 'native_loader'
require 'pathname'

# This class knows where to find propane libraries
class Library
attr_reader :name, :path, :dir, :ppath

def initialize(name)
@name = name
@ruby = true
end

def locate
return if (@path = Pathname.new(
File.join(Propane::SKETCH_ROOT, 'library', name, "#{name}.rb")
)).exist?
return if (@path = Pathname.new(
File.join(PROPANE_ROOT, 'library', name, "#{name}.rb")
)).exist?
locate_java
end

def locate_java
@dir = Pathname.new(
File.join(Propane::SKETCH_ROOT, 'library', name)
)
locate_installed_java
end

def locate_installed_java
unless dir.directory?
@dir = Pathname.new(
File.join(ENV['HOME'], '.propane', 'libraries', name, 'library')
)
end
@path = dir.join(Pathname.new("#{name}.jar"))
end

def ruby?
path.extname == '.rb'
end

def exist?
path.exist?
end

def load_jars
Dir.glob("#{dir}/*.jar").each do |jar|
require jar
end
return true unless native_binaries?
add_binaries_to_classpath
end

def native_binaries?
native_folder = NativeFolder.new
native = native_folder.name
@ppath = File.join(dir, native)
File.directory?(ppath) &&
!Dir.glob(File.join(ppath, native_folder.extension)).empty?
end

def add_binaries_to_classpath
native_loader = NativeLoader.new
native_loader.add_native_path(ppath)
true
end
end
108 changes: 23 additions & 85 deletions lib/propane/library_loader.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# frozen_string_literal: false

# The processing wrapper module
module Propane
require_relative 'library'

# Encapsulate library loader functionality as a class
class LibraryLoader
attr_reader :library

def initialize
@loaded_libraries = Hash.new(false)
end
Expand All @@ -13,103 +18,36 @@ def library_loaded?(library_name)
end

# Load a list of Ruby or Java libraries (in that order)
# Usage: load_libraries :opengl, :boids
# Usage: load_libraries :video, :video_event
#
# If a library is put into a 'library' folder next to the sketch it will
# be used instead of the library that ships with Propane.
# be used instead of an installed propane library.
def load_libraries(*args)
message = 'no such file to load -- %s'
args.each do |lib|
loaded = load_ruby_library(lib) || load_java_library(lib)
fail(LoadError.new, format(message, lib)) unless loaded
loaded = loader(lib)
raise(LoadError.new, format(message, lib)) unless loaded
end
end
alias_method :load_library, :load_libraries

# For pure ruby libraries.
# The library should have an initialization ruby file
# of the same name as the library folder.
def load_ruby_library(library_name)
library_name = library_name.to_sym
return true if @loaded_libraries.include?(library_name)
path = get_library_paths(library_name, 'rb').first
return false unless path
@loaded_libraries[library_name] = (require path)
end
alias load_library load_libraries

# HACK: For pure java libraries, such as the ones that are available
# on this page: http://processing.org/reference/libraries/index.html
# that include native code, we mess with the 'Java ClassLoader', so that
# you don't have to futz with your PATH. But it's probably bad juju.
def load_java_library(library_name)
library_name = library_name.to_sym
return true if @loaded_libraries.include?(library_name)
jpath = get_library_directory_path(library_name, 'jar')
jars = get_library_paths(library_name, 'jar')
return false if jars.empty?
jars.each { |jar| require jar }
platform_specific_library_paths = get_platform_specific_library_paths(jpath)
platform_specific_library_paths = platform_specific_library_paths.select do |ppath|
FileTest.directory?(ppath) && !Dir.glob(File.join(ppath, '*.{so,dll,jnilib}')).empty?
end
unless platform_specific_library_paths.empty?
platform_specific_library_paths << java.lang.System.getProperty('java.library.path')
new_library_path = platform_specific_library_paths.join(java.io.File.pathSeparator)
java.lang.System.setProperty('java.library.path', new_library_path)
field = java.lang.Class.for_name('java.lang.ClassLoader').get_declared_field('sys_paths')
if field
field.accessible = true
field.set(java.lang.Class.for_name('java.lang.System').get_class_loader, nil)
end
end
@loaded_libraries[library_name] = true
def loader(name)
return true if @loaded_libraries.include?(name)
fname = name.to_s
library = Library.new(fname)
library.locate
return require_library(library, name) if library.ruby?
warn("Not found library: #{fname}") unless library.exist?
load_jars(library, name)
end

def platform
match = %w(mac linux windows).find do |os|
java.lang.System.getProperty('os.name').downcase.index(os)
end
return 'other' unless match
return match unless match =~ /mac/
'macosx'
def load_jars(lib, name)
lib.load_jars
@loaded_libraries[name] = true
end

def get_platform_specific_library_paths(basename)
# for MacOSX, but does this even work, or does Mac return '64'?
bits = 'universal'
if java.lang.System.getProperty('sun.arch.data.model') == '32' ||
java.lang.System.getProperty('java.vm.name').index('32')
bits = '32'
elsif java.lang.System.getProperty('sun.arch.data.model') == '64' ||
java.lang.System.getProperty('java.vm.name').index('64')
bits = '64' unless platform =~ /macosx/
end
[platform, platform + bits].map { |p| File.join(basename, p) }
end

def get_library_paths(library_name, extension = nil)
dir = get_library_directory_path(library_name, extension)
Dir.glob("#{dir}/*.{rb,jar}")
end

protected

def get_library_directory_path(library_name, extension = nil)
extensions = extension ? [extension] : %w(jar rb)
extensions.each do |ext|
[
"#{SKETCH_ROOT}/library/#{library_name}",
"#{PROPANE_ROOT}/library/#{library_name}",
"#{PROPANE_ROOT}/library/#{library_name}/library",
"#{PROPANE_ROOT}/library/#{library_name}",
"#{ENV['HOME']}/.propane/libraries/#{library_name}/library"
].each do |jpath|
if File.exist?(jpath) && !Dir.glob(format('%s/*.%s', jpath, ext)).empty?
return jpath
end
end
end
nil
def require_library(lib, name)
@loaded_libraries[name] = require lib.path
end
end
end
Loading