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

Add support for <dependencyManagement> namespace in pom.xml #451

Merged
merged 1 commit into from
May 3, 2019
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
23 changes: 11 additions & 12 deletions lib/bibliothecary/parsers/maven.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ def self.parse_gradle_resolved(file_contents)

def self.parse_pom_manifest(file_contents)
manifest = Ox.parse file_contents
if manifest.respond_to?('project')
xml = manifest.project
else
xml = manifest
end
return [] unless xml.respond_to?('dependencies')
xml.dependencies.locate('dependency').map do |dependency|
{
name: "#{extract_pom_dep_info(xml, dependency, 'groupId')}:#{extract_pom_dep_info(xml, dependency, 'artifactId')}",
requirement: extract_pom_dep_info(xml, dependency, 'version'),
type: extract_pom_dep_info(xml, dependency, 'scope') || 'runtime'
}
xml = manifest.respond_to?('project') ? manifest.project : manifest
[].tap do |deps|
['dependencies/dependency', 'dependencyManagement/dependencies/dependency'].each do |deps_xpath|
xml.locate(deps_xpath).each do |dep|
deps.push({
name: "#{extract_pom_dep_info(xml, dep, 'groupId')}:#{extract_pom_dep_info(xml, dep, 'artifactId')}",
requirement: extract_pom_dep_info(xml, dep, 'version'),
type: extract_pom_dep_info(xml, dep, 'scope') || 'runtime'
})
end
end
end
end

Expand Down
17 changes: 17 additions & 0 deletions spec/fixtures/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@
</developer>
</developers>


<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.9.2</version>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!--JERSEY SERVLET-->
<dependency>
Expand Down
5 changes: 4 additions & 1 deletion spec/parsers/maven_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
:type=>"runtime"},
{:name=>"com.typesafe:config", :requirement=>"1.2.1", :type=>"runtime"},
{:name=>"org.testng:testng", :requirement=>"6.8.7", :type=>"test"},
{:name=>"org.mockito:mockito-all", :requirement=>"1.8.4", :type=>"test"}
{:name=>"org.mockito:mockito-all", :requirement=>"1.8.4", :type=>"test"},
# From dependencyManagement section
{:name=>"org.apache.ant:ant", :requirement=>"1.9.2", :type=>"runtime"},
{:name=>"commons-lang:commons-lang",:requirement=>"2.6", :type=>"runtime"}
],
kind: 'manifest',
success: true
Expand Down