Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 094b282

Browse files
authored
Migrate to Dokka 0.10.1 (#385)
* Migrate to Dokka 0.10.1 * Upgrade other dependencies * Fix dependency injection issue and cover it with a test * Fix dependency injection issue and cover it with a test * Adjust sample project * Extend contribution with instructions for the Dokka test JAR * Add note that Dokka only builds with JDK 8 * Review feedback and spell checker
1 parent 61b3c09 commit 094b282

File tree

12 files changed

+222
-312
lines changed

12 files changed

+222
-312
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ before_install:
1616
- mvn install:install-file -Dfile=lib/spring-restdocs-core-2.0.4.RELEASE-test.jar
1717
-DgroupId=org.springframework.restdocs -DartifactId=spring-restdocs-core -Dversion=2.0.4.RELEASE
1818
-Dpackaging=jar -Dclassifier=test
19+
- mvn install:install-file -Dfile=lib/dokka-core-0.10.1-tests.jar
20+
-DgroupId=org.jetbrains.dokka -DartifactId=dokka-core -Dversion=0.10.1
21+
-Dpackaging=jar -Dclassifier=test
1922
script:
2023
- mvn install -B -V
2124
- cd samples

lib/dokka-core-0.10.1-tests.jar

415 KB
Binary file not shown.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5050
<snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
5151
<spring-restdocs.version>2.0.4.RELEASE</spring-restdocs.version>
52+
<dokka.version>0.10.1</dokka.version>
5253
</properties>
5354

5455
<build>

samples/kotlin-webmvc/build.gradle

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
springAutoRestDocsVersion = "2.0.9-SNAPSHOT"
55
springRestDocsVersion = "2.0.4.RELEASE"
66
springBootVersion = "2.2.6.RELEASE"
7-
dokkaVersion = "0.9.18"
7+
dokkaPluginVersion = "0.10.1"
88
}
99
repositories {
1010
jcenter()
@@ -17,7 +17,7 @@ buildscript {
1717
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlinVersion"
1818
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
1919
classpath "org.asciidoctor:asciidoctor-gradle-plugin:1.5.9.2"
20-
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion"
20+
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaPluginVersion"
2121
}
2222
}
2323

@@ -67,16 +67,8 @@ dependencies {
6767
testImplementation "com.jayway.jsonpath:json-path-assert"
6868
testImplementation "org.springframework.restdocs:spring-restdocs-core:$springRestDocsVersion"
6969
testImplementation "org.springframework.restdocs:spring-restdocs-mockmvc:$springRestDocsVersion"
70-
// Java 11 fix for https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j
71-
testImplementation "javax.xml.bind:jaxb-api:2.3.0"
72-
testImplementation "com.sun.xml.bind:jaxb-core:2.3.0.1"
73-
testImplementation "com.sun.xml.bind:jaxb-impl:2.3.0.1"
74-
testImplementation "javax.activation:activation:1.1.1"
75-
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
76-
testImplementation "capital.scalable:spring-auto-restdocs-json-doclet:$springAutoRestDocsVersion"
77-
} else {
78-
testImplementation "capital.scalable:spring-auto-restdocs-json-doclet-jdk9:$springAutoRestDocsVersion"
79-
}}
70+
dokkaRuntime "capital.scalable:spring-auto-restdocs-dokka-json:$springAutoRestDocsVersion"
71+
}
8072

