Skip to content

Commit 9cbee94

Browse files
barblinskhokhlov
authored andcommitted
Signed-off-by: Johannes Özkan Preisinger <[email protected]>
1 parent a03550a commit 9cbee94

File tree

2 files changed

+142
-1
lines changed

2 files changed

+142
-1
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.cyclonedx.model.Hash;
5151
import org.cyclonedx.model.LicenseChoice;
5252
import org.cyclonedx.model.Metadata;
53+
import org.cyclonedx.model.OrganizationalEntity;
5354
import org.cyclonedx.model.Property;
5455
import org.cyclonedx.model.Tool;
5556
import org.cyclonedx.model.metadata.ToolInformation;
@@ -127,7 +128,10 @@ private Metadata buildMetadata(final SbomComponent parentComponent) {
127128
e);
128129
}
129130
metadata.setLicenseChoice(task.getLicenseChoice());
130-
metadata.setManufacture(task.getOrganizationalEntity());
131+
132+
if (!(new OrganizationalEntity()).equals(task.getOrganizationalEntity())) {
133+
metadata.setManufacturer(task.getOrganizationalEntity());
134+
}
131135

132136
final Properties pluginProperties = readPluginProperties();
133137
if (!pluginProperties.isEmpty()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package org.cyclonedx.gradle.utils
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper
4+
import org.cyclonedx.gradle.TestUtils
5+
import org.cyclonedx.model.Bom
6+
import org.gradle.testkit.runner.GradleRunner
7+
import org.gradle.testkit.runner.TaskOutcome
8+
import spock.lang.Specification
9+
10+
class OrganizationalEntityUtilTest extends Specification {
11+
12+
def "manufacturer should be empty if no organizational entity is provided"() {
13+
given: "A mocked project directory with no git repo configuration"
14+
File testDir = TestUtils.createFromString(
15+
"""
16+
plugins {
17+
id 'org.cyclonedx.bom'
18+
id 'java'
19+
}
20+
repositories {
21+
mavenCentral()
22+
}
23+
group = 'com.example'
24+
version = '1.0.0'
25+
26+
cyclonedxBom {
27+
}
28+
29+
dependencies {
30+
implementation("org.hibernate:hibernate-core:5.6.15.Final")
31+
}""", "rootProject.name = 'hello-world'"
32+
)
33+
34+
and: "given the current test directory context (otherwise it will pick up the repo url from cycloneDx repo)"
35+
System.setProperty("user.dir", testDir.toPath().toString())
36+
37+
when:
38+
def result = GradleRunner.create()
39+
.withProjectDir(testDir)
40+
.withArguments("cyclonedxBom")
41+
.withPluginClasspath()
42+
.build()
43+
44+
then:
45+
result.task(":cyclonedxBom").outcome == TaskOutcome.SUCCESS
46+
File jsonBom = new File(testDir, "build/reports/bom.json")
47+
Bom bom = new ObjectMapper().readValue(jsonBom, Bom.class)
48+
49+
assert bom.getMetadata().getManufacturer() == null
50+
}
51+
52+
def "manufacturer should be empty if empty organizational entity is provided"() {
53+
given: "A mocked project directory with no git repo configuration"
54+
File testDir = TestUtils.createFromString(
55+
"""
56+
plugins {
57+
id 'org.cyclonedx.bom'
58+
id 'java'
59+
}
60+
repositories {
61+
mavenCentral()
62+
}
63+
group = 'com.example'
64+
version = '1.0.0'
65+
66+
cyclonedxBom {
67+
setOrganizationalEntity { oe ->
68+
oe.name = null
69+
}
70+
}
71+
72+
dependencies {
73+
implementation("org.hibernate:hibernate-core:5.6.15.Final")
74+
}""", "rootProject.name = 'hello-world'"
75+
)
76+
77+
and: "given the current test directory context (otherwise it will pick up the repo url from cycloneDx repo)"
78+
System.setProperty("user.dir", testDir.toPath().toString())
79+
80+
when:
81+
def result = GradleRunner.create()
82+
.withProjectDir(testDir)
83+
.withArguments("cyclonedxBom")
84+
.withPluginClasspath()
85+
.build()
86+
87+
then:
88+
result.task(":cyclonedxBom").outcome == TaskOutcome.SUCCESS
89+
File jsonBom = new File(testDir, "build/reports/bom.json")
90+
Bom bom = new ObjectMapper().readValue(jsonBom, Bom.class)
91+
92+
assert bom.getMetadata().getManufacturer() == null
93+
}
94+
95+
def "manufacturer should not be empty if organizational entity is provided"() {
96+
given: "A mocked project directory with no git repo configuration"
97+
File testDir = TestUtils.createFromString(
98+
"""
99+
plugins {
100+
id 'org.cyclonedx.bom'
101+
id 'java'
102+
}
103+
repositories {
104+
mavenCentral()
105+
}
106+
group = 'com.example'
107+
version = '1.0.0'
108+
109+
cyclonedxBom {
110+
setOrganizationalEntity { oe ->
111+
oe.name = "name"
112+
}
113+
}
114+
115+
dependencies {
116+
implementation("org.hibernate:hibernate-core:5.6.15.Final")
117+
}""", "rootProject.name = 'hello-world'"
118+
)
119+
120+
and: "given the current test directory context (otherwise it will pick up the repo url from cycloneDx repo)"
121+
System.setProperty("user.dir", testDir.toPath().toString())
122+
123+
when:
124+
def result = GradleRunner.create()
125+
.withProjectDir(testDir)
126+
.withArguments("cyclonedxBom")
127+
.withPluginClasspath()
128+
.build()
129+
130+
then:
131+
result.task(":cyclonedxBom").outcome == TaskOutcome.SUCCESS
132+
File jsonBom = new File(testDir, "build/reports/bom.json")
133+
Bom bom = new ObjectMapper().readValue(jsonBom, Bom.class)
134+
135+
assert bom.getMetadata().getManufacturer().getName() == "name"
136+
}
137+
}

0 commit comments

Comments
 (0)