Class: Maven::Tools::DSL::JarfileLock

Inherits:
Object
  • Object
show all
Defined in:
lib/maven/tools/dsl/jarfile_lock.rb

Instance Method Summary collapse

Constructor Details

#initialize(jarfile) ⇒ JarfileLock

Returns a new instance of JarfileLock.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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

Instance Method Details

#coordinates(scope = :runtime) ⇒ Object



52
53
54
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 52

def coordinates( scope = :runtime )
  data[ scope ] || []
end

#dumpObject



44
45
46
47
48
49
50
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 44

def dump
  if @data and not @data.empty?
    File.write( @file, @data.to_yaml )
  else
    FileUtils.rm_f( @file )
  end
end

#exists?(coordinate) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 86

def exists?( coordinate )
  all.member?( coordinate )
end

#locked?(coordinate) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
94
95
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 90

def locked?( coordinate )
  coord = coordinate.sub(/^([^:]+:[^:]+):.+/) { $1 }
  all.detect do |l|
    l.sub(/^([^:]+:[^:]+):.+/) { $1 } == coord 
  end != nil
end

#replace(deps) ⇒ Object



56
57
58
59
60
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 56

def replace( deps )
  data.clear
  @all = nil
  update_unlocked( deps )
end

#update_unlocked(deps) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 62

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