Skip to content

Commit 590b24a

Browse files
committed
Unify javadoc as Mockito Javadoc plugin
Fixes #3446 # Conflicts: # gradle/libs.versions.toml
1 parent c519c14 commit 590b24a

14 files changed

Lines changed: 105 additions & 100 deletions

File tree

buildSrc/src/main/kotlin/Common.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import org.gradle.accessors.dm.LibrariesForLibs
12
import org.gradle.api.Project
3+
import org.gradle.api.tasks.SourceSetContainer
24
import org.gradle.kotlin.dsl.the
35

46
val Project.libs
5-
get() = the<org.gradle.accessors.dm.LibrariesForLibs>()
7+
get() = the<LibrariesForLibs>()
8+
9+
val Project.sourceSets
10+
get() = the<SourceSetContainer>()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import org.gradle.api.provider.Property
2+
3+
interface MockitoJavadocExtension {
4+
val title: Property<String>
5+
val docTitle: Property<String>
6+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import org.gradle.api.tasks.javadoc.Javadoc
2+
3+
plugins {
4+
java
5+
}
6+
7+
val mockitoJavadocExtension = project.extensions.create<MockitoJavadocExtension>("mockitoJavadoc").apply {
8+
title.convention(project.name)
9+
docTitle.convention("<h1>${project.name}</h1>")
10+
}
11+
12+
val javadocConfigDir = "$rootDir/config/javadoc"
13+
14+
tasks.named<Javadoc>("javadoc") {
15+
inputs.dir(javadocConfigDir)
16+
description = "Creates javadoc html for ${project.name}."
17+
18+
// For more details on the format
19+
// see https://docs.oracle.com/en/java/javase/21/javadoc/javadoc.html
20+
21+
source = project.sourceSets["main"].allJava
22+
23+
options {
24+
title = mockitoJavadocExtension.title.get()
25+
destinationDirectory = project.layout.buildDirectory.dir("javadoc").get().asFile
26+
encoding = "UTF-8"
27+
28+
if (this is StandardJavadocDocletOptions) {
29+
addBooleanOption("-allow-script-in-comments", true)
30+
addFileOption("-add-stylesheet", file("$javadocConfigDir/resources/mockito-theme.css"))
31+
addStringOption("Xwerror", "-quiet")
32+
charSet = "UTF-8"
33+
docEncoding = "UTF-8"
34+
docTitle = mockitoJavadocExtension.docTitle.get()
35+
36+
bottom(
37+
"""
38+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/obsidian.min.css">
39+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
40+
<script>hljs.highlightAll();</script>
41+
""".trimIndent().replace("\r|\n|[ ]{8}".toRegex(), "")
42+
)
43+
44+
group("Main package", "org.mockito")
45+
links("https://junit.org/junit4/javadoc/${project.libs.versions.junit4.get()}/")
46+
linksOffline(
47+
"https://docs.oracle.com/en/java/javase/11/docs/api/",
48+
"$javadocConfigDir/jdk-package-list"
49+
)
50+
51+
isSplitIndex = true
52+
isUse = true
53+
windowTitle = mockitoJavadocExtension.title.get()
54+
55+
addBooleanOption("html5", true)
56+
}
57+
memberLevel = JavadocMemberLevel.PROTECTED
58+
outputLevel = JavadocOutputLevel.QUIET
59+
60+
doLast {
61+
copy {
62+
from("$javadocConfigDir/resources")
63+
into(project.layout.buildDirectory.dir("javadoc"))
64+
}
65+
}
66+
}
67+
}

buildSrc/src/main/kotlin/mockito.publication-conventions.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ plugins.withType<JavaPlugin>().configureEach {
8989

9090
val sourcesJar by tasks.registering(Jar::class) {
9191
archiveClassifier.set("sources")
92-
val sourceSets: SourceSetContainer by project
93-
from(sourceSets["main"].allSource)
92+
from(project.sourceSets["main"].allSource)
9493
with(licenseSpec)
9594
}
9695

File renamed without changes.
File renamed without changes.
File renamed without changes.

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[versions]
22
bytebuddy = "1.15.4"
33
errorprone = "2.23.0"
4+
junit4 = "4.13.2"
45
junit-jupiter = "5.11.2"
56
junit-platform = "1.11.2"
67
kotlin = "2.0.21"
@@ -24,7 +25,7 @@ errorprone = { module = "com.google.errorprone:error_prone_core", version.ref =
2425
errorprone-test-api = { module = "com.google.errorprone:error_prone_test_helpers", version.ref = "errorprone" }
2526
groovy = { module = "org.codehaus.groovy:groovy", version = "3.0.22" }
2627
hamcrest = { module = "org.hamcrest:hamcrest-core", version = "3.0" }
27-
junit4 = { module = "junit:junit", version = "4.13.2" }
28+
junit4 = { module = "junit:junit", version.ref = "junit4" }
2829
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" }
2930
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter" }
3031
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter" }

0 commit comments

Comments
 (0)