Sha256: 344f3ad05870489462f9d285b2e7ba0f6197a36519bc52625a8d9dc21114fb43

Contents?: true

Size: 900 Bytes

Versions: 2

Compression:

Stored size: 900 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Parsers
    class Csproj < Base
      def self.matches?(filename)
        filename.match?(/.*\.csproj/)
      end

      def parse(lockfile)
        document = from_xml(IO.read(lockfile))
        document.search('//PackageReference').map do |node|
          name = attribute_for('Include', node)
          version = attribute_for('Version', node)
          Dependency.new(
            name: name,
            version: version,
            licenses: nuget.licenses_for(name, version).map { |x| catalogue[x] }
          )
        end
      end

      private

      def from_xml(xml)
        Nokogiri::XML(xml)
      end

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

      def nuget
        @nuget ||= Gateways::Nuget.new
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spandx-0.1.5 lib/spandx/parsers/csproj.rb
spandx-0.1.4 lib/spandx/parsers/csproj.rb