dependabot-maven 0.308.0 → 0.309.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecad9ed68d5e38fdcbf2d655b868ea282629e93d6cbc5f19c1732d2b59b329eb
4
- data.tar.gz: 77a824b0906e80df4847d0c5c5b8ac1f4a288051002a694d6e6bfc50171368da
3
+ metadata.gz: 280386e839ade4655181e1cf43a6ac57c1258082bd6eddf71936eb59ba16dc5c
4
+ data.tar.gz: 0f3fa2c05fa23352eb9985ce388c7626fa12742dd3141e41a3649219eff62386
5
5
  SHA512:
6
- metadata.gz: 7205996fea2c8447c8e0d6d013e8c552d35adb7ebec3321a392979ebc6844d9f62b819ab6540051a680b8c84f3efe44f1cae796edd39694ac6e6ad0b0983d27d
7
- data.tar.gz: d1a56abe418c71031e9afa1d730a399eaaf85399b2c56b9e03489d47523a41a29bf39952665114406eb43e991263629c5e3ebba3296a4af24b107f1e71628729
6
+ metadata.gz: 5b0afa1d41c41c19d2d43e1b52f51227bdc3450e88d1be98c486cbb6b95e12dd374ecc32246b3d3b42349115df224896e227303ea1cc6e08fe62416d1309ffe9
7
+ data.tar.gz: cc3b88872953f7f641758c5b4947e9428485d25ce5a1cdf66dc7ee2247bb3c9e724d5ce18b19f02a45c8f3e27ad2ade5feda09bc6a9be5f38b1fad3f59cc31e4
@@ -21,7 +21,13 @@ module Dependabot
21
21
 
22
22
  DOT_SEPARATOR_REGEX = %r{\.(?!\d+([.\/_\-]|$)+)}
23
23
 
24
- sig { params(dependency_files: T::Array[DependencyFile], credentials: T::Array[String]).void }
24
+ sig do
25
+ params(
26
+ dependency_files: T::Array[DependencyFile],
27
+ credentials: T::Array[Dependabot::Credential]
28
+ )
29
+ .void
30
+ end
25
31
  def initialize(dependency_files:, credentials: [])
26
32
  @dependency_files = dependency_files
27
33
  @credentials = credentials
@@ -1,4 +1,4 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "nokogiri"
@@ -20,9 +20,19 @@ module Dependabot
20
20
  # In theory we should check the artifact type and either look in
21
21
  # <repositories> or <pluginRepositories>. In practice it's unlikely
22
22
  # anyone makes this distinction.
23
+ extend T::Sig
24
+
23
25
  REPOSITORY_SELECTOR = "repositories > repository, " \
24
26
  "pluginRepositories > pluginRepository"
25
27
 
28
+ sig do
29
+ params(
30
+ pom_fetcher: T.nilable(Dependabot::Maven::FileParser::PomFetcher),
31
+ dependency_files: T::Array[Dependabot::DependencyFile],
32
+ credentials: T::Array[Dependabot::Credential],
33
+ evaluate_properties: T::Boolean
34
+ ).void
35
+ end
26
36
  def initialize(pom_fetcher:, dependency_files: [], credentials: [], evaluate_properties: true)
27
37
  @pom_fetcher = pom_fetcher
28
38
  @dependency_files = dependency_files
@@ -34,25 +44,35 @@ module Dependabot
34
44
  @evaluate_properties = evaluate_properties
35
45
  # Aggregates URLs seen in POMs to avoid short term memory loss.
36
46
  # For instance a repository in a child POM might apply to the parent too.
37
- @known_urls = []
47
+ @known_urls = T.let([], T::Array[T::Hash[Symbol, T.untyped]])
48
+ @property_value_finder = T.let(nil, T.nilable(PropertyValueFinder))
38
49
  end
39
50
 
51
+ sig { returns(String) }
40
52
  def central_repo_url
41
53
  base = @credentials.find { |cred| cred["type"] == "maven_repository" && cred.replaces_base? }
42
- base ? base["url"] : "https://repo.maven.apache.org/maven2"
54
+ base ? T.must(base["url"]) : "https://repo.maven.apache.org/maven2"
43
55
  end
