class LicenseScout::Collector
Attributes
dependencies[R]
Public Instance Methods
collect()
click to toggle source
# File lib/license_scout/collector.rb, line 28 def collect @dependencies = Set.new if dependency_managers.empty? raise LicenseScout::Exceptions::Error.new("Failed to find any files associated with known dependency managers in the following directories:\n#{LicenseScout::Config.directories.map { |dir| "\t• #{dir}" }.join("\n")}\n") end dependency_managers.each { |d| collect_licenses_from(d) } LicenseScout::Log.info("[collector] All licenses successfully collected") rescue Exceptions::UpstreamFetchError => e LicenseScout::Log.error("[collector] Encountered an error attempting to fetch package metadata from upstream source:") LicenseScout::Log.error("[collector] #{e}") raise Exceptions::FailExit.new(e) rescue Exceptions::PackageNotFound => e LicenseScout::Log.error("[collector] One of the project's transitive dependencies could not be found:") LicenseScout::Log.error("[collector] #{e}") raise Exceptions::FailExit.new(e) end
Private Instance Methods
collect_licenses_from(dep_mgr)
click to toggle source
# File lib/license_scout/collector.rb, line 50 def collect_licenses_from(dep_mgr) LicenseScout::Log.info("[collector] Collecting licenses for #{dep_mgr.type} dependencies found in #{dep_mgr.directory}/#{dep_mgr.signature}") dep_mgr.dependencies.each do |dep| @dependencies << dep end rescue LicenseScout::Exceptions::MissingSourceDirectory => e raise LicenseScout::Exceptions::Error.new("#{e.message}\n\n\tPlease try running `#{dep_mgr.install_command}` to download the dependency.\n") end
dependency_managers()
click to toggle source
# File lib/license_scout/collector.rb, line 59 def dependency_managers @dependency_managers ||= LicenseScout::Config.all_directories.map do |dir| LicenseScout::DependencyManager.implementations.map do |implementation| dep_mgr = implementation.new(File.expand_path(dir)) if dep_mgr.detected? LicenseScout::Log.info("[collector] Found #{dep_mgr.signature} in #{dir}") dep_mgr else nil end end end.flatten.compact end