Class: Jars::LockDown
- Inherits:
-
Object
- Object
- Jars::LockDown
- Defined in:
- lib/jars/lock_down.rb
Instance Method Summary collapse
- #attach_jar_coordinates_from_bundler_dependencies(artifacts, done) ⇒ Object
- #basedir ⇒ Object
-
#lock_down(vendor_dir = nil, force: false, update: false, tree: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
Instance Method Details
#attach_jar_coordinates_from_bundler_dependencies(artifacts, done) ⇒ Object
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 |
# File 'lib/jars/lock_down.rb', line 36 def attach_jar_coordinates_from_bundler_dependencies(artifacts, done) load_path = $LOAD_PATH.dup require 'bundler' # TODO: make this group a commandline option Bundler.setup('default') cwd = File.('.') Gem.loaded_specs.each_value do |spec| all = cwd == spec.full_gem_path # if gemspec is local then include all dependencies ga = GemspecArtifacts.new(spec) ga.artifacts.each do |a| next if done.include?(a.key) next unless all || (a.scope != 'provided' && a.scope != 'test') artifacts << a done << a.key end end rescue LoadError => e Jars.warn "bundler unavailable (#{e.}); skipping dependency discovery" if Jars.verbose? rescue Bundler::GemfileNotFound # bundler is available, but there is no Gemfile to inspect rescue Bundler::GemNotFound Jars.warn "cannot set up bundler with #{Bundler.default_lockfile}" raise ensure $LOAD_PATH.replace(load_path) end |
#basedir ⇒ Object
9 10 11 |
# File 'lib/jars/lock_down.rb', line 9 def basedir File.('.') end |
#lock_down(vendor_dir = nil, force: false, update: false, tree: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/jars/lock_down.rb', line 64 def lock_down(vendor_dir = nil, force: false, update: false, tree: nil) # rubocop:disable Lint/UnusedMethodArgument lock_file = File.(Jars.lock) if !force && File.exist?(lock_file) puts 'Jars.lock already exists, use --force to overwrite' return end artifacts = collect_artifacts if artifacts.empty? puts 'no jar dependencies found' return end puts puts '-- jar root dependencies --' puts artifacts.each do |a| puts " #{a.to_gacv}:#{a.scope || 'compile'}" puts " exclusions: #{a.exclusions}" if a.exclusions && !a.exclusions.empty? end context = Jars::Mima.create_context begin resolved = Jars::Mima.resolve_with_context(context, artifacts, all_dependencies: true) ensure context.close end # Write Jars.lock File.open(lock_file, 'w') do |f| resolved.each do |dep| next unless dep.type == 'jar' f.puts dep.to_lock_entry end end # Optionally vendor jars if vendor_dir require 'fileutils' vendor_path = File.(vendor_dir) resolved.each do |dep| next unless dep.type == 'jar' && dep.runtime? && !dep.system? target = File.join(vendor_path, dep.jar_path) FileUtils.mkdir_p(File.dirname(target)) FileUtils.cp(dep.file, target) end end if tree puts puts '-- jar dependency tree --' puts resolved.each do |dep| prefix = dep.classifier ? "#{dep.classifier}:" : '' puts " #{dep.group_id}:#{dep.artifact_id}:#{prefix}#{dep.version}:#{dep.scope}" end puts end puts puts File.read(lock_file) puts end |