Class: Dependabot::Gradle::UpdateChecker::VersionFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/gradle/update_checker/version_finder.rb

Constant Summary collapse

GOOGLE_MAVEN_REPO =
"https://maven.google.com"
TYPE_SUFFICES =
%w(jre android java).freeze

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, dependency_files:, ignored_versions:) ⇒ VersionFinder

Returns a new instance of VersionFinder.



17
18
19
20
21
# File 'lib/dependabot/gradle/update_checker/version_finder.rb', line 17

def initialize(dependency:, dependency_files:, ignored_versions:)
  @dependency = dependency
  @dependency_files = dependency_files
  @ignored_versions = ignored_versions
end

Instance Method Details

#latest_version_detailsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dependabot/gradle/update_checker/version_finder.rb', line 23

def latest_version_details
  possible_versions = versions

  unless wants_prerelease?
    possible_versions =
      possible_versions.
      reject { |v| v.fetch(:version).prerelease? }
  end

  unless wants_date_based_version?
    possible_versions =
      possible_versions.
      reject { |v| v.fetch(:version) > version_class.new(1900) }
  end

  possible_versions =
    possible_versions.
    select { |v| matches_dependency_version_type?(v.fetch(:version)) }

  ignored_versions.each do |req|
    ignore_req = Gradle::Requirement.new(req.split(","))
    possible_versions =
      possible_versions.
      reject { |v| ignore_req.satisfied_by?(v.fetch(:version)) }
  end

  possible_versions.last
end

#versionsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dependabot/gradle/update_checker/version_finder.rb', line 52

def versions
  version_details =
    repository_urls.map do |url|
      next google_version_details if url == GOOGLE_MAVEN_REPO

      (url).css("versions > version").
        select { |node| version_class.correct?(node.content) }.
        map { |node| version_class.new(node.content) }.
        map { |version| { version: version, source_url: url } }
    end.flatten.compact

  version_details.sort_by { |details| details.fetch(:version) }
end