44
56
 
45
57
  # Collect all repository URLs from this POM and its parents
58
+ sig do
59
+ params(
60
+ pom: Dependabot::DependencyFile,
61
+ exclude_inherited: T::Boolean,
62
+ exclude_snapshots: T::Boolean
63
+ )
64
+ .returns(T::Array[String])
65
+ end
46
66
  def repository_urls(pom:, exclude_inherited: false, exclude_snapshots: true)
47
67
  entries = gather_repository_urls(pom: pom, exclude_inherited: exclude_inherited)
48
68
  ids = Set.new
49
- @known_urls += entries.map do |entry|
69
+ @known_urls += entries.filter_map do |entry|
50
70
  next if entry[:id] && ids.include?(entry[:id])
51
71
 
52
72
  ids.add(entry[:id]) unless entry[:id].nil?
53
73
  entry
54
74
  end
55
- @known_urls = @known_urls.uniq.compact
75
+ @known_urls = @known_urls.uniq
56
76
 
57
77
  urls = urls_from_credentials + @known_urls.reject { |entry| exclude_snapshots && entry[:snapshots] }
58
78
  .map { |entry| entry[:url] }
@@ -62,14 +82,17 @@ module Dependabot
62
82
 
63
83
  private
64
84
 
85
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
65
86
  attr_reader :dependency_files
66
87
 
67
88
  # The Central Repository is included in the Super POM, which is
68
89
  # always inherited from.
90
+ sig { returns(T::Hash[Symbol, String]) }
69
91
  def super_pom
70
92
  { url: central_repo_url, id: "central" }
71
93
  end
72
94
 
95
+ sig { params(entry: Nokogiri::XML::Element).returns(T::Hash[Symbol, T.nilable(String)]) }
73
96
  def serialize_mvn_repo(entry)
74
97
  {
75
98
  url: entry.at_css("url").content.strip,
@@ -79,10 +102,18 @@ module Dependabot
79
102
  }
80
103
  end
81
104
 
105
+ sig { params(entry: T::Hash[Symbol, T.untyped]).returns(T::Boolean) }
82
106
  def snapshot_repo(entry)
83
107
  entry[:releases] == "false" && (entry[:snapshots].nil? || entry[:snapshots] == "true")
84
108
  end
85
109
 
110
+ sig do
111
+ params(
112
+ entry: T::Hash[Symbol, T.untyped],
113
+ pom: Dependabot::DependencyFile
114
+ )
115
+ .returns(T::Hash[Symbol, T.untyped])
116
+ end
86
117
  def serialize_urls(entry, pom)
87
118
  {
88
119
  url: evaluated_value(entry[:url], pom).gsub(%r{/$}, ""),
@@ -91,6 +122,13 @@ module Dependabot
91
122
  }
92
123
  end
93
124
 
125
+ sig do
126
+ params(
127
+ pom: Dependabot::DependencyFile,
128
+ exclude_inherited: T::Boolean
129
+ )
130
+ .returns(T::Array[T::Hash[Symbol, T.untyped]])
131
+ end
94
132
  def gather_repository_urls(pom:, exclude_inherited: false)
95
133
  repos_in_pom =
96
134
  Nokogiri::XML(pom.content)
@@ -110,11 +148,19 @@ module Dependabot
110
148
  repos_in_pom + gather_repository_urls(pom: parent)
111
149
  end
112
150
 
151
+ sig { returns(T::Boolean) }
113
152
  def evaluate_properties?
114
153
  @evaluate_properties
115
154
  end
116
155
 
117
156
  # rubocop:disable Metrics/PerceivedComplexity
157
+ sig do
158
+ params(
159
+ pom: T.untyped,
160
+ repo_urls: T::Array[String]
161
+ )
162
+ .returns(T.untyped)
163
+ end
118
164
  def parent_pom(pom, repo_urls)
119
165
  doc = Nokogiri::XML(pom.content)
120
166
  doc.remove_namespaces!
@@ -127,35 +173,41 @@ module Dependabot
127
173
 
