From 5503c68efb21acbcdad5d1594cabb7aaa6950907 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Mon, 15 Jul 2024 22:48:40 +0200 Subject: [PATCH] refactor(cyclonedx): Continue with remaining formats even if one failed Signed-off-by: Sebastian Schuberth --- .../cyclonedx/src/main/kotlin/CycloneDxReporter.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt b/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt index 5c105da1058bd..b17d2238aaf6a 100644 --- a/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt +++ b/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt @@ -24,6 +24,8 @@ import java.util.Date import java.util.SortedSet import java.util.UUID +import org.apache.logging.log4j.kotlin.logger + import org.cyclonedx.Version import org.cyclonedx.generators.BomGeneratorFactory import org.cyclonedx.model.AttachmentText @@ -368,10 +370,14 @@ class CycloneDxReporter : Reporter { outputFileExtensions.forEach { fileExtension -> val outputFile = outputDir.resolve("$outputName.$fileExtension") - val bom = generateBom(bom, schemaVersion, fileExtension) - - outputFile.bufferedWriter().use { it.write(bom) } - writtenFiles += outputFile + runCatching { + generateBom(bom, schemaVersion, fileExtension) + }.onSuccess { bom -> + outputFile.bufferedWriter().use { it.write(bom) } + writtenFiles += outputFile + }.onFailure { + logger.error("Unable to create CycloneDX report: ", it) + } } return writtenFiles