naether 0.9.2-java → 0.10.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.
- data/README.md +1 -1
- data/VERSION +1 -1
- data/core-0.10.0.jar +0 -0
- data/doc/Naether.html +314 -171
- data/doc/Naether/Bootstrap.html +442 -125
- data/doc/Naether/Configurator.html +43 -32
- data/doc/Naether/Java.html +486 -73
- data/doc/Naether/Java/JRuby.html +371 -89
- data/doc/Naether/Java/Ruby.html +530 -147
- data/doc/Naether/Maven.html +4 -4
- data/doc/Naether/Notation.html +714 -0
- data/doc/_index.html +11 -4
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +5 -5
- data/doc/frames.html +1 -1
- data/doc/index.html +5 -5
- data/doc/method_list.html +94 -22
- data/doc/top-level-namespace.html +3 -3
- data/lib/naether.rb +33 -6
- data/lib/naether/bootstrap.rb +37 -6
- data/lib/naether/configuration.rb +5 -1
- data/lib/naether/java.rb +63 -12
- data/lib/naether/java/jruby.rb +39 -14
- data/lib/naether/java/ruby.rb +69 -16
- data/lib/naether/maven.rb +1 -1
- data/lib/naether/notation.rb +42 -0
- data/naether.gemspec +5 -25
- data/pom.xml +9 -114
- metadata +72 -152
- data/naether-0.9.2.jar +0 -0
data/lib/naether.rb
CHANGED
@@ -17,10 +17,11 @@ require "#{File.dirname(__FILE__)}/naether/configuration"
|
|
17
17
|
require "#{File.dirname(__FILE__)}/naether/bootstrap"
|
18
18
|
require "#{File.dirname(__FILE__)}/naether/java"
|
19
19
|
|
20
|
-
|
21
|
-
# Java dependency resolver
|
20
|
+
#
|
21
|
+
# Java dependency resolver
|
22
22
|
#
|
23
23
|
# @author Michael Guymon
|
24
|
+
# @see https://github.com/mguymon/naether/tree/master/core
|
24
25
|
#
|
25
26
|
class Naether
|
26
27
|
|
@@ -28,7 +29,7 @@ class Naether
|
|
28
29
|
|
29
30
|
class << self
|
30
31
|
|
31
|
-
#
|
32
|
+
# List of Java dependencies needed to bootstrap Naether
|
32
33
|
#
|
33
34
|
# @param [String] dep_file path
|
34
35
|
# @see {Naether::Bootstrap#dependencies}
|
@@ -57,7 +58,7 @@ class Naether
|
|
57
58
|
|
58
59
|
# Create new instance.
|
59
60
|
def initialize
|
60
|
-
@resolver = Naether::Java.create('com.tobedevoured.naether.
|
61
|
+
@resolver = Naether::Java.create('com.tobedevoured.naether.impl.NaetherImpl')
|
61
62
|
end
|
62
63
|
|
63
64
|
# Clear all remote repositories
|
@@ -250,7 +251,7 @@ class Naether
|
|
250
251
|
#
|
251
252
|
# @return [Array]
|
252
253
|
def dependencies
|
253
|
-
Naether::Java.convert_to_ruby_array( @resolver.
|
254
|
+
Naether::Java.convert_to_ruby_array( @resolver.currentDependencies() )
|
254
255
|
end
|
255
256
|
|
256
257
|
# Get array of dependencies as notation
|
@@ -271,11 +272,37 @@ class Naether
|
|
271
272
|
# Convert dependencies to Classpath friendly string
|
272
273
|
#
|
273
274
|
# @return [String]
|
274
|
-
def dependencies_classpath
|
275
|
+
def dependencies_classpath
|
275
276
|
@resolver.getResolvedClassPath()
|
276
277
|
end
|
277
278
|
|
279
|
+
# Dependencies as a Graph of nested Hashes
|
280
|
+
#
|
281
|
+
# @return [Hash]
|
282
|
+
def dependencies_graph(nodes=nil)
|
283
|
+
nodes = @resolver.getDependenciesGraph() unless nodes
|
284
|
+
|
285
|
+
graph = {}
|
286
|
+
if Naether.platform == 'java'
|
287
|
+
nodes.each do |k,v|
|
288
|
+
deps = dependencies_graph(v)
|
289
|
+
graph[k] = Naether::Java.convert_to_ruby_hash( deps )
|
290
|
+
end
|
291
|
+
else
|
292
|
+
iterator = nodes.entrySet().iterator();
|
293
|
+
while iterator.hasNext()
|
294
|
+
entry = iterator.next()
|
295
|
+
deps = dependencies_graph(entry.getValue())
|
296
|
+
graph[entry.getKey().toString()] = Naether::Java.convert_to_ruby_hash( deps )
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
graph
|
301
|
+
end
|
302
|
+
|
278
303
|
# Load dependencies to Classpath
|
304
|
+
#
|
305
|
+
# @return [Array] of loaded jars
|
279
306
|
def load_dependencies_to_classpath
|
280
307
|
jars = dependencies_classpath.split(":")
|
281
308
|
Naether::Java.load_jars(jars)
|
data/lib/naether/bootstrap.rb
CHANGED
@@ -5,12 +5,11 @@ require 'open-uri'
|
|
5
5
|
require 'fileutils'
|
6
6
|
|
7
7
|
class Naether
|
8
|
-
|
8
|
+
|
9
9
|
#
|
10
10
|
# Helper for bootstrapping Naether
|
11
11
|
#
|
12
|
-
#
|
13
|
-
# Michael Guymon
|
12
|
+
# @author Michael Guymon
|
14
13
|
#
|
15
14
|
class Bootstrap
|
16
15
|
|
@@ -18,11 +17,14 @@ class Naether
|
|
18
17
|
|
19
18
|
class << self
|
20
19
|
|
20
|
+
# Default local repo of ENV['M2_REPO'] or ~/.m2/repository
|
21
|
+
#
|
22
|
+
# @return [String]
|
21
23
|
def default_local_repo
|
22
24
|
ENV['M2_REPO'] || File.expand_path('~/.m2/repository')
|
23
25
|
end
|
24
26
|
|
25
|
-
#
|
27
|
+
# Write bootstrap dependencies to yaml file
|
26
28
|
def write_dependencies( dest = 'jar_dependencies.yml' )
|
27
29
|
deps = {};
|
28
30
|
if Naether::Configuration.platform == 'java'
|
@@ -37,7 +39,11 @@ class Naether
|
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
# List of Java dependencies for Naether
|
42
|
+
# List of Java dependencies for Naether from yaml dependency file. Caches
|
43
|
+
# result after first run.
|
44
|
+
#
|
45
|
+
# @param [String] dep_file path, defaults to Naether::Configuration.dependencies_yml
|
46
|
+
# @return [List]
|
41
47
|
def dependencies( dep_file=nil )
|
42
48
|
|
43
49
|
if @@dependencies
|
@@ -53,6 +59,11 @@ class Naether
|
|
53
59
|
end
|
54
60
|
|
55
61
|
|
62
|
+
#
|
63
|
+
# Bootstrap the local repo by downloading Naether's dependencies
|
64
|
+
# @param [String] local_repo defaults to #default_local_repo
|
65
|
+
# @param [hash] opts
|
66
|
+
#
|
56
67
|
def bootstrap_local_repo(local_repo = nil, opts = {} )
|
57
68
|
local_repo = local_repo || default_local_repo
|
58
69
|
|
@@ -71,10 +82,16 @@ class Naether
|
|
71
82
|
install_dependencies_to_local_repo( deps[:downloaded], jars, opts )
|
72
83
|
end
|
73
84
|
|
74
|
-
#raise Naether::Java.
|
85
|
+
#raise Naether::Java.internal_loaded_paths.inspect
|
75
86
|
|
76
87
|
end
|
77
88
|
|
89
|
+
#
|
90
|
+
# Download Naether dependencies
|
91
|
+
#
|
92
|
+
# @param [String] dest to download dependencies t
|
93
|
+
# @param [Hash] opts
|
94
|
+
# @return [Hash] with status of missing, downloaded, exists dependencies
|
78
95
|
def download_dependencies( dest, opts = {} )
|
79
96
|
|
80
97
|
if !File.exists? dest
|
@@ -121,6 +138,12 @@ class Naether
|
|
121
138
|
deps
|
122
139
|
end
|
123
140
|
|
141
|
+
#
|
142
|
+
# Check local_repo for Naether dependencies
|
143
|
+
#
|
144
|
+
# @param [String] local_repo
|
145
|
+
# @param [Hash] opts
|
146
|
+
# @return [Hash] with status of missing, downloaded, exists dependencies
|
124
147
|
def check_local_repo_for_deps(local_repo = nil, opts = {} )
|
125
148
|
|
126
149
|
local_repo = local_repo || default_local_repo
|
@@ -151,6 +174,14 @@ class Naether
|
|
151
174
|
deps
|
152
175
|
end
|
153
176
|
|
177
|
+
#
|
178
|
+
# Install Naether Dependencies to local_repo
|
179
|
+
#
|
180
|
+
# @param [Array<String>] install_jars
|
181
|
+
# @param [Array<String>] naether_jars to bootstrap Naether. These may overlap with install_jars.
|
182
|
+
# @param [Hash] opts
|
183
|
+
# @return [Naether]
|
184
|
+
#
|
154
185
|
def install_dependencies_to_local_repo( install_jars, naether_jars, opts = {} )
|
155
186
|
|
156
187
|
require "#{File.dirname(__FILE__)}/../naether"
|
@@ -1,5 +1,9 @@
|
|
1
1
|
|
2
2
|
class Naether
|
3
|
+
|
4
|
+
#
|
5
|
+
# Naether runtime configuration
|
6
|
+
#
|
3
7
|
class Configurator
|
4
8
|
def initialize(data={})
|
5
9
|
gem_dir = File.expand_path("#{File.dirname(__FILE__)}/../../")
|
@@ -19,7 +23,7 @@ class Naether
|
|
19
23
|
|
20
24
|
@data = {
|
21
25
|
:gem_dir => gem_dir,
|
22
|
-
:naether_jar => File.join( gem_dir, "
|
26
|
+
:naether_jar => File.join( gem_dir, "core-#{version}.jar"),
|
23
27
|
:platform => ($platform || RUBY_PLATFORM[/java/] || 'ruby'),
|
24
28
|
:version => version,
|
25
29
|
:dependencies_yml => File.expand_path("#{File.dirname( __FILE__ )}/../../jar_dependencies.yml")
|
data/lib/naether/java.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require "#{File.dirname(__FILE__)}/configuration"
|
3
3
|
|
4
|
-
# :title:Naether::Java
|
5
4
|
#
|
6
|
-
# Handles loading jars
|
5
|
+
# Handles loading jars using the correct platform, Naether::Java::JRuby
|
7
6
|
# or Naether::Java::Ruby
|
8
7
|
#
|
9
|
-
#
|
10
|
-
# Michael Guymon
|
8
|
+
# @author Michael Guymon
|
11
9
|
#
|
12
10
|
class Naether
|
13
11
|
class Java
|
@@ -15,6 +13,10 @@ class Naether
|
|
15
13
|
|
16
14
|
attr_reader :java
|
17
15
|
|
16
|
+
#
|
17
|
+
# Creates new instance by loading the Naether jar to the parent ClassLoader
|
18
|
+
# and creating the internal Naether ClassLoader
|
19
|
+
#
|
18
20
|
def initialize()
|
19
21
|
naether_jar = Naether::Configuration.naether_jar
|
20
22
|
|
@@ -24,44 +26,93 @@ class Naether
|
|
24
26
|
|
25
27
|
if Naether::Configuration.platform == 'java'
|
26
28
|
require "#{File.dirname(__FILE__)}/java/jruby"
|
27
|
-
@java = Naether::Java::JRuby.
|
29
|
+
@java = Naether::Java::JRuby.new
|
28
30
|
else
|
29
31
|
require "#{File.dirname(__FILE__)}/java/ruby"
|
30
|
-
@java = Naether::Java::Ruby.
|
32
|
+
@java = Naether::Java::Ruby.new
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
36
|
+
#
|
34
37
|
# Paths loaded
|
38
|
+
#
|
39
|
+
# @return [Array] of String paths
|
40
|
+
#
|
35
41
|
def self.loaded_paths
|
36
42
|
instance.java.loaded_paths
|
37
43
|
end
|
38
44
|
|
39
|
-
#
|
45
|
+
#
|
46
|
+
# Load a path onto the parent ClassLoader
|
47
|
+
#
|
48
|
+
# @param [Array] paths as an Array of String paths or a String path
|
49
|
+
#
|
40
50
|
def self.load_paths(paths)
|
41
51
|
instance.java.load_paths(paths)
|
42
52
|
end
|
43
53
|
|
44
|
-
|
54
|
+
def self.internal_loaded_paths
|
55
|
+
convert_to_ruby_array( instance.java.class_loader.getLoadedPaths, true )
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Load a path into the internal Naether ClassLoader
|
60
|
+
#
|
61
|
+
# @param [Array] paths as an Array of String paths or a String path
|
62
|
+
#
|
45
63
|
def self.internal_load_paths(paths)
|
46
64
|
instance.java.internal_load_paths(paths)
|
47
65
|
end
|
48
|
-
|
66
|
+
|
67
|
+
#
|
68
|
+
# Create a Java Object from the Naether Class Loader
|
69
|
+
#
|
70
|
+
# @param [String] target_class to create
|
71
|
+
# @param [Array] args Array of constructor arguments
|
49
72
|
def self.create( target_class, *args )
|
50
73
|
instance.java.create( target_class, *args )
|
51
74
|
end
|
52
75
|
|
53
|
-
|
54
|
-
|
76
|
+
#
|
77
|
+
# Execute a Staic method on a Java class from the Naether Class Loader
|
78
|
+
#
|
79
|
+
# @param [String] target_class
|
80
|
+
# @param [String] target_method
|
81
|
+
# @param [Array] params Array of method parameters
|
82
|
+
# @param [Array] types if defined, a Array of String classes of params type that lines up with params one to one.
|
83
|
+
# @return [Object]
|
84
|
+
def self.exec_static_method( target_class, target_method, params, types = nil )
|
85
|
+
instance.java.exec_static_method( target_class, target_method, params, types )
|
55
86
|
end
|
56
87
|
|
88
|
+
#
|
89
|
+
# Convert a Ruby Array to a java.util.ArrayList
|
90
|
+
#
|
91
|
+
# @param [Array] ruby_array to convert to Java.util.ArrayList
|
92
|
+
# @return [java.util.ArrayList]
|
93
|
+
#
|
57
94
|
def self.convert_to_java_list( ruby_array )
|
58
95
|
instance.java.convert_to_java_list( ruby_array )
|
59
96
|
end
|
60
97
|
|
98
|
+
#
|
99
|
+
# Convert a java,util.List to a Ruby Array
|
100
|
+
#
|
101
|
+
# @param [java.util.ArrayList] java_array
|
102
|
+
# @param [Boolean] to_string platform dependent helper
|
103
|
+
# @return [Array]
|
104
|
+
#
|
61
105
|
def self.convert_to_ruby_array( java_array, to_string = false )
|
62
106
|
instance.java.convert_to_ruby_array( java_array, to_string )
|
63
107
|
end
|
64
|
-
|
108
|
+
|
109
|
+
#
|
110
|
+
# Convert a java.util.Map to a Ruby Hash
|
111
|
+
#
|
112
|
+
# @param [java.util.Map] java_hash
|
113
|
+
# @param [Boolean] to_string platform dependent helper
|
114
|
+
# @return [Hash]
|
115
|
+
#
|
65
116
|
def self.convert_to_ruby_hash( java_hash, to_string = false )
|
66
117
|
instance.java.convert_to_ruby_hash( java_hash, to_string )
|
67
118
|
end
|
data/lib/naether/java/jruby.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/../configuration"
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
# Singletn that handles Java interactions for JRuby. Providers helpers for
|
3
|
+
|
4
|
+
# Handles Java interactions for JRuby. Providers helpers for
|
6
5
|
# nomalizing accesss.
|
7
6
|
|
8
|
-
#
|
9
|
-
# Michael Guymon
|
7
|
+
# @author Michael Guymon
|
10
8
|
#
|
11
9
|
class Naether
|
12
10
|
class Java
|
13
11
|
|
14
12
|
class JRuby
|
15
|
-
include Singleton
|
16
13
|
|
17
14
|
attr_reader :loaded_paths, :class_loader
|
18
15
|
|
19
16
|
#
|
20
|
-
# Creates new instance by loading the Naether jar to the
|
17
|
+
# Creates new instance by loading the Naether jar to the parent ClassLoader
|
21
18
|
# and creating the internal Naether ClassLoader
|
22
19
|
#
|
23
20
|
def initialize
|
@@ -33,15 +30,22 @@ class Naether
|
|
33
30
|
end
|
34
31
|
|
35
32
|
#
|
36
|
-
# Create a Java Object
|
33
|
+
# Create a Java Object from the Naether Class Loader
|
37
34
|
#
|
35
|
+
# @param [String] target_class to create
|
36
|
+
# @param [Array] args Array of constructor arguments
|
38
37
|
def create( target_class, *args )
|
39
38
|
@class_loader.newInstance(target_class, *args )
|
40
39
|
end
|
41
40
|
|
42
41
|
#
|
43
|
-
# Execute a Staic method on a Java class
|
42
|
+
# Execute a Staic method on a Java class from the Naether Class Loader
|
44
43
|
#
|
44
|
+
# @param [String] target_class
|
45
|
+
# @param [String] target_method
|
46
|
+
# @param [Array] params Array of method parameters
|
47
|
+
# @param [Array] types if defined, a Array of String classes of params type that lines up with params one to one.
|
48
|
+
# @return [Object]
|
45
49
|
def exec_static_method( target_class, target_method, params, types = nil )
|
46
50
|
unless params.is_a? Array
|
47
51
|
params = [params]
|
@@ -59,6 +63,8 @@ class Naether
|
|
59
63
|
#
|
60
64
|
# Load a path into the internal Naether ClassLoader
|
61
65
|
#
|
66
|
+
# @param [Array] paths as an Array of String paths or a String path
|
67
|
+
#
|
62
68
|
def internal_load_paths(paths)
|
63
69
|
load_paths = []
|
64
70
|
unless paths.is_a? Array
|
@@ -78,7 +84,9 @@ class Naether
|
|
78
84
|
end
|
79
85
|
|
80
86
|
#
|
81
|
-
# Load a path onto the
|
87
|
+
# Load a path onto the parent ClassLoader
|
88
|
+
#
|
89
|
+
# @param [Array] paths as an Array of String paths or a String path
|
82
90
|
#
|
83
91
|
def load_paths(paths)
|
84
92
|
load_paths = []
|
@@ -99,7 +107,10 @@ class Naether
|
|
99
107
|
end
|
100
108
|
|
101
109
|
#
|
102
|
-
# Convert a Ruby Array to a
|
110
|
+
# Convert a Ruby Array to a java.util.ArrayList
|
111
|
+
#
|
112
|
+
# @param [Array] ruby_array Array to convert to Java.util.ArrayList
|
113
|
+
# @return [java.util.ArrayList]
|
103
114
|
#
|
104
115
|
def convert_to_java_list( ruby_array )
|
105
116
|
list = java.util.ArrayList.new
|
@@ -111,17 +122,31 @@ class Naether
|
|
111
122
|
end
|
112
123
|
|
113
124
|
#
|
114
|
-
# Convert a
|
125
|
+
# Convert a java,util.List to a Ruby Array
|
126
|
+
#
|
127
|
+
# @param [java.util.ArrayList] java_array
|
128
|
+
# @param [Boolean] to_string has no affect on conversion.
|
129
|
+
# @return [Array]
|
115
130
|
#
|
116
131
|
def convert_to_ruby_array( java_array, to_string = false )
|
117
132
|
java_array.to_a
|
118
133
|
end
|
119
134
|
|
120
135
|
#
|
121
|
-
# Convert a
|
136
|
+
# Convert a java.util.Map to a Ruby Hash
|
137
|
+
#
|
138
|
+
# @param [java.util.Map] java_hash
|
139
|
+
# @param [Boolean] to_string has no affect on conversion
|
140
|
+
# @return [Hash]
|
122
141
|
#
|
123
142
|
def convert_to_ruby_hash( java_hash, to_string = false )
|
124
|
-
java_hash.to_hash
|
143
|
+
hash = java_hash.to_hash
|
144
|
+
|
145
|
+
hash.each do |k,v|
|
146
|
+
if v.is_a? java.util.Map
|
147
|
+
hash[k] = convert_to_ruby_hash(v, to_string )
|
148
|
+
end
|
149
|
+
end
|
125
150
|
end
|
126
151
|
|
127
152
|
end
|
data/lib/naether/java/ruby.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/../configuration"
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# Sngleton that handles Java interactions for Ruby using RJB. Providers helpers for
|
3
|
+
# Handles Java interactions for Ruby using RJB. Providers helpers for
|
6
4
|
# nomalizing accesss.
|
7
5
|
#
|
8
|
-
#
|
9
|
-
# Michael Guymon
|
6
|
+
# @author Michael Guymon
|
10
7
|
#
|
11
8
|
class Naether
|
12
9
|
class Java
|
13
10
|
|
14
11
|
class Ruby
|
15
|
-
include Singleton
|
16
12
|
|
17
13
|
attr_reader :loaded_paths, :class_loader
|
18
14
|
|
15
|
+
#
|
16
|
+
# Creates new instance by loading the Naether jar to the parent ClassLoader
|
17
|
+
# and creating the internal Naether ClassLoader
|
18
|
+
#
|
19
19
|
def initialize
|
20
20
|
require 'rjb'
|
21
21
|
|
@@ -35,6 +35,11 @@ class Naether
|
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
+
#
|
39
|
+
# Create a Java Object from the Naether Class Loader
|
40
|
+
#
|
41
|
+
# @param [String] target_class to create
|
42
|
+
# @param [Array] args Array of constructor arguments
|
38
43
|
def create( target_class, *args )
|
39
44
|
#@class_loader.newInstance(target_class, *args )
|
40
45
|
if args.size > 0
|
@@ -44,6 +49,14 @@ class Naether
|
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
52
|
+
#
|
53
|
+
# Execute a Staic method on a Java class from the Naether Class Loader
|
54
|
+
#
|
55
|
+
# @param [String] target_class
|
56
|
+
# @param [String] target_method
|
57
|
+
# @param [Array] params Array of method parameters
|
58
|
+
# @param [Array] types if defined, a Array of String classes of params type that lines up with params one to one.
|
59
|
+
# @return [Object]
|
47
60
|
def exec_static_method( target_class, target_method, params, types = nil )
|
48
61
|
unless params.is_a? Array
|
49
62
|
params = [params]
|
@@ -72,7 +85,12 @@ class Naether
|
|
72
85
|
end
|
73
86
|
end
|
74
87
|
end
|
75
|
-
|
88
|
+
|
89
|
+
#
|
90
|
+
# Load a path into the internal Naether ClassLoader
|
91
|
+
#
|
92
|
+
# @param [Array] paths as an Array of String paths or a String path
|
93
|
+
#
|
76
94
|
def internal_load_paths(paths)
|
77
95
|
loadable_paths = []
|
78
96
|
unless paths.is_a? Array
|
@@ -90,6 +108,11 @@ class Naether
|
|
90
108
|
loadable_paths
|
91
109
|
end
|
92
110
|
|
111
|
+
#
|
112
|
+
# Load a path onto the parent ClassLoader
|
113
|
+
#
|
114
|
+
# @param [Array] paths as an Array of String paths or a String path
|
115
|
+
#
|
93
116
|
def load_paths(paths)
|
94
117
|
loadable_paths = []
|
95
118
|
unless paths.is_a? Array
|
@@ -108,6 +131,12 @@ class Naether
|
|
108
131
|
loadable_paths
|
109
132
|
end
|
110
133
|
|
134
|
+
#
|
135
|
+
# Convert a Ruby Array to a java.util.ArrayList
|
136
|
+
#
|
137
|
+
# @param [Array] ruby_array Array to convert to Java.util.ArrayList
|
138
|
+
# @return [java.util.ArrayList]
|
139
|
+
#
|
111
140
|
def convert_to_java_list( ruby_array )
|
112
141
|
list = Rjb::import("java.util.ArrayList").new
|
113
142
|
ruby_array.each do |item|
|
@@ -117,6 +146,13 @@ class Naether
|
|
117
146
|
list
|
118
147
|
end
|
119
148
|
|
149
|
+
#
|
150
|
+
# Convert a java,util.List to a Ruby Array
|
151
|
+
#
|
152
|
+
# @param [java.util.ArrayList] java_array
|
153
|
+
# @param [Boolean] to_string converts each element using toString
|
154
|
+
# @return [Array]
|
155
|
+
#
|
120
156
|
def convert_to_ruby_array( java_array, to_string = false )
|
121
157
|
ruby_array = java_array.toArray()
|
122
158
|
|
@@ -127,20 +163,37 @@ class Naether
|
|
127
163
|
ruby_array
|
128
164
|
end
|
129
165
|
|
166
|
+
#
|
167
|
+
# Convert a java.util.Map to a Ruby Hash
|
168
|
+
#
|
169
|
+
# @param [java.util.Map] java_hash
|
170
|
+
# @param [Boolean] to_string converts each element using toString
|
171
|
+
# @return [Hash]
|
172
|
+
#
|
130
173
|
def convert_to_ruby_hash( java_hash, to_string = false )
|
131
174
|
|
132
175
|
hash = {}
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
176
|
+
unless java_hash.is_a? Hash
|
177
|
+
keys = java_hash.keySet()
|
178
|
+
iterator = keys.iterator()
|
179
|
+
if to_string
|
180
|
+
while iterator.hasNext()
|
181
|
+
key = iterator.next().toString()
|
182
|
+
hash[key] = java_hash.get( key ).toString()
|
183
|
+
end
|
184
|
+
else
|
185
|
+
while iterator.hasNext()
|
186
|
+
key = iterator.next()
|
187
|
+
hash[key] = java_hash.get( key )
|
188
|
+
end
|
139
189
|
end
|
140
190
|
else
|
141
|
-
|
142
|
-
|
143
|
-
|
191
|
+
if to_string
|
192
|
+
java_hash.each do |k,v|
|
193
|
+
hash[k.toString()] = v.toString()
|
194
|
+
end
|
195
|
+
else
|
196
|
+
hash = java_hash
|
144
197
|
end
|
145
198
|
end
|
146
199
|
|