Skip to content

Commit

Permalink
use jar-dependencies for creating the vendored directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mkristian committed Apr 10, 2014
1 parent 5b911a4 commit 346ccb5
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 198 deletions.
51 changes: 20 additions & 31 deletions bin/jbundle
Expand Up @@ -11,7 +11,9 @@ if ARGV[0] == 'help'

else

ARGV << 'install' if ARGV.size == 0
if ARGV == [] || ARGV.all?{ |a| a.match( /^-/ ) }
ARGV.unshift 'install'
end

if ARGV[0] == 'console'
require 'irb'
Expand All @@ -22,37 +24,24 @@ else
require 'jbundler/config'
config = JBundler::Config.new

if ['install', 'update', 'show', 'console'].member?( ARGV[0] )
if ['lock_down', 'install', 'update', 'show', 'console'].member?( ARGV[0] )
begin
file = File.join( ENV['HOME'], '.bundle', 'config' )
if File.exists?( file )
require 'yaml'
bundle_config = YAML.load_file( file )
mirrors = bundle_config.select { |k,v| nil != (k =~ /BUNDLE_MIRROR__/) }
if config.rubygems_mirror || mirrors.size > 0
mirrors.each do |k,v|
ENV[ k ] = v
end
if config.rubygems_mirror
ENV['BUNDLE_MIRROR__HTTP://RUBYGEMS.ORG'] = config.rubygems_mirror
ENV['BUNDLE_MIRROR__HTTPS://RUBYGEMS.ORG'] = config.rubygems_mirror
end

begin
load Gem.bin_path('nexus', 'nbundle')
rescue Gem::GemNotFoundException
warn ''
warn 'to use a rubygems mirror you need to install the nexus gem'
warn ' $ gem install nexus'
warn ''
warn 'rubygems mirror ignored !'
end
else
load Gem.bin_path('bundler', 'bundle')
end
else
load Gem.bin_path('bundler', 'bundle')
end
is_lock_down = ARGV.delete( 'lock_down' )
ARGV.delete( 0 ) if is_lock_down
is_vendor = ARGV.delete( '--vendor' )
is_debug = ARGV.delete( '--debug' )
is_verbose = ARGV.delete( '--verbose' )
ARGV.delete( '--skip-vendor' )
ARGV.delete( '--skip-debug' )
ARGV.delete( '--skip-verbose' )

load Gem.bin_path('bundler', 'bundle')

ARGV.insert( 0, 'lock_down' ) if is_lock_down
ARGV.insert( 1, '--debug' ) if is_debug
ARGV.insert( 1, '--vendor' ) if is_vendor
ARGV.insert( 1, '--verbose' ) if is_verbose

require 'jbundler/cli'
JBundler::Cli.start
rescue Exception => e
Expand Down
8 changes: 4 additions & 4 deletions integration/tree/ref.txt
@@ -1,9 +1,9 @@
dummy:tree:jar:0.0.0
+- rubygems:rspec:gem:2.14.1:compile
| +- rubygems:rspec-core:gem:2.14.8:compile (version selected from constraint [2.14.0,2.14.99999])
| +- rubygems:rspec-expectations:gem:2.14.5:compile (version selected from constraint [2.14.0,2.14.99999])
| | \- rubygems:diff-lcs:gem:1.2.5:compile (version selected from constraint [1.1.3,2.0))
| \- rubygems:rspec-mocks:gem:2.14.6:compile (version selected from constraint [2.14.0,2.14.99999])
| +- rubygems:rspec-core:gem:2.14.8:compile
| +- rubygems:rspec-expectations:gem:2.14.5:compile
| | \- rubygems:diff-lcs:gem:1.2.5:compile
| \- rubygems:rspec-mocks:gem:2.14.6:compile
+- org.jruby:jruby-noasm:jar:1.7.6:provided
| +- org.jruby:jruby-core:jar:noasm:1.7.6:provided
| | +- org.jruby.joni:joni:jar:2.0.0:provided
Expand Down
Binary file modified lib/jbundler.jar
Binary file not shown.
8 changes: 6 additions & 2 deletions lib/jbundler/classpath_file.rb
Expand Up @@ -26,15 +26,19 @@ def initialize(classpathfile = '.jbundler/classpath.rb')
@classpathfile = classpathfile
end

