Skip to content

Commit

Permalink
refactor(cyclonedx): Continue with remaining formats even if one failed
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Jul 16, 2024
1 parent 229a76e commit 5503c68
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5503c68

Please sign in to comment.