Class: Dependabot::Gradle::FileParser::PropertyValueFinder
- Inherits:
-
Object
- Object
- Dependabot::Gradle::FileParser::PropertyValueFinder
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/gradle/file_parser/property_value_finder.rb
Constant Summary collapse
- SUPPORTED_BUILD_FILE_NAMES =
rubocop:disable Layout/LineLength
%w(build.gradle build.gradle.kts).freeze
- QUOTED_VALUE_REGEX =
/\s*['"][^\s]+['"]\s*/
- FIND_PROPERTY_REGEX =
project.findProperty(‘property’) ?:
/\s*project\.findProperty\(#{QUOTED_VALUE_REGEX}\)\s*\?:/
- GROOVY_HAS_PROPERTY_REGEX =
project.hasProperty(‘property’) ? project.getProperty(‘property’) :
/\s*project\.hasProperty\(#{QUOTED_VALUE_REGEX}\)\s*\?\s*project\.getProperty\(#{QUOTED_VALUE_REGEX}\)\s*:/
- KOTLIN_HAS_PROPERTY_REGEX =
if(project.hasProperty(“property”)) project.getProperty(“property”) else
/\s*if\s*\(project\.hasProperty\(#{QUOTED_VALUE_REGEX}\)\)\s+project\.getProperty\(#{QUOTED_VALUE_REGEX}\)\s+else\s+/
- GROOVY_PROPERTY_DECLARATION_AS_DEFAULTS_REGEX =
/(?:#{FIND_PROPERTY_REGEX}|#{GROOVY_HAS_PROPERTY_REGEX})?/
- KOTLIN_PROPERTY_DECLARATION_AS_DEFAULTS_REGEX =
/(?:#{FIND_PROPERTY_REGEX}|#{KOTLIN_HAS_PROPERTY_REGEX})?/
- PROPERTY_DECLARATION_AS_DEFAULTS_REGEX =
/(#{GROOVY_PROPERTY_DECLARATION_AS_DEFAULTS_REGEX}|#{KOTLIN_PROPERTY_DECLARATION_AS_DEFAULTS_REGEX})?/
- VALUE_REGEX =
/#{PROPERTY_DECLARATION_AS_DEFAULTS_REGEX}\s*['"](?<value>[^\s]+)['"]/
- GROOVY_SINGLE_PROPERTY_DECLARATION_REGEX =
/(?:^|\s+|ext.)(?<name>[^\s=]+)\s*=#{VALUE_REGEX}/
- KOTLIN_SINGLE_PROPERTY_INDEX_DECLARATION_REGEX =
/\s*extra\[['"](?<name>[^\s=]+)['"]\]\s*=#{VALUE_REGEX}/
- KOTLIN_SINGLE_PROPERTY_SET_REGEX =
/\s*set\(['"](?<name>[^\s=]+)['"]\s*,#{VALUE_REGEX}\)/
- KOTLIN_SINGLE_PROPERTY_SET_DECLARATION_REGEX =
/\s*extra\.#{KOTLIN_SINGLE_PROPERTY_SET_REGEX}/
- KOTLIN_SINGLE_PROPERTY_DECLARATION_REGEX =
/(#{KOTLIN_SINGLE_PROPERTY_INDEX_DECLARATION_REGEX}|#{KOTLIN_SINGLE_PROPERTY_SET_DECLARATION_REGEX})/
- SINGLE_PROPERTY_DECLARATION_REGEX =
/(#{KOTLIN_SINGLE_PROPERTY_DECLARATION_REGEX}|#{GROOVY_SINGLE_PROPERTY_DECLARATION_REGEX})/
- GROOVY_MULTI_PROPERTY_DECLARATION_REGEX =
/(?:^|\s+|ext.)(?<namespace>[^\s=]+)\s*=\s*\[(?<values>[^\]]+)\]/m
- KOTLIN_BLOCK_PROPERTY_DECLARATION_REGEX =
/\s*(?<namespace>[^\s=]+)\.apply\s*{(?<values>[^\]]+)}/m
- KOTLIN_MULTI_PROPERTY_DECLARATION_REGEX =
/\s*extra\[['"](?<namespace>[^\s=]+)['"]\]\s*=\s*mapOf\((?<values>[^\]]+)\)/m
- MULTI_PROPERTY_DECLARATION_REGEX =
/(#{KOTLIN_MULTI_PROPERTY_DECLARATION_REGEX}|#{GROOVY_MULTI_PROPERTY_DECLARATION_REGEX})/
- KOTLIN_MAP_NAMESPACED_DECLARATION_REGEX =
/(?:^|\s+)['"](?<name>[^\s:]+)['"]\s*to#{VALUE_REGEX}\s*/
- REGULAR_NAMESPACED_DECLARATION_REGEX =
/(?:^|\s+)(?<name>[^\s:]+)\s*[:=]#{VALUE_REGEX}\s*/
- NAMESPACED_DECLARATION_REGEX =
/(#{REGULAR_NAMESPACED_DECLARATION_REGEX}|#{KOTLIN_MAP_NAMESPACED_DECLARATION_REGEX})/
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
71 72 73 |
# File 'lib/dependabot/gradle/file_parser/property_value_finder.rb', line 71 def initialize(dependency_files:) @dependency_files = dependency_files end |
Instance Method Details
#property_details(property_name:, callsite_buildfile:) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/dependabot/gradle/file_parser/property_value_finder.rb', line 75 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 property_name = property_name.sub("project.", "") if property_name.start_with?("project.") # If a `properties` prefix was specified strip that out, too property_name = property_name.sub("properties.", "") if property_name.start_with?("properties.") # Look for a property in the callsite buildfile. If that fails, look # for the property in the top-level buildfile all_files = [callsite_buildfile, top_level_buildfile].concat( FileParser.find_includes(callsite_buildfile, dependency_files), FileParser.find_includes(top_level_buildfile, dependency_files) ).compact all_files.each do |file| details = properties(file).fetch(property_name, nil) return details if details end nil end |
#property_value(property_name:, callsite_buildfile:) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/dependabot/gradle/file_parser/property_value_finder.rb', line 102 def property_value(property_name:, callsite_buildfile:) property_details( property_name: property_name, callsite_buildfile: callsite_buildfile )&.fetch(:value) end |