Class: Maven::Tools::DSL::JarfileLock
- Inherits:
-
Object
- Object
- Maven::Tools::DSL::JarfileLock
- Defined in:
- lib/maven/tools/dsl/jarfile_lock.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #coordinates(scope = :runtime) ⇒ Object
- #dump ⇒ Object
- #exists?(coordinate) ⇒ Boolean
-
#initialize(jarfile) ⇒ JarfileLock
constructor
A new instance of JarfileLock.
- #locked?(coordinate) ⇒ Boolean
- #replace(deps) ⇒ Object
- #update_unlocked(deps) ⇒ Object
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.( 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 Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
43 44 45 |
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 43 def file @file end |
Instance Method Details
#coordinates(scope = :runtime) ⇒ Object
53 54 55 |
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 53 def coordinates( scope = :runtime ) data[ scope ] || [] end |
#dump ⇒ Object
45 46 47 48 49 50 51 |
# 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) ⇒ Boolean
87 88 89 |
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 87 def exists?( coordinate ) all.member?( coordinate ) end |
#locked?(coordinate) ⇒ Boolean
91 92 93 94 95 96 |
# 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) ⇒ Object
57 58 59 60 61 |
# File 'lib/maven/tools/dsl/jarfile_lock.rb', line 57 def replace( deps ) data.clear @all = nil update_unlocked( deps ) end |
#update_unlocked(deps) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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 |