128
174
  name = [group_id, artifact_id].join(":")
129
175
 
130
- return @pom_fetcher.internal_dependency_poms[name] if @pom_fetcher.internal_dependency_poms[name]
176
+ if T.must(@pom_fetcher).internal_dependency_poms[name]
177
+ return T.must(@pom_fetcher).internal_dependency_poms[name]
178
+ end
131
179
 
132
180
  return unless version && !version.include?(",")
133
181
 
134
182
  urls = urls_from_credentials + repo_urls + [central_repo_url]
135
- @pom_fetcher.fetch_remote_parent_pom(group_id, artifact_id, version, urls)
183
+ T.must(@pom_fetcher).fetch_remote_parent_pom(group_id, artifact_id, version, urls)
136
184
  end
137
185
  # rubocop:enable Metrics/PerceivedComplexity
138
186
 
187
+ sig { returns(T::Array[String]) }
139
188
  def urls_from_credentials
140
189
  @credentials
141
190
  .select { |cred| cred["type"] == "maven_repository" }
142
191
  .filter_map { |cred| cred["url"]&.strip&.gsub(%r{/$}, "") }
143
192
  end
144
193
 
194
+ sig { params(value: String).returns(T::Boolean) }
145
195
  def contains_property?(value)
146
196
  value.match?(property_regex)
147
197
  end
148
198
 
199
+ sig { params(value: String, pom: Dependabot::DependencyFile).returns(T.untyped) }
149
200
  def evaluated_value(value, pom)
150
201
  return value unless contains_property?(value)
151
202
 
152
- property_name = value.match(property_regex)
153
- .named_captures.fetch("property")
154
- property_value = value_for_property(property_name, pom)
203
+ match_data = value.match(property_regex)
204
+ property_name = T.must(match_data).named_captures.fetch("property")
205
+ property_value = value_for_property(T.cast(property_name, String), pom)
155
206
 
156
207
  value.gsub(property_regex, property_value)
157
208
  end
158
209
 
210
+ sig { params(property_name: String, pom: Dependabot::DependencyFile).returns(String) }
159
211
  def value_for_property(property_name, pom)
160
212
  value =
161
213
  property_value_finder
@@ -172,11 +224,13 @@ module Dependabot
172
224
 
173
225
  # Cached, since this can makes calls to the registry (to get property
174
226
  # values from parent POMs)
227
+ sig { returns(Dependabot::Maven::FileParser::PropertyValueFinder) }
175
228
  def property_value_finder
176
229
  @property_value_finder ||=
177
230
  PropertyValueFinder.new(dependency_files: dependency_files, credentials: @credentials)
178
231
  end
179
232
 
233
+ sig { returns(Regexp) }
180
234
  def property_regex
181
235
  Maven::FileParser::PROPERTY_REGEX
182
236
  end
@@ -342,7 +342,7 @@ module Dependabot
342
342
  sig { returns(Dependabot::Maven::FileParser::PropertyValueFinder) }
343
343
  def property_value_finder
344
344
  @property_value_finder ||= T.let(
345
- PropertyValueFinder.new(dependency_files: dependency_files, credentials: credentials.map(&:to_s)),
345
+ PropertyValueFinder.new(dependency_files: dependency_files, credentials: @credentials),
346
346
  T.nilable(Dependabot::Maven::FileParser::PropertyValueFinder)
347
347
  )
348
348
  end
@@ -1,4 +1,4 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "nokogiri"
@@ -10,6 +10,8 @@ module Dependabot
10
10
  module Maven
11
11
  class FileUpdater
12
12
  class DeclarationFinder
13
+ extend T::Sig
14
+
13
15
  DECLARATION_REGEX = %r{
14
16
  <parent>.*?</parent>|
15
17
  <dependency>.*?</dependency>|
@@ -19,20 +21,36 @@ module Dependabot
19
21
  <artifactItem>.*?</artifactItem>
20
22
  }mx
21
23
 
24
+ sig { returns(Dependabot::Dependency) }
22
25
  attr_reader :dependency
