naether 0.2.5-java → 0.2.6-java

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
data/lib/naether.rb ADDED
@@ -0,0 +1,94 @@
1
+ require "#{File.dirname(__FILE__)}/naether/bootstrap"
2
+ require "#{File.dirname(__FILE__)}/naether/java"
3
+
4
+ # :title:Naether
5
+ #
6
+ # Java dependency resolver using Maven's Aether.
7
+ #
8
+ # = Authors
9
+ # Michael Guymon
10
+ #
11
+ class Naether
12
+
13
+ # Naether jar path will default to packaged in the gem
14
+ JAR_LIB = "#{File.dirname(__FILE__)}/.."
15
+
16
+ class << self
17
+ # Helper to determine the platform
18
+ def platform
19
+ $platform || RUBY_PLATFORM[/java/] || 'ruby'
20
+ end
21
+
22
+ # Java dependencies needed to bootstrap Naether
23
+ def bootstrap_dependencies( dep_file=nil )
24
+ Naether::Bootstrap.dependencies( dep_file )
25
+ end
26
+
27
+ def create_from_paths( deps_jar_dir, naether_jar_dir = nil )
28
+ naether_jar_dir = naether_jar_dir || JAR_LIB
29
+ Naether::Java.load_jars_dir( [deps_jar_dir, naether_jar_dir] )
30
+
31
+ Naether.new
32
+ end
33
+
34
+ def create_from_jars( jars )
35
+ Naether::Java.load_jars( jars )
36
+
37
+ Naether.new
38
+ end
39
+ end
40
+
41
+ #
42
+ # Create new instance
43
+ #
44
+ def initialize()
45
+
46
+ if Naether.platform == 'java'
47
+ @resolver = com.slackworks.Naether.new
48
+ else
49
+ naetherClass = Rjb::import('com.slackworks.Naether')
50
+ @resolver = naetherClass.new
51
+ end
52
+ end
53
+
54
+ def clear_remote_repositories
55
+ @resolver.clearRemoteRepositories()
56
+ end
57
+
58
+ # Add remote repository
59
+ def add_remote_repository( url )
60
+ @resolver.addRemoteRepository( url )
61
+ end
62
+
63
+ def remote_repositories
64
+ @resolver.getRemoteRepositories()
65
+ end
66
+
67
+ # Add a dependency in the notation: groupId:artifactId:type:version
68
+ def add_dependency( notation )
69
+ @resolver.addDependency( notation )
70
+ end
71
+
72
+ # Set array of dependencies in the notation: groupId:artifactId:type:version
73
+ def dependencies=(dependencies)
74
+ dependencies.each do |dependent|
75
+ add_dependency( dependent )
76
+ end
77
+ end
78
+
79
+ # Get dependencies
80
+ def dependencies
81
+ if Naether.platform == 'java'
82
+ return @resolver.getDependenciesNotation().to_a
83
+ else
84
+ bootstrap = Rjb::import('com.slackworks.Bootstrap')
85
+ return @resolver.getDependenciesNotation().toArray().map{ |dep| dep.toString() }
86
+ end
87
+ end
88
+
89
+ # Resolve dependencies, finding related additional dependencies
90
+ def resolve_dependencies
91
+ @resolver.resolveDependencies();
92
+ dependencies
93
+ end
94
+ end
@@ -0,0 +1,55 @@
1
+ require "#{File.dirname(__FILE__)}/java"
2
+ require 'yaml'
3
+
4
+ class Naether
5
+ # :title:Naether::Bootstrap
6
+ #
7
+ # Helper for bootstrapping Naether
8
+ #
9
+ # = Authors
10
+ # Michael Guymon
11
+ #
12
+ class Bootstrap
13
+
14
+ @@dependencies = nil
15
+
16
+ class << self
17
+
18
+ # Find naether jar relative to the gem install
19
+ def naether_jar
20
+ Dir.glob(File.expand_path("#{File.dirname(__FILE__)}/../../naether*.jar")).first
21
+ end
22
+
23
+ # write bootstrap dependencies to yaml file
24
+ def write_dependencies( jar_path = nil, dest = 'jar_dependencies.yml' )
25
+ Naether::Java.load_jars_dir( jar_path || Naether::JAR_LIB )
26
+ deps = {};
27
+ if Naether.platform == 'java'
28
+ deps[:dependencies] = com.slackworks.Bootstrap.dependencies.to_a
29
+ else
30
+ bootstrap = Rjb::import('com.slackworks.Bootstrap')
31
+ deps[:dependencies] = bootstrap.dependencies.toArray().map{ |dep| dep.toString() }
32
+ end
33
+
34
+ File.open( dest, 'w' ) do |out|
35
+ YAML.dump( deps, out )
36
+ end
37
+ end
38
+
39
+ # List of Java dependencies for Naether
40
+ def dependencies( dep_file=nil )
41
+
42
+ if @@dependencies
43
+ return @@dependencies
44
+ end
45
+
46
+ if dep_file.nil?
47
+ dep_file = "#{File.dirname( __FILE__ )}/../../jar_dependencies.yml"
48
+ end
49
+
50
+ dep = YAML.load_file( dep_file )
51
+ @@dependencies = dep[:dependencies]
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,124 @@
1
+ require 'singleton'
2
+
3
+ # :title:Naether::Java
4
+ #
5
+ # Handles loading jars. Determines correct platform to use, Naether::Java::JRuby
6
+ # or Naether::Java::Ruby
7
+ #
8
+ # = Authors
9
+ # Michael Guymon
10
+ #
11
+ class Naether
12
+ class Java
13
+
14
+ # Jars loaded
15
+ def self.loaded_jars
16
+ if Naether.platform == 'java'
17
+ Naether::Java::JRuby.instance.loaded_jars
18
+ else
19
+ Naether::Java::Ruby.instance.loaded_jars
20
+ end
21
+ end
22
+
23
+ #
24
+ #
25
+ #
26
+ def self.load_jars_dir(paths)
27
+ unless paths.is_a? Array
28
+ paths = [paths]
29
+ end
30
+
31
+ jars = []
32
+ paths.each do |path|
33
+ jars = jars + Dir.glob( "#{File.expand_path(path)}/*.jar")
34
+ end
35
+
36
+ Naether::Java.load_jars(jars)
37
+
38
+ end
39
+
40
+ #
41
+ # Load jars
42
+ #
43
+ def self.load_jars(jars)
44
+ if Naether.platform == 'java'
45
+ Naether::Java::JRuby.instance.load_jars(jars)
46
+ else
47
+ Naether::Java::Ruby.instance.load_jars(jars)
48
+ end
49
+ end
50
+
51
+ #
52
+ # Handle loading for JRuby
53
+ #
54
+ class JRuby
55
+ include Singleton
56
+
57
+ attr_reader :loaded_jars
58
+
59
+ def initialize
60
+ require 'java'
61
+
62
+ @loaded_jars = []
63
+ end
64
+
65
+ def load_jars(jars)
66
+ loaded_jars = []
67
+ unless jars.is_a? Array
68
+ jars = [jars]
69
+ end
70
+
71
+ jars.each do |jar|
72
+ expanded_jar = File.expand_path(jar)
73
+ if !@loaded_jars.include? expanded_jar
74
+ require expanded_jar
75
+ loaded_jars << expanded_jar
76
+ @loaded_jars << expanded_jar
77
+ end
78
+ end
79
+
80
+ loaded_jars
81
+ end
82
+ end
83
+
84
+ #
85
+ # Handle loading jars for Ruby via Rjb
86
+ #
87
+ class Ruby
88
+ include Singleton
89
+
90
+ attr_reader :loaded_jars
91
+
92
+ def initialize()
93
+ require 'rjb'
94
+
95
+ # Call Rjb::load with an empty classpath, incase Rjb::load has already been called
96
+ java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split
97
+ Rjb::load("", java_opts)
98
+
99
+ @loaded_jars = []
100
+ end
101
+
102
+ def load_jars(jars)
103
+ loaded_jars = []
104
+ unless jars.is_a?( Array )
105
+ jars = [jars]
106
+ end
107
+
108
+ jars.each do |jar|
109
+ expanded_jar = File.expand_path(jar)
110
+ if !@loaded_jars.include? expanded_jar
111
+ loaded_jars << expanded_jar
112
+ @loaded_jars << expanded_jar
113
+ end
114
+ end
115
+
116
+ unless loaded_jars.empty?
117
+ Rjb::add_jar( loaded_jars )
118
+ end
119
+
120
+ loaded_jars
121
+ end
122
+ end
123
+ end
124
+ end
data/naether-0.2.1.jar ADDED
Binary file
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: naether
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.5
5
+ version: 0.2.6
6
6
  platform: java
7
7
  authors:
8
8
  - Michael Guymon
@@ -71,6 +71,10 @@ files:
71
71
  - README.rdoc
72
72
  - VERSION
73
73
  - jar_dependencies.yml
74
+ - lib/naether.rb
75
+ - lib/naether/bootstrap.rb
76
+ - lib/naether/java.rb
77
+ - naether-0.2.1.jar
74
78
  - pom.xml
75
79
  has_rdoc: true
76
80
  homepage: http://github.com/mguymon/naether