@@ -65,6 +65,60 @@ public static async Task<int> Merge(MergeCommandOptions options)
6565 return ( int ) ExitCode . ParameterValidationError ;
6666 }
6767
68+ var inputBoms = await InputBoms ( DetermineInputFiles ( options ) , options . InputFormat , outputToConsole ) . ConfigureAwait ( false ) ;
69+
70+ Component bomSubject = null ;
71+ if ( options . Group != null || options . Name != null || options . Version != null )
72+ bomSubject = new Component
73+ {
74+ Type = Component . Classification . Application ,
75+ Group = options . Group ,
76+ Name = options . Name ,
77+ Version = options . Version ,
78+ } ;
79+
80+ Bom outputBom ;
81+ if ( options . Hierarchical )
82+ {
83+ outputBom = CycloneDXUtils . HierarchicalMerge ( inputBoms , bomSubject ) ;
84+ }
85+ else
86+ {
87+ outputBom = CycloneDXUtils . FlatMerge ( inputBoms ) ;
88+ if ( outputBom . Metadata is null ) outputBom . Metadata = new Metadata ( ) ;
89+ if ( bomSubject != null )
90+ {
91+ // use the params provided if possible
92+ outputBom . Metadata . Component = bomSubject ;
93+ }
94+ else
95+ {
96+ // otherwise use the first non-null component from the input BOMs as the default
97+ foreach ( var bom in inputBoms )
98+ {
99+ if ( bom . Metadata != null && bom . Metadata . Component != null )
100+ {
101+ outputBom . Metadata . Component = bom . Metadata . Component ;
102+ break ;
103+ }
104+ }
105+ }
106+ }
107+
108+ outputBom . Version = 1 ;
109+ outputBom . SerialNumber = "urn:uuid:" + System . Guid . NewGuid ( ) . ToString ( ) ;
110+
111+ if ( ! outputToConsole )
112+ {
113+ Console . WriteLine ( "Writing output file..." ) ;
114+ Console . WriteLine ( $ " Total { outputBom . Components ? . Count ?? 0 } components") ;
115+ }
116+
117+ return await CliUtils . OutputBomHelper ( outputBom , options . OutputFormat , options . OutputFile ) . ConfigureAwait ( false ) ;
118+ }
119+
120+ private static List < string > DetermineInputFiles ( MergeCommandOptions options )
121+ {
68122 List < string > InputFiles ;
69123 if ( options . InputFiles != null )
70124 {
@@ -124,56 +178,8 @@ public static async Task<int> Merge(MergeCommandOptions options)
124178 // in case the parameter was not passed
125179 InputFiles = null ;
126180 }
127- var inputBoms = await InputBoms ( InputFiles , options . InputFormat , outputToConsole ) . ConfigureAwait ( false ) ;
128181
129- Component bomSubject = null ;
130- if ( options . Group != null || options . Name != null || options . Version != null )
131- bomSubject = new Component
132- {
133- Type = Component . Classification . Application ,
134- Group = options . Group ,
135- Name = options . Name ,
136- Version = options . Version ,
137- } ;
138-
139- Bom outputBom ;
140- if ( options . Hierarchical )
141- {
142- outputBom = CycloneDXUtils . HierarchicalMerge ( inputBoms , bomSubject ) ;
143- }
144- else
145- {
146- outputBom = CycloneDXUtils . FlatMerge ( inputBoms ) ;
147- if ( outputBom . Metadata is null ) outputBom . Metadata = new Metadata ( ) ;
148- if ( bomSubject != null )
149- {
150- // use the params provided if possible
151- outputBom . Metadata . Component = bomSubject ;
152- }
153- else
154- {
155- // otherwise use the first non-null component from the input BOMs as the default
156- foreach ( var bom in inputBoms )
157- {
158- if ( bom . Metadata != null && bom . Metadata . Component != null )
159- {
160- outputBom . Metadata . Component = bom . Metadata . Component ;
161- break ;
162- }
163- }
164- }
165- }
166-
167- outputBom . Version = 1 ;
168- outputBom . SerialNumber = "urn:uuid:" + System . Guid . NewGuid ( ) . ToString ( ) ;
169-
170- if ( ! outputToConsole )
171- {
172- Console . WriteLine ( "Writing output file..." ) ;
173- Console . WriteLine ( $ " Total { outputBom . Components ? . Count ?? 0 } components") ;
174- }
175-
176- return await CliUtils . OutputBomHelper ( outputBom , options . OutputFormat , options . OutputFile ) . ConfigureAwait ( false ) ;
182+ return InputFiles ;
177183 }
178184
179185 private static async Task < IEnumerable < Bom > > InputBoms ( IEnumerable < string > inputFilenames , CycloneDXBomFormat inputFormat , bool outputToConsole )
0 commit comments