Skip to content

Commit 5efaf99

Browse files
ThomasVitaleglefloch
authored andcommitted
Fix support for CycloneDX 1.5
Fix bug causing the CycloneDX 1.5 schema version to be ignored by the plugin with fallback to 1.4. Update docs with spec references to version 1.5. Fixes gh-361 Signed-off-by: Thomas Vitale <[email protected]>
1 parent 9454b4e commit 5efaf99

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ allprojects{
132132
## How to manually modify Metadata
133133

134134
The Plugin makes it possible to manually add Manufacture-Data and Licenses-Data to the Metadata of the BOM. <br>
135-
The structure of the Metadata is shown on https://cyclonedx.org/docs/1.4/json/#metadata. <br>
135+
The structure of the Metadata is shown on https://cyclonedx.org/docs/1.5/json/#metadata. <br>
136136
The editing of the Manufacture and Licenses-Data is optional. If the Manufacture/Licenses-Date isn't edited,
137137
then the respective structure won't appear in the BOM.
138138

@@ -184,7 +184,7 @@ cyclonedxBom {
184184
It should be noted that some Data like OrganizationalContact, Url, Name,... can be left out. <br>
185185
OrganizationalEntity can also include multiple OrganizationalContact.
186186

187-
For details look at https://cyclonedx.org/docs/1.4/json/#metadata.
187+
For details look at https://cyclonedx.org/docs/1.5/json/#metadata.
188188

189189

190190
## Adding Licenses-Data
@@ -263,7 +263,7 @@ cyclonedxBom {
263263
}
264264
```
265265
---
266-
For details of the BOM structure look at https://cyclonedx.org/docs/1.4/json/#metadata.
266+
For details of the BOM structure look at https://cyclonedx.org/docs/1.5/json/#metadata.
267267

268268
## CycloneDX Schema Support
269269

src/main/java/org/cyclonedx/gradle/CycloneDxTask.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
import java.util.stream.Collectors;
8080
import java.util.stream.Stream;
8181

82-
8382
public class CycloneDxTask extends DefaultTask {
8483

8584
/**
@@ -115,7 +114,7 @@ public class CycloneDxTask extends DefaultTask {
115114

116115
public CycloneDxTask() {
117116
schemaVersion = getProject().getObjects().property(String.class);
118-
schemaVersion.convention(CycloneDxSchema.Version.VERSION_15.getVersionString());
117+
schemaVersion.convention(CycloneDxUtils.DEFAULT_SCHEMA_VERSION.getVersionString());
119118

120119
outputName = getProject().getObjects().property(String.class);
121120
outputName.convention("bom");

src/main/java/org/cyclonedx/gradle/utils/CycloneDxUtils.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
public class CycloneDxUtils {
66

7+
public static final CycloneDxSchema.Version DEFAULT_SCHEMA_VERSION = CycloneDxSchema.Version.VERSION_15;
8+
79
/**
810
* Resolves the CycloneDX schema the mojo has been requested to use.
911
* @return the CycloneDX schema to use
@@ -14,7 +16,9 @@ public static CycloneDxSchema.Version schemaVersion(String version) {
1416
case "1.1": return CycloneDxSchema.Version.VERSION_11;
1517
case "1.2": return CycloneDxSchema.Version.VERSION_12;
1618
case "1.3": return CycloneDxSchema.Version.VERSION_13;
17-
default: return CycloneDxSchema.Version.VERSION_14;
19+
case "1.4": return CycloneDxSchema.Version.VERSION_14;
20+
case "1.5": return CycloneDxSchema.Version.VERSION_15;
21+
default: return DEFAULT_SCHEMA_VERSION;
1822
}
1923
}
2024

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.cyclonedx.gradle
22

33
import com.fasterxml.jackson.databind.ObjectMapper
4+
import org.cyclonedx.gradle.utils.CycloneDxUtils
45
import org.cyclonedx.model.Bom
56
import org.cyclonedx.model.Component
67
import org.gradle.testkit.runner.GradleRunner
@@ -27,7 +28,7 @@ class PluginConfigurationSpec extends Specification {
2728
assert reportDir.exists()
2829
}
2930

30-
def "simple-project should output boms in build/reports with version 1.4"() {
31+
def "simple-project should output boms in build/reports with default schema version"() {
3132
given:
3233
File testDir = TestUtils.duplicate("simple-project")
3334

@@ -44,7 +45,7 @@ class PluginConfigurationSpec extends Specification {
4445
assert reportDir.exists()
4546
reportDir.listFiles().length == 2
4647
File jsonBom = new File(reportDir, "bom.json")
47-
assert jsonBom.text.contains("\"specVersion\" : \"1.4\"")
48+
assert jsonBom.text.contains("\"specVersion\" : \"${CycloneDxUtils.DEFAULT_SCHEMA_VERSION.versionString}\"")
4849
}
4950

5051
def "custom-destination project should output boms in output-dir"() {

0 commit comments

Comments
 (0)