Skip to content

Commit 5bb098b

Browse files
tiegzkatzj
authored andcommitted
Add support for dependencyManagement namespace in pom.xml
1 parent a796f71 commit 5bb098b

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

lib/bibliothecary/parsers/maven.rb

+11-12
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,17 @@ def self.parse_gradle_resolved(file_contents)
111111

112112
def self.parse_pom_manifest(file_contents)
113113
manifest = Ox.parse file_contents
114-
if manifest.respond_to?('project')
115-
xml = manifest.project
116-
else
117-
xml = manifest
118-
end
119-
return [] unless xml.respond_to?('dependencies')
120-
xml.dependencies.locate('dependency').map do |dependency|
121-
{
122-
name: "#{extract_pom_dep_info(xml, dependency, 'groupId')}:#{extract_pom_dep_info(xml, dependency, 'artifactId')}",
123-
requirement: extract_pom_dep_info(xml, dependency, 'version'),
124-
type: extract_pom_dep_info(xml, dependency, 'scope') || 'runtime'
125-
}
114+
xml = manifest.respond_to?('project') ? manifest.project : manifest
115+
[].tap do |deps|
116+
['dependencies/dependency', 'dependencyManagement/dependencies/dependency'].each do |deps_xpath|
117+
xml.locate(deps_xpath).each do |dep|
118+
deps.push({
119+
name: "#{extract_pom_dep_info(xml, dep, 'groupId')}:#{extract_pom_dep_info(xml, dep, 'artifactId')}",
120+
requirement: extract_pom_dep_info(xml, dep, 'version'),
121+
type: extract_pom_dep_info(xml, dep, 'scope') || 'runtime'
122+
})
123+
end
124+
end
126125
end
127126
end
128127

spec/fixtures/pom.xml

+17
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@
6666
</developer>
6767
</developers>
6868

69+
70+
<dependencyManagement>
71+
<dependencies>
72+
<dependency>
73+
<groupId>org.apache.ant</groupId>
74+
<artifactId>ant</artifactId>
75+
<version>1.9.2</version>
76+
</dependency>
77+
78+
<dependency>
79+
<groupId>commons-lang</groupId>
80+
<artifactId>commons-lang</artifactId>
81+
<version>2.6</version>
82+
</dependency>
83+
</dependencies>
84+
</dependencyManagement>
85+
6986
<dependencies>
7087
<!--JERSEY SERVLET-->
7188
<dependency>

spec/parsers/maven_spec.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@
7979
:type=>"runtime"},
8080
{:name=>"com.typesafe:config", :requirement=>"1.2.1", :type=>"runtime"},
8181
{:name=>"org.testng:testng", :requirement=>"6.8.7", :type=>"test"},
82-
{:name=>"org.mockito:mockito-all", :requirement=>"1.8.4", :type=>"test"}
82+
{:name=>"org.mockito:mockito-all", :requirement=>"1.8.4", :type=>"test"},
83+
# From dependencyManagement section
84+
{:name=>"org.apache.ant:ant", :requirement=>"1.9.2", :type=>"runtime"},
85+
{:name=>"commons-lang:commons-lang",:requirement=>"2.6", :type=>"runtime"}
8386
],
8487
kind: 'manifest',
8588
success: true

0 commit comments

Comments
 (0)