collect_licenses

in lib/omnibus/dependency_information.rb [41:124]


    def collect_licenses
      
      project.library.each do |component|
        result = {
          name: component.name,
          version: component.version,
          license: component.license,
          license_texts: [],
          dependencies: [],
        }

        license_texts = []
        component.license_files.each do |license_file|

          
          
          
          
          
          
          
          license_file_path = license_package_location(component.name, license_file)
          license_texts << File.read(license_file_path) if File.exist?(license_file_path)
        end
        result[:license_texts] = license_texts.flatten

        component.dependencies.each do |name|
          dependency = project.library.find { |software| software.name == name }

          item = {
            name: name,
            version: dependency.version,
            license: dependency.license,
            license_texts: [],
          }

          
          
          
          
          
          
          license_texts = []
          dependency.license_files.each do |license_file|
            license_file_path = license_package_location(name, license_file)
            license_texts << File.read(license_file_path) if File.exist?(license_file_path)
          end
          item[:license_texts] = license_texts.flatten

          result[:dependencies] << item
        end

        @final_output << result
      end

      
      json_licenses_dir = File.expand_path("licenses", project.install_dir)
      Dir.glob(File.expand_path("*.json", json_licenses_dir)).each do |json_file|
        
        component = File.basename(json_file, File.extname(json_file))

        
        index = @final_output.each_index.find { |software_index| @final_output[software_index][:name] == component }

        
        dependencies_info = JSON.parse(File.read(json_file))["dependencies"]
        dependencies_info.map do |info|
          license_texts = []
          %w{texts notice}.each do |type|
            license_texts << info[type] if info[type] && !info[type].empty?
          end

          item = {
            name: info["name"],
            version: info["version"],
            license: info["licenses"].join(", "),
            license_texts: license_texts.flatten,
          }

          @final_output[index][:dependencies] << item
        end
      end
    end