26
+
27
+ sig { returns(T::Hash[Symbol, T.untyped]) }
23
28
  attr_reader :declaring_requirement
29
+
30
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
24
31
  attr_reader :dependency_files
25
32
 
33
+ sig do
34
+ params(
35
+ dependency: Dependabot::Dependency,
36
+ dependency_files: T::Array[Dependabot::DependencyFile],
37
+ declaring_requirement: T::Hash[Symbol, T.untyped]
38
+ ).void
39
+ end
26
40
  def initialize(dependency:, dependency_files:, declaring_requirement:)
27
- @dependency = dependency
28
- @dependency_files = dependency_files
41
+ @dependency = dependency
42
+ @dependency_files = dependency_files
29
43
  @declaring_requirement = declaring_requirement
44
+ @declaration_strings = T.let(nil, T.nilable(T::Array[String]))
45
+ @property_value_finder = T.let(nil, T.nilable(Maven::FileParser::PropertyValueFinder))
30
46
  end
31
47
 
48
+ sig { returns(T::Array[String]) }
32
49
  def declaration_strings
33
50
  @declaration_strings ||= fetch_pom_declaration_strings
34
51
  end
35
52
 
53
+ sig { returns(T::Array[Nokogiri::XML::Document]) }
36
54
  def declaration_nodes
37
55
  declaration_strings.map do |declaration_string|
38
56
  Nokogiri::XML(declaration_string)
@@ -41,6 +59,7 @@ module Dependabot
41
59
 
42
60
  private
43
61
 
62
+ sig { returns(Dependabot::DependencyFile) }
44
63
  def declaring_pom
45
64
  filename = declaring_requirement.fetch(:file)
46
65
  declaring_pom = dependency_files.find { |f| f.name == filename }
@@ -49,12 +68,14 @@ module Dependabot
49
68
  raise "No pom found with name #{filename}!"
50
69
  end
51
70
 
71
+ sig { returns(String) }
52
72
  def dependency_name
53
73
  dependency.name
54
74
  end
55
75
 
76
+ sig { returns(T::Array[String]) }
56
77
  def fetch_pom_declaration_strings
57
- deep_find_declarations(declaring_pom.content).select do |nd|
78
+ deep_find_declarations(T.must(declaring_pom.content)).select do |nd|
58
79
  node = Nokogiri::XML(nd)
59
80
  node.remove_namespaces!
60
81
  next false unless node_group_id(node)
@@ -67,7 +88,7 @@ module Dependabot
67
88
 
68
89
  if node.at_xpath("./*/classifier")
69
90
  classifier = evaluated_value(node.at_xpath("./*/classifier").content.strip)
70
- dep_classifier = dependency.requirements.first.dig(:metadata, :classifier)
91
+ dep_classifier = dependency.requirements.first&.dig(:metadata, :classifier)
71
92
  next false if classifier != dep_classifier
72
93
  end
73
94
 
@@ -79,6 +100,7 @@ module Dependabot
79
100
  end
80
101
  end
81
102
 
103
+ sig { params(node: Nokogiri::XML::Document).returns(T.nilable(String)) }
82
104
  def node_group_id(node)
83
105
  return unless node.at_xpath("./*/groupId") || node.at_xpath("./plugin")
84
106
  return "org.apache.maven.plugins" unless node.at_xpath("./*/groupId")
@@ -86,12 +108,14 @@ module Dependabot
86
108
  evaluated_value(node.at_xpath("./*/groupId").content.strip)
87
109
  end
88
110
 
111
+ sig { params(string: String).returns(T::Array[String]) }
89
112
  def deep_find_declarations(string)
90
113
  string.scan(DECLARATION_REGEX).flat_map do |matching_node|
91
- [matching_node, *deep_find_declarations(matching_node[1..-1])]
92
- end
114
+ [matching_node, *deep_find_declarations(matching_node[1..-1].to_s)]
115
+ end.flatten
93
116
  end
94
117
 
118
+ sig { params(node: Nokogiri::XML::Document).returns(T::Boolean) }
95
119
  def declaring_requirement_matches?(node)
96
120
  node_requirement = node.at_css("version")&.content&.strip
