summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-04-12 10:14:10 -0600
committermo khan <mo.khan@gmail.com>2020-04-12 10:14:10 -0600
commitddce2f342e47b0f06774c896e5d689b06a6d90b2 (patch)
tree6dd1e118f43a2da3f13267dc0b6adc093ae23ad6
parent296201db71b8dfd84de06bdd5a5d5c8383ddeb24 (diff)
Remove unrelated code
-rw-r--r--lib/spandx/cli/commands/scan.rb2
-rw-r--r--lib/spandx/core/plugin.rb2
-rw-r--r--lib/spandx/dotnet/license_plugin.rb35
-rw-r--r--spec/fixtures/recordings/nuget-jive-0_1_0.yml32
-rw-r--r--spec/unit/dotnet/license_plugin_spec.rb2
5 files changed, 43 insertions, 30 deletions
diff --git a/lib/spandx/cli/commands/scan.rb b/lib/spandx/cli/commands/scan.rb
index 6fb0c4b..563acce 100644
--- a/lib/spandx/cli/commands/scan.rb
+++ b/lib/spandx/cli/commands/scan.rb
@@ -51,7 +51,7 @@ module Spandx
end
def enhance(dependency)
- ::Spandx::Core::Plugin.map { |plugin| plugin.enhance(dependency) }
+ ::Spandx::Core::Plugin.map { |plugin| plugin.new.enhance(dependency) }
end
end
end
diff --git a/lib/spandx/core/plugin.rb b/lib/spandx/core/plugin.rb
index 2dfbcdc..5e45d5f 100644
--- a/lib/spandx/core/plugin.rb
+++ b/lib/spandx/core/plugin.rb
@@ -8,7 +8,7 @@ module Spandx
def each(&block)
registry.each do |x|
- block.call(x.new)
+ block.call(x)
end
end
diff --git a/lib/spandx/dotnet/license_plugin.rb b/lib/spandx/dotnet/license_plugin.rb
index 6a48bf5..cf7ed68 100644
--- a/lib/spandx/dotnet/license_plugin.rb
+++ b/lib/spandx/dotnet/license_plugin.rb
@@ -3,13 +3,6 @@
module Spandx
module Dotnet
class LicensePlugin < Spandx::Core::Plugin
- GATEWAYS = {
- composer: ::Spandx::Php::PackagistGateway,
- maven: ::Spandx::Java::Gateway,
- nuget: ::Spandx::Dotnet::NugetGateway,
- rubygems: ::Spandx::Ruby::Gateway,
- }.freeze
-
def initialize(catalogue: Spdx::Catalogue.from_git)
@catalogue = catalogue
end
@@ -28,28 +21,16 @@ module Spandx
attr_reader :catalogue
def licenses_for(dependency)
- Spdx::GatewayAdapter
- .new(catalogue: catalogue, gateway: combine(cache_for(dependency.package_manager), gateway_for(dependency.package_manager)))
- .licenses_for(dependency.name, dependency.version)
- end
-
- def combine(gateway, other_gateway)
- ::Spandx::Core::CompositeGateway.new(gateway, other_gateway)
- end
-
- def gateway_for(package_manager)
- case package_manager
- when :yarn, :npm
- js_gateway
- when :pypi
- python_gateway
- else
- GATEWAYS.fetch(package_manager, ::Spandx::Core::NullGateway).new
- end
+ @adapter ||= Spdx::GatewayAdapter.new(catalogue: catalogue, gateway: gateway)
+ @adapter.licenses_for(dependency.name, dependency.version)
end
- def cache_for(package_manager)
- ::Spandx::Core::Cache.new(package_manager, url: package_manager == :rubygems ? 'https://github.com/mokhan/spandx-rubygems.git' : 'https://github.com/mokhan/spandx-index.git')
+ def gateway
+ @gateway ||=
+ ::Spandx::Core::CompositeGateway.new(
+ ::Spandx::Core::Cache.new(:nuget, url: 'https://github.com/mokhan/spandx-rubygems.git'),
+ ::Spandx::Dotnet::NugetGateway.new
+ )
end
end
end
diff --git a/spec/fixtures/recordings/nuget-jive-0_1_0.yml b/spec/fixtures/recordings/nuget-jive-0_1_0.yml
new file mode 100644
index 0000000..e15b050
--- /dev/null
+++ b/spec/fixtures/recordings/nuget-jive-0_1_0.yml
@@ -0,0 +1,32 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://api.nuget.org/v3-flatcontainer/jive/0.1.0/jive.nuspec
+ response:
+ status:
+ code: 200
+ message: OK
+ body:
+ encoding: UTF-8
+ string: |-
+ <?xml version="1.0" encoding="utf-8"?>
+ <package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
+ <metadata>
+ <id>jive</id>
+ <version>0.1.0</version>
+ <authors>mo khan</authors>
+ <owners>mo khan</owners>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <license type="expression">MIT</license>
+ <licenseUrl>https://licenses.nuget.org/MIT</licenseUrl>
+ <description>Add a little jive talk to your csharp.</description>
+ <repository url="https://github.com/mokhan/jive.net" />
+ <dependencies>
+ <group targetFramework=".NETCoreApp3.0" />
+ </dependencies>
+ </metadata>
+ </package>
+ http_version: null
+ recorded_at: Sun, 12 Apr 2020 16:04:34 GMT
+recorded_with: VCR 5.1.0
diff --git a/spec/unit/dotnet/license_plugin_spec.rb b/spec/unit/dotnet/license_plugin_spec.rb
index fb4e73a..82f05f6 100644
--- a/spec/unit/dotnet/license_plugin_spec.rb
+++ b/spec/unit/dotnet/license_plugin_spec.rb
@@ -3,7 +3,7 @@ RSpec.describe Spandx::Dotnet::LicensePlugin do
describe "#enhance" do
context "when the dependency is not managed by the `nuget` package manager" do
- let(:dependency) { ::Spandx::Core::Dependency.new(package_manager: :rubygems, name: 'jive', version: '0.1.0') }
+ let(:dependency) { ::Spandx::Core::Dependency.new(package_manager: :rubygems, name: 'spandx', version: '0.1.0') }
specify { expect(subject.enhance(dependency)).to eql(dependency) }
end