Class: Dependabot::Gradle::FileParser::PropertyValueFinder
- Inherits:
-
Object
- Object
- Dependabot::Gradle::FileParser::PropertyValueFinder
- Defined in:
- lib/dependabot/gradle/file_parser/property_value_finder.rb
Constant Summary collapse
- QUOTED_VALUE_REGEX =
rubocop:disable Layout/LineLength
/\s*['"][^\s]+['"]\s*/.freeze
- FIND_PROPERTY_REGEX =
project.findProperty(‘property’) ?:
/\s*project\.findProperty\(#{QUOTED_VALUE_REGEX}\)\s*\?:/.freeze
- HAS_PROPERTY_REGEX =
project.hasProperty(‘property’) ? project.getProperty(‘property’) :
/\s*project\.hasProperty\(#{QUOTED_VALUE_REGEX}\)\s*\?\s*project\.getProperty\(#{QUOTED_VALUE_REGEX}\)\s*:/.freeze
- PROPERTY_DECLARATION_AS_DEFAULTS_REGEX =
/(?:#{FIND_PROPERTY_REGEX}|#{HAS_PROPERTY_REGEX})?/.freeze
- SINGLE_PROPERTY_DECLARATION_REGEX =
/(?:^|\s+|ext.)(?<name>[^\s=]+)\s*=#{PROPERTY_DECLARATION_AS_DEFAULTS_REGEX}\s*['"](?<value>[^\s]+)['"]/.freeze
- MULTI_PROPERTY_DECLARATION_REGEX =
/(?:^|\s+|ext.)(?<namespace>[^\s=]+)\s*=\s*\[(?<values>[^\]]+)\]/m.freeze
- NAMESPACED_DECLARATION_REGEX =
/(?:^|\s+)(?<name>[^\s:]+)\s*:#{PROPERTY_DECLARATION_AS_DEFAULTS_REGEX}\s*['"](?<value>[^\s]+)['"]\s*/.freeze
Instance Method Summary collapse
-
#initialize(dependency_files:) ⇒ PropertyValueFinder
constructor
rubocop:enable Layout/LineLength.
- #property_details(property_name:, callsite_buildfile:) ⇒ Object
- #property_value(property_name:, callsite_buildfile:) ⇒ Object
Constructor Details
#initialize(dependency_files:) ⇒ PropertyValueFinder
rubocop:enable Layout/LineLength
34 35 36 |
# File 'lib/dependabot/gradle/file_parser/property_value_finder.rb', line 34 def initialize(dependency_files:) @dependency_files = dependency_files end |
Instance Method Details
#property_details(property_name:, callsite_buildfile:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dependabot/gradle/file_parser/property_value_finder.rb', line 38 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
65 66 67 68 69 70 |
# File 'lib/dependabot/gradle/file_parser/property_value_finder.rb', line 65 def property_value(property_name:, callsite_buildfile:) property_details( property_name: property_name, callsite_buildfile: callsite_buildfile )&.fetch(:value) end |