naether 0.8.6 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +106 -0
- data/Rakefile +14 -0
- data/VERSION +1 -1
- data/doc/Naether.html +3136 -0
- data/doc/Naether/Bootstrap.html +796 -0
- data/doc/Naether/Configurator.html +490 -0
- data/doc/Naether/Java.html +795 -0
- data/doc/Naether/Java/JRuby.html +926 -0
- data/doc/Naether/Java/Ruby.html +931 -0
- data/doc/Naether/Maven.html +1143 -0
- data/doc/_index.html +192 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/file.README.html +195 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +195 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +708 -0
- data/doc/top-level-namespace.html +112 -0
- data/jar_dependencies.yml +19 -25
- data/lib/naether.rb +147 -142
- data/lib/naether/bootstrap.rb +41 -43
- data/lib/naether/configuration.rb +61 -0
- data/lib/naether/java.rb +22 -198
- data/lib/naether/java/jruby.rb +129 -0
- data/lib/naether/java/ruby.rb +153 -0
- data/lib/naether/maven.rb +142 -0
- data/naether-0.9.0.jar +0 -0
- data/naether.gemspec +95 -0
- data/pom.xml +153 -132
- metadata +86 -10
- data/README.rdoc +0 -47
- data/naether-0.8.6.jar +0 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../configuration"
|
2
|
+
|
3
|
+
# :title:Naether::Java::JRuby
|
4
|
+
#
|
5
|
+
# Singletn that handles Java interactions for JRuby. Providers helpers for
|
6
|
+
# nomalizing accesss.
|
7
|
+
|
8
|
+
# = Authors
|
9
|
+
# Michael Guymon
|
10
|
+
#
|
11
|
+
class Naether
|
12
|
+
class Java
|
13
|
+
|
14
|
+
class JRuby
|
15
|
+
include Singleton
|
16
|
+
|
17
|
+
attr_reader :loaded_paths, :class_loader
|
18
|
+
|
19
|
+
#
|
20
|
+
# Creates new instance by loading the Naether jar to the global ClassLoader
|
21
|
+
# and creating the internal Naether ClassLoader
|
22
|
+
#
|
23
|
+
def initialize
|
24
|
+
require 'java'
|
25
|
+
|
26
|
+
naether_jar = Naether::Configuration.naether_jar
|
27
|
+
|
28
|
+
@loaded_paths = []
|
29
|
+
|
30
|
+
load_paths(naether_jar)
|
31
|
+
@class_loader = com.tobedevoured.naether.PathClassLoader.new()
|
32
|
+
internal_load_paths(naether_jar)
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Create a Java Object
|
37
|
+
#
|
38
|
+
def create( target_class, *args )
|
39
|
+
@class_loader.newInstance(target_class, *args )
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Execute a Staic method on a Java class
|
44
|
+
#
|
45
|
+
def exec_static_method( target_class, target_method, params, types = nil )
|
46
|
+
unless params.is_a? Array
|
47
|
+
params = [params]
|
48
|
+
end
|
49
|
+
|
50
|
+
if types
|
51
|
+
unless types.is_a? Array
|
52
|
+
types = [types]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@class_loader.execStaticMethod( target_class, target_method, params, types )
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Load a path into the internal Naether ClassLoader
|
61
|
+
#
|
62
|
+
def internal_load_paths(paths)
|
63
|
+
load_paths = []
|
64
|
+
unless paths.is_a? Array
|
65
|
+
paths = [paths]
|
66
|
+
end
|
67
|
+
|
68
|
+
paths.each do |path|
|
69
|
+
expanded_path = File.expand_path(path)
|
70
|
+
if File.exists?( expanded_path )
|
71
|
+
@class_loader.addPath( expanded_path )
|
72
|
+
|
73
|
+
load_paths << expanded_path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
load_paths
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Load a path onto the Global ClassLoader
|
82
|
+
#
|
83
|
+
def load_paths(paths)
|
84
|
+
load_paths = []
|
85
|
+
unless paths.is_a? Array
|
86
|
+
paths = [paths]
|
87
|
+
end
|
88
|
+
|
89
|
+
paths.each do |path|
|
90
|
+
expanded_path = File.expand_path(path)
|
91
|
+
if !@loaded_paths.include?( expanded_path ) && File.exists?( expanded_path )
|
92
|
+
$CLASSPATH << expanded_path
|
93
|
+
load_paths << expanded_path
|
94
|
+
@loaded_paths << expanded_path
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
load_paths
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Convert a Ruby Array to a Java ArrayList
|
103
|
+
#
|
104
|
+
def convert_to_java_list( ruby_array )
|
105
|
+
list = java.util.ArrayList.new
|
106
|
+
ruby_array.each do |item|
|
107
|
+
list.add( item )
|
108
|
+
end
|
109
|
+
|
110
|
+
list
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# Convert a Java List to a Ruby Array
|
115
|
+
#
|
116
|
+
def convert_to_ruby_array( java_array, to_string = false )
|
117
|
+
java_array.to_a
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# Convert a Java Map to a Ruby Hash
|
122
|
+
#
|
123
|
+
def convert_to_ruby_hash( java_hash, to_string = false )
|
124
|
+
java_hash.to_hash
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../configuration"
|
2
|
+
|
3
|
+
# :title:Naether::Java::Ruby
|
4
|
+
#
|
5
|
+
# Sngleton that handles Java interactions for Ruby using RJB. Providers helpers for
|
6
|
+
# nomalizing accesss.
|
7
|
+
#
|
8
|
+
# = Authors
|
9
|
+
# Michael Guymon
|
10
|
+
#
|
11
|
+
class Naether
|
12
|
+
class Java
|
13
|
+
|
14
|
+
class Ruby
|
15
|
+
include Singleton
|
16
|
+
|
17
|
+
attr_reader :loaded_paths, :class_loader
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
require 'rjb'
|
21
|
+
|
22
|
+
naether_jar = Naether::Configuration.naether_jar
|
23
|
+
|
24
|
+
# Call Rjb::load with an empty classpath, incase Rjb::load has already been called
|
25
|
+
java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split
|
26
|
+
Rjb::load("", java_opts)
|
27
|
+
|
28
|
+
@loaded_paths = []
|
29
|
+
load_paths( naether_jar )
|
30
|
+
|
31
|
+
class_loader_class = Rjb::import( "com.tobedevoured.naether.PathClassLoader" )
|
32
|
+
@class_loader = class_loader_class.new()
|
33
|
+
|
34
|
+
internal_load_paths( naether_jar )
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def create( target_class, *args )
|
39
|
+
#@class_loader.newInstance(target_class, *args )
|
40
|
+
if args.size > 0
|
41
|
+
@class_loader._invoke('newInstance', 'Ljava.lang.String;[Ljava.lang.Object;', target_class, args )
|
42
|
+
else
|
43
|
+
@class_loader._invoke('newInstance', 'Ljava.lang.String;', target_class )
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def exec_static_method( target_class, target_method, params, types = nil )
|
48
|
+
unless params.is_a? Array
|
49
|
+
params = [params]
|
50
|
+
end
|
51
|
+
|
52
|
+
if types
|
53
|
+
unless types.is_a? Array
|
54
|
+
types = [types]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
result = nil
|
58
|
+
if params.nil?
|
59
|
+
result = @class_loader._invoke('execStaticMethod','Ljava.lang.String;Ljava.lang.String;', target_class, target_method )
|
60
|
+
elsif types.nil?
|
61
|
+
result = @class_loader._invoke('execStaticMethod','Ljava.lang.String;Ljava.lang.String;Ljava.util.List;', target_class, target_method, convert_to_java_list(params) )
|
62
|
+
else
|
63
|
+
result = @class_loader._invoke('execStaticMethod','Ljava.lang.String;Ljava.lang.String;Ljava.util.List;Ljava.util.List;', target_class, target_method, convert_to_java_list(params), convert_to_java_list(types) )
|
64
|
+
end
|
65
|
+
|
66
|
+
unless result.nil?
|
67
|
+
# Force toString on java.lang.String otherwise the result will be a Rjb::Proxy
|
68
|
+
if result.getClass().getName() == 'java.lang.String'
|
69
|
+
result.toString()
|
70
|
+
else
|
71
|
+
result
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def internal_load_paths(paths)
|
77
|
+
loadable_paths = []
|
78
|
+
unless paths.is_a? Array
|
79
|
+
paths = [paths]
|
80
|
+
end
|
81
|
+
|
82
|
+
paths.each do |path|
|
83
|
+
expanded_path = File.expand_path(path)
|
84
|
+
if File.exists?( expanded_path )
|
85
|
+
@class_loader.addPath( path )
|
86
|
+
loadable_paths << expanded_path
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
loadable_paths
|
91
|
+
end
|
92
|
+
|
93
|
+
def load_paths(paths)
|
94
|
+
loadable_paths = []
|
95
|
+
unless paths.is_a? Array
|
96
|
+
paths = [paths]
|
97
|
+
end
|
98
|
+
|
99
|
+
paths.each do |path|
|
100
|
+
expanded_path = File.expand_path(path)
|
101
|
+
if !@loaded_paths.include?(expanded_path) && File.exists?( expanded_path )
|
102
|
+
@loaded_paths << expanded_path
|
103
|
+
Rjb::add_jar( expanded_path )
|
104
|
+
loadable_paths << expanded_path
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
loadable_paths
|
109
|
+
end
|
110
|
+
|
111
|
+
def convert_to_java_list( ruby_array )
|
112
|
+
list = Rjb::import("java.util.ArrayList").new
|
113
|
+
ruby_array.each do |item|
|
114
|
+
list.add( item )
|
115
|
+
end
|
116
|
+
|
117
|
+
list
|
118
|
+
end
|
119
|
+
|
120
|
+
def convert_to_ruby_array( java_array, to_string = false )
|
121
|
+
ruby_array = java_array.toArray()
|
122
|
+
|
123
|
+
if to_string
|
124
|
+
ruby_array = ruby_array.map { |x| x.toString()}
|
125
|
+
end
|
126
|
+
|
127
|
+
ruby_array
|
128
|
+
end
|
129
|
+
|
130
|
+
def convert_to_ruby_hash( java_hash, to_string = false )
|
131
|
+
|
132
|
+
hash = {}
|
133
|
+
keys = java_hash.keySet()
|
134
|
+
iterator = keys.iterator()
|
135
|
+
if to_string
|
136
|
+
while iterator.hasNext()
|
137
|
+
key = iterator.next().toString()
|
138
|
+
hash[key] = java_hash.get( key ).toString()
|
139
|
+
end
|
140
|
+
else
|
141
|
+
while iterator.hasNext()
|
142
|
+
key = iterator.next()
|
143
|
+
hash[key] = java_hash.get( key )
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
hash
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
require "#{File.dirname(__FILE__)}/java"
|
17
|
+
|
18
|
+
class Naether
|
19
|
+
|
20
|
+
# Helper for interacting with a Maven POM
|
21
|
+
#
|
22
|
+
# @author Michael Guymon
|
23
|
+
#
|
24
|
+
class Maven
|
25
|
+
|
26
|
+
class << self
|
27
|
+
|
28
|
+
# Create an instance from a POM
|
29
|
+
#
|
30
|
+
# @param [String] pom_path
|
31
|
+
# @return [Naether::Maven]
|
32
|
+
def create_from_pom( pom_path )
|
33
|
+
maven = Maven.new( pom_path )
|
34
|
+
end
|
35
|
+
|
36
|
+
# Create an instance based on notation
|
37
|
+
#
|
38
|
+
# @param [String] notation
|
39
|
+
# @return [Naether::Maven]
|
40
|
+
# @see https://github.com/mguymon/naether/wiki/Notations
|
41
|
+
def create_from_notation( notation )
|
42
|
+
maven = Maven.new
|
43
|
+
maven.notation = notation
|
44
|
+
maven
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Create new instance
|
50
|
+
#
|
51
|
+
def initialize(pom_path = nil)
|
52
|
+
if pom_path
|
53
|
+
@project = Naether::Java.create("com.tobedevoured.naether.maven.Project", pom_path )
|
54
|
+
else
|
55
|
+
@project = Naether::Java.create("com.tobedevoured.naether.maven.Project" )
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
# Set the Notation for this Project
|
61
|
+
#
|
62
|
+
# @param [String] notation
|
63
|
+
# @see https://github.com/mguymon/naether/wiki/Notations
|
64
|
+
def notation=(notation)
|
65
|
+
@project.setProjectNotation( notation )
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get dependences for Project as notations
|
69
|
+
#
|
70
|
+
# @param [Array<String>] scopes valid options are compile,test,runtime
|
71
|
+
def dependencies( scopes = nil)
|
72
|
+
if scopes
|
73
|
+
unless scopes.is_a? Array
|
74
|
+
scopes = [scopes]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if Naether.platform == 'java'
|
79
|
+
if scopes.nil?
|
80
|
+
deps = @project.getDependenciesNotation()
|
81
|
+
else
|
82
|
+
deps = @project.getDependenciesNotation( scopes )
|
83
|
+
end
|
84
|
+
|
85
|
+
else
|
86
|
+
list = nil
|
87
|
+
if scopes
|
88
|
+
list = Naether::Java.convert_to_java_list( scopes )
|
89
|
+
|
90
|
+
deps = @project._invoke('getDependenciesNotation', 'Ljava.util.List;', list)
|
91
|
+
else
|
92
|
+
deps = @project.getDependenciesNotation()
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
Naether::Java.convert_to_ruby_array( deps, true )
|
98
|
+
end
|
99
|
+
|
100
|
+
# Set dependencies
|
101
|
+
#
|
102
|
+
# @param [Array] dependencies
|
103
|
+
def dependencies=(dependencies)
|
104
|
+
@project.setDependencies( dependencies )
|
105
|
+
end
|
106
|
+
|
107
|
+
# Set repositories
|
108
|
+
#
|
109
|
+
# @param [Array] repositories of urls
|
110
|
+
def repositories=( repositories )
|
111
|
+
@project.setRepositories( repositories )
|
112
|
+
end
|
113
|
+
|
114
|
+
# Get the version
|
115
|
+
#
|
116
|
+
# return [String] version
|
117
|
+
def version()
|
118
|
+
return @project.getVersion()
|
119
|
+
end
|
120
|
+
|
121
|
+
# Load dependencies and remote repo from a {Naether} instance
|
122
|
+
def load_naether( naether )
|
123
|
+
self.dependencies= naether.resolver.getDependencies()
|
124
|
+
self.repositories= naether.resolver.getRemoteRepositoryUrls()
|
125
|
+
end
|
126
|
+
|
127
|
+
# Create the XML for a Maven Pom
|
128
|
+
#
|
129
|
+
# @return [String] pom xml
|
130
|
+
def build_pom()
|
131
|
+
@project.toXml()
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
# Write Maven Pom
|
136
|
+
#
|
137
|
+
# @param [String] file_path
|
138
|
+
def write_pom( file_path )
|
139
|
+
@project.writePom( file_path )
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/naether-0.9.0.jar
ADDED
Binary file
|
data/naether.gemspec
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "naether"
|
8
|
+
s.version = "0.9.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Guymon"]
|
12
|
+
s.date = "2012-09-12"
|
13
|
+
s.description = "Java dependency resolver using Maven's Aether"
|
14
|
+
s.email = "michael@tobedevoured.com"
|
15
|
+
s.extensions = ["Rakefile"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
"LICENSE",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"doc/Naether.html",
|
26
|
+
"doc/Naether/Bootstrap.html",
|
27
|
+
"doc/Naether/Configurator.html",
|
28
|
+
"doc/Naether/Java.html",
|
29
|
+
"doc/Naether/Java/JRuby.html",
|
30
|
+
"doc/Naether/Java/Ruby.html",
|
31
|
+
"doc/Naether/Maven.html",
|
32
|
+
"doc/_index.html",
|
33
|
+
"doc/class_list.html",
|
34
|
+
"doc/css/common.css",
|
35
|
+
"doc/css/full_list.css",
|
36
|
+
"doc/css/style.css",
|
37
|
+
"doc/file.README.html",
|
38
|
+
"doc/file_list.html",
|
39
|
+
"doc/frames.html",
|
40
|
+
"doc/index.html",
|
41
|
+
"doc/js/app.js",
|
42
|
+
"doc/js/full_list.js",
|
43
|
+
"doc/js/jquery.js",
|
44
|
+
"doc/method_list.html",
|
45
|
+
"doc/top-level-namespace.html",
|
46
|
+
"jar_dependencies.yml",
|
47
|
+
"lib/naether.rb",
|
48
|
+
"lib/naether/bootstrap.rb",
|
49
|
+
"lib/naether/configuration.rb",
|
50
|
+
"lib/naether/java.rb",
|
51
|
+
"lib/naether/java/jruby.rb",
|
52
|
+
"lib/naether/java/ruby.rb",
|
53
|
+
"lib/naether/maven.rb",
|
54
|
+
"naether-0.9.0.jar",
|
55
|
+
"naether.gemspec",
|
56
|
+
"pom.xml"
|
57
|
+
]
|
58
|
+
s.homepage = "http://github.com/mguymon/naether"
|
59
|
+
s.licenses = ["Apache"]
|
60
|
+
s.require_paths = ["lib"]
|
61
|
+
s.rubyforge_project = "naether"
|
62
|
+
s.rubygems_version = "1.8.24"
|
63
|
+
s.summary = "Java dependency resolver using Maven's Aether"
|
64
|
+
|
65
|
+
if s.respond_to? :specification_version then
|
66
|
+
s.specification_version = 3
|
67
|
+
|
68
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
69
|
+
s.add_runtime_dependency(%q<rjb>, ["> 1.3.2"])
|
70
|
+
s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
|
71
|
+
s.add_development_dependency(%q<rspec>, ["> 2.9.0"])
|
72
|
+
s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
|
73
|
+
s.add_development_dependency(%q<jeweler>, ["> 1.5.2"])
|
74
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
75
|
+
s.add_development_dependency(%q<kramdown>, [">= 0"])
|
76
|
+
else
|
77
|
+
s.add_dependency(%q<rjb>, ["> 1.3.2"])
|
78
|
+
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
79
|
+
s.add_dependency(%q<rspec>, ["> 2.9.0"])
|
80
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
81
|
+
s.add_dependency(%q<jeweler>, ["> 1.5.2"])
|
82
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
83
|
+
s.add_dependency(%q<kramdown>, [">= 0"])
|
84
|
+
end
|
85
|
+
else
|
86
|
+
s.add_dependency(%q<rjb>, ["> 1.3.2"])
|
87
|
+
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
88
|
+
s.add_dependency(%q<rspec>, ["> 2.9.0"])
|
89
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
90
|
+
s.add_dependency(%q<jeweler>, ["> 1.5.2"])
|
91
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
92
|
+
s.add_dependency(%q<kramdown>, [">= 0"])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|