Class: JBundler::GemfileLock

Inherits:
Object
  • Object
show all
Defined in:
lib/jbundler/gemfile_lock.rb

Instance Method Summary collapse

Constructor Details

#initialize(jarfile, lockfile = 'Gemfile.lock') ⇒ GemfileLock

Returns a new instance of GemfileLock.



29
30
31
32
# File 'lib/jbundler/gemfile_lock.rb', line 29

def initialize(jarfile, lockfile = 'Gemfile.lock')
  @jarfile = jarfile
  @lockfile = lockfile if File.exists?(lockfile)
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/jbundler/gemfile_lock.rb', line 34

def exists?
  !@lockfile.nil?
end

#mtimeObject



38
39
40
# File 'lib/jbundler/gemfile_lock.rb', line 38

def mtime
  File.mtime(@lockfile) if @lockfile
end

#populate_dependencies(aether) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jbundler/gemfile_lock.rb', line 42

def populate_dependencies(aether)
  if @lockfile
    # assuming we run in Bundler context here 
    # since we have a Gemfile.lock :)
    Bundler.load.specs.each do |spec|
      jars = []
      spec.requirements.each do |rr|
        rr.split(/\n/).each do |r|
          jars << r if r =~ /^\s*(jar|pom)\s/
        end
      end
      unless jars.empty?
        pom = Pom.new(spec.name, spec.version, jars, "pom")
        aether.install(pom.coordinate, pom.file)
        unless @jarfile.locked?(pom.coordinate)
          aether.add_artifact(pom.coordinate)
        end
      end
    end
  end
end