Skip to content

Commit

Permalink
Merge pull request #4374 from anatawa12/settings-gradle-kts
Browse files Browse the repository at this point in the history
Support updating dependencies on settings file
  • Loading branch information
jurre authored Nov 19, 2021
2 parents 417dd1d + e1411a7 commit 9b142c2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
1 change: 1 addition & 0 deletions gradle/lib/dependabot/gradle/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def self.required_files_message
def fetch_files
fetched_files = []
fetched_files << buildfile if buildfile
fetched_files << settings_file if settings_file
fetched_files += subproject_buildfiles
fetched_files += dependency_script_plugins
check_required_files_present
Expand Down
2 changes: 1 addition & 1 deletion gradle/lib/dependabot/gradle/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FileParser < Dependabot::FileParsers::Base
require "dependabot/file_parsers/base/dependency_set"
require_relative "file_parser/property_value_finder"

SUPPORTED_BUILD_FILE_NAMES = %w(build.gradle build.gradle.kts).freeze
SUPPORTED_BUILD_FILE_NAMES = %w(build.gradle build.gradle.kts settings.gradle settings.gradle.kts).freeze

PROPERTY_REGEX =
/
Expand Down
16 changes: 8 additions & 8 deletions gradle/spec/dependabot/gradle/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def stub_content_request(path, fixture)
end

it "fetches the main buildfile and subproject buildfile" do
expect(file_fetcher_instance.files.count).to eq(2)
expect(file_fetcher_instance.files.count).to eq(3)
expect(file_fetcher_instance.files.map(&:name)).
to match_array(%w(build.gradle app/build.gradle))
to match_array(%w(build.gradle settings.gradle app/build.gradle))
end

context "when the subproject can't fe found" do
Expand All @@ -73,9 +73,9 @@ def stub_content_request(path, fixture)
end

it "fetches the main buildfile" do
expect(file_fetcher_instance.files.count).to eq(1)
expect(file_fetcher_instance.files.count).to eq(2)
expect(file_fetcher_instance.files.map(&:name)).
to match_array(%w(build.gradle))
to match_array(%w(build.gradle settings.gradle))
end
end
end
Expand All @@ -89,9 +89,9 @@ def stub_content_request(path, fixture)
end

it "fetches the main buildfile and subproject buildfile" do
expect(file_fetcher_instance.files.count).to eq(1)
expect(file_fetcher_instance.files.count).to eq(2)
expect(file_fetcher_instance.files.map(&:name)).
to match_array(%w(app/build.gradle))
to match_array(%w(settings.gradle app/build.gradle))
end
end

Expand All @@ -118,9 +118,9 @@ def stub_content_request(path, fixture)
end

it "fetches the main buildfile and subproject buildfile" do
expect(file_fetcher_instance.files.count).to eq(2)
expect(file_fetcher_instance.files.count).to eq(3)
expect(file_fetcher_instance.files.map(&:name)).
to match_array(%w(build.gradle.kts app/build.gradle.kts))
to match_array(%w(build.gradle.kts settings.gradle.kts app/build.gradle.kts))
end
end
end
Expand Down
30 changes: 30 additions & 0 deletions gradle/spec/dependabot/gradle/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,21 @@
end
end

describe "settings script" do
let(:files) { [buildfile, settings_file] }
let(:settings_file) do
Dependabot::DependencyFile.new(
name: "settings.gradle",
content: fixture("settings_files", settings_file_fixture_name)
)
end
let(:settings_file_fixture_name) { "buildscript_dependencies_settings.gradle" }

subject(:dependencies) { parser.parse }

its(:length) { is_expected.to eq(20) }
end

context "with kotlin" do
let(:buildfile) do
Dependabot::DependencyFile.new(
Expand Down Expand Up @@ -751,6 +766,21 @@
end
end
end

describe "kotlin settings script" do
let(:files) { [buildfile, settings_file] }
let(:settings_file) do
Dependabot::DependencyFile.new(
name: "settings.gradle.kts",
content: fixture("settings_files", settings_file_fixture_name)
)
end
let(:settings_file_fixture_name) { "buildscript_dependencies_settings.gradle.kts" }

subject(:dependencies) { parser.parse }

its(:length) { is_expected.to eq(20) }
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ow2.asm:asm:9.2'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.ow2.asm:asm:9.2")
}
}

0 comments on commit 9b142c2

Please sign in to comment.