Class: Dependabot::Maven::UpdateChecker::RequirementsUpdater

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Sig
Includes:
RequirementsUpdater::Base
Defined in:
lib/dependabot/maven/update_checker/requirements_updater.rb

Constant Summary collapse

Version =
type_member { { fixed: Dependabot::Maven::Version } }
Requirement =
type_member { { fixed: Dependabot::Maven::Requirement } }

Instance Method Summary collapse

Constructor Details

#initialize(requirements:, latest_version:, source_url:, properties_to_update:) ⇒ RequirementsUpdater

Returns a new instance of RequirementsUpdater.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dependabot/maven/update_checker/requirements_updater.rb', line 36

def initialize(
  requirements:,
  latest_version:,
  source_url:,
  properties_to_update:
)
  @requirements = T.let(
    requirements.map { |req| Dependabot::DependencyRequirement.create(req) },
    T::Array[Dependabot::DependencyRequirement]
  )
  @source_url = source_url
  @properties_to_update = properties_to_update
  return unless latest_version

  @latest_version = T.let(version_class.new(latest_version), Version)
end

Instance Method Details

#updated_requirementsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/dependabot/maven/update_checker/requirements_updater.rb', line 54

def updated_requirements
  return requirements unless latest_version

  # NOTE: Order is important here. The FileUpdater needs the updated
  # requirement at index `i` to correspond to the previous requirement
  # at the same index.
  requirements.map do |req|
    # Wrapper property requirements (distributionUrl, wrapperVersion,
    # wrapperUrl) live in maven-wrapper.properties, not in a pom.xml.
    # They must not go through POM XML update logic; instead we bump the
    # requirement and keep the version metadata / artifact URL the
    # FileUpdater reads in sync with it.
    if req.source_string("type") == Distributions::DISTRIBUTION_DEPENDENCY_TYPE
      next bump_distribution_requirement(req)
    end

    requirement = req.requirement_string
    next req if requirement.nil?
    next req if requirement.include?(",")

    property_name = req.("property_name")
    next req if property_name && !properties_to_update.include?(property_name)

    new_req = update_requirement(requirement)
    next req if new_req == requirement

    Dependabot::DependencyRequirement.create(req.merge(requirement: new_req, source: updated_source))
  end
end