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

Java: Fetch all poms for multimodule projects #354

Merged
merged 9 commits into from
Apr 20, 2018
Prev Previous commit
Next Next commit
Java: Filter out internal dependencies when parsing multimodule poms
  • Loading branch information
greysteil committed Apr 20, 2018
commit aa31d032d91b0948b7d81923179edf02e4d2a725
21 changes: 17 additions & 4 deletions lib/dependabot/file_parsers/java/maven.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ def pomfile_dependencies(pom)

doc = Nokogiri::XML(pom.content)
doc.css(DEPENDENCY_SELECTOR).each do |dependency_node|
next unless dependency_name(dependency_node)

# TODO: Filter out internal dependencies
next unless (name = dependency_name(dependency_node))
next if internal_dependency_names.include?(name)

dependency_set <<
Dependency.new(
name: dependency_name(dependency_node),
name: name,
version: dependency_version(dependency_node),
package_manager: "maven",
requirements: [{
Expand Down Expand Up @@ -108,6 +107,20 @@ def pomfiles
dependency_files.select { |f| f.name.end_with?("pom.xml") }
end

def internal_dependency_names
@internal_dependency_names =
pomfiles.map do |pom|
doc = Nokogiri::XML(pom.content)
group_id = doc.at_css("project > groupId") ||
doc.at_css("project > parent > groupId")
artifact_id = doc.at_css("project > artifactId")

next unless group_id && artifact_id

[group_id.content.strip, artifact_id.content.strip].join(":")
end.compact
end

def check_required_files
raise "No pom.xml!" unless get_original_file("pom.xml")
end
Expand Down
15 changes: 13 additions & 2 deletions spec/dependabot/file_parsers/java/maven_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
end
end

context "with a repeated dependency" do
context "with a multimodule pom" do
let(:files) do
[
multimodule_pom, util_pom, business_app_pom, legacy_pom, webapp_pom,
Expand Down Expand Up @@ -417,7 +417,18 @@
)
end

its(:length) { is_expected.to eq(8) }
it "gets the right dependencies" do
expect(dependencies.map(&:name)).
to match_array(
%w(
com.google.guava:guava
junit:junit
org.apache.struts:struts-core
org.springframework:spring-aop
org.apache.maven.plugins:maven-compiler-plugin
)
)
end

describe "the first dependency" do
subject(:dependency) { dependencies.first }
Expand Down