8173
test {
8274
systemProperty "org.springframework.restdocs.outputDir", snippetsDir
@@ -109,6 +101,8 @@ jar {
109101
dokka {
110102
outputFormat = "auto-restdocs-json"
111103
outputDirectory = javadocJsonDir
112-
includeNonPublic = true
113-
dokkaFatJar = "capital.scalable:spring-auto-restdocs-dokka-json:$springAutoRestDocsVersion"
104+
configuration {
105+
includeNonPublic = true
106+
reportUndocumented = false
107+
}
114108
}

samples/kotlin-webmvc/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<spring-restdocs.version>2.0.4.RELEASE</spring-restdocs.version>
3737
<spring-auto-restdocs.version>2.0.9-SNAPSHOT</spring-auto-restdocs.version>
3838
<kotlin.version>1.3.71</kotlin.version>
39-
<dokka.version>0.9.18</dokka.version>
39+
<dokka.version>0.10.1</dokka.version>
4040
<jsonDirectory>${project.build.directory}/generated-javadoc-json</jsonDirectory>
4141
</properties>
4242

@@ -343,6 +343,7 @@
343343
<prefix>capital.scalable.restdocs.example</prefix>
344344
<!-- This feature only works inside packageOptions for the Maven plugin -->
345345
<includeNonPublic>true</includeNonPublic>
346+
<reportUndocumented>false</reportUndocumented>
346347
</packageOptions>
347348
</perPackageOptions>
348349
</configuration>

spring-auto-restdocs-docs/contributing.adoc

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
[[contributing-building]]
55
=== Building from source
66

7-
[[contributing-installing-testjar]]
7+
[[contributing-installing-restdocs-testjar]]
88
==== Install Spring REST Docs test JAR
99

1010
The Spring REST Docs test JAR is not published via Maven, but this project relies on it.
1111
If you want to build this project yourself, you need to install the test JAR.
12-
The test JAR is located in the lib folder and can be installed as follow:
12+
The test JAR is located in the lib folder and can be installed as follows:
1313

1414
.Bash
1515
[source,bash]
@@ -19,7 +19,22 @@ mvn install:install-file -Dfile=lib/spring-restdocs-core-${spring-restdocs.versi
1919
-Dversion=${spring-restdocs.version} -Dpackaging=test-jar -Dclassifier=test
2020
----
2121

22-
[[contributing-building-testjar]]
22+
[[contributing-installing-dokka-testjar]]
23+
==== Install Dokka Core test JAR
24+
25+
Dokka publishes no test JAR, but the Spring Auto REST Docs Dokka extension uses their test utilities.
26+
If you want to build this project yourself, you need to install the test JAR.
27+
The test JAR is located in the lib folder and can be installed as follows:
28+
29+
.Bash
30+
[source,bash]
31+
----
32+
mvn install:install-file -Dfile=lib/dokka-core-${dokka.version}-tests.jar \
33+
-DgroupId=org.jetbrains.dokka -DartifactId=dokka-core -Dversion=${dokka.version} \
34+
-Dpackaging=jar -Dclassifier=test
35+
----
36+
37+
[[contributing-building-restdocs-testjar]]
2338
==== Build Spring REST Docs test JAR
2439

2540
Building the Spring REST Docs test JAR is not required to build the project,
@@ -57,6 +72,49 @@ Afterwards the test JAR is located at
5772
`spring-restdocs/spring-restdocs-core/build/libs/spring-restdocs-core-${spring-restdocs.version}-test.jar`
5873
and has to be installed with the Maven command shown in the section above.
5974

75+
[[contributing-building-dokka-testjar]]
76+
==== Build Dokka Core test JAR
77+
78+
Building the Dokka core test JAR is not required to build the project,
79+
but if you ever want to upgrade the version of Dokka in this project this step has to be done.
80+
81+
We use version ${dokka.version} of Dokka in this example.
82+
83+
Clone and checkout a specific version of Dokka:
84+
85+
.Bash
86+
[source,bash]
87+
----
88+
git clone git@github.com:Kotlin/dokka.git
89+
cd dokka
90+
git checkout ${dokka.version}
91+
----
92+
93+
Add the following snippet at the end of `core/build.gradle`:
94+
95+
[source,groovy]
96+
----
97+
task testJar(type: Jar) {
98+
classifier = 'tests'
99+
from sourceSets.test.output
100+
}
101+
----
102+
103+
To speed the build up and avoid test issues, once can reduce the list of sub-projects in
104+
`settings.gradle` to just `core` and `integration`.
105+
106+
Make sure to use JDK 8 for the build.
107+
Create the test JAR by running the following command on the top-level:
108+
109+
.Bash
110+
[source,bash]
111+
----
112+
./gradlew testJar
113+
----
114+
115+
Afterwards the test JAR is located at
116+
`core/build/libs/core-${dokka.version}-SNAPSHOT-tests.jar`
117+
60118
[[contributing-building-build]]
61119
==== Build
62120

spring-auto-restdocs-dokka-json/pom.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
<properties>
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<kotlin.version>1.3.41</kotlin.version>
21+
<!-- Kotlin version bundled with Dokka -->
22+
<kotlin.version>1.3.61</kotlin.version>
2223
<junit.version>4.12</junit.version>
23-
<jackson.version>2.9.9</jackson.version>
24-
<dokka.version>0.9.18</dokka.version>
24+
<jackson.version>2.10.3</jackson.version>
2525
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
26+
<maven.compiler.source>1.8</maven.compiler.source>
27+
<maven.compiler.target>1.8</maven.compiler.target>
2628
</properties>
2729

2830
<dependencies>
@@ -48,6 +50,13 @@
4850
<artifactId>dokka-fatjar</artifactId>
4951
<version>${dokka.version}</version>
5052
</dependency>
53+
<dependency>
54+
<groupId>org.jetbrains.dokka</groupId>
55+
<artifactId>dokka-core</artifactId>
56+
<version>${dokka.version}</version>
57+
<classifier>test</classifier>
58+
<scope>test</scope>
59+
</dependency>
5160
<dependency>
5261
<groupId>com.fasterxml.jackson.core</groupId>
5362
<artifactId>jackson-core</artifactId>

spring-auto-restdocs-dokka-json/src/main/kotlin/capital/scalable/dokka/json/JsonFormatDescriptor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class JsonFormatDescriptor
4242
override fun configureOutput(binder: Binder): Unit = with(binder) {
4343
bind<Generator>() toType NodeLocationAwareGenerator::class
4444
bind<NodeLocationAwareGenerator>() toType JsonFileGenerator::class
45+
bind(JsonFileGenerator::class.java) // https://github.com/google/guice/issues/847
4546
bind<LanguageService>() toType KotlinLanguageService::class
4647
bind<FormatService>() toType JsonFormatService::class
4748
bind<PackageListService>() toType DefaultPackageListService::class

spring-auto-restdocs-dokka-json/src/test/kotlin/capital/scalable/dokka/json/JsonFileGeneratorTest.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ package capital.scalable.dokka.json
2222
import com.intellij.openapi.util.io.FileUtil
2323
import org.jetbrains.dokka.DocumentationModule
2424
import org.jetbrains.dokka.DokkaConsoleLogger
25+
import org.jetbrains.dokka.Platform
2526
import org.jetbrains.dokka.contentRootFromPath
27+
import org.jetbrains.dokka.tests.ModelConfig
28+
import org.jetbrains.dokka.tests.verifyJavaModel
29+
import org.jetbrains.dokka.tests.verifyModel
30+
import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot
2631
import org.junit.Test
2732
import java.io.File
2833
import kotlin.test.assertTrue
2934

3035
class JsonFileGeneratorTest {
3136

37+
private val analysisPlatform = Platform.common
38+
3239
private val root: File = FileUtil.createTempDirectory("dokka-json", "file-generator-test")
3340

3441
@Test
@@ -47,7 +54,12 @@ class JsonFileGeneratorTest {
4754

4855
private fun verifyOutput(inputFile: String, verifier: (DocumentationModule) -> Unit) {
4956
verifyModel(
50-
contentRootFromPath("testdata/$inputFile"),
57+
ModelConfig(
58+
roots = arrayOf(
59+
KotlinSourceRoot("testdata/$inputFile", false)
60+
),
61+
analysisPlatform = analysisPlatform
62+
),
5163
verifier = verifier
5264
)
5365
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*-
2+
* #%L
3+
* Spring Auto REST Docs Dokka JSON
4+
* %%
5+
* Copyright (C) 2015 - 2020 Scalable Capital GmbH
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package capital.scalable.dokka.json
21+
22+
import com.google.inject.Binder
23+
import com.google.inject.Guice
24+
import com.google.inject.Module
25+
import com.google.inject.name.Names
26+
import com.intellij.openapi.util.io.FileUtil
27+
import org.jetbrains.dokka.Content
28+
import org.jetbrains.dokka.DefaultPackageListService
29+
import org.jetbrains.dokka.DocumentationNode
30+
import org.jetbrains.dokka.DokkaConfiguration
31+
import org.jetbrains.dokka.DokkaConsoleLogger
32+
import org.jetbrains.dokka.DokkaGenerator
33+
import org.jetbrains.dokka.DokkaLogger
34+
import org.jetbrains.dokka.FormatService
35+
import org.jetbrains.dokka.Formats.FormatDescriptor
36+
import org.jetbrains.dokka.Generator
37+
import org.jetbrains.dokka.KotlinLanguageService
38+
import org.jetbrains.dokka.LanguageService
39+
import org.jetbrains.dokka.NodeKind
40+
import org.jetbrains.dokka.NodeLocationAwareGenerator
41+
import org.jetbrains.dokka.PackageListService
42+
import org.jetbrains.dokka.Platform
43+
import org.jetbrains.dokka.Utilities.DokkaRunModule
44+
import org.jetbrains.dokka.Utilities.ServiceLocator
45+
import org.junit.Test
46+
import java.io.File
47+
48+
class JsonFormatIntegrationTest {
49+
50+
@Test
51+
fun `Should load descriptor from properties file, bind and use it`() {
52+
DokkaGenerator(DokkaConfigurationImpl(), DokkaConsoleLogger).generate()
53+
}
54+
}
55+
56+
data class SourceLinkDefinitionImpl(override val path: String,
57+
override val url: String,
58+
override val lineSuffix: String?) : DokkaConfiguration.SourceLinkDefinition {
59+
companion object {
60+
fun parseSourceLinkDefinition(srcLink: String): DokkaConfiguration.SourceLinkDefinition {
61+
val (path, urlAndLine) = srcLink.split('=')
62+
return SourceLinkDefinitionImpl(
63+
File(path).canonicalPath,
64+
urlAndLine.substringBefore("#"),
65+
urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#$it" })
66+
}
67+
}
68+
}
69+
70+
class SourceRootImpl(path: String) : DokkaConfiguration.SourceRoot {
71+
override val path: String = File(path).absolutePath
72+
73+
companion object {
74+
fun parseSourceRoot(sourceRoot: String): DokkaConfiguration.SourceRoot = SourceRootImpl(sourceRoot)
75+
}
76+
}
77+
78+
data class PackageOptionsImpl(override val prefix: String,
79+
override val includeNonPublic: Boolean = false,
80+
override val reportUndocumented: Boolean = true,
81+
override val skipDeprecated: Boolean = false,
82+
override val suppress: Boolean = false) : DokkaConfiguration.PackageOptions
83+
84+
class DokkaConfigurationImpl(
85+
override val outputDir: String = "",
86+
override val format: String = "auto-restdocs-json",
87+
override val generateIndexPages: Boolean = false,
88+
override val cacheRoot: String? = null,
89+
override val impliedPlatforms: List<String> = emptyList(),
90+
override val passesConfigurations: List<DokkaConfiguration.PassConfiguration> = listOf(PassConfigurationImpl())
91+
) : DokkaConfiguration
92+
93+
class PassConfigurationImpl (
94+
override val classpath: List<String> = emptyList(),
95+
override val moduleName: String = "",
96+
override val sourceRoots: List<DokkaConfiguration.SourceRoot> = emptyList(),
97+
override val samples: List<String> = emptyList(),
98+
override val includes: List<String> = emptyList(),
99+
override val includeNonPublic: Boolean = false,
100+
override val includeRootPackage: Boolean = false,
101+
override val reportUndocumented: Boolean = false,
102+
override val skipEmptyPackages: Boolean = false,
103+
override val skipDeprecated: Boolean = false,
104+
override val jdkVersion: Int = 8,
105+
override val sourceLinks: List<DokkaConfiguration.SourceLinkDefinition> = emptyList(),
106+
override val perPackageOptions: List<DokkaConfiguration.PackageOptions> = emptyList(),
107+
override val externalDocumentationLinks: List<DokkaConfiguration.ExternalDocumentationLink> = emptyList(),
108+
override val languageVersion: String? = null,
109+
override val apiVersion: String? = null,
110+
override val noStdlibLink: Boolean = false,
111+
override val noJdkLink: Boolean = false,
112+
override val suppressedFiles: List<String> = emptyList(),
113+
override val collectInheritedExtensionsFromLibraries: Boolean = false,
114+
override val analysisPlatform: Platform = Platform.DEFAULT,
115+
override val targets: List<String> = emptyList(),
116+
override val sinceKotlin: String? = null
117+
): DokkaConfiguration.PassConfiguration

0 commit comments

Comments
 (0)