Class: Dependabot::Maven::FileParser::PropertyValueFinder
- Inherits:
-
Object
- Object
- Dependabot::Maven::FileParser::PropertyValueFinder
- Defined in:
- lib/dependabot/maven/file_parser/property_value_finder.rb
Constant Summary collapse
- DOT_SEPARATOR_REGEX =
%r{\.(?:(?!\d+[.\/])+)}.freeze
Instance Method Summary collapse
-
#initialize(dependency_files:) ⇒ PropertyValueFinder
constructor
A new instance of PropertyValueFinder.
- #property_details(property_name:, callsite_pom:) ⇒ Object
Constructor Details
#initialize(dependency_files:) ⇒ PropertyValueFinder
Returns a new instance of PropertyValueFinder.
20 21 22 |
# File 'lib/dependabot/maven/file_parser/property_value_finder.rb', line 20 def initialize(dependency_files:) @dependency_files = dependency_files end |
Instance Method Details
#property_details(property_name:, callsite_pom:) ⇒ Object
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/dependabot/maven/file_parser/property_value_finder.rb', line 24 def property_details(property_name:, callsite_pom:) pom = callsite_pom doc = Nokogiri::XML(pom.content) doc.remove_namespaces! # Loop through the paths that would satisfy this property name, # looking for one that exists in this POM nm = sanitize_property_name(property_name) node = loop do candidate_node = doc.at_xpath("/project/#{nm}") || doc.at_xpath("/project/properties/#{nm}") || doc.at_xpath("/project/profiles/profile/properties/#{nm}") break candidate_node if candidate_node break unless nm.match?(DOT_SEPARATOR_REGEX) nm = nm.sub(DOT_SEPARATOR_REGEX, "/") end # If we found a property, return it if node return { file: pom.name, node: node, value: node.content.strip } end # Otherwise, look for a value in this pom's parent return unless (parent = parent_pom(pom)) property_details( property_name: property_name, callsite_pom: parent ) end |