require 'yaml' module Licensed module Command class Verify attr_reader :config def initialize(config) @config = config end def approved?(dependency) @config.whitelisted?(dependency) || @config.reviewed?(dependency) end def dependencies @dependencies ||= @config.sources.map(&:dependencies).flatten end def run @config.ui.info "Verifying licenses for #{dependencies.size} dependencies" @results = dependencies.map do |dependency| next if @config.ignored?(dependency) filename = @config.path.join("#{dependency["type"]}/#{dependency["name"]}.txt") warnings = [] if File.exists?(filename) license = License.read(filename) if license["version"] != dependency["version"] warnings << "cached license data out of date" end warnings << "missing license text" if license.text.strip.empty? unless approved?(license) warnings << "license needs reviewed: #{license["license"]}." end else warnings << "missing license data" end if warnings.size > 0 @config.ui.error("F", false) [filename, warnings] else @config.ui.confirm(".", false) nil end end.compact unless success? @config.ui.warn "\n\nWarnings:" @results.each do |filename, warnings| @config.ui.info "\n#{filename}:" warnings.each do |warning| @config.ui.error " - #{warning}" end end end puts "\n#{dependencies.size} dependencies checked, #{@results.size} warnings found." end def success? @results.empty? end end end end