Skip to content

Commit 2e0cea3

Browse files
authored
#155 add failOnDetection plugin configuration to generate OSS Index report without failing build (#158)
1 parent ba31077 commit 2e0cea3

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ plugins {
6868
}
6969
```
7070

71-
Some basic examples will be provided next, which we strongly advice to read :)
71+
Some basic examples follow, which we strongly advise reading :)
7272

7373
After doing so, specific usage on CI tools can be found at https://github.com/guillermo-varela/example-scan-gradle-plugin
7474

@@ -104,6 +104,10 @@ ossIndexAudit {
104104
excludeCoordinates = ['commons-fileupload:commons-fileupload:1.3'] // list containing coordinate of components which if vulnerable should be ignored
105105
excludeCompileOnly = true // if true then dependencies under the 'compileOnly' configuration will be ignored. By default is false
106106
107+
// By default, the audit scan will fail the task/build if any vulnerabilities are found.
108+
// Set this to 'false' to allow the task to succeed even when vulnerabilities are detected.
109+
failOnDetection = true
110+
107111
// Output options
108112
outputFormat = 'DEFAULT' // Optional, other values are: 'DEPENDENCY_GRAPH' prints dependency graph showing direct/transitive dependencies, 'JSON_CYCLONE_DX_1_4' prints a CycloneDX 1.4 SBOM in JSON format.
109113
cycloneDxComponentType = 'LIBRARY' // Optional, only used when outputFormat = 'JSON_CYCLONE_DX_1_4' to define the type of component this project is for the BOM metadata with possible values: 'LIBRARY' (default), 'APPLICATION', 'FRAMEWORK', 'CONTAINER', 'OPERATING_SYSTEM', 'DEVICE', 'FIRMWARE' and 'FILE'.
@@ -144,6 +148,10 @@ ossIndexAudit {
144148
listOf("commons-fileupload:commons-fileupload:1.3") // list containing coordinate of components which if vulnerable should be ignored
145149
excludeCompileOnly = true // if true then dependencies under the 'compileOnly' configuration will be ignored. By default is false
146150

151+
// By default, the audit scan will fail the task/build if any vulnerabilities are found.
152+
// Set this to 'false' to allow the task to succeed even when vulnerabilities are detected.
153+
failOnDetection = true
154+
147155
// Output options
148156
outputFormat = "DEFAULT" // Optional, other values are: "DEPENDENCY_GRAPH" prints dependency graph showing direct/transitive dependencies, "JSON_CYCLONE_DX_1_4" prints a CycloneDX 1.4 SBOM in JSON format.
149157
cycloneDxComponentType = "LIBRARY" // Optional, only used when outputFormat = "JSON_CYCLONE_DX_1_4" to define the type of component this project is for the BOM metadata with possible values: "LIBRARY" (default), "APPLICATION", "FRAMEWORK", "CONTAINER", "OPERATING_SYSTEM", "DEVICE", "FIRMWARE" and "FILE".

src/main/java/org/sonatype/gradle/plugins/scan/ossindex/OssIndexAuditTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void audit() {
122122
throw new GradleException("Could not audit the project: " + e.getMessage(), e);
123123
}
124124

125-
if (hasVulnerabilities) {
125+
if (hasVulnerabilities && extension.isFailOnDetection()) {
126126
throw new GradleException("Vulnerabilities detected, check log output to review them");
127127
}
128128
}

src/main/java/org/sonatype/gradle/plugins/scan/ossindex/OssIndexPluginExtension.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public class OssIndexPluginExtension
6363

6464
private boolean printBanner;
6565

66+
private boolean failOnDetection;
67+
6668
private Set<String> excludeVulnerabilityIds;
6769

6870
private Set<String> excludeCoordinates;
@@ -86,6 +88,7 @@ public OssIndexPluginExtension(Project project) {
8688
colorEnabled = true;
8789
showAll = false;
8890
printBanner = true;
91+
failOnDetection = true;
8992
excludeVulnerabilityIds = new HashSet<>();
9093
excludeCoordinates = new HashSet<>();
9194
outputFormat = OutputFormat.DEFAULT;
@@ -214,6 +217,14 @@ public void setPrintBanner(boolean printBanner) {
214217
this.printBanner = printBanner;
215218
}
216219

220+
public boolean isFailOnDetection() {
221+
return failOnDetection;
222+
}
223+
224+
public void setFailOnDetection(boolean failOnDetection) {
225+
this.failOnDetection = failOnDetection;
226+
}
227+
217228
public Set<String> getExcludeVulnerabilityIds() {
218229
return excludeVulnerabilityIds;
219230
}

src/test/java/org/sonatype/gradle/plugins/scan/ossindex/OssIndexAuditTaskTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.mockito.junit.MockitoJUnitRunner;
4545

4646
import static org.assertj.core.api.Assertions.assertThat;
47+
import static org.assertj.core.api.Assertions.assertThatCode;
4748
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4849
import static org.gradle.api.plugins.JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME;
4950
import static org.mockito.ArgumentMatchers.anyList;
@@ -91,6 +92,16 @@ public void testAudit_vulnerabilities() throws Exception {
9192
verify(ossIndexClientMock).requestComponentReports(eq(Collections.singletonList(COMMONS_COLLECTIONS_PURL)));
9293
}
9394

95+
@Test
96+
public void testAudit_vulnerabilitiesNoFailOnDetection() throws Exception {
97+
setupComponentReport(true);
98+
OssIndexAuditTask taskSpy = buildAuditTaskSpy(false, (project, extension) -> extension.setFailOnDetection(false));
99+
100+
assertThatCode(taskSpy::audit).doesNotThrowAnyException();
101+
102+
verify(ossIndexClientMock).requestComponentReports(eq(Collections.singletonList(COMMONS_COLLECTIONS_PURL)));
103+
}
104+
94105
@Test
95106
public void testAudit_verifyModulesIncludedIsApplied() throws Exception {
96107
setupComponentReport(true);

0 commit comments

Comments
 (0)