1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package locationProvider
import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider
import org.jetbrains.dokka.base.resolvers.external.javadoc.JavadocExternalLocationProvider
import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation
import org.jetbrains.dokka.base.resolvers.shared.PackageList
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.DRIExtraContainer
import org.jetbrains.dokka.links.EnumEntryDRIExtra
import org.jetbrains.dokka.links.PointingToDeclaration
import org.jetbrains.dokka.plugability.DokkaContext
import java.net.URL
import kotlin.test.Test
import kotlin.test.assertEquals
class JavadocExternalLocationProviderTest : BaseAbstractTest() {
private val testDataDir =
getTestDataDir("locationProvider").toAbsolutePath().toString().removePrefix("/").let { "/$it" }
private val jdk = "https://docs.oracle.com/javase/8/docs/api/"
private val jdkPackageListURL = URL("file://$testDataDir/jdk8-package-list")
private val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
classpath += jvmStdlibPath!!
}
}
}
private fun getTestLocationProvider(context: DokkaContext? = null): DefaultExternalLocationProvider {
val dokkaContext = context ?: DokkaContext.create(configuration, logger, emptyList())
val packageList = PackageList.load(jdkPackageListURL, 8, true)!!
val externalDocumentation =
ExternalDocumentation(URL(jdk), packageList)
return JavadocExternalLocationProvider(externalDocumentation, "--", "-", dokkaContext)
}
@Test
fun `link to enum entity of javadoc`() {
val locationProvider = getTestLocationProvider()
val ktDri = DRI(
"java.nio.file",
"StandardOpenOption.CREATE",
extra = DRIExtraContainer().also { it[EnumEntryDRIExtra] = EnumEntryDRIExtra }.encode()
)
val javaDri = DRI(
"java.nio.file",
"StandardOpenOption.CREATE",
null,
PointingToDeclaration,
DRIExtraContainer().also { it[EnumEntryDRIExtra] = EnumEntryDRIExtra }.encode()
)
assertEquals(
"https://docs.oracle.com/javase/8/docs/api/java/nio/file/StandardOpenOption.html#CREATE",
locationProvider.resolve(ktDri)
)
assertEquals(
"https://docs.oracle.com/javase/8/docs/api/java/nio/file/StandardOpenOption.html#CREATE",
locationProvider.resolve(javaDri)
)
}
@Test
fun `link to nested class of javadoc`() {
val locationProvider = getTestLocationProvider()
val dri = DRI(
"java.rmi.activation",
"ActivationGroupDesc.CommandEnvironment"
)
assertEquals(
"https://docs.oracle.com/javase/8/docs/api/java/rmi/activation/ActivationGroupDesc.CommandEnvironment.html",
locationProvider.resolve(dri)
)
}
}
|