Module: Dependabot::Gradle::FileUpdater::Wrapper::ExecutingVersionDetector

Extended by:
T::Sig
Defined in:
lib/dependabot/gradle/file_updater/wrapper/executing_version_detector.rb

Overview

Detects the Gradle version that will actually execute the wrapper task.

The wrapper task runs under whatever Gradle the project currently resolves to (the OLD distribution), not the target version. Knowing that version lets CommandBuilder decide which version-gated CLI flags are safe to pass.

Constant Summary collapse

DISTRIBUTION_URL_VERSION_REGEX =

Matches the version embedded in a Gradle distribution URL, e.g. https://services.gradle.org/distributions/gradle-9.5.0-bin.zip Anchored to the gradle-<version>-(bin|all).zip filename so host/port numbers in custom mirror URLs are never mistaken for the version. The captured token is validated with Version.correct? so non-version matches (and RC/milestone names) are handled safely.

/gradle-(?<version>.+?)-(?:bin|all)\.zip/
GRADLE_VERSION_OUTPUT_REGEX =

Matches the version printed by gradle --version, e.g. "Gradle 9.2.1".

/^Gradle\s+(?<version>\d+(?:\.\d+){1,2}(?:-[\w.]+)?)/

Class Method Summary collapse

Class Method Details

.build_version(captured) ⇒ Object



48
49
50
51
52
# File 'lib/dependabot/gradle/file_updater/wrapper/executing_version_detector.rb', line 48

def self.build_version(captured)
  return nil if captured.nil? || !Dependabot::Gradle::Version.correct?(captured)

  T.cast(Dependabot::Gradle::Version.new(captured), Dependabot::Gradle::Version)
end

.from_distribution_url(distribution_url) ⇒ Object



32
33
34
35
36
37
# File 'lib/dependabot/gradle/file_updater/wrapper/executing_version_detector.rb', line 32

def self.from_distribution_url(distribution_url)
  return nil if distribution_url.nil?

  captured = distribution_url.match(DISTRIBUTION_URL_VERSION_REGEX)&.named_captures&.fetch("version", nil)
  build_version(captured)
end

.from_version_output(output) ⇒ Object



40
41
42
43
44
45
# File 'lib/dependabot/gradle/file_updater/wrapper/executing_version_detector.rb', line 40

def self.from_version_output(output)
  return nil if output.nil?

  captured = output.match(GRADLE_VERSION_OUTPUT_REGEX)&.named_captures&.fetch("version", nil)
  build_version(captured)
end