42
42
import org .cyclonedx .model .LifecycleChoice ;
43
43
import org .cyclonedx .model .Lifecycles ;
44
44
import org .cyclonedx .model .Metadata ;
45
+ import org .cyclonedx .model .OrganizationalContact ;
46
+ import org .cyclonedx .model .OrganizationalEntity ;
45
47
import org .cyclonedx .model .Property ;
48
+ import org .cyclonedx .model .organization .PostalAddress ;
46
49
import org .cyclonedx .parsers .JsonParser ;
47
50
import org .cyclonedx .parsers .Parser ;
48
51
import org .cyclonedx .parsers .XmlParser ;
57
60
import java .util .LinkedHashSet ;
58
61
import java .util .List ;
59
62
import java .util .Map ;
63
+ import java .util .Objects ;
60
64
import java .util .Set ;
61
65
import java .util .UUID ;
62
66
@@ -247,6 +251,13 @@ public abstract class BaseCycloneDxMojo extends AbstractMojo {
247
251
@ Parameter
248
252
private ExternalReference [] externalReferences ;
249
253
254
+ /**
255
+ * Manufacturer information for automatic creator information
256
+ * @since 2.9.1
257
+ */
258
+ @ Parameter (property = "cyclonedx.manufacturer" , required = false )
259
+ private OrganizationalEntity manufacturer = null ;
260
+
250
261
@ org .apache .maven .plugins .annotations .Component
251
262
private MavenProjectHelper mavenProjectHelper ;
252
263
@@ -351,6 +362,10 @@ public void execute() throws MojoExecutionException {
351
362
if (detectUnusedForOptionalScope ) {
352
363
metadata .addProperty (newProperty ("maven.optional.unused" , Boolean .toString (detectUnusedForOptionalScope )));
353
364
}
365
+
366
+ if (hasManufacturerInformation ()) {
367
+ metadata .setManufacturer (manufacturer );
368
+ }
354
369
}
355
370
356
371
final Component rootComponent = metadata .getComponent ();
@@ -362,6 +377,82 @@ public void execute() throws MojoExecutionException {
362
377
}
363
378
}
364
379
380
+ /**
381
+ * Check the mojo configuration for the optional manufacturer contents.
382
+ *
383
+ * @return {@code true} if there is any manufacturer information configured.
384
+ */
385
+ boolean hasManufacturerInformation () {
386
+ if (manufacturer == null ) {
387
+ return false ;
388
+ }
389
+
390
+ return isNotNullOrEmpty (manufacturer .getAddress ()) ||
391
+ isNotNullOrEmpty (manufacturer .getName ()) ||
392
+ isNotNullOrEmptyContacts (manufacturer .getContacts ()) ||
393
+ isNotNullOrEmptyString (manufacturer .getUrls ());
394
+ }
395
+
396
+ /**
397
+ * @param text Some text
398
+ * @return {@code true} if there is any text
399
+ */
400
+ boolean isNotNullOrEmpty (String text ) {
401
+ return text != null && !text .trim ().isEmpty ();
402
+ }
403
+
404
+ /**
405
+ * @param list A list of text
406
+ * @return {@code true} if there is any element has a text value
407
+ */
408
+ boolean isNotNullOrEmptyString (List <String > list ) {
409
+ if (list != null && !list .isEmpty ()) {
410
+ return list .stream ().filter (Objects ::nonNull ).anyMatch (this ::isNotNullOrEmpty );
411
+ }
412
+ return false ;
413
+ }
414
+
415
+ /**
416
+ * @param list A list of contacts
417
+ * @return {@code true} if there is any contact has something configured
418
+ */
419
+ boolean isNotNullOrEmptyContacts (List <OrganizationalContact > list ) {
420
+ if (list != null && !list .isEmpty ()) {
421
+ return list .stream ().filter (Objects ::nonNull ).anyMatch (this ::isNotNullOrEmpty );
422
+
423
+ }
424
+ return false ;
425
+ }
426
+
427
+ /**
428
+ * @param address A postal address entry
429
+ * @return {@code true} if there is any postal address information exists
430
+ */
431
+ boolean isNotNullOrEmpty (PostalAddress address ) {
432
+ if (address == null ) {
433
+ return false ;
434
+ }
435
+ return isNotNullOrEmpty (address .getStreetAddress ()) ||
436
+ isNotNullOrEmpty (address .getCountry ()) ||
437
+ isNotNullOrEmpty (address .getPostalCode ()) ||
438
+ isNotNullOrEmpty (address .getLocality ()) ||
439
+ isNotNullOrEmpty (address .getPostOfficeBoxNumber ()) ||
440
+ isNotNullOrEmpty (address .getRegion ());
441
+ }
442
+
443
+ /**
444
+ * @param contact A contact entry
445
+ * @return {@code true} if there is any contact information exists
446
+ */
447
+ boolean isNotNullOrEmpty (OrganizationalContact contact ) {
448
+ if (null == contact ) {
449
+ return false ;
450
+ }
451
+ return isNotNullOrEmpty (contact .getName ()) ||
452
+ isNotNullOrEmpty (contact .getEmail ()) ||
453
+ isNotNullOrEmpty (contact .getPhone ());
454
+ }
455
+
365
456
private Property newProperty (String name , String value ) {
366
457
Property property = new Property ();
367
458
property .setName (name );
0 commit comments