rubyjams 0.1.0

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.
@@ -0,0 +1,75 @@
1
+ require 'rubygems/commands/install_command'
2
+ require 'jbundler/aether'
3
+ require 'maven/tools/coordinate'
4
+
5
+ class Gem::Commands::InstallCommand
6
+
7
+ include Maven::Tools::Coordinate
8
+
9
+ unless respond_to? :execute_without_jars
10
+ alias :execute_without_jars :execute
11
+ def execute
12
+ begin
13
+ execute_without_jars
14
+ rescue Gem::SystemExitException => e
15
+ if e.exit_code == 0
16
+ gems.each do |g|
17
+ gg = g.sub /-java/, ''
18
+ name = gg.sub( /-[^-]+$/, '' )
19
+ version = gg.sub( /^.*-/, '' )
20
+
21
+ # just load the gem
22
+ gem( name, version )
23
+
24
+ spec = Gem.loaded_specs.values.detect { |s| s.full_name == g }
25
+ spec.requirements.each do |req|
26
+ req.split(/\n/).each do |r|
27
+ coord = to_coordinate( r )
28
+ if coord
29
+ aether.add_artifact( "#{coord}" ) rescue nil
30
+ end
31
+ end
32
+ end
33
+ aether.resolve
34
+ aether.classpath_array.each do |path|
35
+ if require path
36
+ warn "using #{path}"# if jb_config.verbose
37
+ jb_classpath << path
38
+ end
39
+ end
40
+ end
41
+ else
42
+ raise e
43
+ end
44
+ end
45
+ end
46
+
47
+ def gems
48
+ @gems ||= []
49
+ end
50
+
51
+ alias :_s_a_y_ :say
52
+ def say( arg )
53
+ if arg =~ /^Successfully/
54
+ arg.sub /([^ ]+$)/ do
55
+ gems << $1
56
+ end
57
+ end
58
+ _s_a_y_( arg )
59
+ end
60
+
61
+ private
62
+
63
+ def jb_classpath
64
+ @jb_cp ||= defined?(JBUNDLER_CLASSPATH) ? JBUNDLER_CLASSPATH.dup : []
65
+ end
66
+
67
+ def jb_config
68
+ @_jb_c ||= JBundler::Config.new
69
+ end
70
+
71
+ def aether
72
+ @_aether ||= JBundler::AetherRuby.new(jb_config)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,2 @@
1
+ require "commands/install_with_jars"
2
+
@@ -0,0 +1,103 @@
1
+ require 'rubygems'
2
+ require 'jbundler/aether'
3
+ require 'maven/tools/coordinate'
4
+
5
+ class Rubyjams
6
+
7
+ include Maven::Tools::Coordinate
8
+
9
+ def loaded
10
+ @loaded ||= {}
11
+ end
12
+
13
+ def loaded_coordinates
14
+ @loaded_coordinates ||= {}
15
+ end
16
+
17
+ def add_coordinates( coords )
18
+ coords.each do |coord|
19
+ c = coord.sub( /:[^:]+$/, '')
20
+ v = coord.sub( /^.*:/, '')
21
+ if loaded_coordinates.keys.member?( c )
22
+
23
+ if loaded_coordinates[ c ] != v
24
+ raise "conflict:\n\t#{c} already loaded with version #{loaded_coordinates[ c ]}\n\tthe request to load version #{v} can not be processed."
25
+ end
26
+ else
27
+ loaded_coordinates[ c ] = v
28
+ end
29
+ end
30
+ end
31
+
32
+ def maybe_load_jars( specs )
33
+ load_jars( (specs.keys - loaded.keys).collect { |k| specs[ k ] } )
34
+ loaded.replace( specs )
35
+ end
36
+
37
+ def load_jars( specs )
38
+ specs.each do |spec|
39
+ spec.requirements.each do |req|
40
+ req.split(/\n/).each do |r|
41
+ coord = to_coordinate( r )
42
+ if coord
43
+ aether.add_artifact( "#{coord}" ) rescue nil
44
+ end
45
+ end
46
+ end
47
+ aether.resolve
48
+ add_coordinates( aether.resolved_coordinates )
49
+ aether.classpath_array.each do |path|
50
+ if require_without_jars path
51
+ warn "using #{path}" if jb_config.verbose
52
+ jb_classpath << path
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def jb_classpath
61
+ @jb_cp ||= defined?(JBUNDLER_CLASSPATH) ? JBUNDLER_CLASSPATH.dup : []
62
+ end
63
+
64
+ def jb_config
65
+ @_jb_c ||= JBundler::Config.new
66
+ end
67
+
68
+ def aether
69
+ @_aether ||= JBundler::AetherRuby.new(jb_config, true)
70
+ end
71
+ end
72
+ module Kernel
73
+
74
+ unless respond_to? :require_without_jars
75
+ def jars
76
+ @jars ||= Rubyjams.new
77
+ end
78
+
79
+ # alias :gem_without_jars :gem
80
+
81
+ # def gem( *args )
82
+ # puts args
83
+ # gem_without_jars( *args )
84
+ # end
85
+
86
+ alias :require_without_jars :require
87
+
88
+ def require( filename )
89
+ maybe_load_jars
90
+ require_without_jars( filename )
91
+ end
92
+
93
+ def maybe_load_jars
94
+ @@gems_size ||= 0
95
+ Gem.loaded_specs if @@gems_size == 0
96
+ if @@gems_size < Gem.loaded_specs.size
97
+ @@gems_size = Gem.loaded_specs.size
98
+ jars.maybe_load_jars( Gem.loaded_specs )
99
+ end
100
+ true
101
+ end
102
+ end
103
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyjams
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - mkristian
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-24 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description:
22
+ email:
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/commands/install_with_jars.rb
31
+ - lib/rubyjams.rb
32
+ - lib/rubygems_plugin.rb
33
+ homepage:
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.21
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: jar dependency support for rubygems
66
+ test_files: []
67
+