Class: Tetra::Pom
- Inherits:
-
Object
- Object
- Tetra::Pom
- Defined in:
- lib/tetra/pom.rb
Overview
encapsulates a pom.xml file
Instance Method Summary collapse
- #artifact_id ⇒ Object
- #description ⇒ Object
- #group_id ⇒ Object
-
#initialize(filename) ⇒ Pom
constructor
A new instance of Pom.
- #license_name ⇒ Object
- #modules ⇒ Object
- #name ⇒ Object
- #runtime_dependency_ids ⇒ Object
- #scm_connection ⇒ Object
- #scm_url ⇒ Object
- #url ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(filename) ⇒ Pom
Returns a new instance of Pom.
6 7 8 9 10 11 12 13 14 |
# File 'lib/tetra/pom.rb', line 6 def initialize(filename) # ROBUSTNESS: Handle missing file gracefully by initializing empty content content = if filename && File.file?(filename) File.read(filename) else "<project></project>" end @doc = REXML::Document.new(content) end |
Instance Method Details
#artifact_id ⇒ Object
20 21 22 |
# File 'lib/tetra/pom.rb', line 20 def artifact_id xpath_text("project/artifactId") end |
#description ⇒ Object
32 33 34 |
# File 'lib/tetra/pom.rb', line 32 def description xpath_text("project/description") end |
#group_id ⇒ Object
16 17 18 |
# File 'lib/tetra/pom.rb', line 16 def group_id xpath_text("project/groupId") end |
#license_name ⇒ Object
40 41 42 |
# File 'lib/tetra/pom.rb', line 40 def license_name xpath_text("project/licenses/license/name") end |
#modules ⇒ Object
61 62 63 |
# File 'lib/tetra/pom.rb', line 61 def modules REXML::XPath.match(@doc, "project/modules/module").map(&:text) end |
#name ⇒ Object
24 25 26 |
# File 'lib/tetra/pom.rb', line 24 def name xpath_text("project/name") end |
#runtime_dependency_ids ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tetra/pom.rb', line 44 def runtime_dependency_ids # CLEANUP: Use standard multi-line string for complex XPath xpath = "project/dependencies/dependency[" \ "not(optional='true') and " \ "not(scope='provided') and " \ "not(scope='test') and " \ "not(scope='system')]" REXML::XPath.match(@doc, xpath).map do |element| [ element.elements["groupId"]&.text, element.elements["artifactId"]&.text, element.elements["version"]&.text ] end end |
#scm_connection ⇒ Object
65 66 67 |
# File 'lib/tetra/pom.rb', line 65 def scm_connection xpath_text("project/scm/connection") end |
#scm_url ⇒ Object
69 70 71 |
# File 'lib/tetra/pom.rb', line 69 def scm_url xpath_text("project/scm/url") end |
#url ⇒ Object
36 37 38 |
# File 'lib/tetra/pom.rb', line 36 def url xpath_text("project/url") end |
#version ⇒ Object
28 29 30 |
# File 'lib/tetra/pom.rb', line 28 def version xpath_text("project/version") end |