diff options
| -rw-r--r-- | lib/spandx/cli/commands/scan.rb | 9 | ||||
| -rw-r--r-- | lib/spandx/core/gateway.rb | 26 | ||||
| -rw-r--r-- | lib/spandx/core/parser.rb | 29 | ||||
| -rw-r--r-- | lib/spandx/core/plugin.rb | 20 | ||||
| -rw-r--r-- | lib/spandx/core/registerable.rb | 27 | ||||
| -rw-r--r-- | lib/spandx/dotnet/parsers/csproj.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/dotnet/parsers/packages_config.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/dotnet/parsers/sln.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/java/parsers/maven.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/js/parsers/npm.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/js/parsers/yarn.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/php/parsers/composer.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/python/parsers/pipfile_lock.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/ruby/parsers/gemfile_lock.rb | 2 | ||||
| -rw-r--r-- | spec/unit/dotnet/parsers/csproj_spec.rb | 2 | ||||
| -rw-r--r-- | spec/unit/dotnet/parsers/sln_spec.rb | 2 | ||||
| -rw-r--r-- | spec/unit/java/parsers/maven_spec.rb | 2 |
17 files changed, 62 insertions, 73 deletions
diff --git a/lib/spandx/cli/commands/scan.rb b/lib/spandx/cli/commands/scan.rb index 986a42e..91d4ad9 100644 --- a/lib/spandx/cli/commands/scan.rb +++ b/lib/spandx/cli/commands/scan.rb @@ -33,6 +33,7 @@ module Spandx if File.directory?(file) each_file_in(file, &block) if recursive? else + Spandx.logger.debug(file) block.call(file) end end @@ -51,11 +52,9 @@ module Spandx end def enhance(dependency) - plugins.inject(dependency) { |memo, plugin| plugin.enhance(memo) } - end - - def plugins - @plugins ||= ::Spandx::Core::Plugin.map(&:new) + ::Spandx::Core::Plugin + .all + .inject(dependency) { |memo, plugin| plugin.enhance(memo) } end end end diff --git a/lib/spandx/core/gateway.rb b/lib/spandx/core/gateway.rb index 82bf0a8..68f0ec7 100644 --- a/lib/spandx/core/gateway.rb +++ b/lib/spandx/core/gateway.rb @@ -3,26 +3,16 @@ module Spandx module Core class Gateway - class << self - include Enumerable - - def all - @all ||= registry.map { |x| x.new(http: Spandx.http) } - end - - def each(&block) - all.each do |x| - block.call(x) - end - end + def matches?(_dependency) + raise ::Spandx::Error, :matches? + end - def inherited(subclass) - registry.push(subclass) - end + def licenses_for(_dependency) + raise ::Spandx::Error, :licenses_for + end - def registry - @registry ||= [] - end + class << self + include Registerable end end end diff --git a/lib/spandx/core/parser.rb b/lib/spandx/core/parser.rb index 8c79a22..4c92854 100644 --- a/lib/spandx/core/parser.rb +++ b/lib/spandx/core/parser.rb @@ -9,30 +9,19 @@ module Spandx end end - class << self - include Enumerable - - def each(&block) - registry.each do |x| - block.call(x) - end - end + def matches?(_filename) + raise ::Spandx::Error, :matches? + end - def inherited(subclass) - registry.push(subclass) - end + def parse(_dependency) + raise ::Spandx::Error, :parse + end - def registry - @registry ||= [] - end + class << self + include Registerable def for(path) - Spandx.logger.debug(path) - result = ::Spandx::Core::Parser.find do |x| - x.matches?(File.basename(path)) - end - - result&.new || UNKNOWN + find { |x| x.matches?(File.basename(path)) } || UNKNOWN end end end diff --git a/lib/spandx/core/plugin.rb b/lib/spandx/core/plugin.rb index 5e45d5f..f4841cf 100644 --- a/lib/spandx/core/plugin.rb +++ b/lib/spandx/core/plugin.rb @@ -3,22 +3,12 @@ module Spandx module Core class Plugin - class << self - include Enumerable - - def each(&block) - registry.each do |x| - block.call(x) - end - end - - def inherited(subclass) - registry.push(subclass) - end + def enhance(_dependency) + raise ::Spandx::Error, :enhance + end - def registry - @registry ||= [] - end + class << self + include Registerable end end end diff --git a/lib/spandx/core/registerable.rb b/lib/spandx/core/registerable.rb new file mode 100644 index 0000000..0e25e24 --- /dev/null +++ b/lib/spandx/core/registerable.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Spandx + module Core + module Registerable + include Enumerable + + def all + @all ||= registry.map(&:new) + end + + def each(&block) + all.each do |x| + block.call(x) + end + end + + def inherited(subclass) + registry.push(subclass) + end + + def registry + @registry ||= [] + end + end + end +end diff --git a/lib/spandx/dotnet/parsers/csproj.rb b/lib/spandx/dotnet/parsers/csproj.rb index e5430d0..63753e0 100644 --- a/lib/spandx/dotnet/parsers/csproj.rb +++ b/lib/spandx/dotnet/parsers/csproj.rb @@ -4,7 +4,7 @@ module Spandx module Dotnet module Parsers class Csproj < ::Spandx::Core::Parser - def self.matches?(filename) + def matches?(filename) ['.csproj', '.props'].include?(File.extname(filename)) end diff --git a/lib/spandx/dotnet/parsers/packages_config.rb b/lib/spandx/dotnet/parsers/packages_config.rb index e5fd2b5..4544dec 100644 --- a/lib/spandx/dotnet/parsers/packages_config.rb +++ b/lib/spandx/dotnet/parsers/packages_config.rb @@ -4,7 +4,7 @@ module Spandx module Dotnet module Parsers class PackagesConfig < ::Spandx::Core::Parser - def self.matches?(filename) + def matches?(filename) filename.match?(/packages\.config/) end diff --git a/lib/spandx/dotnet/parsers/sln.rb b/lib/spandx/dotnet/parsers/sln.rb index 06e17ab..ce5a699 100644 --- a/lib/spandx/dotnet/parsers/sln.rb +++ b/lib/spandx/dotnet/parsers/sln.rb @@ -4,7 +4,7 @@ module Spandx module Dotnet module Parsers class Sln < ::Spandx::Core::Parser - def self.matches?(filename) + def matches?(filename) filename.match?(/.*\.sln/) end diff --git a/lib/spandx/java/parsers/maven.rb b/lib/spandx/java/parsers/maven.rb index 676771f..73f0d2f 100644 --- a/lib/spandx/java/parsers/maven.rb +++ b/lib/spandx/java/parsers/maven.rb @@ -4,7 +4,7 @@ module Spandx module Java module Parsers class Maven < ::Spandx::Core::Parser - def self.matches?(filename) + def matches?(filename) File.basename(filename) == 'pom.xml' end diff --git a/lib/spandx/js/parsers/npm.rb b/lib/spandx/js/parsers/npm.rb index 4087a55..3ebdc58 100644 --- a/lib/spandx/js/parsers/npm.rb +++ b/lib/spandx/js/parsers/npm.rb @@ -4,7 +4,7 @@ module Spandx module Js module Parsers class Npm < ::Spandx::Core::Parser - def self.matches?(filename) + def matches?(filename) File.basename(filename) == 'package-lock.json' end diff --git a/lib/spandx/js/parsers/yarn.rb b/lib/spandx/js/parsers/yarn.rb index 6bb4dc8..ad52be1 100644 --- a/lib/spandx/js/parsers/yarn.rb +++ b/lib/spandx/js/parsers/yarn.rb @@ -4,7 +4,7 @@ module Spandx module Js module Parsers class Yarn < ::Spandx::Core::Parser - def self.matches?(filename) + def matches?(filename) File.basename(filename) == 'yarn.lock' end diff --git a/lib/spandx/php/parsers/composer.rb b/lib/spandx/php/parsers/composer.rb index 252ea5b..f6add49 100644 --- a/lib/spandx/php/parsers/composer.rb +++ b/lib/spandx/php/parsers/composer.rb @@ -4,7 +4,7 @@ module Spandx module Php module Parsers class Composer < ::Spandx::Core::Parser - def self.matches?(filename) + def matches?(filename) File.basename(filename) == 'composer.lock' end diff --git a/lib/spandx/python/parsers/pipfile_lock.rb b/lib/spandx/python/parsers/pipfile_lock.rb index b6884c3..5183af1 100644 --- a/lib/spandx/python/parsers/pipfile_lock.rb +++ b/lib/spandx/python/parsers/pipfile_lock.rb @@ -4,7 +4,7 @@ module Spandx module Python module Parsers class PipfileLock < ::Spandx::Core::Parser - def self.matches?(filename) + def matches?(filename) filename.match?(/Pipfile.*\.lock/) end diff --git a/lib/spandx/ruby/parsers/gemfile_lock.rb b/lib/spandx/ruby/parsers/gemfile_lock.rb index c0831e6..bd26735 100644 --- a/lib/spandx/ruby/parsers/gemfile_lock.rb +++ b/lib/spandx/ruby/parsers/gemfile_lock.rb @@ -6,7 +6,7 @@ module Spandx class GemfileLock < ::Spandx::Core::Parser STRIP_BUNDLED_WITH = /^BUNDLED WITH$(\r?\n) (?<major>\d+)\.\d+\.\d+/m.freeze - def self.matches?(filename) + def matches?(filename) filename.match?(/Gemfile.*\.lock/) || filename.match?(/gems.*\.lock/) end diff --git a/spec/unit/dotnet/parsers/csproj_spec.rb b/spec/unit/dotnet/parsers/csproj_spec.rb index b9a8d19..c377f8c 100644 --- a/spec/unit/dotnet/parsers/csproj_spec.rb +++ b/spec/unit/dotnet/parsers/csproj_spec.rb @@ -34,8 +34,6 @@ RSpec.describe Spandx::Dotnet::Parsers::Csproj do end describe '.matches?' do - subject { described_class } - specify { expect(subject.matches?('/root/simple.csproj')).to be(true) } specify { expect(subject.matches?('C:\Documents and Settings\simple.csproj')).to be(true) } specify { expect(subject.matches?('C:\Documents and Settings\hello world.csproj')).to be(true) } diff --git a/spec/unit/dotnet/parsers/sln_spec.rb b/spec/unit/dotnet/parsers/sln_spec.rb index e29db13..41b9981 100644 --- a/spec/unit/dotnet/parsers/sln_spec.rb +++ b/spec/unit/dotnet/parsers/sln_spec.rb @@ -19,8 +19,6 @@ RSpec.describe Spandx::Dotnet::Parsers::Sln do end describe '.matches?' do - subject { described_class } - specify { expect(subject.matches?('/root/example.sln')).to be(true) } specify { expect(subject.matches?('C:\development\hello world.sln')).to be(true) } end diff --git a/spec/unit/java/parsers/maven_spec.rb b/spec/unit/java/parsers/maven_spec.rb index aef08fd..218c4c7 100644 --- a/spec/unit/java/parsers/maven_spec.rb +++ b/spec/unit/java/parsers/maven_spec.rb @@ -15,8 +15,6 @@ RSpec.describe Spandx::Java::Parsers::Maven do end describe '.matches?' do - subject { described_class } - specify { expect(subject.matches?('pom.xml')).to be(true) } specify { expect(subject.matches?('sitemap.xml')).to be(false) } end |
