lib/spandx/java/parsers/maven.rb in spandx-0.11.0 vs lib/spandx/java/parsers/maven.rb in spandx-0.12.0
- old
+ new
@@ -2,42 +2,32 @@
module Spandx
module Java
module Parsers
class Maven < ::Spandx::Core::Parser
- def self.matches?(filename)
+ def matches?(filename)
File.basename(filename) == 'pom.xml'
end
def parse(filename)
document = Nokogiri.XML(IO.read(filename)).tap(&:remove_namespaces!)
document.search('//project/dependencies/dependency').map do |node|
- metadata = metadata_for(node)
- ::Spandx::Core::Dependency.new(
- name: metadata.artifact_id,
- version: metadata.version,
- licenses: metadata.licenses.map { |x| search_catalogue_for(x) }.compact
- )
+ map_from(node)
end
end
private
- def metadata_for(node)
- ::Spandx::Java::Metadata.new(
- artifact_id: node.at_xpath('./artifactId').text,
- group_id: node.at_xpath('./groupId').text,
- version: node.at_xpath('./version').text
- )
- end
+ def map_from(node)
+ artifact_id = node.at_xpath('./artifactId').text
+ group_id = node.at_xpath('./groupId').text
+ version = node.at_xpath('./version').text
- def search_catalogue_for(license_hash)
- name = ::Spandx::Core::Content.new(license_hash[:name])
-
- catalogue.find do |license|
- score = name.similarity_score(::Spandx::Core::Content.new(license.name))
- score > 85
- end
+ ::Spandx::Core::Dependency.new(
+ package_manager: :maven,
+ name: "#{group_id}:#{artifact_id}",
+ version: version
+ )
end
end
end
end
end