Class: LicenseFinder::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/license_finder/scanner.rb

Constant Summary collapse

PACKAGE_MANAGERS =
[
  GoModules, GoDep, GoWorkspace, Go15VendorExperiment, Glide, Gvt, Govendor, Trash, Dep, Bundler, NPM, Pip,
  Yarn, Bower, Maven, Gradle, CocoaPods, Rebar, Erlangmk, Nuget, Carthage, Mix, Conan, Sbt, Cargo, Dotnet, Composer, Pipenv,
  Conda, Spm
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = { project_path: Pathname.new('') }) ⇒ Scanner

Returns a new instance of Scanner.



32
33
34
35
36
37
# File 'lib/license_finder/scanner.rb', line 32

def initialize(config = { project_path: Pathname.new('') })
  @config = config
  @project_path = @config[:project_path]
  @logger = @config[:logger]
  @enabled_package_manager_ids = @config[:enabled_package_manager_ids]
end

Class Method Details

.remove_subprojects(paths) ⇒ Object



12
13
14
# File 'lib/license_finder/scanner.rb', line 12

def remove_subprojects(paths)
  paths.reject { |path| subproject?(Pathname(path)) }
end

.supported_package_manager_idsObject



16
17
18
# File 'lib/license_finder/scanner.rb', line 16

def supported_package_manager_ids
  PACKAGE_MANAGERS.map(&:id)
end

Instance Method Details

#active_package_managersObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/license_finder/scanner.rb', line 45

def active_package_managers
  return @package_managers if @package_managers

  active_pm_classes = []
  enabled_package_managers.each do |pm_class|
    active = pm_class.new(@config).active?

    if active
      @logger.info pm_class, 'is active', color: :green
      active_pm_classes << pm_class
    else
      @logger.debug pm_class, 'is not active', color: :red
    end
  end

  @logger.info 'License Finder', 'No active and installed package managers found for project.', color: :red if active_pm_classes.empty?

  active_pm_classes -= active_pm_classes.map(&:takes_priority_over)
  @package_managers = active_pm_classes.map { |pm_class| pm_class.new(@config) }
end

#active_packagesObject



39
40
41
42
43
# File 'lib/license_finder/scanner.rb', line 39

def active_packages
  package_managers = active_package_managers
  installed_package_managers = package_managers.select { |pm| pm.installed?(@logger) }
  installed_package_managers.flat_map(&:current_packages_with_relations)
end