lib/licensed/dependency.rb in licensed-0.6.0 vs lib/licensed/dependency.rb in licensed-0.10.0
- old
+ new
@@ -1,20 +1,30 @@
require "licensee"
module Licensed
class Dependency < License
- LEGAL_FILES = /\A(COPYING|NOTICE|LEGAL)(?:\..*)?\z/i
+ LEGAL_FILES = /\A(AUTHORS|COPYING|NOTICE|LEGAL)(?:\..*)?\z/i
attr_reader :path
+ attr_reader :search_root
def initialize(path, metadata = {})
@path = path
+ @search_root = metadata.delete("search_root")
+
+ # with licensee now providing license_file[:dir],
+ # enforcing absolute paths makes life much easier when determining
+ # an absolute file path in notices\
+ unless Pathname.new(path).absolute?
+ raise "Dependency path #{path} must be absolute"
+ end
+
super metadata
end
def project
- @project ||= Licensee::FSProject.new(path, detect_packages: true, detect_readme: true)
+ @project ||= Licensee::Projects::FSProject.new(path, search_root: search_root, detect_packages: true, detect_readme: true)
end
def detect_license!
if project.license_file
license = project.license.key if project.license
@@ -37,14 +47,22 @@
project.license.key if project.license
end
# Extract legal notices from the dependency source
def notices
+ return [] unless Dir.exist? path
+
files = Dir.foreach(path).select do |file|
File.file?(File.join(path, file)) && file.match(LEGAL_FILES)
end
- files.unshift project.license_file.filename if project.license_file
- files.uniq.map { |f| File.read(File.join(path, f)) }
+ if license_file = project.license_file
+ files.unshift File.join(license_file[:dir], license_file.filename)
+ end
+
+ files.uniq.map do |f|
+ absolute_path = Pathname.new(f).absolute? ? f : File.join(path, f)
+ File.read(absolute_path)
+ end
end
end
end