@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
44import org.cyclonedx.gradle.utils.CycloneDxUtils
55import org.cyclonedx.model.Bom
66import org.cyclonedx.model.Component
7+ import org.cyclonedx.model.Tool
78import org.gradle.testkit.runner.GradleRunner
89import org.gradle.testkit.runner.TaskOutcome
910import spock.lang.Specification
@@ -654,4 +655,40 @@ class PluginConfigurationSpec extends Specification {
654655 assert cycloneDxTool. getName() == " cyclonedx-gradle-plugin"
655656 assert cycloneDxTool. getAuthor() == " CycloneDX"
656657 }
658+
659+ def " should use legacy tools section if schema is below 1.5" () {
660+ given :
661+ File testDir = TestUtils . createFromString("""
662+ plugins {
663+ id 'org.cyclonedx.bom'
664+ id 'java'
665+ }
666+ repositories {
667+ mavenCentral()
668+ }
669+ group = 'com.example'
670+ version = '1.0.0'
671+ cyclonedxBom {
672+ schemaVersion = "1.4"
673+ }
674+ dependencies {
675+ implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.15.0'
676+ }""" , " rootProject.name = 'hello-world'" )
677+
678+ when :
679+ def result = GradleRunner . create()
680+ .withProjectDir(testDir)
681+ .withArguments(" cyclonedxBom" , " --configuration-cache" )
682+ .withPluginClasspath()
683+ .build()
684+
685+ then :
686+ result. task(" :cyclonedxBom" ). outcome == TaskOutcome . SUCCESS
687+ File jsonBom = new File (testDir, " build/reports/bom.json" )
688+ Bom bom = new ObjectMapper (). readValue(jsonBom, Bom . class)
689+ assert bom. getMetadata(). getTools(). size() == 1
690+ Tool tool = bom. getMetadata(). getTools(). get(0 );
691+ assert tool. getName() == " cyclonedx-gradle-plugin"
692+ assert tool. getVendor() == " CycloneDX"
693+ }
657694}
0 commit comments