Class: Dependabot::Gradle::FileParser::RepositoriesFinder

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

Constant Summary collapse

SUPPORTED_BUILD_FILE_NAMES =
%w(build.gradle build.gradle.kts).freeze
CENTRAL_REPO_URL =

The Central Repo doesn’t have special status for Gradle, but until we’re confident we’re selecting repos correctly it’s wise to include it as a default.

"https://repo.maven.apache.org/maven2"
GOOGLE_MAVEN_REPO =
"https://maven.google.com"
GRADLE_PLUGINS_REPO =
"https://plugins.gradle.org/m2"
REPOSITORIES_BLOCK_START =
/(?:^|\s)repositories\s*\{/.freeze
GROOVY_MAVEN_REPO_REGEX =
/maven\s*\{[^\}]*\surl[\s\(]=?[^'"]*['"](?<url>[^'"]+)['"]/.freeze
KOTLIN_MAVEN_REPO_REGEX =
/maven\((url\s?\=\s?)?["](?<url>[^"]+)["]\)/.freeze
MAVEN_REPO_REGEX =
/(#{KOTLIN_MAVEN_REPO_REGEX}|#{GROOVY_MAVEN_REPO_REGEX})/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(dependency_files:, target_dependency_file:) ⇒ RepositoriesFinder

Returns a new instance of RepositoriesFinder.



29
30
31
32
33
# File 'lib/dependabot/gradle/file_parser/repositories_finder.rb', line 29

def initialize(dependency_files:, target_dependency_file:)
  @dependency_files = dependency_files
  @target_dependency_file = target_dependency_file
  raise "No target file!" unless target_dependency_file
end

Instance Method Details

#repository_urlsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dependabot/gradle/file_parser/repositories_finder.rb', line 35

def repository_urls
  repository_urls = []
  repository_urls += inherited_repository_urls(top_level_buildfile)
  FileParser.find_includes(top_level_buildfile, dependency_files).each do |dependency_file|
    repository_urls += inherited_repository_urls(dependency_file)
  end
  repository_urls += own_buildfile_repository_urls
  repository_urls = repository_urls.uniq

  return repository_urls unless repository_urls.empty?

  [CENTRAL_REPO_URL]
end