Class: Dependabot::Gradle::FileParser::DistributionsFinder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/gradle/file_parser/distributions_finder.rb

Constant Summary collapse

DISTRIBUTION_URL_REGEX =
/.*?(?<version>(\d+(?:\.\d+){1,3}(?:-(?!bin|all)\w++)*(?:\+\w++)*))(?:-bin|-all)?.*?/

Class Method Summary collapse

Class Method Details

.resolve_dependency(properties_file) ⇒ Object

rubocop:disable Metrics/MethodLength



18
19
20
21
22
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
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dependabot/gradle/file_parser/distributions_finder.rb', line 18

def self.resolve_dependency(properties_file) # rubocop:disable Metrics/MethodLength
  content = properties_file.content
  return nil unless content

  distribution_url, checksum = load_properties(content)
  match = distribution_url&.match(DISTRIBUTION_URL_REGEX)&.named_captures
  return nil unless match

  version = match.fetch("version")

  requirements = T.let(
    [{
      requirement: version,
      file: properties_file.name,
      source: {
        type: Distributions::DISTRIBUTION_DEPENDENCY_TYPE,
        url: distribution_url,
        property: "distributionUrl"
      },
      groups: []
    }],
    T::Array[T::Hash[Symbol, T.untyped]]
  )

  if checksum
    requirements << {
      requirement: checksum,
      file: properties_file.name,
      source: {
        type: Distributions::DISTRIBUTION_DEPENDENCY_TYPE,
        url: "#{distribution_url}.sha256",
        property: "distributionSha256Sum"
      },
      groups: []
    }
  end

  Dependency.new(
    name: "gradle-wrapper",
    version: version,
    requirements: requirements,
    package_manager: "gradle"
  )
end