97
121
 
@@ -110,11 +134,13 @@ module Dependabot
110
134
  end
111
135
  end
112
136
 
137
+ sig { params(node: Nokogiri::XML::Document).returns(T::Boolean) }
113
138
  def packaging_type_matches?(node)
114
139
  type = declaring_requirement.dig(:metadata, :packaging_type)
115
140
  type == packaging_type(node)
116
141
  end
117
142
 
143
+ sig { params(node: Nokogiri::XML::Document).returns(T::Boolean) }
118
144
  def scope_matches?(node)
119
145
  dependency_type = declaring_requirement.fetch(:groups)
120
146
  node_type = dependency_scope(node) == "test" ? ["test"] : []
@@ -122,6 +148,7 @@ module Dependabot
122
148
  dependency_type == node_type
123
149
  end
124
150
 
151
+ sig { params(dependency_node: Nokogiri::XML::Document).returns(String) }
125
152
  def packaging_type(dependency_node)
126
153
  return "pom" if dependency_node.child.node_name == "parent"
127
154
  return "jar" unless dependency_node.at_xpath("./*/type")
@@ -132,6 +159,7 @@ module Dependabot
132
159
  evaluated_value(packaging_type_content)
133
160
  end
134
161
 
162
+ sig { params(dependency_node: Nokogiri::XML::Document).returns(String) }
135
163
  def dependency_scope(dependency_node)
136
164
  return "compile" unless dependency_node.at_xpath("./*/scope")
137
165
 
@@ -141,12 +169,15 @@ module Dependabot
141
169
  scope_content.empty? ? "compile" : scope_content
142
170
  end
143
171
 
172
+ sig { params(value: String).returns(String) }
144
173
  def evaluated_value(value)
145
174
  return value unless value.match?(Maven::FileParser::PROPERTY_REGEX)
146
175
 
147
- property_name =
148
- value.match(Maven::FileParser::PROPERTY_REGEX)
149
- .named_captures.fetch("property")
176
+ match_data = value.match(Maven::FileParser::PROPERTY_REGEX)
177
+ return value unless match_data
178
+
179
+ property_name = match_data.named_captures.fetch("property")
180
+ return value unless property_name
150
181
 
151
182
  property_value =
152
183
  property_value_finder
@@ -158,11 +189,12 @@ module Dependabot
158
189
  return value unless property_value
159
190
 
160
191
  value.gsub(
161
- value.match(Maven::FileParser::PROPERTY_REGEX).to_s,
192
+ match_data.to_s,
162
193
  property_value
163
194
  )
164
195
  end
165
196
 
197
+ sig { returns(Maven::FileParser::PropertyValueFinder) }
166
198
  def property_value_finder
167
199
  @property_value_finder ||=
168
200
  Maven::FileParser::PropertyValueFinder
@@ -28,8 +28,7 @@ module Dependabot
28
28
  updated_value: String
29
29
  ).returns(T::Array[DependencyFile])
30
30
  end
