class Maven::Tools::DSL::JarfileLock

Attributes

file[R]

Public Class Methods

new( jarfile ) click to toggle source
# File lib/maven/tools/dsl/jarfile_lock.rb, line 28
def initialize( jarfile )
  @file = File.expand_path( jarfile + ".lock" ) if jarfile
  if @file && File.exists?( @file )
    lock = YAML.load( File.read( @file ) )
    case lock
    when Hash
      @data = lock
    when String
      # fallback on old format and treat them all as "runtime"
      data[ :runtime ] = lock.split( /\ / )
    else
      warn "unknown format of #{@file} - skip it"
    end
  end
end

Public Instance Methods

coordinates( scope = :runtime ) click to toggle source
# File lib/maven/tools/dsl/jarfile_lock.rb, line 53
def coordinates( scope = :runtime )
  data[ scope ] || []
end
dump() click to toggle source
# File lib/maven/tools/dsl/jarfile_lock.rb, line 45
def dump
  if @data and not @data.empty?
    File.write( @file, @data.to_yaml )
  else
    FileUtils.rm_f( @file )
  end
end
exists?( coordinate ) click to toggle source
# File lib/maven/tools/dsl/jarfile_lock.rb, line 87
def exists?( coordinate )
  all.member?( coordinate )
end
locked?( coordinate ) click to toggle source
# File lib/maven/tools/dsl/jarfile_lock.rb, line 91
def locked?( coordinate )
  coord = coordinate.sub(/^([^:]+:[^:]+):.+/) { $1 }
  all.detect do |l|
    l.sub(/^([^:]+:[^:]+):.+/) { $1 } == coord 
  end != nil
end
replace( deps ) click to toggle source
# File lib/maven/tools/dsl/jarfile_lock.rb, line 57
def replace( deps )
  data.clear
  @all = nil
  update_unlocked( deps )
end
update_unlocked( deps ) click to toggle source
# File lib/maven/tools/dsl/jarfile_lock.rb, line 63
def update_unlocked( deps )
  success = true
  deps.each do |k,v|
    bucket = ( data[ k ] ||= [] )
    v.each do |e|
      # TODO remove check and use only e.coord
      coord = e.respond_to?( :coord ) ? e.coord : e
      if exists?( coord )
        # do nothing
      elsif locked?( coord )
        # mark result as conflict
        success = false
      else
        # add it
        if not e.respond_to?( :coord ) && e.gav =~ /system$/
          bucket << coord
        end
      end
    end
  end
  @all = nil
  success
end

Private Instance Methods

all() click to toggle source
# File lib/maven/tools/dsl/jarfile_lock.rb, line 100
def all
  @all ||= coordinates( :runtime ) + coordinates( :test )
end
data() click to toggle source
# File lib/maven/tools/dsl/jarfile_lock.rb, line 104
def data
  @data ||= {}
end