Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Gradle Plugin #1194

Merged
merged 21 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6da0af7
Simplify Dokka Gradle Plugin
sellmair Jul 18, 2020
be62537
DokkaConfiguration: Use `Set` instead of `List` when collections are …
sellmair Jul 22, 2020
e5e4a82
Adapt KotlinDslDokkaTaskConfigurationTest.kt
sellmair Jul 22, 2020
6625fc1
Use Gradle's new Property/Provider APIs
sellmair Jul 22, 2020
ac3bc7c
Replace ExternalDocumentationLink.Builder with factory functions
sellmair Jul 31, 2020
f78f75f
Re-introduce changes from aaf0e377a383f916b8dfff9dc78e4274b9b30b9c (P…
sellmair Aug 3, 2020
0b72bc4
Cover GradleDokkaSourceSetBuilder with tests
sellmair Jul 31, 2020
fd1b4de
API refinement for AbstractDokkaParentTask and DokkaMultiModuleTask
sellmair Aug 5, 2020
9aa8c19
Add documentation to DokkaMultiModuleFileLayout
sellmair Aug 10, 2020
ccafa0b
Declare `checkChildDokkaTasksIsNotEmpty` as internal
sellmair Aug 10, 2020
809e66a
Handle wrongly implemented `DokkaMultiModuleFileLayout`
sellmair Aug 10, 2020
b518561
Refine and test `GradleSourceLinkBuilder` and SourceLinkDefinition API
sellmair Aug 11, 2020
44de958
DokkaMultiModuleTask: Use Property/Provider API
sellmair Aug 12, 2020
f16b3d0
toDokkaSourceSetImpl: Use `getSafe` instead of `get` everywhere
sellmair Aug 12, 2020
951f982
Use List for representing classpaths instead of Set
sellmair Aug 13, 2020
6ad42fc
fixup! API refinement for AbstractDokkaParentTask and DokkaMultiModul…
sellmair Aug 14, 2020
9120f5c
Gradle Plugin: Code style improvements
sellmair Aug 14, 2020
689a528
Remove unnecessary "isMultiplatform" util
sellmair Aug 14, 2020
665eef6
Use java.net.URL consistently across Gradle Plugin API surface
sellmair Aug 14, 2020
69a6ac7
Extract `kotlinSourceSet()` from `GradleDokkaSourceSetBuilder`
kamildoleglo Aug 14, 2020
52fb041
Fix `GradleDokkaSourceSetBuilder.sourceRoots` annotation
sellmair Aug 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .run/it-basic_dokka.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/integration-tests/gradle/projects/it-basic" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="scriptParameters" value="--configuration-cache" />
<option name="taskDescriptions">
<list />
</option>
Expand Down
34 changes: 2 additions & 32 deletions core/src/main/kotlin/DokkaBootstrapImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,8 @@ class DokkaBootstrapImpl : DokkaBootstrap {

private lateinit var generator: DokkaGenerator

fun configure(logger: DokkaLogger, configuration: DokkaConfigurationImpl) = with(configuration) {

fun defaultLinks(config: DokkaSourceSetImpl): List<ExternalDocumentationLinkImpl> {
val links = mutableListOf<ExternalDocumentationLinkImpl>()
if (!config.noJdkLink) {
val javadocLink =
if (config.jdkVersion < 11) "https://docs.oracle.com/javase/${config.jdkVersion}/docs/api/"
else "https://docs.oracle.com/en/java/javase/${config.jdkVersion}/docs/api/java.base/"
val packageListLink =
if (config.jdkVersion < 11) "${javadocLink}/package-list"
else "https://docs.oracle.com/en/java/javase/${config.jdkVersion}/docs/api/element-list"
links += DokkaConfiguration.ExternalDocumentationLink
.Builder(javadocLink, packageListLink)
.build() as ExternalDocumentationLinkImpl
}

if (!config.noStdlibLink)
links += DokkaConfiguration.ExternalDocumentationLink
.Builder("https://kotlinlang.org/api/latest/jvm/stdlib/")
.build() as ExternalDocumentationLinkImpl
return links
}

val configurationWithLinks = configuration.copy(
sourceSets = sourceSets.map {
val links: List<ExternalDocumentationLinkImpl> =
it.externalDocumentationLinks + defaultLinks(it)
it.copy(externalDocumentationLinks = links)
}
)

generator = DokkaGenerator(configurationWithLinks, logger)
fun configure(logger: DokkaLogger, configuration: DokkaConfigurationImpl) {
generator = DokkaGenerator(configuration, logger)
}

override fun configure(serializedConfigurationJSON: String, logger: BiConsumer<String, String>) = configure(
Expand Down
82 changes: 44 additions & 38 deletions core/src/main/kotlin/configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

package org.jetbrains.dokka

import org.jetbrains.dokka.utilities.toJsonString
import org.jetbrains.dokka.utilities.parseJson
import org.jetbrains.dokka.utilities.toJsonString
import java.io.File
import java.io.Serializable
import java.net.URL

object DokkaDefaults {
const val outputDir = "./dokka"
val outputDir = File("./dokka")
const val format: String = "html"
val cacheRoot: String? = null
val cacheRoot: File? = null
const val offlineMode: Boolean = false
const val failOnWarning: Boolean = false

const val includeNonPublic: Boolean = false
const val includeRootPackage: Boolean = false
const val reportUndocumented: Boolean = false
const val skipEmptyPackages: Boolean = true
const val skipDeprecated: Boolean = false
Expand Down Expand Up @@ -45,12 +44,20 @@ enum class Platform(val key: String) {
js.key -> js
native.key -> native
common.key -> common
"androidjvm", "android" -> jvm
"metadata" -> common
else -> throw IllegalArgumentException("Unrecognized platform: $key")
}
}
}
}

interface DokkaConfigurationBuilder<T : Any> {
fun build(): T
}

fun <T : Any> Iterable<DokkaConfigurationBuilder<T>>.build(): List<T> = this.map { it.build() }

data class DokkaSourceSetID(
val moduleName: String,
val sourceSetName: String
Expand All @@ -65,8 +72,8 @@ fun DokkaConfigurationImpl(json: String): DokkaConfigurationImpl = parseJson(jso
fun DokkaConfiguration.toJsonString(): String = toJsonString(this)

interface DokkaConfiguration : Serializable {
val outputDir: String
val cacheRoot: String?
val outputDir: File
val cacheRoot: File?
val offlineMode: Boolean
val failOnWarning: Boolean
val sourceSets: List<DokkaSourceSet>
Expand All @@ -78,42 +85,37 @@ interface DokkaConfiguration : Serializable {
val sourceSetID: DokkaSourceSetID
val displayName: String
val moduleDisplayName: String
val classpath: List<String>
val sourceRoots: List<SourceRoot>
val classpath: List<File>
val sourceRoots: Set<File>
val dependentSourceSets: Set<DokkaSourceSetID>
val samples: List<String>
val includes: List<String>
val samples: Set<File>
val includes: Set<File>
val includeNonPublic: Boolean
val includeRootPackage: Boolean
val reportUndocumented: Boolean
val skipEmptyPackages: Boolean
val skipDeprecated: Boolean
val jdkVersion: Int
val sourceLinks: List<SourceLinkDefinition>
val sourceLinks: Set<SourceLinkDefinition>
val perPackageOptions: List<PackageOptions>
val externalDocumentationLinks: List<ExternalDocumentationLink>
val externalDocumentationLinks: Set<ExternalDocumentationLink>
val languageVersion: String?
val apiVersion: String?
val noStdlibLink: Boolean
val noJdkLink: Boolean
val suppressedFiles: List<String>
val suppressedFiles: Set<File>
val analysisPlatform: Platform
}

interface SourceRoot : Serializable {
val path: String
}

interface SourceLinkDefinition : Serializable {
val path: String
val url: String
val lineSuffix: String?
val localDirectory: String
val remoteUrl: URL
val remoteLineSuffix: String?
}

interface DokkaModuleDescription : Serializable {
val name: String
val path: String
val docFile: String
val path: File
val docFile: File
}

interface PackageOptions : Serializable {
Expand All @@ -128,22 +130,26 @@ interface DokkaConfiguration : Serializable {
val url: URL
val packageListUrl: URL

open class Builder(
open var url: URL? = null,
open var packageListUrl: URL? = null
) {

constructor(root: String, packageList: String? = null) : this(URL(root), packageList?.let { URL(it) })

fun build(): ExternalDocumentationLink =
if (packageListUrl != null && url != null)
ExternalDocumentationLinkImpl(url!!, packageListUrl!!)
else if (url != null)
ExternalDocumentationLinkImpl(url!!, URL(url!!, "package-list"))
else
throw IllegalArgumentException("url or url && packageListUrl must not be null for external documentation link")
}
companion object
}
}

fun ExternalDocumentationLink(
url: URL? = null,
packageListUrl: URL? = null
): ExternalDocumentationLinkImpl {
return if (packageListUrl != null && url != null)
ExternalDocumentationLinkImpl(url, packageListUrl)
else if (url != null)
ExternalDocumentationLinkImpl(url, URL(url, "package-list"))
else
throw IllegalArgumentException("url or url && packageListUrl must not be null for external documentation link")
}


fun ExternalDocumentationLink(
url: String, packageListUrl: String? = null
): ExternalDocumentationLinkImpl =
ExternalDocumentationLink(url.let(::URL), packageListUrl?.let(::URL))


36 changes: 16 additions & 20 deletions core/src/main/kotlin/defaultConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import java.io.File
import java.net.URL

data class DokkaConfigurationImpl(
override val outputDir: String = DokkaDefaults.outputDir,
override val cacheRoot: String? = DokkaDefaults.cacheRoot,
override val outputDir: File = DokkaDefaults.outputDir,
override val cacheRoot: File? = DokkaDefaults.cacheRoot,
override val offlineMode: Boolean = DokkaDefaults.offlineMode,
override val sourceSets: List<DokkaSourceSetImpl> = emptyList(),
override val pluginsClasspath: List<File> = emptyList(),
Expand All @@ -15,53 +15,49 @@ data class DokkaConfigurationImpl(
override val failOnWarning: Boolean = DokkaDefaults.failOnWarning
) : DokkaConfiguration


data class DokkaSourceSetImpl(
override val moduleDisplayName: String,
override val displayName: String = DokkaDefaults.sourceSetDisplayName,
override val sourceSetID: DokkaSourceSetID,
override val classpath: List<String> = emptyList(),
override val sourceRoots: List<SourceRootImpl>,
override val classpath: List<File> = emptyList(),
override val sourceRoots: Set<File> = emptySet(),
override val dependentSourceSets: Set<DokkaSourceSetID> = emptySet(),
override val samples: List<String> = emptyList(),
override val includes: List<String> = emptyList(),
override val samples: Set<File> = emptySet(),
override val includes: Set<File> = emptySet(),
override val includeNonPublic: Boolean = DokkaDefaults.includeNonPublic,
override val includeRootPackage: Boolean = DokkaDefaults.includeRootPackage,
override val reportUndocumented: Boolean = DokkaDefaults.reportUndocumented,
override val skipEmptyPackages: Boolean = DokkaDefaults.skipEmptyPackages,
override val skipDeprecated: Boolean = DokkaDefaults.skipDeprecated,
override val jdkVersion: Int = DokkaDefaults.jdkVersion,
override val sourceLinks: List<SourceLinkDefinitionImpl> = emptyList(),
override val sourceLinks: Set<SourceLinkDefinitionImpl> = emptySet(),
override val perPackageOptions: List<PackageOptionsImpl> = emptyList(),
override var externalDocumentationLinks: List<ExternalDocumentationLinkImpl> = emptyList(),
override val externalDocumentationLinks: Set<ExternalDocumentationLinkImpl> = emptySet(),
override val languageVersion: String? = null,
override val apiVersion: String? = null,
override val noStdlibLink: Boolean = DokkaDefaults.noStdlibLink,
override val noJdkLink: Boolean = DokkaDefaults.noJdkLink,
override val suppressedFiles: List<String> = emptyList(),
override val suppressedFiles: Set<File> = emptySet(),
override val analysisPlatform: Platform = DokkaDefaults.analysisPlatform
) : DokkaSourceSet

data class DokkaModuleDescriptionImpl(
override val name: String,
override val path: String,
override val docFile: String
override val path: File,
override val docFile: File
) : DokkaConfiguration.DokkaModuleDescription

data class SourceRootImpl(
override val path: String
) : DokkaConfiguration.SourceRoot

data class SourceLinkDefinitionImpl(
override val path: String,
override val url: String,
override val lineSuffix: String?
override val localDirectory: String,
override val remoteUrl: URL,
override val remoteLineSuffix: String?
) : DokkaConfiguration.SourceLinkDefinition {
companion object {
fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinitionImpl {
val (path, urlAndLine) = srcLink.split('=')
return SourceLinkDefinitionImpl(
File(path).canonicalPath,
urlAndLine.substringBefore("#"),
URL(urlAndLine.substringBefore("#")),
urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#$it" })
}
}
Expand Down
30 changes: 30 additions & 0 deletions core/src/main/kotlin/defaultExternalLinks.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jetbrains.dokka

import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink
import java.net.URL


fun ExternalDocumentationLink.Companion.jdk(jdkVersion: Int): ExternalDocumentationLinkImpl =
ExternalDocumentationLink(
url =
if (jdkVersion < 11) "https://docs.oracle.com/javase/${jdkVersion}/docs/api/"
else "https://docs.oracle.com/en/java/javase/${jdkVersion}/docs/api/java.base/",
packageListUrl =
if (jdkVersion < 11) "https://docs.oracle.com/javase/${jdkVersion}/docs/api/package-list"
else "https://docs.oracle.com/en/java/javase/${jdkVersion}/docs/api/element-list"
)


fun ExternalDocumentationLink.Companion.kotlinStdlib(): ExternalDocumentationLinkImpl =
ExternalDocumentationLink("https://kotlinlang.org/api/latest/jvm/stdlib/")


fun ExternalDocumentationLink.Companion.androidSdk(): ExternalDocumentationLinkImpl =
ExternalDocumentationLink("https://developer.android.com/reference/")


fun ExternalDocumentationLink.Companion.androidX(): ExternalDocumentationLinkImpl = ExternalDocumentationLink(
url = URL("https://developer.android.com/reference/kotlin/"),
packageListUrl = URL("https://developer.android.com/reference/androidx/package-list")
)

18 changes: 0 additions & 18 deletions core/src/main/kotlin/utilities/json.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package org.jetbrains.dokka.utilities

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import org.jetbrains.dokka.DokkaConfiguration.SourceRoot
import org.jetbrains.dokka.SourceRootImpl
import java.io.File
import com.fasterxml.jackson.core.type.TypeReference as JacksonTypeReference

private val objectMapper = run {
val module = SimpleModule().apply {
addSerializer(FileSerializer)
addSerializer(SourceRoot::class.java, SourceRootSerializer)
addDeserializer(SourceRootImpl::class.java, SourceRootImplDeserializer)
addDeserializer(SourceRoot::class.java, SourceRootImplDeserializer)
}
jacksonObjectMapper()
.registerModule(module)
Expand Down Expand Up @@ -53,13 +45,3 @@ private object FileSerializer : StdScalarSerializer<File>(File::class.java) {
g.writeString(value.path)
}
}

private object SourceRootSerializer : StdScalarSerializer<SourceRoot>(SourceRoot::class.java) {
override fun serialize(value: SourceRoot, g: JsonGenerator, provider: SerializerProvider) {
g.writeString(value.path)
}
}

private object SourceRootImplDeserializer : StdScalarDeserializer<SourceRootImpl>(SourceRootImpl::class.java) {
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): SourceRootImpl = SourceRootImpl(p.text)
}
10 changes: 5 additions & 5 deletions core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class DokkaConfigurationJsonTest {
@Test
fun `simple configuration toJsonString then parseJson`() {
val configuration = DokkaConfigurationImpl(
outputDir = "customOutputDir",
outputDir = File("customOutputDir"),
pluginsClasspath = listOf(File("plugins/customPlugin.jar")),
sourceSets = listOf(
DokkaSourceSetImpl(
moduleDisplayName = "customModuleDisplayName",
sourceRoots = listOf(SourceRootImpl("customSourceRoot")),
sourceRoots = setOf(File("customSourceRoot")),
sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName")
)
)
Expand Down Expand Up @@ -48,14 +48,14 @@ class DokkaConfigurationJsonTest {
val parsedConfiguration = DokkaConfigurationImpl(json)
assertEquals(
DokkaConfigurationImpl(
outputDir = "customOutputDir",
outputDir = File("customOutputDir"),
pluginsClasspath = listOf(File("plugins/customPlugin.jar")),
sourceSets = listOf(
DokkaSourceSetImpl(
moduleDisplayName = "customModuleDisplayName",
sourceRoots = listOf(SourceRootImpl("customSourceRoot")),
sourceRoots = setOf(File("customSourceRoot")),
sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName"),
classpath = listOf("classpath/custom1.jar", "classpath/custom2.jar")
classpath = listOf(File("classpath/custom1.jar"), File("classpath/custom2.jar"))
)
)
),
Expand Down
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Jul 21 13:56:13 CEST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Loading