Class: Dependabot::Maven::UpdateChecker

Inherits:
UpdateCheckers::Base
  • Object
show all
Defined in:
lib/dependabot/maven/update_checker.rb,
lib/dependabot/maven/update_checker/version_finder.rb,
lib/dependabot/maven/update_checker/property_updater.rb,
lib/dependabot/maven/update_checker/requirements_updater.rb

Defined Under Namespace

Classes: PropertyUpdater, RequirementsUpdater, VersionFinder

Constant Summary collapse

VersionDetails =
T.type_alias do
  {
    version: T.nilable(Dependabot::Version),
    source_url: T.nilable(String)
  }
end

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, dependency_files:, credentials:, repo_contents_path: nil, ignored_versions: [], raise_on_ignored: false, security_advisories: [], requirements_update_strategy: nil, dependency_group: nil, update_cooldown: nil, options: {}) ⇒ UpdateChecker

Returns a new instance of UpdateChecker.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dependabot/maven/update_checker.rb', line 38

def initialize(
  dependency:,
  dependency_files:,
  credentials:,
  repo_contents_path: nil,
  ignored_versions: [],
  raise_on_ignored: false,
  security_advisories: [],
  requirements_update_strategy: nil,
  dependency_group: nil,
  update_cooldown: nil,
  options: {}
)
  super

  @version_finder = T.let(nil, T.nilable(VersionFinder))
  @property_updater = T.let(nil, T.nilable(PropertyUpdater))
  @property_value_finder = T.let(nil, T.nilable(Maven::FileParser::PropertyValueFinder))
  @declarations_using_a_property = T.let(nil, T.nilable(T::Array[Dependabot::DependencyRequirement]))
  @all_property_based_dependencies = T.let(nil, T.nilable(T::Array[Dependabot::Dependency]))
end

Instance Method Details

#latest_resolvable_versionObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dependabot/maven/update_checker.rb', line 69

def latest_resolvable_version
  # Maven's version resolution algorithm is very simple: it just uses
  # the version defined "closest", with the first declaration winning
  # if two declarations are equally close. As a result, we can just
  # return that latest version unless dealing with a property dep.
  # https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies
  return nil if version_comes_from_multi_dependency_property?
  return nil if version_comes_from_project_parent_version?

  latest_version
end

#latest_resolvable_version_with_no_unlockObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/dependabot/maven/update_checker.rb', line 95

def latest_resolvable_version_with_no_unlock
  # Irrelevant, since Maven has a single dependency file (the pom.xml).
  #
  # For completeness we ought to resolve the pom.xml and return the
  # latest version that satisfies the current constraint AND any
  # constraints placed on it by other dependencies. Seeing as we're
  # never going to take any action as a result, though, we just return
  # nil.
  nil
end

#latest_versionObject



61
62
63
64
65
66
# File 'lib/dependabot/maven/update_checker.rb', line 61

def latest_version
  version = latest_version_details&.fetch(:version)
  return version if version.is_a?(Dependabot::Version)

  nil
end

#lowest_resolvable_security_fix_versionObject



90
91
92
# File 'lib/dependabot/maven/update_checker.rb', line 90

def lowest_resolvable_security_fix_version
  lowest_security_fix_version
end

#lowest_security_fix_versionObject



82
83
84
85
86
87
# File 'lib/dependabot/maven/update_checker.rb', line 82

def lowest_security_fix_version
  version = lowest_security_fix_version_details&.fetch(:version)
  return version if version.is_a?(Dependabot::Version)

  nil
end

#requirements_unlocked_or_can_be?Boolean

Returns:

  • (Boolean)


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/dependabot/maven/update_checker.rb', line 121

def requirements_unlocked_or_can_be?
  declarations_using_a_property.none? do |requirement|
    prop_name = requirement.dig(:metadata, :property_name)
    pom = dependency_files.find { |f| f.name == requirement[:file] }

    return false unless prop_name && pom

    declaration_pom_name =
      property_value_finder
      .property_details(property_name: prop_name, callsite_pom: pom)
      &.fetch(:file)

    declaration_pom_name == "remote_pom.xml"
  end
end

#updated_requirementsObject



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dependabot/maven/update_checker.rb', line 107

def updated_requirements
  property_names =
    declarations_using_a_property
    .map { |req| req.dig(:metadata, :property_name) }

  RequirementsUpdater.new(
    requirements: dependency.requirements,
    latest_version: preferred_resolvable_version&.to_s,
    source_url: preferred_version_details&.fetch(:source_url),
    properties_to_update: property_names
  ).updated_requirements
end