Sha256: 77802abf881c746c89d9f63b2d997ec71774bd15b57814c9fc71fafd699f3570

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Spandx
  module Java
    module Parsers
      class Maven < ::Spandx::Core::Parser
        def self.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
            )
          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 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
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spandx-0.11.0 lib/spandx/java/parsers/maven.rb
spandx-0.10.1 lib/spandx/java/parsers/maven.rb
spandx-0.10.0 lib/spandx/java/parsers/maven.rb
spandx-0.9.0 lib/spandx/java/parsers/maven.rb
spandx-0.8.0 lib/spandx/java/parsers/maven.rb
spandx-0.7.0 lib/spandx/java/parsers/maven.rb
spandx-0.6.0 lib/spandx/java/parsers/maven.rb