lib/licensed/dependency.rb in licensed-4.0.4 vs lib/licensed/dependency.rb in licensed-4.1.0

- old
+ new

@@ -7,10 +7,11 @@ attr_reader :name attr_reader :version attr_reader :errors attr_reader :path + attr_reader :additional_terms # Create a new project dependency # # name - unique dependency name # version - dependency version @@ -26,10 +27,11 @@ @version = version @metadata = metadata @errors = errors path = path.to_s @path = path + @additional_terms = [] # enforcing absolute paths makes life much easier when determining # an absolute file path in #notices if File.exist?(path) && !Pathname.new(path).absolute? # this is an internal error related to source implementation and @@ -78,10 +80,17 @@ files << generated_license_contents if files.empty? files.compact end + + # Override the behavior of Licensee::Projects::FSProject#project_files to include + # additional license terms + def project_files + super + additional_license_terms_files + end + # Returns legal notices found at the dependency path def notice_contents Dir.glob(dir_path.join("*")) .grep(LEGAL_FILES_PATTERN) .select { |path| File.file?(path) } @@ -100,10 +109,11 @@ # # Sources are returned as a single string with sources separated by ", " def license_content_sources(files) paths = Array(files).map do |file| next file[:uri] if file[:uri] + next file[:source] if file[:source] path = dir_path.join(file[:dir], file[:name]) normalize_source_path(path) end @@ -154,8 +164,25 @@ { "sources" => "Auto-generated #{license.spdx_id} license text", "text" => text } + end + + # Returns an array of Licensee::ProjectFiles::LicenseFile created from + # this dependency's additional license terms + def additional_license_terms_files + @additional_license_terms_files ||= begin + files = additional_terms.map do |path| + next unless File.file?(path) + + metadata = { dir: File.dirname(path), name: File.basename(path) } + Licensee::ProjectFiles::LicenseFile.new( + load_file(metadata), + { source: "License terms loaded from #{metadata[:name]}" } + ) + end + files.compact + end end end end