def load_classpath
load File.expand_path @classpathfile
end

def require_classpath( local_repo = nil )
ENV[ '_LOCAL_REPO_' ] ||= local_repo
load File.expand_path @classpathfile
load_classpath
JBUNDLER_CLASSPATH.each { |c| require c }
end

def require_test_classpath( local_repo = nil )
ENV[ '_LOCAL_REPO_' ] ||= local_repo
load File.expand_path @classpathfile unless defined? JBUNLDER_TEST_CLASSPATH
load_classpath
JBUNDLER_TEST_CLASSPATH.each { |c| require c }
end

Expand Down
89 changes: 52 additions & 37 deletions lib/jbundler/cli.rb
Expand Up @@ -23,33 +23,26 @@
require 'jbundler/executable'
require 'jbundler/tree'
require 'jbundler/lock_down'
require 'jbundler/jruby_complete'
module JBundler
class Cli < Thor
no_tasks do
def config
@config ||= JBundler::Config.new
end
end

def do_show
require 'java'
require 'jbundler/classpath_file'
require 'jbundler/vendor'
classpath_file = JBundler::ClasspathFile.new( config.classpath_file )
vendor = JBundler::Vendor.new( config.vendor_dir )
if vendor.vendored?
puts "JBundler classpath:"
vendor.require_jars.each do |path|
puts " * #{path}"
end
elsif classpath_file.exists?
classpath_file.require_classpath unless defined? JBUNDLER_CLASSPATH
puts "JBundler classpath:"
JBUNDLER_CLASSPATH.each do |path|
puts " * #{path}"
end
else
puts "JBundler classpath is not installed."
end
desc 'jruby_complete', 'pack a jruby-complete jar with custom dependencies and maybe adjust jruby dependencies like newer versions of joda-time or snakeyaml', :hide => true
method_option :clean, :type => :boolean, :default => false
method_option :verbose, :type => :boolean, :default => false
method_option :debug, :type => :boolean, :default => false
method_option :show, :type => :boolean, :default => false, :desc => 'show versions of all libraries from jruby'
def jruby_complete
jc = JBundler::JRubyComplete.new( config, options )
if options[ :show ]
jc.show_versions
else
jc.packit
end
end

Expand All @@ -59,12 +52,30 @@ def tree
JBundler::Tree.new( config ).show_it
end

desc 'lock_down', 'using a different library to create the Jarfile.lock - experimental'
method_option :vendor, :type => :boolean, :default => false, :desc => 'vendor jars in given vendor directory.'
method_option :debug, :type => :boolean, :default => false, :desc => 'enable maven output'
def lock_down
desc 'install', "first `bundle install` is called and then the jar dependencies will be installed. for more details see `bundle help install`, jbundler will ignore most options. the install command is also the default when no command is given."
method_option :vendor, :type => :boolean, :default => false, :desc => 'vendor jars into vendor directory (jbundler only).'
method_option :debug, :type => :boolean, :default => false, :desc => 'enable maven debug output (jbundler only).'
method_option :verbose, :type => :boolean, :default => false, :desc => 'enable maven output (jbundler only).'
method_option :deployment, :type => :boolean, :default => false, :desc => "copy the jars into the vendor/jars directory (or as configured). these vendored jars have preference before the classpath jars !"
method_option :no_deployment, :type => :boolean, :default => false, :desc => 'clears the vendored jars'
method_option :path, :type => :string
method_option :without, :type => :array
method_option :system, :type => :boolean
method_option :local, :type => :boolean
method_option :binstubs, :type => :string
method_option :trust_policy, :type => :string
method_option :gemfile, :type => :string
method_option :jobs, :type => :string
method_option :retry, :type => :string
method_option :no_cache, :type => :boolean
method_option :quiet, :type => :boolean
def install
JBundler::LockDown.new( config ).lock_down( options[ :vendor ],
options[ :debug ] )
options[ :debug ] ,
options[ :verbose ] )
config.verbose = ! options[ :quiet ]
Show.new( config ).show_classpath
puts 'jbundle complete' unless options[ :quiet ]
end

