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

Adds license text gathering #20

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions cyclonedx-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
spec.add_dependency('nokogiri', '~> 1.8')
spec.add_dependency('ostruct', '~> 0.1')
spec.add_dependency('rest-client', '~> 2.0')
spec.add_dependency('activesupport')
spec.add_development_dependency 'rake', '~> 12'
spec.add_development_dependency 'rspec', '~> 3.7'
end
17 changes: 17 additions & 0 deletions lib/bom_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#
# frozen_string_literal: true
require 'bundler'
require 'bundler/cli'
require 'fileutils'
require 'json'
require 'logger'
Expand Down Expand Up @@ -90,6 +91,9 @@ def self.setup(path)
opts.on('-f', '--format bom_output_format', '(Optional) Output format for bom. Currently support xml (default) and json.') do |bom_output_format|
@options[:bom_output_format] = bom_output_format
end
opts.on('-l', '--include-license-text', '(Optional) Include full license text') do |l|
@options[:include_licenses] = l
end
opts.on_tail('-h', '--help', 'Show help message') do
puts opts
exit
Expand Down Expand Up @@ -170,6 +174,19 @@ def self.specs_list
else
object.license_name = gem['licenses'].first
end

if @options[:include_licenses]
if spec = Bundler::CLI::Common.select_spec(dependency.name, :regex_match)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/AssignmentInCondition: Use == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

gem_path = spec.full_gem_path
potential_license_files.each do |potential_license_file|
potential_license_full_path = "#{gem_path}/#{potential_license_file}"
if File.exist?(potential_license_full_path)
object.license_text = File.read(potential_license_full_path)
break
end
end
end
end
end

object.author = gem['authors']
Expand Down
31 changes: 17 additions & 14 deletions lib/bom_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ def hash_val
]
}

if @gem['license_id']
component_hash[:"licenses"] = [
"license": {
"id": @gem['license_id']
}
]
elsif @gem['license_name']
component_hash[:"licenses"] = [
"license": {
"name": @gem['license_name']
}
]
if @gem['license_text'] || @gem['license_name']
license_section = {
license: {}
}

if @gem['license_id']
license_section[:license][:id] = @gem['license_id']
elsif @gem['license_name']
license_section[:license][:name] = @gem['license_name']
end

if @gem['license_text']
license_section[:license][:text] = { content: @gem['license_text'] }
end

component_hash[:licenses] = [license_section]
end

[component_hash]

end
end
end
16 changes: 16 additions & 0 deletions lib/bom_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,19 @@ def get_gem(name, version)
nil
end
end

def potential_license_files
%w[
COPYING
LICENSE
license.md
Licence.md
LICENSE.md
LICENSE.txt
License.rdoc
LICENSE.rdoc
MIT-LICENSE
MIT-LICENSE.txt
]
end