propane 0.9.0-java → 2.0.0.pre-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/.github/CONTRIBUTING.md +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +7 -1
- data/CHANGELOG.md +2 -1
- data/LICENSE +674 -0
- data/README.md +16 -22
- data/Rakefile +2 -2
- data/lib/propane.rb +1 -4
- data/lib/propane/app.rb +23 -31
- data/lib/propane/creators/sketch_writer.rb +8 -7
- data/lib/propane/helper_methods.rb +1 -2
- data/lib/propane/library_loader.rb +2 -1
- data/lib/propane/runner.rb +12 -54
- data/lib/propane/version.rb +1 -1
- data/library/video_event/video_event.rb +3 -0
- data/pom.rb +10 -9
- data/pom.xml +13 -8
- data/propane.gemspec +10 -10
- data/src/monkstone/videoevent/VideoInterface.java +42 -0
- data/src/monkstone/videoevent/package-info.java +20 -0
- data/test/create_test.rb +10 -3
- data/test/respond_to_test.rb +10 -1
- data/vendors/Rakefile +56 -48
- metadata +17 -17
- data/LICENSE.txt +0 -22
- data/src/monkstone/CodeListener.java +0 -7
- data/src/monkstone/WatchSketchDir.java +0 -190
data/propane.gemspec
CHANGED
@@ -6,21 +6,21 @@ require 'propane/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = 'propane'
|
8
8
|
gem.version = Propane::VERSION
|
9
|
-
gem.authors = ['
|
9
|
+
gem.authors = ['monkstone']
|
10
10
|
gem.email = ['mamba2928@yahoo.co.uk']
|
11
11
|
gem.license = 'MIT'
|
12
12
|
gem.description = %q{A Standalone Ruby Processing implementation}
|
13
|
-
gem.summary = %q{A really slim layer between Ruby and Processing-
|
14
|
-
gem.homepage = 'https://github.
|
13
|
+
gem.summary = %q{A really slim layer between Ruby and Processing-3.1.1.}
|
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-
|
18
|
-
gem.files << 'lib/gluegen-rt-2.
|
19
|
-
gem.files << 'lib/jogl-all-2.
|
20
|
-
gem.files << 'lib/gluegen-rt-2.
|
21
|
-
gem.files << 'lib/gluegen-rt-2.
|
22
|
-
gem.files << 'lib/jogl-all-2.
|
23
|
-
gem.files << 'lib/jogl-all-2.
|
17
|
+
gem.files << 'lib/core-3.1.1.jar'
|
18
|
+
gem.files << 'lib/gluegen-rt-2.3.2.jar'
|
19
|
+
gem.files << 'lib/jogl-all-2.3.2.jar'
|
20
|
+
gem.files << 'lib/gluegen-rt-2.3.2-natives-linux-amd64.jar'
|
21
|
+
gem.files << 'lib/gluegen-rt-2.3.2-natives-macosx-universal.jar'
|
22
|
+
gem.files << 'lib/jogl-all-2.3.2-natives-linux-amd64.jar'
|
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
26
|
gem.add_runtime_dependency 'arcball', '~> 0.0.3'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015-16 Martin Prout
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU Lesser General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* http://creativecommons.org/licenses/LGPL/2.1/
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
package monkstone.videoevent;
|
22
|
+
import processing.video.Movie;
|
23
|
+
import processing.video.Capture;
|
24
|
+
/**
|
25
|
+
* This interface makes it easier/possible to use the reflection methods
|
26
|
+
* from Movie and Capture classes in Propane::App in propane
|
27
|
+
* @author Martin Prout
|
28
|
+
*/
|
29
|
+
public interface VideoInterface {
|
30
|
+
/**
|
31
|
+
* Used to implement reflection method in PApplet
|
32
|
+
* @see processing.video.Movie
|
33
|
+
* @param movie Movie
|
34
|
+
*/
|
35
|
+
public void movieEvent(Movie movie);
|
36
|
+
/**
|
37
|
+
* Used to implement reflection method in PApplet
|
38
|
+
* @see processing.video.Capture
|
39
|
+
* @param capture Capture
|
40
|
+
*/
|
41
|
+
public void captureEvent(Capture capture);
|
42
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015-16 Martin Prout
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU Lesser General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* http://creativecommons.org/licenses/LGPL/2.1/
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
package monkstone.videoevent;
|
data/test/create_test.rb
CHANGED
@@ -10,25 +10,32 @@ CLASS_SKETCH = <<~CODE
|
|
10
10
|
require 'propane'
|
11
11
|
|
12
12
|
class FredSketch < Propane::App
|
13
|
-
def
|
13
|
+
def settings
|
14
14
|
size 200, 200, P2D
|
15
15
|
end
|
16
16
|
|
17
|
+
def setup
|
18
|
+
sketch_title 'Fred Sketch'
|
19
|
+
end
|
20
|
+
|
17
21
|
def draw
|
18
22
|
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
26
|
+
FredSketch.new
|
27
|
+
|
22
28
|
CODE
|
23
29
|
|
24
30
|
class SketchWriterTest < Minitest::Test
|
25
|
-
ParamMethods = Struct.new(:name, :class_name, :sketch_size)
|
31
|
+
ParamMethods = Struct.new(:name, :class_name, :sketch_size, :sketch_title)
|
26
32
|
|
27
33
|
def setup
|
28
34
|
@param = ParamMethods.new(
|
29
35
|
'fred_sketch',
|
30
36
|
'FredSketch',
|
31
|
-
'size 200, 200, P2D'
|
37
|
+
'size 200, 200, P2D',
|
38
|
+
"sketch_title 'Fred Sketch'"
|
32
39
|
)
|
33
40
|
end
|
34
41
|
|
data/test/respond_to_test.rb
CHANGED
@@ -156,6 +156,7 @@ METHODS = %i(
|
|
156
156
|
shear_x
|
157
157
|
shear_y
|
158
158
|
shininess
|
159
|
+
sketch_title
|
159
160
|
size
|
160
161
|
smooth
|
161
162
|
specular
|
@@ -186,6 +187,14 @@ METHODS = %i(
|
|
186
187
|
)
|
187
188
|
|
188
189
|
class TestSketch < Propane::App
|
190
|
+
def settings
|
191
|
+
size 100, 100
|
192
|
+
end
|
193
|
+
|
194
|
+
def setup
|
195
|
+
sketch_title 'Sketch Test'
|
196
|
+
end
|
197
|
+
|
189
198
|
def draw
|
190
199
|
exit if frame_count > 30
|
191
200
|
end
|
@@ -193,7 +202,7 @@ end
|
|
193
202
|
|
194
203
|
class SpecTest < Minitest::Test
|
195
204
|
def setup
|
196
|
-
@processing_sketch = TestSketch.new
|
205
|
+
@processing_sketch = TestSketch.new
|
197
206
|
end
|
198
207
|
|
199
208
|
def test_respond
|
data/vendors/Rakefile
CHANGED
@@ -1,78 +1,86 @@
|
|
1
|
-
#
|
2
|
-
# frozen_string_literal: false
|
1
|
+
# frozen_string_literal: true
|
3
2
|
require 'rake/clean'
|
4
3
|
|
5
4
|
WARNING = <<-EOS
|
6
5
|
WARNING: you may not have wget installed, you could just download
|
7
|
-
the correct version of
|
8
|
-
re-run
|
6
|
+
the correct version of propane-examples (see EXAMPLES vendors directory)
|
9
7
|
EOS
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
SOUND = 'sound.zip'.freeze
|
9
|
+
SOUND_VERSION = 'v1.3.2' # version 1.3.2
|
10
|
+
VIDEO = 'video-2.zip'
|
11
|
+
VIDEO_VERSION = '2' # version 1.0.1
|
12
|
+
EXAMPLES = '0.2'.freeze
|
13
13
|
HOME_DIR = ENV['HOME']
|
14
|
-
MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
|
15
|
-
|
16
|
-
CLOBBER.include("jruby-complete-#{JRUBYC_VERSION}.jar")
|
17
|
-
|
18
|
-
desc 'download, and copy to propane'
|
19
|
-
task default: [:download, :copy_ruby, :download_examples, :copy_examples]
|
14
|
+
MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
|
20
15
|
|
21
|
-
desc 'download
|
22
|
-
task
|
23
|
-
|
24
|
-
|
16
|
+
desc 'download, and copy propane examples'
|
17
|
+
task default: [:download_examples, :copy_examples]
|
18
|
+
desc 'download and copy examples to user home'
|
19
|
+
task :download_examples
|
20
|
+
file_name = MAC_OR_LINUX.nil? ? "#{EXAMPLES}.zip" : "#{EXAMPLES}.tar.gz"
|
21
|
+
wget_base = 'wget https://github.com/ruby-processing/propane-examples'
|
22
|
+
wget_string = [wget_base, 'archive', file_name].join('/')
|
23
|
+
file file_name do
|
25
24
|
begin
|
26
|
-
sh
|
25
|
+
sh wget_string
|
27
26
|
rescue
|
28
27
|
warn(WARNING)
|
29
28
|
end
|
30
|
-
check_sha256("jruby-complete-#{JRUBYC_VERSION}.jar", "b9a6838ff7bbb0b3eda4eeba26017329572bc2fa014008a069b3848482275283")
|
31
29
|
end
|
32
30
|
|
33
|
-
|
31
|
+
desc 'download and copy sound library to ~/.propane'
|
32
|
+
task download_and_copy_sound: [:download_sound, :copy_sound]
|
34
33
|
|
35
|
-
desc 'copy
|
36
|
-
task
|
37
|
-
sh "cp -v jruby-complete-#{JRUBYC_VERSION}.jar ../lib/ruby/jruby-complete.jar"
|
38
|
-
end
|
34
|
+
desc 'download and copy video library to ~/.propane'
|
35
|
+
task download_and_copy_video: [:download_video, :copy_video]
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
raise "bad sha256 checksum for #{filename} (expected #{expected_hash} got #{sha256.hexdigest})"
|
37
|
+
|
38
|
+
desc 'download sound library'
|
39
|
+
task :download_sound do
|
40
|
+
wget_base = 'wget https://github.com/processing/processing-sound'
|
41
|
+
wget_string = [wget_base, 'releases/download', SOUND_VERSION, SOUND].join('/')
|
42
|
+
begin
|
43
|
+
sh wget_string
|
44
|
+
rescue
|
45
|
+
warn(WARNING)
|
50
46
|
end
|
51
47
|
end
|
52
48
|
|
53
|
-
desc 'download
|
54
|
-
task :
|
55
|
-
|
56
|
-
|
49
|
+
desc 'download video library'
|
50
|
+
task :download_video do
|
51
|
+
wget_base = 'wget https://github.com/processing/processing-video'
|
52
|
+
wget_string = [wget_base, 'releases/download', VIDEO_VERSION, VIDEO].join('/')
|
57
53
|
begin
|
58
|
-
|
59
|
-
sh "wget https://github.com/ruby-processing/propane-examples/archive/#{EXAMPLES}.zip"
|
60
|
-
else
|
61
|
-
sh "wget https://github.com/ruby-processing/propane-examples/archive/#{EXAMPLES}.tar.gz"
|
62
|
-
end
|
54
|
+
sh wget_string
|
63
55
|
rescue
|
64
56
|
warn(WARNING)
|
65
57
|
end
|
66
58
|
end
|
67
59
|
|
68
|
-
desc
|
60
|
+
desc 'copy examples'
|
69
61
|
task :copy_examples => file_name do
|
70
62
|
if MAC_OR_LINUX.nil?
|
71
|
-
sh "unzip #{EXAMPLES}
|
63
|
+
sh "unzip #{EXAMPLES}.zip"
|
72
64
|
else
|
73
|
-
sh "tar xzvf #{EXAMPLES}.tar.gz"
|
65
|
+
sh "tar xzvf #{EXAMPLES}.tar.gz"
|
74
66
|
end
|
75
|
-
sh "rm -r #{HOME_DIR}/
|
76
|
-
sh "cp -r propane-examples-#{EXAMPLES} #{HOME_DIR}/propane_samples"
|
67
|
+
sh "rm -r #{HOME_DIR}/propane_samples" if File.exist? "#{HOME_DIR}/propane_samples"
|
68
|
+
sh "cp -r propane-examples-#{EXAMPLES} #{HOME_DIR}/propane_samples"
|
77
69
|
sh "rm -r propane-examples-#{EXAMPLES}"
|
78
70
|
end
|
71
|
+
|
72
|
+
desc 'copy sound library'
|
73
|
+
task :copy_sound => SOUND do
|
74
|
+
sh "unzip #{SOUND}"
|
75
|
+
sh "rm -r #{HOME_DIR}/.propane/libraries/sound" if File.exist? "#{HOME_DIR}/.propane/libraries/sound"
|
76
|
+
sh "cp -r sound #{HOME_DIR}/.propane/libraries/sound"
|
77
|
+
sh 'rm -r sound'
|
78
|
+
end
|
79
|
+
|
80
|
+
desc 'copy video library'
|
81
|
+
task :copy_video => VIDEO do
|
82
|
+
sh "unzip #{VIDEO}"
|
83
|
+
sh "rm -r #{HOME_DIR}/.propane/libraries/video" if File.exist? "#{HOME_DIR}/.propane/libraries/video"
|
84
|
+
sh "cp -r video #{HOME_DIR}/.propane/libraries/video"
|
85
|
+
sh 'rm -r video'
|
86
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: propane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0.pre
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
|
-
- filib
|
8
7
|
- monkstone
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-11 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: arcball
|
@@ -41,19 +40,19 @@ files:
|
|
41
40
|
- ".travis.yml"
|
42
41
|
- CHANGELOG.md
|
43
42
|
- Gemfile
|
44
|
-
- LICENSE
|
43
|
+
- LICENSE
|
45
44
|
- README.md
|
46
45
|
- Rakefile
|
47
46
|
- bin/propane
|
48
47
|
- lib/PROCESSING_LICENSE.txt
|
49
|
-
- lib/core-
|
48
|
+
- lib/core-3.1.1.jar
|
50
49
|
- lib/export.txt
|
51
|
-
- lib/gluegen-rt-2.
|
52
|
-
- lib/gluegen-rt-2.
|
53
|
-
- lib/gluegen-rt-2.
|
54
|
-
- lib/jogl-all-2.
|
55
|
-
- lib/jogl-all-2.
|
56
|
-
- lib/jogl-all-2.
|
50
|
+
- lib/gluegen-rt-2.3.2-natives-linux-amd64.jar
|
51
|
+
- lib/gluegen-rt-2.3.2-natives-macosx-universal.jar
|
52
|
+
- lib/gluegen-rt-2.3.2.jar
|
53
|
+
- lib/jogl-all-2.3.2-natives-linux-amd64.jar
|
54
|
+
- lib/jogl-all-2.3.2-natives-macosx-universal.jar
|
55
|
+
- lib/jogl-all-2.3.2.jar
|
57
56
|
- lib/propane.jar
|
58
57
|
- lib/propane.rb
|
59
58
|
- lib/propane/app.rb
|
@@ -68,14 +67,13 @@ files:
|
|
68
67
|
- library/file_chooser/chooser.rb
|
69
68
|
- library/file_chooser/file_chooser.rb
|
70
69
|
- library/slider/slider.rb
|
70
|
+
- library/video_event/video_event.rb
|
71
71
|
- pom.rb
|
72
72
|
- pom.xml
|
73
73
|
- propane.gemspec
|
74
|
-
- src/monkstone/CodeListener.java
|
75
74
|
- src/monkstone/ColorUtil.java
|
76
75
|
- src/monkstone/MathToolModule.java
|
77
76
|
- src/monkstone/PropaneLibrary.java
|
78
|
-
- src/monkstone/WatchSketchDir.java
|
79
77
|
- src/monkstone/core/AbstractLibrary.java
|
80
78
|
- src/monkstone/fastmath/Deglut.java
|
81
79
|
- src/monkstone/fastmath/package-info.java
|
@@ -97,10 +95,12 @@ files:
|
|
97
95
|
- src/monkstone/vecmath/vec2/package-info.java
|
98
96
|
- src/monkstone/vecmath/vec3/Vec3.java
|
99
97
|
- src/monkstone/vecmath/vec3/package-info.java
|
98
|
+
- src/monkstone/videoevent/VideoInterface.java
|
99
|
+
- src/monkstone/videoevent/package-info.java
|
100
100
|
- test/create_test.rb
|
101
101
|
- test/respond_to_test.rb
|
102
102
|
- vendors/Rakefile
|
103
|
-
homepage: https://github.
|
103
|
+
homepage: https://ruby-processing.github.io/propane/
|
104
104
|
licenses:
|
105
105
|
- MIT
|
106
106
|
metadata: {}
|
@@ -115,15 +115,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
|
-
- - "
|
118
|
+
- - ">"
|
119
119
|
- !ruby/object:Gem::Version
|
120
|
-
version:
|
120
|
+
version: 1.3.1
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
123
|
rubygems_version: 2.6.3
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
|
-
summary: A really slim layer between Ruby and Processing-
|
126
|
+
summary: A really slim layer between Ruby and Processing-3.1.1.
|
127
127
|
test_files:
|
128
128
|
- test/create_test.rb
|
129
129
|
- test/respond_to_test.rb
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Philip Cunningham
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,190 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* This class allows JRubyArt to watch for changes to sketch files
|
3
|
-
* specifically those with a 'rb' or 'glsl' extension requires user to supply
|
4
|
-
* a path String and code listener to constructor. The code listener should
|
5
|
-
* accept a filesystem WatchEvent
|
6
|
-
*/
|
7
|
-
|
8
|
-
/*
|
9
|
-
* This code is a modified version of WatchDir.java
|
10
|
-
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
|
11
|
-
*
|
12
|
-
* Redistribution and use in source and binary forms, with or without
|
13
|
-
* modification, are permitted provided that the following conditions
|
14
|
-
* are met:
|
15
|
-
*
|
16
|
-
* - Redistributions of source code must retain the above copyright
|
17
|
-
* notice, this list of conditions and the following disclaimer.
|
18
|
-
*
|
19
|
-
* - Redistributions in binary form must reproduce the above copyright
|
20
|
-
* notice, this list of conditions and the following disclaimer in the
|
21
|
-
* documentation and/or other materials provided with the distribution.
|
22
|
-
*
|
23
|
-
* - Neither the name of Oracle nor the names of its
|
24
|
-
* contributors may be used to endorse or promote products derived
|
25
|
-
* from this software without specific prior written permission.
|
26
|
-
*
|
27
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
28
|
-
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
29
|
-
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
30
|
-
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
31
|
-
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
32
|
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
33
|
-
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
34
|
-
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
35
|
-
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
36
|
-
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
37
|
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
38
|
-
*/
|
39
|
-
package monkstone;
|
40
|
-
|
41
|
-
import java.io.IOException;
|
42
|
-
import java.nio.file.FileSystems;
|
43
|
-
import java.nio.file.FileVisitResult;
|
44
|
-
import java.nio.file.Files;
|
45
|
-
import java.nio.file.Path;
|
46
|
-
import java.nio.file.Paths;
|
47
|
-
import java.nio.file.SimpleFileVisitor;
|
48
|
-
import static java.nio.file.StandardWatchEventKinds.*;
|
49
|
-
import java.nio.file.WatchEvent;
|
50
|
-
import java.nio.file.WatchKey;
|
51
|
-
import java.nio.file.WatchService;
|
52
|
-
import java.nio.file.attribute.BasicFileAttributes;
|
53
|
-
import java.util.HashMap;
|
54
|
-
import java.util.Map;
|
55
|
-
|
56
|
-
/**
|
57
|
-
* Example to watch a directory (or tree) for changes to files.
|
58
|
-
*/
|
59
|
-
public class WatchSketchDir {
|
60
|
-
|
61
|
-
private final WatchService watcher;
|
62
|
-
private final Map<WatchKey, Path> keys;
|
63
|
-
private boolean trace = false;
|
64
|
-
|
65
|
-
@SuppressWarnings("unchecked")
|
66
|
-
static <T> WatchEvent<T> cast(WatchEvent<?> event) {
|
67
|
-
return (WatchEvent<T>) event;
|
68
|
-
}
|
69
|
-
|
70
|
-
|
71
|
-
/**
|
72
|
-
* Register the given directory with the WatchService
|
73
|
-
*/
|
74
|
-
private void register(Path dir) throws IOException {
|
75
|
-
WatchKey key = dir.register(watcher, ENTRY_MODIFY);
|
76
|
-
if (trace) {
|
77
|
-
Path prev = keys.get(key);
|
78
|
-
if (prev == null) {
|
79
|
-
System.out.format("register: %s\n", dir);
|
80
|
-
} else if (!dir.equals(prev)) {
|
81
|
-
System.out.format("update: %s -> %s\n", prev, dir);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
keys.put(key, dir);
|
85
|
-
}
|
86
|
-
|
87
|
-
/**
|
88
|
-
* Register the given directory, and all its sub-directories, with the
|
89
|
-
* WatchService.
|
90
|
-
*/
|
91
|
-
private void registerAll(final Path start) throws IOException {
|
92
|
-
// register directory and sub-directories
|
93
|
-
Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
|
94
|
-
@Override
|
95
|
-
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
|
96
|
-
throws IOException {
|
97
|
-
register(dir);
|
98
|
-
return FileVisitResult.CONTINUE;
|
99
|
-
}
|
100
|
-
});
|
101
|
-
}
|
102
|
-
|
103
|
-
static final WatchSketchDir watch(String dir) throws IOException{
|
104
|
-
return new WatchSketchDir(dir);
|
105
|
-
}
|
106
|
-
|
107
|
-
/**
|
108
|
-
* Creates a WatchService and registers the given directory
|
109
|
-
* @param dir String
|
110
|
-
* @param obj CodeListener
|
111
|
-
* @throws IOException
|
112
|
-
*/
|
113
|
-
private WatchSketchDir(String dir) throws IOException {
|
114
|
-
this(Paths.get(dir));
|
115
|
-
}
|
116
|
-
|
117
|
-
/**
|
118
|
-
* Creates a WatchService and registers the given directory
|
119
|
-
*
|
120
|
-
* @param dir Path
|
121
|
-
* @param obj CodeListener
|
122
|
-
* @throws java.io.IOException
|
123
|
-
*/
|
124
|
-
private WatchSketchDir(Path dir) throws IOException {
|
125
|
-
this.watcher = FileSystems.getDefault().newWatchService();
|
126
|
-
this.keys = new HashMap<>();
|
127
|
-
|
128
|
-
System.out.format("Scanning Codebase\n", dir);
|
129
|
-
registerAll(dir);
|
130
|
-
System.out.format("Watching %s\n", dir);
|
131
|
-
|
132
|
-
// enable trace after initial registration
|
133
|
-
this.trace = true;
|
134
|
-
}
|
135
|
-
|
136
|
-
/**
|
137
|
-
* Process all events for keys queued to the watcher
|
138
|
-
*/
|
139
|
-
public void addListener(CodeListener obj) {
|
140
|
-
for (;;) {
|
141
|
-
|
142
|
-
// wait for key to be signalled
|
143
|
-
WatchKey key;
|
144
|
-
try {
|
145
|
-
key = watcher.take();
|
146
|
-
} catch (InterruptedException x) {
|
147
|
-
return;
|
148
|
-
}
|
149
|
-
|
150
|
-
Path dir = keys.get(key);
|
151
|
-
if (dir == null) {
|
152
|
-
System.err.println("WatchKey not recognized!!");
|
153
|
-
continue;
|
154
|
-
}
|
155
|
-
|
156
|
-
key.pollEvents().stream().forEach((WatchEvent<?> event) -> {
|
157
|
-
WatchEvent.Kind kind = event.kind();
|
158
|
-
// TBD - provide example of how OVERFLOW event is handled
|
159
|
-
if (!(kind == OVERFLOW)) {
|
160
|
-
// Context for directory entry event is the file name of entry
|
161
|
-
WatchEvent<Path> ev = cast(event);
|
162
|
-
Path name = ev.context();
|
163
|
-
Path child = dir.resolve(name);
|
164
|
-
if (kind == ENTRY_MODIFY){
|
165
|
-
if (child.toFile().getAbsolutePath().endsWith(".rb")
|
166
|
-
|| child.toFile().getAbsolutePath().endsWith(".glsl")) {
|
167
|
-
|
168
|
-
obj.code_event(event);
|
169
|
-
key.reset();
|
170
|
-
}
|
171
|
-
}
|
172
|
-
// if directory is created, and watching recursively, then
|
173
|
-
// register it and its sub-directories
|
174
|
-
}
|
175
|
-
});
|
176
|
-
|
177
|
-
// reset key and remove from set if directory no longer accessible
|
178
|
-
boolean valid = key.reset();
|
179
|
-
if (!valid) {
|
180
|
-
keys.remove(key);
|
181
|
-
|
182
|
-
// all directories are inaccessible
|
183
|
-
if (keys.isEmpty()) {
|
184
|
-
break;
|
185
|
-
}
|
186
|
-
}
|
187
|
-
}
|
188
|
-
}
|
189
|
-
|
190
|
-
}
|