Class: Dependabot::Gradle::FileParser::PropertyValueFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/gradle/file_parser/property_value_finder.rb

Constant Summary collapse

PROPERTY_DECLARATION_REGEX =
/(?:^|\s+|ext.)(?<name>[^\s=]+)\s*=\s*['"](?<value>[^\s]+)['"]/.
freeze

Instance Method Summary collapse

Constructor Details

#initialize(dependency_files:) ⇒ PropertyValueFinder

Returns a new instance of PropertyValueFinder.



13
14
15
# File 'lib/dependabot/gradle/file_parser/property_value_finder.rb', line 13

def initialize(dependency_files:)
  @dependency_files = dependency_files
end

Instance Method Details

#property_details(property_name:, callsite_buildfile:) ⇒ Object



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/dependabot/gradle/file_parser/property_value_finder.rb', line 17

def property_details(property_name:, callsite_buildfile:)
  # If the root project was specified, just look in the top-level
  # buildfile
  if property_name.start_with?("rootProject.")
    property_name = property_name.sub("rootProject.", "")
    return properties(top_level_buildfile).fetch(property_name, nil)
  end

  # If this project was specified strip the specifier
  if property_name.start_with?("project.")
    property_name = property_name.sub("project.", "")
  end

  # If a `properties` prefix was specified strip that out, too
  if property_name.start_with?("properties.")
    property_name = property_name.sub("properties.", "")
  end

  # Look for a property in the callsite buildfile. If that fails, look
  # for the property in the top-level buildfile
  if properties(callsite_buildfile).fetch(property_name, nil)
    return properties(callsite_buildfile).fetch(property_name)
  end

  properties(top_level_buildfile).fetch(property_name, nil)
end

#property_value(property_name:, callsite_buildfile:) ⇒ Object



44
45
46
47
48
49
# File 'lib/dependabot/gradle/file_parser/property_value_finder.rb', line 44

def property_value(property_name:, callsite_buildfile:)
  property_details(
    property_name: property_name,
    callsite_buildfile: callsite_buildfile
  )&.fetch(:value)
end