Class: JBundler::Mavenfile
- Inherits:
-
Object
- Object
- JBundler::Mavenfile
show all
- Includes:
- MavenUtil
- Defined in:
- lib/jbundler/mavenfile.rb
Instance Method Summary
collapse
Methods included from MavenUtil
#to_coordinate, #to_version
Constructor Details
#initialize(file = 'Mvnfile') ⇒ Mavenfile
Returns a new instance of Mavenfile.
7
8
9
10
|
# File 'lib/jbundler/mavenfile.rb', line 7
def initialize(file = 'Mvnfile')
@file = file
@lockfile = file + ".lock"
end
|
Instance Method Details
#exists? ⇒ Boolean
16
17
18
|
# File 'lib/jbundler/mavenfile.rb', line 16
def exists?
File.exists?(@file)
end
|
#exists_lock? ⇒ Boolean
24
25
26
|
# File 'lib/jbundler/mavenfile.rb', line 24
def exists_lock?
File.exists?(@lockfile)
end
|
#generate_lockfile(dependency_coordinates) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/jbundler/mavenfile.rb', line 68
def generate_lockfile(dependency_coordinates)
File.open(@lockfile, 'w') do |f|
dependency_coordinates.each do |d|
f.puts d.to_s
end
end
end
|
#load_lockfile ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/jbundler/mavenfile.rb', line 28
def load_lockfile
_locked = []
if exists_lock?
File.read(@lockfile).each_line do |line|
line.strip!
if line.size > 0 && !(line =~ /^\s*#/)
_locked << line
end
end
end
_locked
end
|
#locked ⇒ Object
41
42
43
|
# File 'lib/jbundler/mavenfile.rb', line 41
def locked
@locked ||= load_lockfile
end
|
#locked?(coordinate) ⇒ Boolean
45
46
47
48
|
# File 'lib/jbundler/mavenfile.rb', line 45
def locked?(coordinate)
coord = coordinate.sub(/^([^:]+:[^:]+):.+/) { $1 }
locked.detect { |l| l.sub(/^([^:]+:[^:]+):.+/) { $1 } == coord } != nil
end
|
#mtime ⇒ Object
12
13
14
|
# File 'lib/jbundler/mavenfile.rb', line 12
def mtime
File.mtime(@file)
end
|
#mtime_lock ⇒ Object
20
21
22
|
# File 'lib/jbundler/mavenfile.rb', line 20
def mtime_lock
File.mtime(@lockfile)
end
|
#populate_locked(aether) ⇒ Object
64
65
66
|
# File 'lib/jbundler/mavenfile.rb', line 64
def populate_locked(aether)
locked.each { |l| aether.add_artifact(l) }
end
|
#populate_unlocked(aether) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/jbundler/mavenfile.rb', line 50
def populate_unlocked(aether)
File.read(@file).each_line do |line|
if coord = to_coordinate(line)
unless locked?(coord)
aether.add_artifact(coord)
end
elsif line =~ /^\s*(repository|source)\s/
name, url = line.sub(/.*(repository|source)\s+/, '').gsub(/['":]/,'').split(/,/)
url = name unless url
aether.add_repository(name, url)
end
end
end
|