Sha256: f0d61a289338111c44585ded288a5b7e447458eda4a1c849c36a31479ca5eaed

Contents?: true

Size: 867 Bytes

Versions: 8

Compression:

Stored size: 867 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Java
    module Parsers
      class Maven < ::Spandx::Core::Parser
        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|
            map_from(node)
          end
        end

        private

        def map_from(node)
          artifact_id = node.at_xpath('./artifactId').text
          group_id = node.at_xpath('./groupId').text
          version = node.at_xpath('./version').text

          ::Spandx::Core::Dependency.new(
            package_manager: :maven,
            name: "#{group_id}:#{artifact_id}",
            version: version
          )
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
spandx-0.13.3 lib/spandx/java/parsers/maven.rb
spandx-0.13.2 lib/spandx/java/parsers/maven.rb
spandx-0.13.1 lib/spandx/java/parsers/maven.rb
spandx-0.13.0 lib/spandx/java/parsers/maven.rb
spandx-0.12.3 lib/spandx/java/parsers/maven.rb
spandx-0.12.2 lib/spandx/java/parsers/maven.rb
spandx-0.12.1 lib/spandx/java/parsers/maven.rb
spandx-0.12.0 lib/spandx/java/parsers/maven.rb