dependabot-gradle 0.317.0 → 0.318.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: acefd7f8494da6724543be0a5dbb4626ce68db9ced94cc52edf1c68afee82aef
4
- data.tar.gz: d06d70680f12ece53e92c3734f9323147652e76aea7d9b069fd39e47a55153eb
3
+ metadata.gz: 4268f828f36a83767b3cef6b863677885bc0f75cedf46bed022dc6e2245f3156
4
+ data.tar.gz: 7334fea2720015456d756a60c58baf745092f818b4186a4cd605d9010f627910
5
5
  SHA512:
6
- metadata.gz: c9bf3b966a9fd7d9ad65b7ad0feb5a43d6eae5bd0600a17c38f30ceaf6f67b308b6d073c5540cfbb90bb93d1cc954b6790cd81e49caa393aa8b2bcb86da4cc6b
7
- data.tar.gz: 8fdd869384b907d818771a579b15a0930db1007ca9f9c967546603639ff3cad00af5781082ef7bd2852ff945d062b48ca03e71eaf8f52f58333948bc9d06d449
6
+ metadata.gz: 03d47d0033440eaf928d36dd13928a5daedea639034e4d9a07b8daa3d9a9da8a98b17925e2a8db02cee8edd826b6c3678b738c452a2ba173dee57a9d9c42ecbb
7
+ data.tar.gz: 6980420566a75d5dbc813d9026fecfd36ec238757e7264f002dbfc03c6a47fed05af8e4ab1f06ee388a9c1157afe8b740aea8a33590792214649aef271c60ca5
@@ -15,6 +15,8 @@ module Dependabot
15
15
  require_relative "file_parser"
16
16
  require_relative "file_fetcher/settings_file_parser"
17
17
 
18
+ SUPPORTED_LOCK_FILE_NAMES = T.let(%w(gradle.lockfile).freeze, T::Array[String])
19
+
18
20
  SUPPORTED_BUILD_FILE_NAMES =
19
21
  T.let(%w(build.gradle build.gradle.kts).freeze, T::Array[String])
20
22
 
@@ -38,6 +40,7 @@ module Dependabot
38
40
  def initialize(source:, credentials:, repo_contents_path: nil, options: {})
39
41
  super
40
42
 
43
+ @lockfile_name = T.let(T.must(SUPPORTED_LOCK_FILE_NAMES.first), String)
41
44
  @buildfile_name = T.let(nil, T.nilable(String))
42
45
  end
43
46
 
@@ -62,8 +65,10 @@ module Dependabot
62
65
 
63
66
  sig { params(root_dir: String).returns(T::Array[DependencyFile]) }
64
67
  def all_buildfiles_in_build(root_dir)
65
- files = [buildfile(root_dir), settings_file(root_dir), version_catalog_file(root_dir)].compact
68
+ files = [buildfile(root_dir), settings_file(root_dir), version_catalog_file(root_dir), lockfile(root_dir)]
69
+ .compact
66
70
  files += subproject_buildfiles(root_dir)
71
+ files += subproject_lockfiles(root_dir)
67
72
  files += dependency_script_plugins(root_dir)
68
73
  files + included_builds(root_dir)
69
74
  .flat_map { |dir| all_buildfiles_in_build(dir) }
@@ -93,6 +98,24 @@ module Dependabot
93
98
  Pathname.new(File.join(parts)).cleanpath.to_path
94
99
  end
95
100
 
101
+ sig { params(root_dir: String).returns(T::Array[DependencyFile]) }
102
+ def subproject_lockfiles(root_dir)
103
+ return [] unless settings_file(root_dir)
104
+
105
+ subproject_paths =
106
+ SettingsFileParser
107
+ .new(settings_file: T.must(settings_file(root_dir)))
108
+ .subproject_paths
109
+
110
+ subproject_paths.filter_map do |path|
111
+ lockfile_path = File.join(root_dir, path, @lockfile_name)
112
+ fetch_file_from_host(lockfile_path)
113
+ rescue Dependabot::DependencyFileNotFound
114
+ # Gradle itself doesn't worry about missing subprojects, so we don't
115
+ nil
116
+ end
117
+ end
118
+
96
119
  sig { params(root_dir: String).returns(T::Array[DependencyFile]) }
