class Dependabot::Gradle::FileFetcher

Constants

SUPPORTED_BUILD_FILE_NAMES
SUPPORTED_SETTINGS_FILE_NAMES

Public Class Methods

required_files_in?(filenames) click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 17
def self.required_files_in?(filenames)
  filenames.any? do |filename|
    SUPPORTED_BUILD_FILE_NAMES.include?(filename)
  end
end
required_files_message() click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 23
def self.required_files_message
  "Repo must contain a build.gradle / build.gradle.kts file."
end

Private Instance Methods

buildfile() click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 38
def buildfile
  @buildfile ||= begin
    file = supported_build_file
    @buildfile_name ||= file.name if file
    file
  end
end
check_required_files_present() click to toggle source

rubocop:enable Metrics/PerceivedComplexity

# File lib/dependabot/gradle/file_fetcher.rb, line 86
def check_required_files_present
  return if buildfile

  path = Pathname.new(File.join(directory, "build.gradle")).cleanpath.to_path
  path += "(.kts)?"
  raise Dependabot::DependencyFileNotFound, path
end
dependency_script_plugins() click to toggle source

rubocop:disable Metrics/PerceivedComplexity

# File lib/dependabot/gradle/file_fetcher.rb, line 63
def dependency_script_plugins
  return [] unless buildfile

  dependency_plugin_paths =
    buildfile.content.
    scan(/apply from:\s+['"]([^'"]+)['"]/).flatten.
    reject { |path| path.include?("://") }.
    reject { |path| !path.include?("/") && path.split(".").count > 2 }.
    select { |filename| filename.include?("dependencies") }.
    map { |path| path.gsub("$rootDir", ".") }.
    uniq

  dependency_plugin_paths.map do |path|
    fetch_file_from_host(path)
  rescue Dependabot::DependencyFileNotFound
    next nil if file_exists_in_submodule?(path)
    next nil if path.include?("${")

    raise
  end.compact
end
fetch_files() click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 29
def fetch_files
  fetched_files = []
  fetched_files << buildfile
  fetched_files += subproject_buildfiles
  fetched_files += dependency_script_plugins
  check_required_files_present
  fetched_files
end
file_exists_in_submodule?(path) click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 94
def file_exists_in_submodule?(path)
  fetch_file_from_host(path, fetch_submodules: true)
  true
rescue Dependabot::DependencyFileNotFound
  false
end
settings_file() click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 101
def settings_file
  @settings_file ||= supported_settings_file
end
subproject_buildfiles() click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 46
def subproject_buildfiles
  return [] unless settings_file

  subproject_paths =
    SettingsFileParser.
    new(settings_file: settings_file).
    subproject_paths

  subproject_paths.map do |path|
    fetch_file_from_host(File.join(path, @buildfile_name))
  rescue Dependabot::DependencyFileNotFound
    # Gradle itself doesn't worry about missing subprojects, so we don't
    nil
  end.compact
end
supported_build_file() click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 105
def supported_build_file
  supported_file(SUPPORTED_BUILD_FILE_NAMES)
end
supported_file(supported_file_names) click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 113
def supported_file(supported_file_names)
  supported_file_names.each do |supported_file_name|
    file = fetch_file_if_present(supported_file_name)
    return file if file
  end

  nil
end
supported_settings_file() click to toggle source
# File lib/dependabot/gradle/file_fetcher.rb, line 109
def supported_settings_file
  supported_file(SUPPORTED_SETTINGS_FILE_NAMES)
end