Class: MavenPom::Pom

Inherits:
Object
  • Object
show all
Defined in:
lib/maven_pom/pom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str, uri) ⇒ Pom

Returns a new instance of Pom.



5
6
7
8
9
10
# File 'lib/maven_pom/pom.rb', line 5

def initialize(str, uri)
  @pom = Nokogiri.XML(str)
  @uri = uri

  MavenPom.all[key] = self
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



3
4
5
# File 'lib/maven_pom/pom.rb', line 3

def uri
  @uri
end

Instance Method Details

#artifact_idObject



69
70
71
# File 'lib/maven_pom/pom.rb', line 69

def artifact_id
  @pom.css("project > artifactId").text
end

#as_json(opts = nil) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/maven_pom/pom.rb', line 12

def as_json(opts = nil)
  {
    :key       => key,
    :name      => name,
    :parent    => parent,
    :packaging => packaging
  }
end

#build_pluginsObject



37
38
39
40
41
# File 'lib/maven_pom/pom.rb', line 37

def build_plugins
  @pom.css("plugins > plugin").map do |node|
    dependency_name_from(node)
  end
end

#dependenciesObject



77
78
79
80
81
# File 'lib/maven_pom/pom.rb', line 77

def dependencies
  @pom.css("dependencies > dependency").map do |node|
    dependency_name_from(node)
  end
end

#dependency_name_from(node) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/maven_pom/pom.rb', line 93

def dependency_name_from(node)
  gid = node.css("groupId").text
  aid = node.css("artifactId").text

  gid = group_id if gid == "${project.groupId}" # ugh

  "#{gid}:#{aid}"
end

#group_idObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/maven_pom/pom.rb', line 54

def group_id
  gid = @pom.css("project > groupId").text
  gid = @pom.css("project > parent > groupId").text if gid.empty?

  if gid.empty?
    raise MissingGroupIdError, "could not find groupId in pom (uri=#{uri.inspect})"
  end

  gid
end

#inspectObject



25
26
27
# File 'lib/maven_pom/pom.rb', line 25

def inspect
  "#<MavenPom::Pom:0x%x key=%s name=%s parent=%s>" % [object_id << 1, key.inspect, name.inspect, parent.inspect]
end

#keyObject



73
74
75
# File 'lib/maven_pom/pom.rb', line 73

def key
  @key ||= "#{group_id}:#{artifact_id}"
end

#nameObject



33
34
35
# File 'lib/maven_pom/pom.rb', line 33

def name
  @pom.css("project > name").text.strip
end

#packagingObject



29
30
31
# File 'lib/maven_pom/pom.rb', line 29

def packaging
  @pom.css("project > packaging").text
end

#parentObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/maven_pom/pom.rb', line 43

def parent
  parent = @pom.css("project > parent").first

  if parent
    gid = parent.css("groupId").text
    aid = parent.css("artifactId").text

    "#{gid}:#{aid}"
  end
end

#parent_pomObject



65
66
67
# File 'lib/maven_pom/pom.rb', line 65

def parent_pom
  MavenPom.all[parent]
end

#propertiesObject



83
84
85
86
87
88
89
90
91
# File 'lib/maven_pom/pom.rb', line 83

def properties
  props = {}

  @pom.css("project > properties > *").each do |element|
    props[element.name] = element.inner_text
  end

  props
end

#to_json(*args) ⇒ Object



21
22
23
# File 'lib/maven_pom/pom.rb', line 21

def to_json(*args)
  as_json.to_json(*args)
end