aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/DokkaBootstrapImpl.kt7
-rw-r--r--core/src/main/kotlin/Generation/DokkaGenerator.kt21
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt17
-rw-r--r--core/src/main/kotlin/Utilities/DokkaModules.kt6
-rw-r--r--core/src/test/kotlin/TestAPI.kt35
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt15
-rw-r--r--core/testdata/format/multiplatform/bar.kt7
-rw-r--r--core/testdata/format/multiplatform/foo.kt8
-rw-r--r--core/testdata/format/multiplatform/foo.package.md9
-rw-r--r--runners/ant/src/main/kotlin/ant/dokka.kt7
-rw-r--r--runners/cli/src/main/kotlin/cli/main.kt2
-rw-r--r--runners/maven-plugin/src/main/kotlin/DokkaMojo.kt9
12 files changed, 108 insertions, 35 deletions
diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt
index eb2b2a65..59139263 100644
--- a/core/src/main/kotlin/DokkaBootstrapImpl.kt
+++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt
@@ -10,6 +10,11 @@ fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition {
urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#" + it })
}
+fun parseSourceRoot(sourceRoot: String): SourceRoot {
+ val components = sourceRoot.split("::", limit = 2)
+ return SourceRoot(components.first(), components.getOrNull(1)?.split(',').orEmpty())
+}
+
class DokkaBootstrapImpl : DokkaBootstrap {
class DokkaProxyLogger(val consumer: BiConsumer<String, String>) : DokkaLogger {
@@ -46,7 +51,7 @@ class DokkaBootstrapImpl : DokkaBootstrap {
generator = DokkaGenerator(
DokkaProxyLogger(logger),
classpath,
- sources,
+ sources.map(::parseSourceRoot),
samples,
includes,
moduleName,
diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt
index aaf0deff..95066eec 100644
--- a/core/src/main/kotlin/Generation/DokkaGenerator.kt
+++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt
@@ -22,9 +22,11 @@ import org.jetbrains.kotlin.utils.PathUtil
import java.io.File
import kotlin.system.measureTimeMillis
+class SourceRoot(val path: String, val implicitPlatforms: List<String> = emptyList())
+
class DokkaGenerator(val logger: DokkaLogger,
val classpath: List<String>,
- val sources: List<String>,
+ val sources: List<SourceRoot>,
val samples: List<String>,
val includes: List<String>,
val moduleName: String,
@@ -33,7 +35,10 @@ class DokkaGenerator(val logger: DokkaLogger,
private val documentationModule = DocumentationModule(moduleName)
fun generate() {
- appendSourceModule()
+ val sourcesGroupedByPlatform = sources.groupBy { it.implicitPlatforms }
+ for ((platforms, roots) in sourcesGroupedByPlatform) {
+ appendSourceModule(platforms, roots.map { it.path })
+ }
val timeBuild = measureTimeMillis {
logger.info("Generating pages... ")
@@ -43,18 +48,18 @@ class DokkaGenerator(val logger: DokkaLogger,
logger.info("done in ${timeBuild / 1000} secs")
}
- private fun appendSourceModule() {
- val environment = createAnalysisEnvironment()
+ private fun appendSourceModule(implicitPlatforms: List<String>, sourcePaths: List<String>) {
+ val environment = createAnalysisEnvironment(sourcePaths)
logger.info("Module: $moduleName")
logger.info("Output: ${File(options.outputDir)}")
- logger.info("Sources: ${environment.sources.joinToString()}")
+ logger.info("Sources: ${sourcePaths.joinToString()}")
logger.info("Classpath: ${environment.classpath.joinToString()}")
logger.info("Analysing sources and libraries... ")
val startAnalyse = System.currentTimeMillis()
- val injector = Guice.createInjector(DokkaAnalysisModule(environment, options, logger))
+ val injector = Guice.createInjector(DokkaAnalysisModule(environment, options, implicitPlatforms, logger))
buildDocumentationModule(injector, documentationModule, { isSample(it) }, includes)
@@ -64,7 +69,7 @@ class DokkaGenerator(val logger: DokkaLogger,
Disposer.dispose(environment)
}
- fun createAnalysisEnvironment(): AnalysisEnvironment {
+ fun createAnalysisEnvironment(sourcePaths: List<String>): AnalysisEnvironment {
val environment = AnalysisEnvironment(DokkaMessageCollector(logger))
environment.apply {
@@ -74,7 +79,7 @@ class DokkaGenerator(val logger: DokkaLogger,
addClasspath(File(element))
}
- addSources(this@DokkaGenerator.sources)
+ addSources(sourcePaths)
addSources(this@DokkaGenerator.samples)
}
diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
index bcbdf5f4..e165a2b5 100644
--- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
import org.jetbrains.kotlin.types.typeUtil.supertypes
+import com.google.inject.name.Named as GuiceNamed
data class DocumentationOptions(val outputDir: String,
val outputFormat: String,
@@ -57,6 +58,8 @@ interface PackageDocumentationBuilder {
allFqNames: Collection<FqName>)
}
+const val implicitPlatformName = "implicitPlatform"
+
class DocumentationBuilder
@Inject constructor(val resolutionFacade: DokkaResolutionFacade,
val descriptorDocumentationParser: DescriptorDocumentationParser,
@@ -64,7 +67,8 @@ class DocumentationBuilder
val refGraph: NodeReferenceGraph,
val platformNodeRegistry: PlatformNodeRegistry,
val logger: DokkaLogger,
- val linkResolver: DeclarationLinkResolver) {
+ val linkResolver: DeclarationLinkResolver,
+ @GuiceNamed(implicitPlatformName) val implicitPlatforms: List<String>) {
val boringBuiltinClasses = setOf(
"kotlin.Unit", "kotlin.Byte", "kotlin.Short", "kotlin.Int", "kotlin.Long", "kotlin.Char", "kotlin.Boolean",
"kotlin.Float", "kotlin.Double", "kotlin.String", "kotlin.Array", "kotlin.Any")
@@ -237,6 +241,12 @@ class DocumentationBuilder
}
}
+ fun DocumentationNode.appendImplicitPlatforms() {
+ for (platform in implicitPlatforms) {
+ append(platformNodeRegistry[platform], RefKind.Platform)
+ }
+ }
+
fun DocumentationNode.isDeprecation() = name == "Deprecated" || name == "deprecated"
fun DocumentationNode.isSinceKotlin() = name == "SinceKotlin" && kind == NodeKind.Annotation
@@ -412,6 +422,7 @@ class DocumentationBuilder
node.appendType(underlyingType, NodeKind.TypeAliasUnderlyingType)
node.appendSourceLink(source)
+ node.appendImplicitPlatforms()
register(this, node)
return node
@@ -453,6 +464,7 @@ class DocumentationBuilder
node.appendAnnotations(this)
node.appendModifiers(this)
node.appendSourceLink(source)
+ node.appendImplicitPlatforms()
register(this, node)
return node
}
@@ -469,6 +481,7 @@ class DocumentationBuilder
fun ConstructorDescriptor.build(): DocumentationNode {
val node = nodeForDescriptor(this, NodeKind.Constructor)
node.appendInPageChildren(valueParameters, RefKind.Detail)
+ node.appendImplicitPlatforms()
register(this, node)
return node
}
@@ -497,6 +510,7 @@ class DocumentationBuilder
node.appendModifiers(this)
node.appendSourceLink(source)
node.appendSignature(this)
+ node.appendImplicitPlatforms()
overriddenDescriptors.forEach {
addOverrideLink(it, this)
@@ -543,6 +557,7 @@ class DocumentationBuilder
overriddenDescriptors.forEach {
addOverrideLink(it, this)
}
+ node.appendImplicitPlatforms()
register(this, node)
return node
diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt
index 69facaa0..3352a846 100644
--- a/core/src/main/kotlin/Utilities/DokkaModules.kt
+++ b/core/src/main/kotlin/Utilities/DokkaModules.kt
@@ -3,6 +3,7 @@ package org.jetbrains.dokka.Utilities
import com.google.inject.Binder
import com.google.inject.Module
import com.google.inject.Provider
+import com.google.inject.TypeLiteral
import com.google.inject.name.Names
import org.jetbrains.dokka.*
import org.jetbrains.dokka.Formats.FormatDescriptor
@@ -12,6 +13,7 @@ import java.io.File
class DokkaAnalysisModule(val environment: AnalysisEnvironment,
val options: DocumentationOptions,
+ val implicitPlatforms: List<String>,
val logger: DokkaLogger) : Module {
override fun configure(binder: Binder) {
val descriptor = ServiceLocator.lookup<FormatDescriptor>("format", options.outputFormat)
@@ -29,9 +31,13 @@ class DokkaAnalysisModule(val environment: AnalysisEnvironment,
binder.bind<DocumentationOptions>().toInstance(options)
binder.bind<DokkaLogger>().toInstance(logger)
+
+ binder.bind(StringListType).annotatedWith(Names.named(implicitPlatformName)).toInstance(implicitPlatforms)
}
}
+object StringListType : TypeLiteral<@JvmSuppressWildcards List<String>>()
+
class DokkaOutputModule(val options: DocumentationOptions,
val logger: DokkaLogger) : Module {
override fun configure(binder: Binder) {
diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt
index 61eab562..b3085008 100644
--- a/core/src/test/kotlin/TestAPI.kt
+++ b/core/src/test/kotlin/TestAPI.kt
@@ -22,6 +22,22 @@ fun verifyModel(vararg roots: ContentRoot,
format: String = "html",
includeNonPublic: Boolean = true,
verifier: (DocumentationModule) -> Unit) {
+ val documentation = DocumentationModule("test")
+ appendDocumentation(documentation, *roots,
+ withJdk = withJdk,
+ withKotlinRuntime = withKotlinRuntime,
+ format = format,
+ includeNonPublic = includeNonPublic)
+ verifier(documentation)
+}
+
+fun appendDocumentation(documentation: DocumentationModule,
+ vararg roots: ContentRoot,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ format: String = "html",
+ includeNonPublic: Boolean = true,
+ implicitPlatforms: List<String> = emptyList()) {
val messageCollector = object : MessageCollector {
override fun clear() {
@@ -65,10 +81,8 @@ fun verifyModel(vararg roots: ContentRoot,
skipEmptyPackages = false,
sourceLinks = listOf<SourceLinkDefinition>(),
generateIndexPages = false)
- val injector = Guice.createInjector(DokkaAnalysisModule(environment, options, DokkaConsoleLogger))
- val documentation = DocumentationModule("test")
+ val injector = Guice.createInjector(DokkaAnalysisModule(environment, options, implicitPlatforms, DokkaConsoleLogger))
buildDocumentationModule(injector, documentation)
- verifier(documentation)
Disposer.dispose(environment)
}
@@ -129,19 +143,18 @@ fun verifyOutput(roots: Array<ContentRoot>,
format: String = "html",
outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
verifyModel(*roots, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, format = format) {
- verifyModelOutput(it, outputExtension, outputGenerator, roots.first().path)
+ verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator)
}
}
-private fun verifyModelOutput(it: DocumentationModule,
- outputExtension: String,
- outputGenerator: (DocumentationModule, StringBuilder) -> Unit,
- sourcePath: String) {
+fun verifyModelOutput(it: DocumentationModule,
+ outputExtension: String,
+ sourcePath: String,
+ outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
val output = StringBuilder()
outputGenerator(it, output)
val ext = outputExtension.removePrefix(".")
- val path = sourcePath
- val expectedFileContent = File(path.replaceAfterLast(".", ext, path + "." + ext)).readText()
+ val expectedFileContent = File(sourcePath.replaceAfterLast(".", ext, sourcePath + "." + ext)).readText()
val expectedOutput =
if (ext.equals("html", true))
expectedFileContent.lines().joinToString(separator = "\n", transform = String::trim)
@@ -164,7 +177,7 @@ fun verifyJavaOutput(path: String,
withKotlinRuntime: Boolean = false,
outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
verifyJavaModel(path, withKotlinRuntime) { model ->
- verifyModelOutput(model, outputExtension, outputGenerator, path)
+ verifyModelOutput(model, outputExtension, path, outputGenerator)
}
}
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 4dd01a20..967bc5e4 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -1,9 +1,6 @@
package org.jetbrains.dokka.tests
-import org.jetbrains.dokka.DocumentationModule
-import org.jetbrains.dokka.DocumentationNode
-import org.jetbrains.dokka.KotlinLanguageService
-import org.jetbrains.dokka.MarkdownFormatService
+import org.jetbrains.dokka.*
import org.junit.Test
class MarkdownFormatTest {
@@ -245,6 +242,16 @@ class MarkdownFormatTest {
verifyMarkdownPackage("sinceKotlin")
}
+ @Test fun multiplePlatforms() {
+ val module = DocumentationModule("test")
+ val sourcePath = "testdata/format/multiplatform/foo.kt"
+ appendDocumentation(module, contentRootFromPath(sourcePath), implicitPlatforms = listOf("JVM"))
+ appendDocumentation(module, contentRootFromPath("testdata/format/multiplatform/bar.kt"), implicitPlatforms = listOf("JS"))
+ verifyModelOutput(module, ".package.md", sourcePath) { model, output ->
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members)
+ }
+ }
+
private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) {
verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output ->
markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members)
diff --git a/core/testdata/format/multiplatform/bar.kt b/core/testdata/format/multiplatform/bar.kt
new file mode 100644
index 00000000..e6d66ffd
--- /dev/null
+++ b/core/testdata/format/multiplatform/bar.kt
@@ -0,0 +1,7 @@
+package foo
+
+/**
+ * This is a bar.
+ */
+class Bar {
+}
diff --git a/core/testdata/format/multiplatform/foo.kt b/core/testdata/format/multiplatform/foo.kt
new file mode 100644
index 00000000..cb77273f
--- /dev/null
+++ b/core/testdata/format/multiplatform/foo.kt
@@ -0,0 +1,8 @@
+package foo
+
+/**
+ * This is a foo.
+ */
+class Foo {
+
+}
diff --git a/core/testdata/format/multiplatform/foo.package.md b/core/testdata/format/multiplatform/foo.package.md
new file mode 100644
index 00000000..3574942c
--- /dev/null
+++ b/core/testdata/format/multiplatform/foo.package.md
@@ -0,0 +1,9 @@
+[test](test/index) / [foo](test/foo/index)
+
+## Package foo
+
+### Types
+
+| [Bar](test/foo/-bar/index)<br>(JS) | `class Bar`<br>This is a bar. |
+| [Foo](test/foo/-foo/index)<br>(JVM) | `class Foo`<br>This is a foo. |
+
diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt
index 38dc543b..98c44d11 100644
--- a/runners/ant/src/main/kotlin/ant/dokka.kt
+++ b/runners/ant/src/main/kotlin/ant/dokka.kt
@@ -5,10 +5,7 @@ import org.apache.tools.ant.Project
import org.apache.tools.ant.Task
import org.apache.tools.ant.types.Path
import org.apache.tools.ant.types.Reference
-import org.jetbrains.dokka.DocumentationOptions
-import org.jetbrains.dokka.DokkaGenerator
-import org.jetbrains.dokka.DokkaLogger
-import org.jetbrains.dokka.SourceLinkDefinition
+import org.jetbrains.dokka.*
import java.io.File
class AntLogger(val task: Task): DokkaLogger {
@@ -87,7 +84,7 @@ class DokkaAntTask(): Task() {
val generator = DokkaGenerator(
AntLogger(this),
compileClasspath.list().toList(),
- sourcePath.list().toList(),
+ sourcePath.list().map { SourceRoot(it) },
samplesPath.list().toList(),
includesPath.list().toList(),
moduleName!!,
diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt
index afc67e45..f41e4715 100644
--- a/runners/cli/src/main/kotlin/cli/main.kt
+++ b/runners/cli/src/main/kotlin/cli/main.kt
@@ -78,7 +78,7 @@ object MainKt {
val generator = DokkaGenerator(
DokkaConsoleLogger,
classPath,
- sources,
+ sources.map(::parseSourceRoot),
samples,
includes,
arguments.moduleName,
diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
index 899d2dde..c3cf7509 100644
--- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
+++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
@@ -7,11 +7,12 @@ import org.apache.maven.plugin.AbstractMojo
import org.apache.maven.plugins.annotations.*
import org.apache.maven.project.MavenProject
import org.apache.maven.project.MavenProjectHelper
-import org.jetbrains.dokka.DokkaGenerator
-import org.jetbrains.dokka.SourceLinkDefinition
-import org.jetbrains.dokka.DocumentationOptions
import org.codehaus.plexus.archiver.Archiver
import org.codehaus.plexus.archiver.jar.JarArchiver
+import org.jetbrains.dokka.DocumentationOptions
+import org.jetbrains.dokka.DokkaGenerator
+import org.jetbrains.dokka.SourceLinkDefinition
+import org.jetbrains.dokka.SourceRoot
import java.io.File
class SourceLinkMapItem {
@@ -66,7 +67,7 @@ abstract class AbstractDokkaMojo : AbstractMojo() {
val gen = DokkaGenerator(
MavenDokkaLogger(log),
classpath,
- sourceDirectories,
+ sourceDirectories.map { SourceRoot(it) },
samplesDirs,
includeDirs + includes,
moduleName,