Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven: fix classifier being part of the dependency name #7980

Merged
merged 6 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion maven/lib/dependabot/maven.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
register_display_name_builder(
"maven",
lambda { |name|
_group_id, artifact_id, _classifier = name.split(":")
_group_id, artifact_id = name.split(":")
name.length <= 100 ? name : artifact_id
}
)
8 changes: 3 additions & 5 deletions maven/lib/dependabot/maven/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ def dependency_from_dependency_node(pom, dependency_node)
return unless (name = dependency_name(dependency_node, pom))
return if internal_dependency_names.include?(name)

classifier = dependency_classifier(dependency_node, pom)
name = "#{name}:#{classifier}" if classifier

build_dependency(pom, dependency_node, name)
end

Expand Down Expand Up @@ -119,8 +116,9 @@ def build_dependency(pom, dependency_node, name)
groups: dependency_groups(pom, dependency_node),
source: nil,
metadata: {
packaging_type: packaging_type(pom, dependency_node)
}.merge(property_details)
packaging_type: packaging_type(pom, dependency_node),
classifier: dependency_classifier(dependency_node, pom)
}.merge(property_details).compact
}]
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def fetch_pom_declaration_strings
].compact.join(":")

if node.at_xpath("./*/classifier")
node_name += ":#{evaluated_value(node.at_xpath('./*/classifier').
content.strip)}"
classifier = evaluated_value(node.at_xpath("./*/classifier").content.strip)
dep_classifier = dependency.requirements.first.dig(:metadata, :classifier)
next false if classifier != dep_classifier
end

next false unless node_name == dependency_name
Expand Down
2 changes: 1 addition & 1 deletion maven/lib/dependabot/maven/metadata_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def dependency_pom_file
end

def dependency_artifact_id
_group_id, artifact_id, _classifier = dependency.name.split(":")
_group_id, artifact_id = dependency.name.split(":")

artifact_id
end
Expand Down
8 changes: 4 additions & 4 deletions maven/lib/dependabot/maven/update_checker/version_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def pom
end

def dependency_metadata_url(repository_url)
group_id, artifact_id, _classifier = dependency.name.split(":")
group_id, artifact_id = dependency.name.split(":")

"#{repository_url}/" \
"#{group_id.tr('.', '/')}/" \
Expand All @@ -260,9 +260,9 @@ def dependency_metadata_url(repository_url)
end

def dependency_files_url(repository_url, version)
group_id, artifact_id, classifier = dependency.name.split(":")
type = dependency.requirements.first.
dig(:metadata, :packaging_type)
group_id, artifact_id = dependency.name.split(":")
type = dependency.requirements.first.dig(:metadata, :packaging_type)
classifier = dependency.requirements.first.dig(:metadata, :classifier)

actual_classifier = classifier.nil? ? "" : "-#{classifier}"
"#{repository_url}/" \
Expand Down
7 changes: 5 additions & 2 deletions maven/spec/dependabot/maven/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@

it "has the right details" do
expect(dependency).to be_a(Dependabot::Dependency)
expect(dependency.name).to eq("io.mockk:mockk:sources")
expect(dependency.name).to eq("io.mockk:mockk")
expect(dependency.version).to eq("1.0.0")
expect(dependency.requirements).to eq(
[{
requirement: "1.0.0",
file: "pom.xml",
groups: [],
source: nil,
metadata: { packaging_type: "jar" }
metadata: {
classifier: "sources",
packaging_type: "jar"
}
}]
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@
end

context "with a dependency that has a classifier" do
let(:dependency_name) { "io.mockk:mockk:sources" }
let(:dependency_name) { "io.mockk:mockk" }
let(:dependency_version) { "1.0.0" }
let(:dependency_metadata) { { packaging_type: "jar", classifier: "sources" } }

it "finds the declaration" do
expect(declaration_nodes.count).to eq(1)
Expand Down
12 changes: 9 additions & 3 deletions maven/spec/dependabot/maven/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,27 @@
end
let(:mockk_dependency) do
Dependabot::Dependency.new(
name: "io.mockk:mockk:sources",
name: "io.mockk:mockk",
version: "1.10.0",
requirements: [{
file: "pom.xml",
requirement: "1.10.0",
groups: [],
source: nil,
metadata: { packaging_type: "jar" }
metadata: {
packaging_type: "jar",
classifier: "sources"
}
}],
previous_requirements: [{
file: "pom.xml",
requirement: "1.0.0",
groups: [],
source: nil,
metadata: { packaging_type: "jar" }
metadata: {
packaging_type: "jar",
classifier: "sources"
}
}],
package_manager: "maven"
)
Expand Down
7 changes: 0 additions & 7 deletions maven/spec/dependabot/maven/metadata_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@
)
end

context "when the dependency name has a classifier" do
let(:dependency_name) { "io.mockk:mockk:sources" }
let(:dependency_version) { "1.10.0" }

it { is_expected.to eq("https://github.com/mockk/mockk") }
end

context "when the github link is buried in the pom" do
let(:maven_response) { fixture("poms", "guava-23.3-jre.xml") }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,17 @@
end

describe "#latest_version_details when the dependency has a classifier" do
let(:dependency_name) { "io.mockk:mockk:sources" }
let(:dependency_name) { "io.mockk:mockk" }
let(:dependency_version) { "1.0.0" }
let(:dependency_requirements) do
[{
file: "pom.xml",
requirement: dependency_version,
groups: [],
source: nil,
metadata: { packaging_type: "jar", classifier: "sources" }
}]
end
subject { finder.latest_version_details }

its([:version]) { is_expected.to eq(version_class.new("1.10.0")) }
Expand Down
Loading