Commit c10de1a0 authored by Balasankar C's avatar Balasankar C Committed by Balasankar C
Browse files

Remove repeated tasks and generate a single file

We were generating a flat JSON file with license information of all
dependencies. However, with , we want to
categorize them based on dependencies. We can do this either using a
separate file (which has additional dependency relationship) or we can
modify the existing code to generate a single file that has all the
necessary information. This commit does the latter and can be reverted
in case it is not needed.
parent 1406534d
...@@ -3,8 +3,8 @@ require 'json' ...@@ -3,8 +3,8 @@ require 'json'
module Omnibus module Omnibus
class DependencyInformation class DependencyInformation
include Logging
JSON_FILE = "dependency_licenses.json".freeze JSON_FILE = "dependency_licenses.json".freeze
DEP_FILE = "dependency_relations.json".freeze
class << self class << self
def process!(project) def process!(project)
...@@ -22,78 +22,46 @@ module Omnibus ...@@ -22,78 +22,46 @@ module Omnibus
File.expand_path(JSON_FILE, project.install_dir) File.expand_path(JSON_FILE, project.install_dir)
end end
def dep_location
File.expand_path(DEP_FILE, project.install_dir)
def process! def process!
csv_output = "" final_output = []
output = {}
# Handling all libraries
project.library.each do |component| project.library.each do |component|
csv_output += "#{},#{component.version},#{component.license}\n" result = {name:, version: component.version, license: component.license, dependencies: []}
end component.dependencies.each do |name|
dependency = project.library.find {|software| == name }
# Concatenating contents of CSV files from individual components with the version = dependency.version
# one generate above. license = dependency.license
csv_dir = File.expand_path("licenses", project.install_dir)
Dir.glob(File.expand_path("*.csv", csv_dir)).each do |csv_file|
csv_output += + "\n"
# Creating JSON output
csv_output.each_line do |line|
line = line.strip
next if line.empty?
components = line.split(",")
output[components[0]] = {"version": components[1], "license": components[2]}
end, "w") do |f|
generate_relation(project, output) result[:dependencies] << {name: name, 'version': version, license: license }
def generate_relation(project, output)
relations = {}
keys = []
project.library.each do |component|
unless relations.has_key?(component)
keys <<
relations[] = []
component.dependencies.each do |dependency|
relations[] << {'name': dependency, 'version': output[dependency][:version], 'license': output[dependency][:license] }
end end
final_output << result
end end
# Handling external dependencies of those libraries, if provided explicitly
csv_dir = File.expand_path("licenses", project.install_dir) csv_dir = File.expand_path("licenses", project.install_dir)
Dir.glob(File.expand_path("*.csv", csv_dir)).each do |csv_file| Dir.glob(File.expand_path("*.csv", csv_dir)).each do |csv_file|
# Getting the software name from file name
component = File.basename(csv_file, File.extname(csv_file)) component = File.basename(csv_file, File.extname(csv_file))
unless relations.has_key?(component) # Find index of the software in final output
keys << component index = final_output.each_index.find{ |software_index| final_output[software_index][:name] == component }
relations[component] = []
csv_output = csv_output =
csv_output.each_line do |line| csv_output.each_line do |line|
line = line.strip line = line.strip
next if line.empty? next if line.empty?
dependencies = line.split(",") information = line.split(",")
dependency = dependencies[0] dependency = information[0]
relations[component] << {'name': dependency, 'version': output[dependency][:version], 'license': output[dependency][:license] } version = information[1]
license = information[2]
final_output[index][:dependencies] << {name: dependency, 'version': version, license: license}
end end
end end
f =, "w"), "w") do |f|
final_output = [] f.write(JSON.pretty_generate(final_output))
keys.each do |key|
final_output << {name: key, version: output[key][:version], license: output[key][:license], dependencies: relations[key]}
end end
end end
end end
end end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment