Class: JBundler::LockDown
- Inherits:
-
Object
- Object
- JBundler::LockDown
- Defined in:
- lib/jbundler/lock_down.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ LockDown
constructor
A new instance of LockDown.
- #lock_down(needs_vendor = false, debug = false) ⇒ Object
Constructor Details
#initialize(config) ⇒ LockDown
Returns a new instance of LockDown.
12 13 14 15 |
# File 'lib/jbundler/lock_down.rb', line 12 def initialize( config ) @config = config @configurator = Configurator.new( config ) end |
Instance Method Details
#lock_down(needs_vendor = false, debug = false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jbundler/lock_down.rb', line 17 def lock_down( needs_vendor = false, debug = false ) jarfile = Maven::Tools::Jarfile.new( @config.jarfile ) vendor = JBundler::Vendor.new( @config.vendor_dir ) classpath_file = JBundler::ClasspathFile.new( @config.classpath_file ) gemfile_lock = JBundler::GemfileLock.new( jarfile, @config.gemfile_lock ) needs_update = classpath_file.needs_update?( jarfile, gemfile_lock ) if( ( ! needs_update || vendor.vendored? ) && ! vendor ) puts 'up to date' else puts '...' exec_maven( debug ) deps_file = File.join( File.( @config.work_dir ), 'dependencies.txt' ) deps = StringIO.new jars = {} vendor_map = {} File.read( deps_file ).each_line do |line| if line.match /:jar:/ jar = line.sub( /.+:/, '' ).sub( /\s$/, '' ) unless line.match /:provided/ vendor_map[ line.sub( /:[^:]+:[^:]+$/, '' ) .sub( /^\s+/, '' ) ] = jar end case line when /:provided:/ ( jars[ :jruby ] ||= [] ) << jar when /:test:/ ( jars[ :test ] ||= [] ) << jar else ( jars[ :runtime ] ||= [] ) << jar end end # TODO make lock depend on jruby version as well on # include test as well, i.e. keep the scope in place if( line.match( /:compile:|:runtime:/ ) && ! line.match( /^ruby.bundler:/ ) ) deps.puts line.sub( /:[^:]+:[^:]+$/, '' ).sub( /^\s+/, '' ) end end if needs_update if deps.string.empty? FileUtils.rm_f @config.jarfile_lock else File.open( @config.jarfile_lock, 'w' ) do |f| f.print deps.string end end classpath_file.generate( jars[ :runtime ], jars[ :test ], jars[ :jruby ] ) end if needs_vendor puts "vendor directory: #{@config.vendor_dir}" vendor_map.each do |key, file| vendor.copy_jar( key, file ) end puts end if @config.verbose Show.new( @config ).show_classpath puts end puts 'jbundle complete' end end |