Class: Doubleshot::Dependencies::JarDependency

Inherits:
Dependency show all
Defined in:
lib/doubleshot/dependencies/jar_dependency.rb

Constant Summary collapse

PACKAGE_TYPES =
[ "pom", "jar", "maven-plugin", "ejb", "war", "ear", "rar", "par", "bundle" ]

Instance Attribute Summary collapse

Attributes inherited from Dependency

#name

Instance Method Summary collapse

Methods inherited from Dependency

#==, #eql?, #hash, #lock, #locked?

Constructor Details

#initialize(maven_coordinate) ⇒ JarDependency

Returns a new instance of JarDependency.



11
12
13
14
15
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
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 11

def initialize(maven_coordinate)
  # This is Maven's default package type, if unspecified.
  @packaging = "jar"

  maven_coordinate_parts = maven_coordinate.split(":")
  @group = maven_coordinate_parts.shift
  @artifact = maven_coordinate_parts.shift

  if version = maven_coordinate_parts.pop
    if !PACKAGE_TYPES.include?(version)
      self.version = version
    else
      raise ArgumentError.new("Expected last coordinate part to be a Version but was a Package Type: #{maven_coordinate}")
    end
  end

  if packaging = maven_coordinate_parts.shift
    self.packaging = packaging
  end

  if classifier = maven_coordinate_parts.shift
    @classifier = classifier
  end

  @name = "#{@group}:#{@artifact}:#{@packaging}:#{@version}"

  if [ @group, @artifact, @packaging, @version ].any? &:blank?
    raise ArgumentError.new("Invalid coordinate: #{@name}")
  end

  @exclusions = []
end

Instance Attribute Details

#artifactObject (readonly)

Returns the value of attribute artifact.



9
10
11
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 9

def artifact
  @artifact
end

#classifierObject (readonly)

Returns the value of attribute classifier.



9
10
11
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 9

def classifier
  @classifier
end

#exclusionsObject (readonly)

Returns the value of attribute exclusions.



9
10
11
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 9

def exclusions
  @exclusions
end

#groupObject (readonly)

Returns the value of attribute group.



9
10
11
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 9

def group
  @group
end

#packagingObject

Returns the value of attribute packaging.



9
10
11
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 9

def packaging
  @packaging
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 9

def path
  @path
end

#versionObject

Returns the value of attribute version.



9
10
11
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 9

def version
  @version
end

Instance Method Details

#exclude(coordinate) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 52

def exclude(coordinate)
  if coordinate.split(":").size != 2
    raise ArgumentError.new("JarDependency#exclude takes a string of format \"groupId:artifactId\", you provided #{coordinate.inspect}")
  end
  @exclusions << coordinate
  self
end

#to_s(long_form = false) ⇒ Object



44
45
46
# File 'lib/doubleshot/dependencies/jar_dependency.rb', line 44

def to_s(long_form = false)
  @classifier.blank? ? @name : "#{@group}:#{@artifact}:#{@packaging}:#{@classifier}:#{@version}"
end