Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add an option to include all licenses in one file #701

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions lib/omnibus/licensing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def project_license_content
# For details, see:
# /opt/opscode/LICENSES/python-LICENSE
# ...
#
# If #{project.license_compiled_output} is set
# it will append the license contents
# @return [String]
#
def components_license_summary
Expand All @@ -218,9 +219,14 @@ def components_license_summary
out << "This product bundles #{name} #{version},\n"
out << "which is available under a \"#{license}\" License.\n"
if !license_files.empty?
out << "For details, see:\n"
out << "Details:\n\n"
license_files.each do |license_file|
out << "#{license_package_location(name, license_file)}\n"
path = license_package_location(name, license_file)
if project.license_compiled_output
out << "#{license_content(path)}"
else
out << "#{path}\n"
end
end
end
out << "\n"
Expand All @@ -229,6 +235,24 @@ def components_license_summary
out
end

#
# Reads the content of the license file
# It is in the form of:
# ...
# MIT License
# Permission is hereby granted, free of charge, to any person obtaining
# ...
#
# @return [String]
#
def license_content(path)
if File.exist?(path)
File.read(path)
else
path
end
end

#
# Map that collects information about the licenses of the softwares
# included in the project.
Expand Down
8 changes: 8 additions & 0 deletions lib/omnibus/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,14 @@ def license_file_path(path = NULL)
end
expose :license_file_path

def license_compiled_output(val = NULL)
if null?(val)
@license_compiled_output
else
@license_compiled_output = val
end
end
expose :license_compiled_output
#
# Location of json-formated version manifest, written at at the
# end of the build. If no path is specified
Expand Down
15 changes: 15 additions & 0 deletions spec/functional/licensing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Omnibus
let(:license_file_path) { nil }
let(:license_file) { nil }
let(:zlib_version_override) { nil }
let(:license_compiled_output) { nil }

let(:install_dir) { File.join(tmp_path, "install_dir") }
let(:software_project_dir) { File.join(tmp_path, "software_project_dir") }
Expand Down Expand Up @@ -95,6 +96,8 @@ module Omnibus
if zlib_version_override
project.override :zlib, version: zlib_version_override
end
project.license_compiled_output(license_compiled_output) unless license_compiled_output.nil?
project.build_version('1.2.3')
end
end

Expand Down Expand Up @@ -271,5 +274,17 @@ def create_licenses
expect { create_licenses }.to raise_error(Omnibus::LicensingError, /Project 'test-project' does not contain licensing information.\s{1,}Software 'private_code' does not contain licensing information./)
end
end

describe "with license_compiled_output set" do
let(:license_compiled_output) { true }

it "creates the main license file for the project correctly" do
create_licenses
project_license = File.join(install_dir, expected_project_license_path)
expect(File.exist?(project_license)).to be(true)
project_license = File.read(project_license)
expect(project_license).to match /THIS PACKAGE IS PROVIDED \"AS IS\" AND WITHOUT ANY EXPRESS OR\nIMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED\nWARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE./
end
end
end
end