desc 'executable', 'create an executable jar with a given bootstrap.rb file\nLIMITATION: only for jruby 1.6.x and newer'
Expand All @@ -82,7 +93,7 @@ def console
# dummy - never executed !!!
end

desc 'install', "first `bundle install` is called and then the jar dependencies will be installed. for more details see `bundle help install`, jbundler will ignore all options. the install command is also the default when no command is given."
desc 'lock_down', "first `bundle install` is called and then the jar dependencies will be installed. for more details see `bundle help install`, jbundler will ignore all options. the install command is also the default when no command is given. that is kept as fall back in cases where the new install does not work as before."
method_option :deployment, :type => :boolean, :default => false, :desc => "copy the jars into the vendor/jars directory (or as configured). these vendored jars have preference before the classpath jars !"
method_option :no_deployment, :type => :boolean, :default => false, :desc => 'clears the vendored jars'
method_option :path, :type => :string
Expand All @@ -96,7 +107,7 @@ def console
method_option :retry, :type => :string
method_option :no_cache, :type => :boolean
method_option :quiet, :type => :boolean
def install
def lock_down
require 'jbundler'
if options[ :no_deployment ]
vendor = JBundler::Vendor.new( config.vendor_dir )
Expand All @@ -110,29 +121,33 @@ def install
vendor.setup( JBundler::ClasspathFile.new( config.classpath_file ) )
end
end
do_show
puts 'Your jbundle is complete! Use `jbundle show` to see where the bundled jars are installed.'
config.verbose = ! options[ :quiet ]
Show.new( config ).show_classpath
unless options[ :quiet ]
puts ''
puts 'Your jbundle is complete! Use `jbundle show` to see where the bundled jars are installed.'
end
end

desc 'update', "first `bundle update` is called and if there are no options then the jar dependencies will be updated. for more details see `bundle help update`."
method_option :debug, :type => :boolean, :default => false, :desc => 'enable maven debug output (jbundler only).'
method_option :verbose, :type => :boolean, :default => false, :desc => 'enable maven output (jbundler only).'
def update
if ARGV.size == 1
require 'java'
config = JBundler::Config.new
FileUtils.rm_f(config.jarfile_lock)

require 'jbundler'
do_show
JBundler::LockDown.new( config ).update( options[ :debug ] ,
options[ :verbose ] )

config.verbose = ! options[ :quiet ]
Show.new( config ).show_classpath
puts ''
puts 'Your jbundle is updated! Use `jbundle show` to see where the bundled jars are installed.'
end
end

desc 'show', "first `bundle show` is called and if there are no options then the jar dependencies will be displayed. for more details see `bundle help show`."
def show
if ARGV.size == 1
do_show
end
Show.new( config ).show_classpath
end
end
end
8 changes: 0 additions & 8 deletions lib/jbundler/config.rb
Expand Up @@ -158,14 +158,6 @@ def mirror
@mirror
end

def rubygems_mirror
@rubygems_mirror ||= jbundler_env('BUNDLE_RUBYGEMS_MIRROR')
# here a leading slash is needed !!
@rubygems_mirror = @rubygems_mirror.sub( /([^\/])$/ , "\\1/" ) if @rubygems_mirror
warn 'rubygems mirror config is deprecated, use bundler >=1.5 and its mirror config'
@rubygems_mirror
end

def work_dir
@work_dir ||= absolute( jbundler_env('JBUNDLE_WORK_DIR') || 'pkg' )
end
Expand Down
1 change: 1 addition & 0 deletions lib/jbundler/configurator.rb
Expand Up @@ -9,6 +9,7 @@ def initialize( config )
end

