Skip to content

Commit 2d578d4

Browse files
committed
fix: add missing test case
Signed-off-by: Jeremy Long <[email protected]>
1 parent a80edd2 commit 2d578d4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/test/groovy/org/cyclonedx/gradle/PluginConfigurationSpec.groovy

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
44
import org.cyclonedx.gradle.utils.CycloneDxUtils
55
import org.cyclonedx.model.Bom
66
import org.cyclonedx.model.Component
7+
import org.cyclonedx.model.Tool
78
import org.gradle.testkit.runner.GradleRunner
89
import org.gradle.testkit.runner.TaskOutcome
910
import 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

Comments
 (0)