From ef81af387fa8c6577d85387e354a491da93f5a47 Mon Sep 17 00:00:00 2001 From: Max True Date: Wed, 21 Jun 2023 11:15:35 +0200 Subject: [PATCH] Support of latest Conan v1.6 --- lib/license_finder/package_managers/conan.rb | 23 ++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/license_finder/package_managers/conan.rb b/lib/license_finder/package_managers/conan.rb index 0ec7f7e3..f475ccf2 100644 --- a/lib/license_finder/package_managers/conan.rb +++ b/lib/license_finder/package_managers/conan.rb @@ -8,6 +8,20 @@ def possible_package_paths [project_path.join('conanfile.txt')] end + def license_file_is_good?(license_file_path) + license_file_path != nil && File.file?(license_file_path) + end + + def license_file(project_path, name) + candidates = Dir.glob("#{project_path}/licenses/#{name}/**/LICENSE*") + candidates.each do |candidate| + if license_file_is_good?(candidate) + return candidate + end + end + nil + end + def current_packages install_command = 'conan install .' info_command = 'conan info .' @@ -19,9 +33,14 @@ def current_packages deps = info_parser.parse(info_output) deps.map do |dep| name, version = dep['name'].split('/') + license_file_path = license_file(project_path, name) + + unless license_file_is_good?(license_file_path) + next + end + url = dep['URL'] - license_file_path = Dir.glob("#{project_path}/licenses/#{name}/**/LICENSE*").first - ConanPackage.new(name, version, File.open(license_file_path).read, url) unless name == 'conanfile.txt' + ConanPackage.new(name, version, File.open(license_file_path).read, url) end.compact end end