97
120
  def subproject_buildfiles(root_dir)
98
121
  return [] unless settings_file(root_dir)
@@ -155,6 +178,11 @@ module Dependabot
155
178
  false
156
179
  end
157
180
 
181
+ sig { params(dir: String).returns(T.nilable(DependencyFile)) }
182
+ def lockfile(dir)
183
+ fetch_file_if_present(File.join(dir, @lockfile_name))
184
+ end
185
+
158
186
  sig { params(dir: String).returns(T.nilable(DependencyFile)) }
159
187
  def buildfile(dir)
160
188
  file = find_first(dir, SUPPORTED_BUILD_FILE_NAMES) || return
@@ -0,0 +1,110 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ require "sorbet-runtime"
5
+ require "shellwords"
6
+
7
+ require "dependabot/gradle/file_parser"
8
+ require "dependabot/gradle/file_updater"
9
+
10
+ module Dependabot
11
+ module Gradle
12
+ class FileUpdater
13
+ class LockfileUpdater
14
+ extend T::Sig
15
+
16
+ sig { params(dependency_files: T::Array[Dependabot::DependencyFile]).void }
17
+ def initialize(dependency_files:)
18
+ @dependency_files = dependency_files
19
+ end
20
+
21
+ sig { params(build_file: Dependabot::DependencyFile).returns(T::Array[Dependabot::DependencyFile]) }
22
+ def update_lockfiles(build_file)
23
+ local_lockfiles = dependency_files.select do |file|
24
+ file.directory == build_file.directory && file.name.end_with?(".lockfile")
25
+ end
26
+
27
+ # If we don't have any lockfiles in the build files don't generate one
28
+ return dependency_files unless local_lockfiles.any?
29
+
30
+ updated_files = dependency_files.dup
31
+ SharedHelpers.in_a_temporary_directory do |temp_dir|
32
+ populate_temp_directory(temp_dir)
33
+ cwd = File.join(temp_dir, build_file.directory, build_file.name)
34
+ cwd = File.dirname(cwd)
35
+
36
+ # Create gradle.properties file with proxy settings
37
+ # Would prefer to use command line arguments, but they don't work.
38
+ properties_filename = File.join(temp_dir, build_file.directory, "gradle.properties")
39
+ write_properties_file(properties_filename)
40
+
41
+ command_parts = [
42
+ "gradle",
43
+ "dependencies",
44
+ "--no-daemon",
45
+ "--write-locks"
46
+ ]
47
+ command = Shellwords.join(command_parts)
48
+
49
+ Dir.chdir(cwd) do
50
+ SharedHelpers.run_shell_command(command, cwd: cwd)
51
+ update_lockfiles_content(temp_dir, local_lockfiles, updated_files)
52
+ rescue SharedHelpers::HelperSubprocessFailed => e
53
+ puts "Failed to update lockfiles: #{e.message}"
54
+ return updated_files
55
+ end
56
+ end
57
+ updated_files
58
+ end
59
+
60
+ sig do
61
+ params(
62
+ temp_dir: T.any(Pathname, String),
63
+ local_lockfiles: T::Array[Dependabot::DependencyFile],
64
+ updated_lockfiles: T::Array[Dependabot::DependencyFile]
65
+ ).void
66
+ end
67
+ def update_lockfiles_content(temp_dir, local_lockfiles, updated_lockfiles)
68
+ local_lockfiles.each do |file|
69
+ f_content = File.read(File.join(temp_dir, file.directory, file.name))
70
+ tmp_file = file.dup
71
+ tmp_file.content = f_content
72
+ updated_lockfiles[T.must(updated_lockfiles.index(file))] = tmp_file
73
+ end
74
+ end
75
+
76
+ sig { params(temp_dir: T.any(Pathname, String)).void }
77
+ def populate_temp_directory(temp_dir)
78
+ @dependency_files.each do |file|
79
+ in_path_name = File.join(temp_dir, file.directory, file.name)
80
+ FileUtils.mkdir_p(File.dirname(in_path_name))
81
+ File.write(in_path_name, file.content)
82
+ end
83
+ end
84
+
85
+ sig { params(file_name: String).void }
86
+ def write_properties_file(file_name) # rubocop:disable Metrics/PerceivedComplexity
87
+ http_proxy = ENV.fetch("HTTP_PROXY", nil)
88
+ https_proxy = ENV.fetch("HTTPS_PROXY", nil)
89
+ http_split = http_proxy&.split(":")
90
+ https_split = https_proxy&.split(":")
91
+ http_proxy_host = http_split&.fetch(1, nil)&.gsub("//", "") || "host.docker.internal"
92
+ https_proxy_host = https_split&.fetch(1, nil)&.gsub("//", "") || "host.docker.internal"
93
+ http_proxy_port = http_split&.fetch(2) || "1080"
94
+ https_proxy_port = https_split&.fetch(2) || "1080"
95
+ properties_content = "
96
+ systemProp.http.proxyHost=#{http_proxy_host}
97
+ systemProp.http.proxyPort=#{http_proxy_port}
98
+ systemProp.https.proxyHost=#{https_proxy_host}
99
+ systemProp.https.proxyPort=#{https_proxy_port}"
100
+ File.write(file_name, properties_content)
101
+ end
102
+
103
+ private
104
+
105
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
106
+ attr_reader :dependency_files
107
+ end
108
+ end
109
+ end
110
+ end
@@ -1,6 +1,8 @@
1
- # typed: true
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
5
+
4
6
  require "dependabot/gradle/file_updater"
