Skip to content

Commit cf41f55

Browse files
committed
Only run native wrapper updated if distribution dependency
1 parent d00aa08 commit cf41f55

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

gradle/lib/dependabot/gradle/file_updater/wrapper_updater.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ def initialize(dependency_files:, dependency:)
3939

4040
sig { params(build_file: Dependabot::DependencyFile).returns(T::Array[Dependabot::DependencyFile]) }
4141
def update_files(build_file)
42+
# We only run this updater if it's a distribution dependency
43+
return [] unless Distributions.distribution_requirements?(dependency.requirements)
44+
4245
local_files = dependency_files.select do |file|
4346
file.directory == build_file.directory && target_file?(file)
4447
end
4548

4649
# If we don't have any files in the build files don't generate one
47-
return dependency_files unless local_files.any?
50+
return [] unless local_files.any?
4851

4952
updated_files = dependency_files.dup
5053
SharedHelpers.in_a_temporary_directory do |temp_dir|

gradle/spec/dependabot/gradle/file_updater_spec.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
)
3838
end
3939
let(:dependencies) { [dependency] }
40-
let(:dependency_files) { [buildfile] }
40+
let(:dependency_files) { [buildfile, wrapper_file] }
4141
let(:updater) do
4242
described_class.new(
4343
dependency_files: dependency_files,
@@ -51,11 +51,34 @@
5151
)
5252
end
5353

54+
let(:wrapper_file) do
55+
Dependabot::DependencyFile.new(
56+
name: "gradle/wrapper/gradle-wrapper.properties",
57+
content: fixture(
58+
"wrapper_files",
59+
"gradle-wrapper-8.14.2-bin.properties"
60+
)
61+
)
62+
end
63+
5464
it_behaves_like "a dependency file updater"
5565

5666
describe "#updated_dependency_files" do
5767
subject(:updated_files) { updater.updated_dependency_files }
5868

69+
before do
70+
allow(Dependabot::SharedHelpers).to receive(:run_shell_command) do |command, _|
71+
raise "Unexpected shell command: #{command}"
72+
end
73+
74+
Dependabot::Experiments.register(:gradle_wrapper_updater, true)
75+
Dependabot::Experiments.register(:gradle_lockfile_updater, true)
76+
end
77+
78+
after do
79+
Dependabot::Experiments.reset!
80+
end
81+
5982
it "returns DependencyFile objects" do
6083
updated_files.each { |f| expect(f).to be_a(Dependabot::DependencyFile) }
6184
end
@@ -634,6 +657,10 @@
634657
end
635658

636659
let(:buildfile) do
660+
wrapper_file
661+
end
662+
663+
let(:wrapper_file) do
637664
Dependabot::DependencyFile.new(
638665
name: "gradle/wrapper/gradle-wrapper.properties",
639666
content: fixture(
@@ -684,16 +711,25 @@
684711
)
685712
end
686713

714+
before do
715+
allow(Dependabot::SharedHelpers).to receive(:run_shell_command)
716+
end
717+
687718
its(:content) do
719+
expected_command = "gradle --no-daemon --stacktrace wrapper --no-validate-url --gradle-version 9.0.0"
720+
688721
is_expected.to include(
689722
"distributionUrl=https\\://services.gradle.org/distributions/gradle-9.0.0-#{type}.zip"
690723
)
691724

692725
if checksum
726+
expected_command += " --gradle-distribution-sha256-sum #{updated_checksum}"
693727
is_expected.to include("distributionSha256Sum=#{updated_checksum}")
694728
else
695729
is_expected.not_to include("distributionSha256Sum=")
696730
end
731+
732+
expect(Dependabot::SharedHelpers).to have_received(:run_shell_command).with(expected_command, cwd: anything)
697733
end
698734
end
699735

0 commit comments

Comments
 (0)