Class: Tetra::Pom

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

Overview

encapsulates a pom.xml file

Instance Method Summary collapse

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_idObject



20
21
22
# File 'lib/tetra/pom.rb', line 20

def artifact_id
  xpath_text("project/artifactId")
end

#descriptionObject



32
33
34
# File 'lib/tetra/pom.rb', line 32

def description
  xpath_text("project/description")
end

#group_idObject



16
17
18
# File 'lib/tetra/pom.rb', line 16

def group_id
  xpath_text("project/groupId")
end

#license_nameObject



40
41
42
# File 'lib/tetra/pom.rb', line 40

def license_name
  xpath_text("project/licenses/license/name")
end

#modulesObject



61
62
63
# File 'lib/tetra/pom.rb', line 61

def modules
  REXML::XPath.match(@doc, "project/modules/module").map(&:text)
end

#nameObject



24
25
26
# File 'lib/tetra/pom.rb', line 24

def name
  xpath_text("project/name")
end

#runtime_dependency_idsObject



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_connectionObject



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

def scm_connection
  xpath_text("project/scm/connection")
end

#scm_urlObject



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

def scm_url
  xpath_text("project/scm/url")
end

#urlObject



36
37
38
# File 'lib/tetra/pom.rb', line 36

def url
  xpath_text("project/url")
end

#versionObject



28
29
30
# File 'lib/tetra/pom.rb', line 28

def version
  xpath_text("project/version")
end