Sha256: ab87f75e2c4f690c11c0a7a0c401c4feb1df22c8ebb92c5253c756dddd73c853

Contents?: true

Size: 875 Bytes

Versions: 7

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Parsers
    class PackagesConfig < Base
      def self.matches?(filename)
        filename.match?(/packages\.config/)
      end

      def parse(lockfile)
        Nokogiri::XML(IO.read(lockfile))
          .search('//package')
          .map { |node| map_from(node) }
      end

      private

      def map_from(node)
        name = attribute_for('id', node)
        version = attribute_for('version', node)
        Dependency.new(
          name: name,
          version: version,
          licenses: nuget.licenses_for(name, version).map { |x| catalogue[x] }
        )
      end

      def attribute_for(key, node)
        node.attribute(key)&.value&.strip || node.at_xpath("./#{key}")&.content&.strip
      end

      def nuget
        @nuget ||= Gateways::Nuget.new(catalogue: catalogue)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spandx-0.5.0 lib/spandx/parsers/packages_config.rb
spandx-0.4.1 lib/spandx/parsers/packages_config.rb
spandx-0.4.0 lib/spandx/parsers/packages_config.rb
spandx-0.3.0 lib/spandx/parsers/packages_config.rb
spandx-0.2.0 lib/spandx/parsers/packages_config.rb
spandx-0.1.7 lib/spandx/parsers/packages_config.rb
spandx-0.1.6 lib/spandx/parsers/packages_config.rb