Sha256: 21e0584f3445af76eb708a87dae32ddd3e803d78867b26f035bc4d1a6ed8183b

Contents?: true

Size: 1.05 KB

Versions: 20

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Spandx
  module Java
    class Metadata
      attr_reader :artifact_id, :group_id, :version, :source

      def initialize(artifact_id:, group_id:, version:, source: 'https://repo.maven.apache.org/maven2')
        @artifact_id = artifact_id
        @group_id = group_id.tr('.', '/')
        @version = version
        @source = source
      end

      def licenses
        return [] unless pom

        pom.search('//licenses/license').map do |node|
          {
            name: node.at_xpath('./name').text,
            url: node.at_xpath('./url').text
          }
        end
      end

      private

      def pom
        @pom ||= fetch
      end

      def spec_url
        [
          source,
          group_id,
          artifact_id,
          version,
          "#{artifact_id}-#{version}.pom"
        ].join('/')
      end

      def fetch
        response = Spandx.http.get(spec_url)
        return unless Spandx.http.ok?(response)

        Nokogiri.XML(response.body).tap(&:remove_namespaces!)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
spandx-0.18.3 lib/spandx/java/metadata.rb
spandx-0.18.2 lib/spandx/java/metadata.rb
spandx-0.18.1 lib/spandx/java/metadata.rb
spandx-0.18.0 lib/spandx/java/metadata.rb
spandx-0.17.0 lib/spandx/java/metadata.rb
spandx-0.16.1 lib/spandx/java/metadata.rb
spandx-0.16.0 lib/spandx/java/metadata.rb
spandx-0.15.1 lib/spandx/java/metadata.rb
spandx-0.15.0 lib/spandx/java/metadata.rb
spandx-0.14.0 lib/spandx/java/metadata.rb
spandx-0.13.5 lib/spandx/java/metadata.rb
spandx-0.13.4 lib/spandx/java/metadata.rb
spandx-0.13.3 lib/spandx/java/metadata.rb
spandx-0.13.2 lib/spandx/java/metadata.rb
spandx-0.13.1 lib/spandx/java/metadata.rb
spandx-0.13.0 lib/spandx/java/metadata.rb
spandx-0.12.3 lib/spandx/java/metadata.rb
spandx-0.12.2 lib/spandx/java/metadata.rb
spandx-0.12.1 lib/spandx/java/metadata.rb
spandx-0.12.0 lib/spandx/java/metadata.rb