Class: Jars::Installer::Dependency

Inherits:
Object
  • Object
show all
Defined in:
lib/jars/installer.rb

Constant Summary collapse

EMPTY =
""
TRAILING_FILE =

the trailing ":" of a dependency line; the file may itself contain a ':' on Windows (C:...), hence the optional drive-letter prefix

/:(?<file>(?:[A-Z]:\\)?[^:]+)\z/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, scope, coord, gav, file, path, system) ⇒ Dependency

Returns a new instance of Dependency.



60
61
62
63
64
65
66
67
68
# File 'lib/jars/installer.rb', line 60

def initialize(type, scope, coord, gav, file, path, system)
  @type = type
  @scope = scope
  @coord = coord
  @gav = gav
  @file = file
  @path = path
  @system = system
end

Instance Attribute Details

#coordObject (readonly)

Returns the value of attribute coord.



58
59
60
# File 'lib/jars/installer.rb', line 58

def coord
  @coord
end

#fileObject (readonly)

Returns the value of attribute file.



58
59
60
# File 'lib/jars/installer.rb', line 58

def file
  @file
end

#gavObject (readonly)

Returns the value of attribute gav.



58
59
60
# File 'lib/jars/installer.rb', line 58

def gav
  @gav
end

#pathObject (readonly)

Returns the value of attribute path.



58
59
60
# File 'lib/jars/installer.rb', line 58

def path
  @path
end

#scopeObject (readonly)

Returns the value of attribute scope.



58
59
60
# File 'lib/jars/installer.rb', line 58

def scope
  @scope
end

#typeObject (readonly)

Returns the value of attribute type.



58
59
60
# File 'lib/jars/installer.rb', line 58

def type
  @type
end

Class Method Details

.parse(line) ⇒ Object

A dependency:list line has the form groupId:artifactId:type:version:scope:/path/to/file



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jars/installer.rb', line 16

def self.parse(line)
  return unless /:jar:|:pom:/.match?(line)

  line = line.dup
  # remove ANSI escape sequences and module section (https://issues.apache.org/jira/browse/MDEP-974)
  line.gsub!(/\e\[\d*m/, EMPTY)
  line.gsub!(/ -- module.*/, EMPTY)
  line.strip!

  # Peel off the trailing file path first: since it may contain a ':' it
  # cannot take part in the split below. What is left (pre_match) is
  # colon-clean, so every field is addressed by position -- never by
  # matching a keyword, which breaks when an artifact id is itself a scope
  # or type keyword (e.g. "com.dylibso.chicory:runtime:jar:1.7.5").
  tail = line.match(TRAILING_FILE)
  file = tail[:file]

  # classifier is the only optional field, so there are exactly 5 or 6
  components = tail.pre_match.split(':')
  if components.size == 6
    group_id, artifact_id, type, classifier, version, scope_name = components
  else
    group_id, artifact_id, type, version, scope_name = components
  end

  coord = [group_id, artifact_id, type, classifier, version].compact.join(':')
  gav = [group_id, artifact_id, classifier, version].compact.join(':')
  path = File.join(*group_id.split('.'), artifact_id, version, file[%r{[^\\/]+\z}])

  scope =
    case scope_name
    when 'provided'
      :provided
    when 'test'
      :test
    else
      :runtime
    end

  new(type.to_sym, scope, coord, gav, file, path, scope_name == 'system')
end

Instance Method Details

#system?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/jars/installer.rb', line 70

def system?
  @system
end