31
- def update_pomfiles_for_property_change(property_name:, callsite_pom:,
32
- updated_value:)
31
+ def update_pomfiles_for_property_change(property_name:, callsite_pom:, updated_value:)
33
32
  declaration_details = property_value_finder.property_details(
34
33
  property_name: property_name,
35
34
  callsite_pom: callsite_pom
@@ -1,16 +1,20 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "nokogiri"
5
+ require "sorbet-runtime"
5
6
  require "dependabot/file_updaters"
6
7
  require "dependabot/file_updaters/base"
7
8
 
8
9
  module Dependabot
9
10
  module Maven
10
11
  class FileUpdater < Dependabot::FileUpdaters::Base
12
+ extend T::Sig
13
+
11
14
  require_relative "file_updater/declaration_finder"
12
15
  require_relative "file_updater/property_value_updater"
13
16
 
17
+ sig { override.returns(T::Array[Regexp]) }
14
18
  def self.updated_files_regex
15
19
  [
16
20
  /^pom\.xml$/, %r{/pom\.xml$},
@@ -19,8 +23,9 @@ module Dependabot
19
23
  ]
20
24
  end
21
25
 
26
+ sig { override.returns(T::Array[Dependabot::DependencyFile]) }
22
27
  def updated_dependency_files
23
- updated_files = T.let(dependency_files.dup, T.untyped)
28
+ updated_files = T.let(dependency_files.dup, T::Array[Dependabot::DependencyFile])
24
29
 
25
30
  # Loop through each of the changed requirements, applying changes to
26
31
  # all pom and extensions files for that change. Note that the logic
@@ -43,51 +48,77 @@ module Dependabot
43
48
 
44
49
  private
45
50
 
51
+ sig { override.void }
46
52
  def check_required_files
47
53
  raise "No pom.xml!" unless get_original_file("pom.xml")
48
54
  end
49
55
 
56
+ # rubocop:disable Metrics/AbcSize
57
+ sig do
58
+ params(
59
+ original_files: T::Array[Dependabot::DependencyFile],
60
+ dependency: Dependabot::Dependency
61
+ )
62
+ .returns(T::Array[Dependabot::DependencyFile])
63
+ end
50
64
  def update_files_for_dependency(original_files:, dependency:)
51
65
  files = original_files.dup
52
66
 
53
67
  # The UpdateChecker ensures the order of requirements is preserved
54
68
  # when updating, so we can zip them together in new/old pairs.
55
- reqs = dependency.requirements.zip(dependency.previous_requirements)
69
+ reqs = dependency.requirements.zip(dependency.previous_requirements.to_a)
56
70
  .reject { |new_req, old_req| new_req == old_req }
57
71
 
58
72
  # Loop through each changed requirement and update the files
59
73
  reqs.each do |new_req, old_req|
60
- raise "Bad req match" unless new_req[:file] == old_req[:file]
61
- next if new_req[:requirement] == old_req[:requirement]
74
+ raise "Bad req match" unless new_req[:file] == T.must(old_req)[:file]
75
+ next if new_req[:requirement] == T.must(old_req)[:requirement]
62
76
 
63
77
  if new_req.dig(:metadata, :property_name)
64
78
  files = update_pomfiles_for_property_change(files, new_req)
65
79
  pom = files.find { |f| f.name == new_req.fetch(:file) }
66
- files[files.index(pom)] =
67
- remove_property_suffix_in_pom(dependency, pom, old_req)
80
+ files[T.must(files.index(pom))] =
81
+ remove_property_suffix_in_pom(dependency, T.must(pom), T.must(old_req))
68
82
  else
69
83
  file = files.find { |f| f.name == new_req.fetch(:file) }
70
- files[files.index(file)] =
71
- update_version_in_file(dependency, file, old_req, new_req)
84
+ files[T.must(files.index(file))] =
85
+ update_version_in_file(dependency, T.must(file), T.must(old_req), new_req)
72
86
  end
73
87
  end
74
88
 
75
89
  files
76
90
  end
91
+ # rubocop:enable Metrics/AbcSize
77
92
 
93
+ sig do
94
+ params(
95
+ pomfiles: T::Array[Dependabot::DependencyFile],
96
+ req: T::Hash[Symbol, T.untyped]
97
+ )
98
+ .returns(T::Array[Dependabot::DependencyFile])
99
+ end
78
100
  def update_pomfiles_for_property_change(pomfiles, req)
79
101
  property_name = req.fetch(:metadata).fetch(:property_name)
80
102
 
81
103
  PropertyValueUpdater.new(dependency_files: pomfiles)
82
104
  .update_pomfiles_for_property_change(
83
105
  property_name: property_name,
84
- callsite_pom: pomfiles.find { |f| f.name == req.fetch(:file) },
106
+ callsite_pom: T.must(pomfiles.find { |f| f.name == req.fetch(:file) }),
85
107
  updated_value: req.fetch(:requirement)
86
108
  )
87
109
  end
88
110
 
111
+ sig do
112
+ params(
113
+ dependency: Dependabot::Dependency,
114
+ file: Dependabot::DependencyFile,
115
+ previous_req: T::Hash[Symbol, T.untyped],
116
+ requirement: T::Hash[Symbol, T.untyped]
117
+ )
118
+ .returns(Dependabot::DependencyFile)
119
+ end
89
120
  def update_version_in_file(dependency, file, previous_req, requirement)
90
- updated_content = file.content
121
+ updated_content = T.must(file.content)
91
122
 
92
123
  original_file_declarations(dependency, previous_req).each do |old_dec|
93
124
  updated_content = updated_content.gsub(old_dec) do
@@ -100,8 +131,16 @@ module Dependabot
100
131
  updated_file(file: file, content: updated_content)
101
132
  end
102
133
 
134
+ sig do
135
+ params(
136
+ dep: Dependabot::Dependency,
137
+ pom: Dependabot::DependencyFile,
138
+ req: T::Hash[Symbol, T.untyped]
139
+ )
140
+ .returns(Dependabot::DependencyFile)
141
+ end
103
142
  def remove_property_suffix_in_pom(dep, pom, req)
104
- updated_content = pom.content
143
+ updated_content = T.must(pom.content)
105
144
 
106
145
  original_file_declarations(dep, req).each do |old_declaration|
107
146
  updated_content = updated_content.gsub(old_declaration) do |old_dec|
@@ -119,15 +158,27 @@ module Dependabot
119
158
  updated_file(file: pom, content: updated_content)
120
159
  end
121
160
 
161
+ sig do
162
+ params(
163
+ dependency: Dependabot::Dependency,
164
+ requirement: T::Hash[Symbol, T.untyped]
165
+ )
166
+ .returns(T::Array[String])
167
+ end
122
168
  def original_file_declarations(dependency, requirement)
123
169
  declaration_finder(dependency, requirement).declaration_strings
124
170
  end
125
171
 
126
- # The declaration finder may need to make remote calls (to get parent
127
- # POMs if it's searching for the value of a property), so we cache it.
172
+ sig do
173
+ params(
174
+ dependency: Dependabot::Dependency,
175
+ requirement: T::Hash[Symbol, T.untyped]
176
+ )
177
+ .returns(DeclarationFinder)
178
+ end
128
179
  def declaration_finder(dependency, requirement)
129
- @declaration_finders ||= {}
130
- @declaration_finders[dependency.hash + requirement.hash] ||=
180
+ @declaration_finders ||= T.let({}, T.nilable(T::Hash[Integer, DeclarationFinder]))
181
+ @declaration_finders[dependency.hash + requirement.hash] =
131
182
  DeclarationFinder.new(
132
183
  dependency: dependency,
133
184
  declaring_requirement: requirement,
@@ -135,6 +186,14 @@ module Dependabot
135
186
  )
136
187
  end
137
188
 
189
+ sig do
190
+ params(
191
+ old_declaration: String,
192
+ previous_req: T::Hash[Symbol, T.untyped],
193
+ requirement: T::Hash[Symbol, T.untyped]
194
+ )
195
+ .returns(String)
196
+ end
138
197
  def updated_file_declaration(old_declaration, previous_req, requirement)
139
198
  original_req_string = previous_req.fetch(:requirement)
140
199
 
@@ -144,9 +203,12 @@ module Dependabot
144
203
  )
145
204
  end
146
205
 
206
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
147
207
  def original_pomfiles
148
- @original_pomfiles ||=
149
- dependency_files.select { |f| f.name.end_with?("pom.xml") }
208
+ @original_pomfiles ||= T.let(
209
+ dependency_files.select { |f| f.name.end_with?("pom.xml") },
210
+ T.nilable(T::Array[Dependabot::DependencyFile])
211
+ )
150
212
  end
151
213
  end
152
214
  end
@@ -164,6 +164,8 @@ module Dependabot
164
164
 
165
165
  source&.fetch(:url, nil) ||
166
166
  source&.fetch("url") ||
167
+ # TODO: Move central_repo_url method to a more appropriate place
168
+ # Then we can remove T.nilable from pom_fetcher
167
169
  Dependabot::Maven::FileParser::RepositoriesFinder.new(credentials: credentials,
168
170
  pom_fetcher: nil).central_repo_url
169
171
  end