Class: Maven::Tools::Jarfile

Inherits:
Object
  • Object
show all
Includes:
Coordinate
Defined in:
lib/maven/tools/jarfile.rb

Instance Method Summary collapse

Methods included from Coordinate

#gav, #group_artifact, #to_coordinate, #to_version

Constructor Details

#initialize(file = 'Jarfile') ⇒ Jarfile

Returns a new instance of Jarfile.



28
29
30
31
# File 'lib/maven/tools/jarfile.rb', line 28

def initialize(file = 'Jarfile')
  @file = file
  @lockfile = file + ".lock"
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/maven/tools/jarfile.rb', line 37

def exists?
  File.exists?(@file)
end

#exists_lock?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/maven/tools/jarfile.rb', line 45

def exists_lock?
  File.exists?(@lockfile)
end

#generate_lockfile(dependency_coordinates) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/maven/tools/jarfile.rb', line 101

def generate_lockfile(dependency_coordinates)
  if dependency_coordinates.empty?
    FileUtils.rm_f(@lockfile) if exists_lock?
  else
    File.open(@lockfile, 'w') do |f|
      dependency_coordinates.each do |d|
        f.puts d.to_s unless d.to_s =~ /^ruby.bundler:/
      end
    end
  end
end

#load_lockfileObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/maven/tools/jarfile.rb', line 49

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

#lockedObject



62
63
64
# File 'lib/maven/tools/jarfile.rb', line 62

def locked
  @locked ||= load_lockfile
end

#locked?(coordinate) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/maven/tools/jarfile.rb', line 66

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

#mtimeObject



33
34
35
# File 'lib/maven/tools/jarfile.rb', line 33

def mtime
  File.mtime(@file)
end

#mtime_lockObject



41
42
43
# File 'lib/maven/tools/jarfile.rb', line 41

def mtime_lock
  File.mtime(@lockfile)
end

#populate_locked(container) ⇒ Object



97
98
99
# File 'lib/maven/tools/jarfile.rb', line 97

def populate_locked(container)
  locked.each { |l| container.add_artifact(l) }
end

#populate_unlocked(container) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/maven/tools/jarfile.rb', line 71

def populate_unlocked(container)
  if File.exists?(@file)
    File.read(@file).each_line do |line| 
      if coord = to_coordinate(line)
        unless locked?(coord)
          container.add_artifact(coord)
        end
      elsif line =~ /^\s*(repository|source)\s/
        # allow `source :name, "http://url"`
        # allow `source "name", "http://url"`
        # allow `source "http://url"`
        # also allow `repository` instead of `source`
        name, url = line.sub(/.*(repository|source)\s+/, '').split(/,/)
        url = name unless url
        # remove whitespace and trailing/leading ' or "
        name.strip!
        name.gsub!(/^:/, '')
        name.gsub!(/^['"]|['"]$/,'')
        url.strip!
        url.gsub!(/^['"]|['"]$/,'')
        container.add_repository(name, url)
      end
    end
  end
end