def configure( maven )
maven.property( 'jbundler.basedir', @config.basedir )
maven.property( 'jbundler.jarfile', @config.jarfile )
maven.property( 'jbundler.gemfile', @config.gemfile )
maven.property( 'jbundler.workdir', work_dir )
Expand Down
20 changes: 12 additions & 8 deletions lib/jbundler/lock_down_pom.rb → lib/jbundler/dependency_pom.rb
@@ -1,23 +1,27 @@
bdir = java.lang.System.getProperty( "jbundler.basedir" )
jfile = java.lang.System.getProperty( "jbundler.jarfile" )
gfile = java.lang.System.getProperty( "jbundler.gemfile" )
jworkdir = java.lang.System.getProperty( "jbundler.workdir" )

basedir( File.dirname( jfile ) )
basedir( bdir )
if basedir != bdir
# older maven-tools needs this
self.instance_variable_set( :@basedir, bdir )
end

gemfile( gfile ) if File.exists? gfile

jarfile( jfile )
jarfile( jfile, :skip_locked => true )

build do
directory = jworkdir
default_goal 'dependency:list'
end

properties( 'project.build.sourceEncoding' => 'utf-8',
'tesla.dump.readOnly' => true,
'tesla.dump.pom' => 'tree.pom.xml' )

plugin( :dependency, '2.8',
:includeTypes => 'jar',
:outputAbsoluteArtifactFilename => true,
:outputFile => "#{jworkdir}/dependencies.txt" )

properties( 'project.build.sourceEncoding' => 'utf-8',
'tesla.dump.readOnly' => true,
'tesla.dump.pom' => 'lockdown.pom.xml' )
:outputFile => java.lang.System.getProperty( "jbundler.outputFile" ) )
19 changes: 6 additions & 13 deletions lib/jbundler/executable_pom.rb
Expand Up @@ -21,7 +21,6 @@
def jruby_home( path )
File.join( 'META-INF/jruby.home/lib/ruby/gems/shared', path )
end


jfile.locked.each do |dep|
artifact( dep )
Expand Down Expand Up @@ -54,19 +53,13 @@ def jruby_home( path )

jfile.populate_unlocked do |dsl|

# setup jruby version
jruby_version = dsl.jruby || JRUBY_VERSION
if ( jruby_version < '1.6' )
raise 'jruby before 1.6 are not supported'
elsif ( jruby_version < '1.7' )
warn 'jruby version below 1.7 uses jruby-complete'
jar 'org.jruby:jruby-complete', jruby_version
elsif ( jruby_version < '1.7.5' )
jar 'org.jruby:jruby-core', jruby_version
else
jar 'org.jruby:jruby', jruby_version
setup_jruby( dsl.jruby || JRUBY_VERSION, :compile )
dsl.artifacts.select do |a|
a[ :scope ] == :provided
end.each do |a|
a[ :scope ] = :compile
artifact( a )
end

local = dsl.artifacts.select do |a|
a[ :system_path ]
end
Expand Down
44 changes: 44 additions & 0 deletions lib/jbundler/jruby_complete.rb
@@ -0,0 +1,44 @@
require 'jbundler/pom_runner'
require 'fileutils'
module JBundler
class JRubyComplete < PomRunner

def initialize( config, options )
super options
work_dir = File.expand_path( config.work_dir )
maven.property( 'jbundler.workdir', work_dir )
maven.property( 'jbundler.basedir', config.basedir )
maven.property( 'jbundler.jarfile', config.jarfile )
maven.property( 'jbundler.gemfile', config.gemfile )
@tree = File.join( work_dir, 'tree.txt' )
maven.property( 'jbundler.outputFile', @tree )
end

def pom_file
File.join( File.dirname( __FILE__ ), 'jruby_complete_pom.rb' )
end

def show_versions
puts '...'

FileUtils.rm_f( @tree )

exec( 'dependency:tree' )

if File.exists?( @tree )
puts File.read( @tree )
end
end

def packit
puts '...'
exec( :package )

puts
puts 'now you can use jruby like this'
puts
puts "\tjava -jar jruby_complete_custom.jar"
puts
end
end
end

0 comments on commit 346ccb5

Please sign in to comment.