dependabot-gradle 0.351.0 → 0.352.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: 30dce402f6a1e1d5d480105632edb8e3d2bfeac81934edb44f31792ee613546a
4
- data.tar.gz: db954fea128d5474b45d3b21996387d80818456cea82f563429872d8a9d2d8cc
3
+ metadata.gz: 9167450605c90c479bfbd32b2f4a0e68458e25a411cc58cee54a380870c3d073
4
+ data.tar.gz: 6162f15731d05b8d9f041d3101d39b47071caaac5e9b78e3b4ae1393d1fb0dfb
5
5
  SHA512:
6
- metadata.gz: e5586d92c24df693f36ae79fadf7bf271d23acc62ff0e513b28e147c32e349b64593b2153355d6e995956d9b39f5430e91bbbb0991d3013e095a0dbdb6b88eaf
7
- data.tar.gz: 71f5a0b55f4613257c37def935459077338c767a715fd246ffab3125661c2c709f725375a5a7972440b733bd23d865324bf306852eed6ca796272ddce62f4697
6
+ metadata.gz: 772120fb47bab993074d800657abff25723b064f4b4b15b776ed26acc41bb87292fbc8bf092d1793527d07295f80e9418fc4defa20ee9e21a356f8b4a2d949a2
7
+ data.tar.gz: 643749b490126dac40f3602a6d7bb428e9072897c0945b6985ddd9163a17460685dd1830ef69fb392343cea06d1e51dcfd15ed225a81b6e26b048e7e4e1f1f1c
@@ -37,6 +37,9 @@ module Dependabot
37
37
  )
38
38
  end
39
39
 
40
+ # rubocop:disable Metrics/AbcSize
41
+ # rubocop:disable Metrics/MethodLength
42
+ # rubocop:disable Metrics/PerceivedComplexity
40
43
  sig { params(build_file: Dependabot::DependencyFile).returns(T::Array[Dependabot::DependencyFile]) }
41
44
  def update_files(build_file)
42
45
  # We only run this updater if it's a distribution dependency
@@ -49,29 +52,57 @@ module Dependabot
49
52
  # If we don't have any files in the build files don't generate one
50
53
  return [] unless local_files.any?
51
54
 
55
+ # we only run this updater if the build file has a requirement for this dependency
56
+ target_requirements = dependency.requirements.select do |req|
57
+ T.let(req[:file], String) == build_file.name
58
+ end
59
+ return [] unless target_requirements.any?
60
+
52
61
  updated_files = dependency_files.dup
53
62
  SharedHelpers.in_a_temporary_directory do |temp_dir|
54
63
  populate_temp_directory(temp_dir)
55
64
  cwd = File.join(temp_dir, base_path(build_file))
56
65
 
57
- # Create gradle.properties file with proxy settings
58
- # Would prefer to use command line arguments, but they don't work.
59
- properties_filename = File.join(temp_dir, build_file.directory, "gradle.properties")
60
- write_properties_file(properties_filename)
61
-
62
- command_parts = %w(gradle --no-daemon --stacktrace) + command_args
63
- command = Shellwords.join(command_parts)
66
+ has_local_script = File.exist?(File.join(cwd, "./gradlew"))
67
+ command_parts = %w(--no-daemon --stacktrace) + command_args(target_requirements)
68
+ command = Shellwords.join([has_local_script ? "./gradlew" : "gradle"] + command_parts)
64
69
 
65
70
  Dir.chdir(cwd) do
66
- SharedHelpers.run_shell_command(command, cwd: cwd)
71
+ FileUtils.chmod("+x", "./gradlew") if has_local_script
72
+
73
+ properties_file = File.join(cwd, "gradle/wrapper/gradle-wrapper.properties")
74
+ validate_option = get_validate_distribution_url_option(properties_file)
75
+ env = { "JAVA_OPTS" => proxy_args.join(" ") } # set proxy for gradle execution
76
+
77
+ begin
78
+ # first attempt: run the wrapper task via the local gradle wrapper (if present)
79
+ # `gradle-wrapper.jar` might be too old to run on host's Java version
80
+ SharedHelpers.run_shell_command(command, cwd: cwd, env: env)
81
+ rescue SharedHelpers::HelperSubprocessFailed => e
82
+ raise e unless has_local_script # already field with system one, there is no point to retry
83
+
84
+ Dependabot.logger.warn("Running #{command} failed, retrying first with system Gradle: #{e.message}")
85
+
86
+ # second attempt: run the wrapper task via system gradle and then retry via local wrapper
87
+ system_command = Shellwords.join(["gradle"] + command_parts)
88
+ SharedHelpers.run_shell_command(system_command, cwd: cwd, env: env) # run via system gradle
89
+ SharedHelpers.run_shell_command(command, cwd: cwd, env: env) # retry via local wrapper
90
+ end
91
+
92
+ # Restore previous validateDistributionUrl option if it existed
93
+ override_validate_distribution_url_option(properties_file, validate_option)
94
+
67
95
  update_files_content(temp_dir, local_files, updated_files)
