Skip to content

Commit f0ac7bd

Browse files
committed
Adds the following analysis tools to the MMTC Gradle build:
- SpotBugs (with FindSecBugs) - This is currently enabled for all subprojects, where it adds two new tasks (spotbugsMain and spotbugsTest) that generate reports - These task's configuration currently do not fail the build when issues are found; we will enable this and start pursuing incremental improvement in future changes - A dependency checker, provided by OWASP - This is currently disabled, as it seems that the database it relies on (NVD) is essentially unavailable at this time Also converted Asciidoctor task to a simpler JavaExec task that can run in a forked JVM, as its SnakeYAML dependency conflicts with a dependency of one of the new plugins.
1 parent 08fe328 commit f0ac7bd

File tree

8 files changed

+96
-42
lines changed

8 files changed

+96
-42
lines changed

build.gradle.kts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import com.netflix.gradle.plugins.packaging.CopySpecEnhancement.permissionGroup
22
import com.netflix.gradle.plugins.packaging.CopySpecEnhancement.user
33
import com.netflix.gradle.plugins.rpm.Rpm
4-
import org.asciidoctor.gradle.jvm.pdf.AsciidoctorPdfTask
54

65
plugins {
76
distribution
87
id("com.netflix.nebula.ospackage") version "11.11.2"
9-
id("org.asciidoctor.jvm.convert") version "4.0.5"
10-
id("org.asciidoctor.jvm.pdf") version "4.0.5"
8+
id("mmtc.java-conventions")
119
}
1210

1311
allprojects {
@@ -29,27 +27,35 @@ allprojects {
2927
}
3028
}
3129

32-
asciidoctorj {
33-
fatalWarnings("Errno")
30+
val asciidoctorRuntime by configurations.creating
31+
32+
dependencies {
33+
asciidoctorRuntime("org.asciidoctor:asciidoctorj:2.5.7")
34+
asciidoctorRuntime("org.asciidoctor:asciidoctorj-pdf:2.3.10")
3435
}
3536

36-
val asciidoctor = tasks.register<AsciidoctorPdfTask>("userGuidePdf") {
37+
// runs in a separate JVM to hide its older snakeyaml dependency from conflicting with a newer snakeyaml dependency brought in by SCA plugins
38+
val asciidoctor = tasks.register<JavaExec>("userGuidePdf") {
3739
inputs.files("docs/MMTC_Users_Guide.adoc")
3840
inputs.files("docs/themes/basic/basic-theme.yml")
39-
40-
setBaseDir(file("docs"))
41-
setSourceDir(file("docs"))
42-
setOutputDir(file("build/docs"))
43-
setTheme("basic")
44-
4541
outputs.dir("build/docs")
46-
}
4742

48-
pdfThemes {
49-
local("basic") {
50-
themeDir = file("docs/themes/basic")
51-
themeName = "basic"
52-
}
43+
group = "documentation"
44+
description = "Generate a PDF of MMTC's User Guide from its .adoc source"
45+
46+
classpath = asciidoctorRuntime
47+
mainClass.set("org.asciidoctor.jruby.cli.AsciidoctorInvoker")
48+
49+
// read from https://github.com/asciidoctor/asciidoctorj/blob/main/asciidoctorj-cli/src/main/java/org/asciidoctor/cli/AsciidoctorCliOptions.java
50+
args(
51+
"-b", "pdf", // backend
52+
"-B", "docs", // 'base' dir
53+
"-R", "docs", // 'source' dir
54+
"-D", "build/docs", // 'destination' dir
55+
"-a", "pdf-theme=basic", // theme attrs
56+
"-a", "pdf-themesdir=themes/basic", // theme attrs
57+
"docs/MMTC_Users_Guide.adoc"
58+
)
5359
}
5460

5561
val createDistDir = tasks.register("createDistDir") {

buildSrc/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ repositories {
1414
gradlePluginPortal()
1515
}
1616

17+
dependencies {
18+
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:6.4.7")
19+
implementation("org.owasp:dependency-check-gradle:12.1.9")
20+
}

buildSrc/src/main/kotlin/java-conventions.gradle.kts

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import com.github.spotbugs.snom.Confidence
2+
3+
plugins {
4+
`java-library`
5+
jacoco
6+
id("com.github.spotbugs")
7+
id("org.owasp.dependencycheck")
8+
}
9+
10+
java.sourceCompatibility = JavaVersion.VERSION_1_8
11+
12+
tasks.withType<JavaCompile>() {
13+
options.encoding = "UTF-8"
14+
}
15+
16+
tasks.withType<Javadoc>() {
17+
options.encoding = "UTF-8"
18+
}
19+
20+
tasks.test {
21+
extensions.configure(JacocoTaskExtension::class) {
22+
includes = listOf("edu.jhuapl.*")
23+
}
24+
}
25+
26+
dependencies {
27+
spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.14.0")
28+
}
29+
30+
// --------------------------------------------
31+
// SpotBugs configuration
32+
// --------------------------------------------
33+
34+
spotbugs {
35+
ignoreFailures.set(true) // todo set to 'false' to fail build upon failures found in spotbugs tasks
36+
reportLevel.set(Confidence.MEDIUM)
37+
}
38+
39+
tasks.spotbugsMain {
40+
enabled = true
41+
reports.create("html") {
42+
required.set(true)
43+
outputLocation.set(file("$buildDir/reports/spotbugs.html"))
44+
setStylesheet("fancy-hist.xsl")
45+
}
46+
}
47+
48+
tasks.spotbugsTest {
49+
enabled = false // disable SCA for test files, for now
50+
reports.create("html") {
51+
required.set(true)
52+
outputLocation.set(file("$buildDir/reports/tests/spotbugsTest.html"))
53+
setStylesheet("fancy-hist.xsl")
54+
}
55+
}
56+
57+
// --------------------------------------------
58+
// OWASP Dependency Check configuration
59+
// --------------------------------------------
60+
61+
dependencyCheck {
62+
failBuildOnCVSS = 7.toFloat() // range is 1 to 10, 7 and above is High and Critical
63+
suppressionFile = file("../buildSrc/src/main/resources/owasp/owasp-dependency-check-suppressions.xml").toString()
64+
}

mmtc-core/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import java.io.ByteArrayOutputStream
22
import java.time.Instant
33

44
plugins {
5-
id("java-conventions")
5+
id("mmtc.java-conventions")
66
`maven-publish`
77
}
88

mmtc-output-plugin-sdk/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import java.time.Instant
22

33
plugins {
4-
id("java-conventions")
4+
id("mmtc.java-conventions")
55
}
66

77
dependencies {

mmtc-plugin-ampcs/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import java.time.Instant
22

33
plugins {
4-
id("java-conventions")
4+
id("mmtc.java-conventions")
55
}
66

77
val precompiledJniSpiceClasses by configurations.creating {

mmtc-tlm-source-plugin-sdk/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import java.time.Instant
22

33
plugins {
4-
id("java-conventions")
4+
id("mmtc.java-conventions")
55
}
66

77
dependencies {

0 commit comments

Comments
 (0)