Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

get it working

  • Loading branch information...
commit 339d259e3eedb8ddb48da850c4a9ba03ddcd2615 1 parent 6e9fc2a
@mkristian authored
View
4 Gemfile
@@ -1,4 +0,0 @@
-# A sample Gemfile
-source "https://rubygems.org"
-
-gemspec
View
34 Gemfile.lock
@@ -1,34 +0,0 @@
-PATH
- remote: .
- specs:
- jars (0.1.0)
- lock_jar (~> 0.6.0)
-
-GEM
- remote: https://rubygems.org/
- specs:
- diff-lcs (1.1.3)
- lock_jar (0.6.0)
- naether (~> 0.9.0)
- thor (> 0.14.0)
- naether (0.9.2-java)
- rspec (2.9.0)
- rspec-core (~> 2.9.0)
- rspec-expectations (~> 2.9.0)
- rspec-mocks (~> 2.9.0)
- rspec-core (2.9.0)
- rspec-expectations (2.9.1)
- diff-lcs (~> 1.1.3)
- rspec-mocks (2.9.0)
- solr_sail (0.0.7-java)
- lock_jar (~> 0.6.0)
- thor (> 0.14.0)
- thor (0.16.0)
-
-PLATFORMS
- java
-
-DEPENDENCIES
- jars!
- rspec (~> 2.9.0)
- solr_sail (~> 0.0.6)
View
3  README.md
@@ -1 +1,2 @@
-`gem build jars.gemspec; gem1.9.1 install jars-*.gem -l; ruby -rubygems -rjars -e 'require "zip"'`
+`gem build rubyjams.gemspec; jruby -S gem install rubyjams-*.gem -l; jruby -S gem install nokogiri-maven; jruby -rubygems -e 'require "rubyjams";gem "nokogiri-maven"; require "nokogiri"'`
+
View
48 lib/commands/install_with_jars.rb
@@ -1,8 +1,11 @@
require 'rubygems/commands/install_command'
-require 'lock_jar'
+require 'jbundler/aether'
+require 'maven/tools/coordinate'
class Gem::Commands::InstallCommand
+ include Maven::Tools::Coordinate
+
unless respond_to? :execute_without_jars
alias :execute_without_jars :execute
def execute
@@ -10,9 +13,34 @@ def execute
execute_without_jars
rescue Gem::SystemExitException => e
if e.exit_code == 0
- puts "DO SOMETHING HERE WITH JARS [#{gems.join(',')}]"
+ gems.each do |g|
+ gg = g.sub /-java/, ''
+ name = gg.sub( /-[^-]+$/, '' )
+ version = gg.sub( /^.*-/, '' )
+
+ # just load the gem
+ gem( name, version )
+
+ spec = Gem.loaded_specs.values.detect { |s| s.full_name == g }
+ spec.requirements.each do |req|
+ req.split(/\n/).each do |r|
+ coord = to_coordinate( r )
+ if coord
+ aether.add_artifact( "#{coord}" ) rescue nil
+ end
+ end
+ end
+ aether.resolve
+ aether.classpath_array.each do |path|
+ if require path
+ warn "using #{path}"# if jb_config.verbose
+ jb_classpath << path
+ end
+ end
+ end
+ else
+ raise e
end
- raise e
end
end
@@ -29,5 +57,19 @@ def say( arg )
end
_s_a_y_( arg )
end
+
+ private
+
+ def jb_classpath
+ @jb_cp ||= defined?(JBUNDLER_CLASSPATH) ? JBUNDLER_CLASSPATH.dup : []
+ end
+
+ def jb_config
+ @_jb_c ||= JBundler::Config.new
+ end
+
+ def aether
+ @_aether ||= JBundler::AetherRuby.new(jb_config)
+ end
end
end
View
49 lib/jars.rb
@@ -1,49 +0,0 @@
-require 'rubygems'
-require 'lock_jar'
-
-class Jars
-
- def loaded
- @loaded ||= {}
- end
-
- def maybe_load_jars( specs )
- load_jars( (specs.keys - loaded.keys).collect { |k| specs[ k ] } )
- loaded.replace( specs )
- end
-
- def load_jars( specs )
- puts "DO LOAD JARS FOR #{specs.collect { |k| k }.join(',')}"
- specs.each do |spec|
- gem_dir = spec.gem_dir rescue spec.full_gem_path # fallback for --1.8 mode
- lockfile = File.join( gem_dir, "Jarfile.lock" )
- if File.exists? lockfile
- puts "#{spec.name} has Jarfile.lock, loading jars"
- LockJar.load( lockfile )
- end
- end
- end
-
-end
-module Kernel
-
- unless respond_to? :require_without_jars
- def jars
- @jars||= Jars.new
- end
- alias :require_without_jars :require
- def require fn
-
- #puts fn.inspect
-
- if require_without_jars fn
- @@gems_size ||= 0
- Gem.loaded_specs if @@gems_size == 0
- if @@gems_size < Gem.loaded_specs.size
- @@gems_size = Gem.loaded_specs.size
- jars.maybe_load_jars( Gem.loaded_specs )
- end
- end
- end
- end
-end
View
103 lib/rubyjams.rb
@@ -0,0 +1,103 @@
+require 'rubygems'
+require 'jbundler/aether'
+require 'maven/tools/coordinate'
+
+class Rubyjams
+
+ include Maven::Tools::Coordinate
+
+ def loaded
+ @loaded ||= {}
+ end
+
+ def loaded_coordinates
+ @loaded_coordinates ||= {}
+ end
+
+ def add_coordinates( coords )
+ coords.each do |coord|
+ c = coord.sub( /:[^:]+$/, '')
+ v = coord.sub( /^.*:/, '')
+ if loaded_coordinates.keys.member?( c )
+
+ if loaded_coordinates[ c ] != v
+ raise "conflict:\n\t#{c} already loaded with version #{loaded_coordinates[ c ]}\n\tthe request to load version #{v} can not be processed."
+ end
+ else
+ loaded_coordinates[ c ] = v
+ end
+ end
+ end
+
+ def maybe_load_jars( specs )
+ load_jars( (specs.keys - loaded.keys).collect { |k| specs[ k ] } )
+ loaded.replace( specs )
+ end
+
+ def load_jars( specs )
+ specs.each do |spec|
+ spec.requirements.each do |req|
+ req.split(/\n/).each do |r|
+ coord = to_coordinate( r )
+ if coord
+ aether.add_artifact( "#{coord}" ) rescue nil
+ end
+ end
+ end
+ aether.resolve
+ add_coordinates( aether.resolved_coordinates )
+ aether.classpath_array.each do |path|
+ if require_without_jars path
+ warn "using #{path}" if jb_config.verbose
+ jb_classpath << path
+ end
+ end
+ end
+ end
+
+ private
+
+ def jb_classpath
+ @jb_cp ||= defined?(JBUNDLER_CLASSPATH) ? JBUNDLER_CLASSPATH.dup : []
+ end
+
+ def jb_config
+ @_jb_c ||= JBundler::Config.new
+ end
+
+ def aether
+ @_aether ||= JBundler::AetherRuby.new(jb_config, true)
+ end
+end
+module Kernel
+
+ unless respond_to? :require_without_jars
+ def jars
+ @jars ||= Rubyjams.new
+ end
+
+# alias :gem_without_jars :gem
+
+# def gem( *args )
+# puts args
+# gem_without_jars( *args )
+# end
+
+ alias :require_without_jars :require
+
+ def require( filename )
+ maybe_load_jars
+ require_without_jars( filename )
+ end
+
+ def maybe_load_jars
+ @@gems_size ||= 0
+ Gem.loaded_specs if @@gems_size == 0
+ if @@gems_size < Gem.loaded_specs.size
+ @@gems_size = Gem.loaded_specs.size
+ jars.maybe_load_jars( Gem.loaded_specs )
+ end
+ true
+ end
+ end
+end
View
6 jars.gemspec → rubyjams.gemspec
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = 'jars'
+ s.name = 'rubyjams'
s.version = "0.1.0"
s.summary = 'jar dependency support for rubygems'
@@ -14,8 +14,6 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
- s.add_dependency('lock_jar', '~> 0.6.0')
- s.add_development_dependency('solr_sail', '~>0.0.6')
- s.add_development_dependency('rspec', ["~> 2.9.0"])
+# s.add_dependency('jbundler', '~> 0.3')
end
View
44 spec/jars_spec.rb
@@ -1,44 +0,0 @@
-require 'rubygems'
-require 'spec_helper'
-require 'lib/jars'
-
-describe "Jars", "#require" do
-
- it "should start with an empty classpath" do
- # this should be nil!!
- $CLASSPATH.size.should == 0
- require 'solr_sail'
- end
-
- it "should set jars" do
- jars.is_a?( Jars ).should be_true
- end
-
- it "should set gems_size" do
- Kernel.class_eval( '@@gems_size' ).size.should eql 8
- end
-
- it "should have loaded jars" do
- jars.loaded.should eql( {} )
- end
-
- it "should set classpath" do
- # XXX: need to assert correct jars are in the classpath
- $CLASSPATH.size.should eql( 58 )
- end
-
- it "should have correctly loaded SolrSail" do
- defined?(SolrSail).should be_true
- SolrSail.class.should eql(Module)
-
- # start and stop solr to prove classpath is valid
- SolrSail.install_config( :solr_home => 'tmp/solr' )
- # manually load the jar packaged with the gem
- $CLASSPATH << SolrSail::DEFAULT_JAR
-
- # Start and stop solr
- @server = com.tobedevoured.solrsail.JettyServer.new( 'tmp/solr' )
- @server.start
- @server.stop
- end
-end
View
12 spec/spec_helper.rb
@@ -1,12 +0,0 @@
-# This file was generated by the `rspec --init` command. Conventionally, all
-# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
-# Require this file using `require "spec_helper.rb"` to ensure that it is only
-# loaded once.
-#
-# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
-RSpec.configure do |config|
- config.order = 'default'
- config.treat_symbols_as_metadata_keys_with_true_values = true
- config.run_all_when_everything_filtered = true
- config.filter_run :focus
-end
Please sign in to comment.
Something went wrong with that request. Please try again.