Class: Dependabot::Gradle::FileParser

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

Defined Under Namespace

Classes: PropertyValueFinder, RepositoriesFinder

Constant Summary collapse

SUPPORTED_BUILD_FILE_NAMES =
%w(build.gradle build.gradle.kts settings.gradle settings.gradle.kts).freeze
PROPERTY_REGEX =
/
  (?:\$\{property\((?<property_name>[^:\s]*?)\)\})|
  (?:\$\{(?<property_name>[^:\s]*?)\})|
  (?:\$(?<property_name>[^:\s"']*))
/x.freeze
PART =
%r{[^\s,@'":/\\]+}.freeze
VSN_PART =
%r{[^\s,'":/\\]+}.freeze
DEPENDENCY_DECLARATION_REGEX =
/(?:\(|\s)\s*['"](?<declaration>#{PART}:#{PART}:#{VSN_PART})['"]/.
freeze
DEPENDENCY_SET_DECLARATION_REGEX =
/(?:^|\s)dependencySet\((?<arguments>[^\)]+)\)\s*\{/.freeze
DEPENDENCY_SET_ENTRY_REGEX =
/entry\s+['"](?<name>#{PART})['"]/.freeze
PLUGIN_BLOCK_DECLARATION_REGEX =
/(?:^|\s)plugins\s*\{/.freeze
PLUGIN_ID_REGEX =
/['"](?<id>#{PART})['"]/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_include_names(buildfile) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/dependabot/gradle/file_parser.rb', line 52

def self.find_include_names(buildfile)
  return [] unless buildfile

  buildfile.content.
    scan(/apply(\(| )\s*from(\s+=|:)\s+['"]([^'"]+)['"]/).
    map { |match| match[2] }
end

.find_includes(buildfile, dependency_files) ⇒ Object



60
61
62
63
64
# File 'lib/dependabot/gradle/file_parser.rb', line 60

def self.find_includes(buildfile, dependency_files)
  FileParser.find_include_names(buildfile).
    map { |f| dependency_files.find { |bf| bf.name == f } }.
    compact
end

Instance Method Details

#parseObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/dependabot/gradle/file_parser.rb', line 41

def parse
  dependency_set = DependencySet.new
  buildfiles.each do |buildfile|
    dependency_set += buildfile_dependencies(buildfile)
  end
  script_plugin_files.each do |plugin_file|
    dependency_set += buildfile_dependencies(plugin_file)
  end
  dependency_set.dependencies
end