68
96
  rescue SharedHelpers::HelperSubprocessFailed => e
69
- puts "Failed to update files: #{e.message}"
97
+ Dependabot.logger.error("Failed to update files: #{e.message}")
70
98
  return updated_files
71
99
  end
72
100
  end
73
101
  updated_files
74
102
  end
103
+ # rubocop:enable Metrics/AbcSize
104
+ # rubocop:enable Metrics/MethodLength
105
+ # rubocop:enable Metrics/PerceivedComplexity
75
106
 
76
107
  private
77
108
 
@@ -80,12 +111,20 @@ module Dependabot
80
111
  @target_files.any? { |r| "/#{file.name}".end_with?(r) }
81
112
  end
82
113
 
83
- sig { returns(T::Array[String]) }
84
- def command_args
85
- version = T.let(dependency.requirements[0]&.[](:requirement), String)
86
- checksum = T.let(dependency.requirements[1]&.[](:requirement), String) if dependency.requirements.size > 1
87
-
88
- args = %W(wrapper --no-validate-url --gradle-version #{version})
114
+ sig { params(requirements: T::Array[T::Hash[Symbol, T.untyped]]).returns(T::Array[String]) }
115
+ def command_args(requirements)
116
+ version = T.let(requirements[0]&.[](:requirement), String)
117
+ checksum = T.let(requirements[1]&.[](:requirement), String) if dependency.requirements.size > 1
118
+ distribution_url = T.let(requirements[0]&.[](:source), T::Hash[Symbol, String])[:url]
119
+ distribution_type = distribution_url&.match(/\b(bin|all)\b/)&.captures&.first
120
+
121
+ # --no-validate-url is required to bypass HTTP proxy issues when running ./gradlew
122
+ # This prevents validation failures during the wrapper update process
123
+ # Note: This temporarily sets validateDistributionUrl=false in gradle-wrapper.properties
124
+ # The original value is restored after the wrapper task completes
125
+ # see method `get_validate_distribution_url_option` for more details
126
+ args = %W(wrapper --gradle-version #{version} --no-validate-url) # see
127
+ args += %W(--distribution-type #{distribution_type}) if distribution_type
89
128
  args += %W(--gradle-distribution-sha256-sum #{checksum}) if checksum
90
129
  args
91
130
  end
@@ -135,8 +174,35 @@ module Dependabot
135
174
  end
136
175
  end
137
176
 
138
- sig { params(file_name: String).void }
139
- def write_properties_file(file_name) # rubocop:disable Metrics/PerceivedComplexity
177
+ # This is a consequence of the lack of proper proxy support in Gradle Wrapper
178
+ # During the update process, Gradle Wrapper logic will try to validate the distribution URL
179
+ # by performing an HTTP request. If the environment requires a proxy, this validation will fail
180
+ # We need to add the `--no-validate-url` the commandline args to disable this validation
181
+ # However, this change is persistent in the `gradle-wrapper.properties` file
182
+ # To avoid side effects, we read the existing value before the update and restore it afterward
183
+ sig { params(properties_file: T.any(Pathname, String)).returns(T.nilable(String)) }
184
+ def get_validate_distribution_url_option(properties_file)
185
+ return nil unless File.exist?(properties_file)
186
+
187
+ properties_content = File.read(properties_file)
188
+ properties_content.match(/^validateDistributionUrl=(.*)$/)&.captures&.first
189
+ end
190
+
191
+ sig { params(properties_file: T.any(Pathname, String), value: T.nilable(String)).void }
192
+ def override_validate_distribution_url_option(properties_file, value)
193
+ return unless File.exist?(properties_file)
194
+
195
+ properties_content = File.read(properties_file)
196
+ updated_content = properties_content.gsub(
197
+ /^validateDistributionUrl=(.*)\n/,
198
+ value ? "validateDistributionUrl=#{value}\n" : ""
199
+ )
200
+ File.write(properties_file, updated_content)
201
+ end
202
+
203
+ # rubocop:disable Metrics/PerceivedComplexity
204
+ sig { returns(T::Array[String]) }
205
+ def proxy_args
140
206
  http_proxy = ENV.fetch("HTTP_PROXY", nil)
141
207
  https_proxy = ENV.fetch("HTTPS_PROXY", nil)
142
208
  http_split = http_proxy&.split(":")
@@ -145,13 +211,15 @@ module Dependabot
145
211
  https_proxy_host = https_split&.fetch(1, nil)&.gsub("//", "") || "host.docker.internal"
146
212
  http_proxy_port = http_split&.fetch(2) || "1080"
147
213
  https_proxy_port = https_split&.fetch(2) || "1080"
148
- properties_content = "
149
- systemProp.http.proxyHost=#{http_proxy_host}
150
- systemProp.http.proxyPort=#{http_proxy_port}
151
- systemProp.https.proxyHost=#{https_proxy_host}
152
- systemProp.https.proxyPort=#{https_proxy_port}"
153
- File.write(file_name, properties_content)
214
+
215
+ args = []
216
+ args += %W(-Dhttp.proxyHost=#{http_proxy_host}) if http_proxy_host
217
+ args += %W(-Dhttp.proxyPort=#{http_proxy_port}) if http_proxy_port
218
+ args += %W(-Dhttps.proxyHost=#{https_proxy_host}) if https_proxy_host
219
+ args += %W(-Dhttps.proxyPort=#{https_proxy_port}) if https_proxy_port
220
+ args
154
221
  end
222
+ # rubocop:enable Metrics/PerceivedComplexity
155
223
 
156
224
  sig { returns(T::Array[Dependabot::DependencyFile]) }
157
225
  attr_reader :dependency_files
@@ -56,9 +56,7 @@ module Dependabot
56
56
  end
57
57
 
58
58
  # rubocop:disable Metrics/AbcSize
59
- # rubocop:disable Metrics/CyclomaticComplexity
60
59
  # rubocop:disable Metrics/PerceivedComplexity
61
- # rubocop:disable Metrics/MethodLength
62
60
  sig do
63
61
  params(buildfiles: T::Array[Dependabot::DependencyFile], dependency: Dependabot::Dependency)
64
62
  .returns(T::Array[Dependabot::DependencyFile])
@@ -103,33 +101,42 @@ module Dependabot
103
101
  end
104
102
 
105
103
  # runs native updaters (e.g. wrapper, lockfile) on relevant build files updated
106
- updated_files = T.let([], T::Array[Dependabot::DependencyFile])
107
- buildfiles_processed.each do |_, buildfile|
108
- if Dependabot::Experiments.enabled?(:gradle_wrapper_updater)
104
+ if Dependabot::Experiments.enabled?(:gradle_wrapper_updater)
105
+ buildfiles_processed.each_value do |buildfile|
109
106
  wrapper_updater = WrapperUpdater.new(dependency_files: files, dependency: dependency)
110
- updated_files += wrapper_updater.update_files(buildfile)
107
+ updated_files = wrapper_updater.update_files(buildfile)
108
+ replace_updated_files(files, updated_files)
111
109
  end
112
- if Dependabot::Experiments.enabled?(:gradle_lockfile_updater)
110
+ end
111
+ if Dependabot::Experiments.enabled?(:gradle_lockfile_updater)
112
+ buildfiles_processed.each_value do |buildfile|
113
113
  lockfile_updater = LockfileUpdater.new(dependency_files: files)
114
- updated_files += lockfile_updater.update_lockfiles(buildfile)
114
+ updated_files = lockfile_updater.update_lockfiles(buildfile)
115
+ replace_updated_files(files, updated_files)
115
116
  end
116
117
  end
117
118
 
119
+ files
120
+ end
121
+ # rubocop:enable Metrics/PerceivedComplexity
122
+ # rubocop:enable Metrics/AbcSize
123
+ sig do
124
+ params(
125
+ files: T::Array[Dependabot::DependencyFile],
126
+ updated_files: T::Array[Dependabot::DependencyFile]
127
+ ).returns(T::Array[Dependabot::DependencyFile])
128
+ end
129
+ def replace_updated_files(files, updated_files)
118
130
  updated_files.each do |file|
119
- existing_file = files.find { |f| f.name == file.name && f.directory == file.directory }
131
+ existing_file = files.find { |f| f.name == file.name }
120
132
  if existing_file.nil?
121
133
  files << file
122
134
  else
123
135
  files[T.must(files.index(existing_file))] = file
124
136
  end
125
137
  end
126
-
127
138
  files
128
139
  end
129
- # rubocop:enable Metrics/PerceivedComplexity
130
- # rubocop:enable Metrics/CyclomaticComplexity
131
- # rubocop:enable Metrics/AbcSize
132
- # rubocop:enable Metrics/MethodLength
133
140
 
134
141
  sig do
135
142
  params(
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.351.0
4
+ version: 0.352.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.351.0
18
+ version: 0.352.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.351.0
25
+ version: 0.352.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.351.0
32
+ version: 0.352.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.351.0
39
+ version: 0.352.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: debug
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -284,7 +284,7 @@ licenses:
284
284
  - MIT
285
285
  metadata:
286
286
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
287
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.351.0
287
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.352.0
288
288
  rdoc_options: []
289
289
  require_paths:
290
290
  - lib