5
7
  require "dependabot/gradle/file_parser/property_value_finder"
6
8
 
@@ -8,23 +10,39 @@ module Dependabot
8
10
  module Gradle
9
11
  class FileUpdater
10
12
  class PropertyValueUpdater
13
+ extend T::Sig
14
+
15
+ sig { params(dependency_files: T::Array[DependencyFile]).void }
11
16
  def initialize(dependency_files:)
12
17
  @dependency_files = dependency_files
18
+ @property_value_finder = T.let(nil, T.nilable(Gradle::FileParser::PropertyValueFinder))
13
19
  end
14
20
 
21
+ sig do
22
+ params(
23
+ property_name: String,
24
+ callsite_buildfile: DependencyFile,
25
+ previous_value: String,
26
+ updated_value: String
27
+ )
28
+ .returns(T::Array[DependencyFile])
29
+ end
15
30
  def update_files_for_property_change(property_name:,
16
31
  callsite_buildfile:,
17
32
  previous_value:,
18
33
  updated_value:)
19
- declaration_details = property_value_finder.property_details(
20
- property_name: property_name,
21
- callsite_buildfile: callsite_buildfile
34
+ declaration_details = T.let(
35
+ property_value_finder.property_details(
36
+ property_name: property_name,
37
+ callsite_buildfile: callsite_buildfile
38
+ ),
39
+ T::Hash[Symbol, String]
22
40
  )
23
41
  declaration_string = declaration_details.fetch(:declaration_string)
24
42
  filename = declaration_details.fetch(:file)
25
43
 
26
- file_to_update = dependency_files.find { |f| f.name == filename }
27
- updated_content = file_to_update.content.sub(
44
+ file_to_update = T.must(dependency_files.find { |f| f.name == filename })
45
+ updated_content = T.must(file_to_update.content).sub(
28
46
  declaration_string,
29
47
  declaration_string.sub(
30
48
  previous_value_regex(previous_value),
@@ -33,7 +51,7 @@ module Dependabot
33
51
  )
34
52
 
35
53
  updated_files = dependency_files.dup
36
- updated_files[updated_files.index(file_to_update)] =
54
+ updated_files[T.must(updated_files.index(file_to_update))] =
37
55
  update_file(file: file_to_update, content: updated_content)
38
56
 
39
57
  updated_files
@@ -41,20 +59,24 @@ module Dependabot
41
59
 
42
60
  private
43
61
 
62
+ sig { returns(T::Array[DependencyFile]) }
44
63
  attr_reader :dependency_files
45
64
 
65
+ sig { returns(Gradle::FileParser::PropertyValueFinder) }
46
66
  def property_value_finder
47
67
  @property_value_finder ||=
48
68
  Gradle::FileParser::PropertyValueFinder
49
69
  .new(dependency_files: dependency_files)
50
70
  end
51
71
 
72
+ sig { params(file: DependencyFile, content: String).returns(DependencyFile) }
52
73
  def update_file(file:, content:)
53
74
  updated_file = file.dup
54
75
  updated_file.content = content
55
76
  updated_file
56
77
  end
57
78
 
79
+ sig { params(previous_value: String).returns(Regexp) }
58
80
  def previous_value_regex(previous_value)
59
81
  /(?<=['"])#{Regexp.quote(previous_value)}(?=['"])/
60
82
  end
@@ -1,4 +1,4 @@
1
- # typed: true
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
@@ -14,9 +14,11 @@ module Dependabot
14
14
 
15
15
  require_relative "file_updater/dependency_set_updater"
16
16
  require_relative "file_updater/property_value_updater"
17
+ require_relative "file_updater/lockfile_updater"
17
18
 
18
- SUPPORTED_BUILD_FILE_NAMES = %w(build.gradle build.gradle.kts).freeze
19
+ SUPPORTED_BUILD_FILE_NAMES = %w(build.gradle build.gradle.kts gradle.lockfile).freeze
19
20
 
21
+ sig { override.returns(T::Array[Regexp]) }
20
22
  def self.updated_files_regex
21
23
  [
22
24
  # Matches build.gradle or build.gradle.kts in root directory
@@ -26,10 +28,12 @@ module Dependabot
26
28
  # Matches settings.gradle or settings.gradle.kts in root or any subdirectory
27
29
  %r{(^|.*/)settings\.gradle(\.kts)?$},
28
30
  # Matches dependencies.gradle in root or any subdirectory
29
- %r{(^|.*/)dependencies\.gradle$}
31
+ %r{(^|.*/)dependencies\.gradle$},
32
+ %r{(^|.*/)?gradle.lockfile$}
30
33
  ]
31
34
  end
32
35
 
36
+ sig { override.returns(T::Array[::Dependabot::DependencyFile]) }
33
37
  def updated_dependency_files
34
38
  updated_files = buildfiles.dup
35
39
 
@@ -53,30 +57,38 @@ module Dependabot
53
57
 
54
58
  private
55
59
 
60
+ sig { override.void }
56
61
  def check_required_files
57
62
  raise "No build.gradle or build.gradle.kts!" if dependency_files.empty?
58
63
  end
59
64
 
65
+ sig { void }
60
66
  def original_file
61
67
  dependency_files.find do |f|
62
68
  SUPPORTED_BUILD_FILE_NAMES.include?(f.name)
63
69
  end
64
70
  end
65
71
 
72
+ # rubocop:disable Metrics/AbcSize
73
+ # rubocop:disable Metrics/CyclomaticComplexity
74
+ # rubocop:disable Metrics/PerceivedComplexity
75
+ sig do
76
+ params(buildfiles: T::Array[Dependabot::DependencyFile], dependency: Dependabot::Dependency)
77
+ .returns(T::Array[Dependabot::DependencyFile])
78
+ end
66
79
  def update_buildfiles_for_dependency(buildfiles:, dependency:)
67
80
  files = buildfiles.dup
68
81
 
69
82
  # The UpdateChecker ensures the order of requirements is preserved
70
83
  # when updating, so we can zip them together in new/old pairs.
71
- reqs = dependency.requirements.zip(dependency.previous_requirements)
84
+ reqs = dependency.requirements.zip(T.must(dependency.previous_requirements))
72
85
  .reject { |new_req, old_req| new_req == old_req }
73
-
74
86
  # Loop through each changed requirement and update the buildfiles
75
87
  reqs.each do |new_req, old_req|
76
- raise "Bad req match" unless new_req[:file] == old_req[:file]
77
- next if new_req[:requirement] == old_req[:requirement]
88
+ raise "Bad req match" if old_req.nil? || T.let(new_req[:file], String) != T.let(old_req[:file], String)
89
+ next if T.let(new_req[:requirement], String) == T.let(old_req[:requirement], String)
78
90
 
79
- buildfile = files.find { |f| f.name == new_req.fetch(:file) }
91
+ buildfile = files.find { |f| f.name == T.let(new_req.fetch(:file), String) }
80
92
 
81
93
  # Currently, Dependabot assumes that Gradle projects using Gradle submodules are all in a single
82
94
  # repo. However, some projects are actually using git submodule references for the Gradle submodules.
@@ -87,65 +99,100 @@ module Dependabot
87
99
 
88
100
  raise DependencyFileNotResolvable, "No build file found to update the dependency" if buildfile.nil?
89
101
 
90
- if new_req.dig(:metadata, :property_name)
102
+ metadata = T.let(new_req[:metadata], T.nilable(T::Hash[Symbol, T.untyped]))
103
+ if T.let(metadata&.[](:property_name), T.nilable(String))
91
104
  files = update_files_for_property_change(files, old_req, new_req)
92
- elsif new_req.dig(:metadata, :dependency_set)
105
+ elsif T.let(metadata&.[](:dependency_set), T.nilable(T::Hash[Symbol, String]))
93
106
  files = update_files_for_dep_set_change(files, old_req, new_req)
94
107
  else
95
- files[files.index(buildfile)] =
96
- update_version_in_buildfile(
97
- dependency,
98
- buildfile,
99
- old_req,
100
- new_req
101
- )
108
+ files[T.must(files.index(buildfile))] = update_version_in_buildfile(dependency, buildfile, old_req, new_req)
109
+ end
110
+
111
+ next unless Dependabot::Experiments.enabled?(:gradle_lockfile_updater)
112
+
113
+ lockfile_updater = LockfileUpdater.new(dependency_files: files)
114
+ lockfiles = lockfile_updater.update_lockfiles(buildfile)
115
+ lockfiles.each do |lockfile|
116
+ existing_file = files.find { |f| f.name == lockfile.name && f.directory == lockfile.directory }
117
+ if existing_file.nil?
118
+ files << lockfile
119
+ else
120
+ files[T.must(files.index(existing_file))] = lockfile
121
+ end
102
122
  end
103
123
  end
104
124
 
105
125
  files
106
126
  end
107
-
127
+ # rubocop:enable Metrics/PerceivedComplexity
128
+ # rubocop:enable Metrics/CyclomaticComplexity
129
+ # rubocop:enable Metrics/AbcSize
130
+
131
+ sig do
132
+ params(
133
+ buildfiles: T::Array[Dependabot::DependencyFile],
134
+ old_req: T::Hash[Symbol, T.untyped],
135
+ new_req: T::Hash[Symbol, T.untyped]
136
+ )
137
+ .returns(T::Array[Dependabot::DependencyFile])
138
+ end
108
139
  def update_files_for_property_change(buildfiles, old_req, new_req)
109
140
  files = buildfiles.dup
110
- property_name = new_req.fetch(:metadata).fetch(:property_name)
111
- buildfile = files.find { |f| f.name == new_req.fetch(:file) }
141
+ metadata = T.let(new_req.fetch(:metadata), T::Hash[Symbol, T.untyped])
142
+ property_name = T.let(metadata.fetch(:property_name), String)
143
+ file = T.let(new_req.fetch(:file), String)
144
+ buildfile = T.must(files.find { |f| f.name == file })
112
145
 
113
146
  PropertyValueUpdater.new(dependency_files: files)
114
147
  .update_files_for_property_change(
115
148
  property_name: property_name,
116
149
  callsite_buildfile: buildfile,
117
- previous_value: old_req.fetch(:requirement),
118
- updated_value: new_req.fetch(:requirement)
150
+ previous_value: T.let(old_req.fetch(:requirement), String),
151
+ updated_value: T.let(new_req.fetch(:requirement), String)
119
152
  )
120
153
  end
121
154
 
155
+ sig do
156
+ params(
157
+ buildfiles: T::Array[Dependabot::DependencyFile],
158
+ old_req: T::Hash[Symbol, T.untyped],
159
+ new_req: T::Hash[Symbol, T.untyped]
160
+ )
161
+ .returns(T::Array[Dependabot::DependencyFile])
162
+ end
122
163
  def update_files_for_dep_set_change(buildfiles, old_req, new_req)
123
164
  files = buildfiles.dup
124
- dependency_set = new_req.fetch(:metadata).fetch(:dependency_set)
125
- buildfile = files.find { |f| f.name == new_req.fetch(:file) }
165
+ metadata = T.let(new_req.fetch(:metadata), T::Hash[Symbol, T.untyped])
166
+ dependency_set = T.let(metadata.fetch(:dependency_set), T::Hash[Symbol, String])
167
+ buildfile = T.must(files.find { |f| f.name == T.let(new_req.fetch(:file), String) })
126
168
 
127
169
  DependencySetUpdater.new(dependency_files: files)
128
170
  .update_files_for_dep_set_change(
129
171
  dependency_set: dependency_set,
130
172
  buildfile: buildfile,
131
- previous_requirement: old_req.fetch(:requirement),
132
- updated_requirement: new_req.fetch(:requirement)
173
+ previous_requirement: T.let(old_req.fetch(:requirement), String),
174
+ updated_requirement: T.let(new_req.fetch(:requirement), String)
133
175
  )
134
176
  end
135
177
 
178
+ sig do
179
+ params(
180
+ dependency: Dependabot::Dependency,
181
+ buildfile: Dependabot::DependencyFile,
182
+ previous_req: T::Hash[Symbol, T.untyped],
183
+ requirement: T::Hash[Symbol, T.untyped]
184
+ )
185
+ .returns(Dependabot::DependencyFile)
186
+ end
136
187
  def update_version_in_buildfile(dependency, buildfile, previous_req,
137
188
  requirement)
138
- original_content = buildfile.content.dup
189
+ original_content = T.must(buildfile.content.dup)
139
190
 
140
191
  updated_content =
141
192
  original_buildfile_declarations(dependency, previous_req).reduce(original_content) do |content, declaration|
142
193
  content.gsub(
143
194
  declaration,
144
- updated_buildfile_declaration(
145
- declaration,
146
- previous_req,
147
- requirement
148
- )
195
+ updated_buildfile_declaration(declaration, previous_req, requirement)
149
196
  )
150
197
  end
151
198
 
@@ -154,18 +201,26 @@ module Dependabot
154
201
  updated_file(file: buildfile, content: updated_content)
155
202
  end
156
203
 
204
+ # rubocop:disable Metrics/AbcSize
205
+ sig do
206
+ params(
207
+ dependency: Dependabot::Dependency,
208
+ requirement: T::Hash[Symbol, T.untyped]
209
+ ).returns(T::Array[String])
210
+ end
157
211
  def original_buildfile_declarations(dependency, requirement)
158
212
  # This implementation is limited to declarations that appear on a
159
213
  # single line.
160
- buildfile = buildfiles.find { |f| f.name == requirement.fetch(:file) }
161
- buildfile.content.lines.select do |line|
214
+ buildfile = T.must(buildfiles.find { |f| f.name == T.let(requirement.fetch(:file), String) })
215
+
216
+ T.must(buildfile.content).lines.select do |line|
162
217
  line = evaluate_properties(line, buildfile)
163
218
  line = line.gsub(%r{(?<=^|\s)//.*$}, "")
164
219
 
165
220
  if dependency.name.include?(":")
166
- next false unless line.include?(dependency.name.split(":").first)
167
- next false unless line.include?(dependency.name.split(":").last)
168
- elsif requirement.fetch(:file).end_with?(".toml")
221
+ dep_parts = dependency.name.split(":")
222
+ next false unless line.include?(T.must(dep_parts.first)) || line.include?(T.must(dep_parts.last))
223
+ elsif T.let(requirement.fetch(:file), String).end_with?(".toml")
169
224
  next false unless line.include?(dependency.name)
170
225
  else
171
226
  name_regex_value = /['"]#{Regexp.quote(dependency.name)}['"]/
@@ -173,18 +228,20 @@ module Dependabot
173
228
  next false unless line.match?(name_regex)
174
229
  end
175
230
 
176
- line.include?(requirement.fetch(:requirement))
231
+ line.include?(T.let(requirement.fetch(:requirement), String))
177
232
  end
178
233
  end
234
+ # rubocop:enable Metrics/AbcSize
179
235
 
236
+ sig { params(string: String, buildfile: Dependabot::DependencyFile).returns(String) }
180
237
  def evaluate_properties(string, buildfile)
181
238
  result = string.dup
182
239
 
183
240
  string.scan(Gradle::FileParser::PROPERTY_REGEX) do
184
241
  prop_name = T.must(Regexp.last_match).named_captures.fetch("property_name")
185
- property_value = property_value_finder.property_value(
186
- property_name: prop_name,
187
- callsite_buildfile: buildfile
242
+ property_value = T.let(
243
+ property_value_finder.property_value(property_name: prop_name, callsite_buildfile: buildfile),
244
+ T.nilable(String)
188
245
  )
189
246
  next unless property_value
190
247
 
@@ -194,23 +251,31 @@ module Dependabot
194
251
  result
195
252
  end
196
253
 
254
+ sig { returns(Gradle::FileParser::PropertyValueFinder) }
197
255
  def property_value_finder
198
- @property_value_finder ||=
199
- Gradle::FileParser::PropertyValueFinder
200
- .new(dependency_files: dependency_files)
256
+ @property_value_finder ||= T.let(
257
+ Gradle::FileParser::PropertyValueFinder.new(dependency_files: dependency_files),
258
+ T.nilable(Gradle::FileParser::PropertyValueFinder)
259
+ )
201
260
  end
202
261
 
262
+ sig do
263
+ params(
264
+ original_buildfile_declaration: String,
265
+ previous_req: T::Hash[Symbol, T.untyped],
266
+ requirement: T::Hash[Symbol, T.untyped]
267
+ ).returns(String)
268
+ end
203
269
  def updated_buildfile_declaration(original_buildfile_declaration, previous_req, requirement)
204
- original_req_string = previous_req.fetch(:requirement)
270
+ original_req_string = T.let(previous_req.fetch(:requirement), String)
271
+ new_req_string = T.let(requirement.fetch(:requirement), String)
205
272
 
206
- original_buildfile_declaration.gsub(
207
- original_req_string,
208
- requirement.fetch(:requirement)
209
- )
273
+ original_buildfile_declaration.gsub(original_req_string, new_req_string)
210
274
  end
211
275
 
276
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
212
277
  def buildfiles
213
- @buildfiles ||= dependency_files.reject(&:support_file?)
278
+ @buildfiles ||= T.let(dependency_files.reject(&:support_file?), T.nilable(T::Array[Dependabot::DependencyFile]))
214
279
  end
215
280
  end
216
281
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-gradle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.317.0
4
+ version: 0.318.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
@@ -15,28 +15,28 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.317.0
18
+ version: 0.318.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.317.0
25
+ version: 0.318.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: dependabot-maven
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 0.317.0
32
+ version: 0.318.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.317.0
39
+ version: 0.318.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: debug
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -263,6 +263,7 @@ files:
263
263
  - lib/dependabot/gradle/file_parser/repositories_finder.rb
264
264
  - lib/dependabot/gradle/file_updater.rb
265
265
  - lib/dependabot/gradle/file_updater/dependency_set_updater.rb
266
+ - lib/dependabot/gradle/file_updater/lockfile_updater.rb
266
267
  - lib/dependabot/gradle/file_updater/property_value_updater.rb
267
268
  - lib/dependabot/gradle/language.rb
268
269
  - lib/dependabot/gradle/metadata_finder.rb
@@ -279,7 +280,7 @@ licenses:
279
280
  - MIT
280
281
  metadata:
281
282
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
282
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.317.0
283
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.318.0
283
284
  rdoc_options: []
284
285
  require_paths:
285
286
  - lib