bundler-sbom 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b738f4193f079f261d93aeb53ac8d3e467cd509b14ccf8a8370296c6c029673
4
- data.tar.gz: fd6f0c0014fb5cdf6ecc1821ece9a7c1d678b9796830d8ebae0c87c81b7fe8fa
3
+ metadata.gz: bb720a4c1407de48380f89d81cfb76c76c9aaf72477e06de9d42e2154b278ddf
4
+ data.tar.gz: '0596c33babc35714c4515f6eb7f018bbabbe22350734650c060f34788a28bb0f'
5
5
  SHA512:
6
- metadata.gz: 89545f261837196ef20c7582f61d10e474a232f22bc87927120f639e22a1d8398e74936a406378b8024f47b05172209ab0fd15195e755477bad16bdc647e9ed4
7
- data.tar.gz: f7a48d2f7768ee3f594f248b24a7b3e0ec62aa803c23ed17f8fa17bd4559770b4ae75b2b3d4bda1184797cf22c1cff99fa56705fbc4f359547b1bcbea74f5423
6
+ metadata.gz: a1878c226f0f1dc92967c05dcb52539de886734eed0395a734164c426d14cffcccebf53c13dab7f5113c4497efe44c9b7bcca2898d638a1f84cc88362502f1f8
7
+ data.tar.gz: 5fb51be53f651ec22422f33fdbb8859842cef43911681ed70d104f9582856f741816491df1a8b67a322122f4eecb21355dabdd9e6d103ab85016f08ea5506a90
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  group :development do
6
+ gem "thor"
6
7
  gem "rake"
7
8
  gem "rspec"
8
9
  gem "simplecov", require: false
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 SHIBATA Hiroshi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
- require "thor"
2
1
  require "json"
3
2
  require "bundler/sbom/generator"
3
+ require "bundler/sbom/reporter"
4
4
 
5
5
  module Bundler
6
6
  module Sbom
@@ -21,7 +21,7 @@ module Bundler
21
21
 
22
22
  begin
23
23
  sbom = JSON.parse(File.read("bom.json"))
24
- Bundler::Sbom::Generator.display_license_report(sbom)
24
+ Bundler::Sbom::Reporter.display_license_report(sbom)
25
25
  rescue JSON::ParserError
26
26
  Bundler.ui.error("Error: bom.json is not a valid JSON file")
27
27
  exit 1
@@ -3,11 +3,14 @@ require "securerandom"
3
3
 
4
4
  module Bundler
5
5
  module Sbom
6
+ class GemfileLockNotFoundError < StandardError; end
7
+
6
8
  class Generator
7
9
  def self.generate_sbom
8
10
  lockfile_path = Bundler.default_lockfile
9
- unless lockfile_path.exist?
10
- abort "No Gemfile.lock found. Run `bundle install` first."
11
+ if !lockfile_path || !lockfile_path.exist?
12
+ Bundler.ui.error "No Gemfile.lock found. Run `bundle install` first."
13
+ raise GemfileLockNotFoundError, "No Gemfile.lock found"
11
14
  end
12
15
 
13
16
  lockfile = Bundler::LockfileParser.new(lockfile_path.read)
@@ -57,6 +60,7 @@ module Bundler
57
60
  "filesAnalyzed" => false,
58
61
  "licenseConcluded" => license_string,
59
62
  "licenseDeclared" => license_string,
63
+ "copyrightText" => "NOASSERTION",
60
64
  "supplier" => "NOASSERTION",
