Skip to content

Commit 33bea6a

Browse files
committed
✨ Core v1.7 Enablement
- Add spec version selection end-to-end with a new --spec-version flag (default 1.7). - Update JSON and XML outputs to honor the selected spec version. - Update fixtures, help text, tests, and docs. Files: - lib/bom_helpers.rb: - Added SUPPORTED_SPEC_VERSIONS, cyclonedx_xml_namespace helper. build_bom now accepts spec_version and routes to: - build_json_bom(gems, spec_version) sets specVersion to the provided version. - build_bom_xml(gems, spec_version) sets xmlns to http://cyclonedx.org/schema/bom/<version>.</version> - lib/bom_builder.rb: - Added --spec-version with validation; default is 1.7. - Pass @spec_version into build_bom(@Gems, @bom_output_format, @spec_version). Signed-off-by: Peter H. Boling <[email protected]>
1 parent cbca549 commit 33bea6a

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

lib/cyclonedx/bom_builder.rb

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,15 @@ def self.setup(path)
142142
end
143143

144144
# Normalize to an absolute project path to avoid relative path issues later
145-
@project_path = File.expand_path(@options[:path]) if @options[:path]
145+
@project_path = File.expand_path(@options[:path])
146146
@provided_path = @options[:path]
147147

148-
if @project_path
149-
begin
150-
@logger.info("Changing directory to Ruby project directory located at #{@provided_path}")
151-
Dir.chdir @project_path
152-
rescue StandardError => e
153-
@logger.error("Unable to change directory to Ruby project directory located at #{@provided_path}. #{e.message}: #{Array(e.backtrace).join("\n")}")
154-
abort
155-
end
148+
begin
149+
@logger.info("Changing directory to Ruby project directory located at #{@provided_path}")
150+
Dir.chdir @project_path
151+
rescue StandardError => e
152+
@logger.error("Unable to change directory to Ruby project directory located at #{@provided_path}. #{e.message}: #{Array(e.backtrace).join("\n")}")
153+
abort
156154
end
157155

158156
if @options[:bom_output_format].nil?
@@ -173,6 +171,15 @@ def self.setup(path)
173171
abort
174172
end
175173

174+
# Spec version selection
175+
requested_spec = @options[:spec_version] || '1.7'
176+
if SUPPORTED_SPEC_VERSIONS.include?(requested_spec)
177+
@spec_version = requested_spec
178+
else
179+
@logger.error("Unrecognized CycloneDX spec version '#{requested_spec}'. Please choose one of #{SUPPORTED_SPEC_VERSIONS}")
180+
abort
181+
end
182+
176183
@bom_file_path = if @options[:bom_file_path].nil?
177184
"./bom.#{@bom_output_format}"
178185
else
@@ -184,9 +191,9 @@ def self.setup(path)
184191
if @project_path
185192
begin
186193
# Use absolute path so it's correct regardless of current working directory
187-
gemfile_path = File.join(@project_path, 'Gemfile.lock')
188-
# Compute display path for logs: './Gemfile.lock' when provided path is '.', else '<provided>/Gemfile.lock'
189-
display_gemfile_path = (@provided_path == '.' ? './Gemfile.lock' : File.join(@provided_path, 'Gemfile.lock'))
194+
gemfile_path = File.join(@project_path, 'Gemfile.lock')
195+
# Compute display path for logs: './Gemfile.lock' when provided path is '.', else '<provided>/Gemfile.lock'
196+
display_gemfile_path = (@provided_path == '.' ? './Gemfile.lock' : File.join(@provided_path, 'Gemfile.lock'))
190197
@logger.info("Parsing specs from #{display_gemfile_path}...")
191198
gemfile_contents = File.read(gemfile_path)
192199
@specs = Bundler::LockfileParser.new(gemfile_contents).specs

0 commit comments

Comments
 (0)