61
65
  "externalRefs" => [
62
66
  {
@@ -69,50 +73,9 @@ module Bundler
69
73
  sbom["packages"] << package
70
74
  end
71
75
 
76
+ sbom["documentDescribes"] = sbom["packages"].map { |p| p["SPDXID"] }
72
77
  sbom
73
78
  end
74
-
75
- def self.display_license_report(sbom)
76
- license_count = analyze_licenses(sbom)
77
- sorted_licenses = license_count.sort_by { |_, count| -count }
78
-
79
- puts "=== License Usage in SBOM ==="
80
- puts "Total packages: #{sbom["packages"].size}"
81
- puts
82
-
83
- sorted_licenses.each do |license, count|
84
- puts "#{license}: #{count} package(s)"
85
- end
86
-
87
- puts "\n=== Packages by License ==="
88
- sorted_licenses.each do |license, _|
89
- packages = sbom["packages"].select do |package|
90
- if package["licenseDeclared"].include?(",")
91
- package["licenseDeclared"].split(",").map(&:strip).include?(license)
92
- else
93
- package["licenseDeclared"] == license
94
- end
95
- end
96
-
97
- puts "\n#{license} (#{packages.size} package(s)):"
98
- packages.each do |package|
99
- puts " - #{package["name"]} (#{package["versionInfo"]})"
100
- end
101
- end
102
- end
103
-
104
- private
105
-
106
- def self.analyze_licenses(sbom)
107
- license_count = Hash.new(0)
108
- sbom["packages"].each do |package|
109
- licenses = package["licenseDeclared"].split(",").map(&:strip)
110
- licenses.each do |license|
111
- license_count[license] += 1
112
- end
113
- end
114
- license_count
115
- end
116
79
  end
117
80
  end
118
81
  end
@@ -0,0 +1,47 @@
1
+ module Bundler
2
+ module Sbom
3
+ class Reporter
4
+ def self.display_license_report(sbom)
5
+ license_count = analyze_licenses(sbom)
6
+ sorted_licenses = license_count.sort_by { |_, count| -count }
7
+
8
+ puts "=== License Usage in SBOM ==="
9
+ puts "Total packages: #{sbom["packages"].size}"
10
+ puts
11
+
12
+ sorted_licenses.each do |license, count|
13
+ puts "#{license}: #{count} package(s)"
14
+ end
15
+
16
+ puts "\n=== Packages by License ==="
17
+ sorted_licenses.each do |license, _|
18
+ packages = sbom["packages"].select do |package|
19
+ if package["licenseDeclared"].include?(",")
20
+ package["licenseDeclared"].split(",").map(&:strip).include?(license)
21
+ else
22
+ package["licenseDeclared"] == license
23
+ end
24
+ end
25
+
26
+ puts "\n#{license} (#{packages.size} package(s)):"
27
+ packages.each do |package|
28
+ puts " - #{package["name"]} (#{package["versionInfo"]})"
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def self.analyze_licenses(sbom)
36
+ license_count = Hash.new(0)
37
+ sbom["packages"].each do |package|
38
+ licenses = package["licenseDeclared"].split(",").map(&:strip)
39
+ licenses.each do |license|
40
+ license_count[license] += 1
41
+ end
42
+ end
43
+ license_count
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  module Bundler
2
2
  module Sbom
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-sbom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - SHIBATA Hiroshi
@@ -23,21 +23,7 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '2.0'
26
- - !ruby/object:Gem::Dependency
27
- name: thor
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
- description: Generate CycloneDX SBOM(Software Bill of Materials) files with Bundler
26
+ description: Generate SPDX SBOM(Software Bill of Materials) files with Bundler
41
27
  email:
42
28
  - hsbt@ruby-lang.org
43
29
  executables: []
@@ -45,15 +31,18 @@ extensions: []
45
31
  extra_rdoc_files: []
46
32
  files:
47
33
  - Gemfile
34
+ - LICENSE
48
35
  - README.md
49
36
  - Rakefile
50
37
  - lib/bundler/sbom.rb
51
38
  - lib/bundler/sbom/cli.rb
52
39
  - lib/bundler/sbom/generator.rb
40
+ - lib/bundler/sbom/reporter.rb
53
41
  - lib/bundler/sbom/version.rb
54
42
  - plugins.rb
55
43
  homepage: https://github.com/hsbt/bundler-sbom
56
- licenses: []
44
+ licenses:
45
+ - MIT
57
46
  metadata:
58
47
  homepage_uri: https://github.com/hsbt/bundler-sbom
59
48
  source_code_uri: https://github.com/hsbt/bundler-sbom
@@ -75,5 +64,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
64
  requirements: []
76
65
  rubygems_version: 3.6.2
77
66
  specification_version: 4
78
- summary: Generate CycloneDX SBOM(Software Bill of Materials) files with Bundler
67
+ summary: Generate SPDX SBOM(Software Bill of Materials) files with Bundler
79
68
  test_files: []