Skip to content

Commit

Permalink
Refactor DokkatooKotlinAdapter, fix AndroidJVM target, add DokkatooAn…
Browse files Browse the repository at this point in the history
…droidAdapter (#59)

* fix getName() in DokkaSourceSetIdSpec.kt

* add DokkatooAndroidAdapter

* align Kotlin version to match Gradle's embedded Kotlin version

* add KotlinPlatform.AndroidJVM, refactor to rename 'key' to 'displayName'

* rm deprecated helper in TestFixtures

* update test after KotlinPlatform refactor

* tidy build config

* add kotlinx-coroutines dependency to DokkaGenerator classpath

* big ol' refactor of DokkatooKotlinAdapter

- tidy up the complication/source set details extractors
- move extractors into specific companion objects
- update logic to better match DGP code

* update API dump

* add link to Kotlin/dokka#2977

* refactor DokkatooKotlinAdapter to better organise logic into specific builder utility classes

* update conventions for Android/JDK documentation links, so they're enabled dynamically based on the analysis platform

* add cacheRoot comment

* sort KotlinPlatform alphabetically

* tidy up KotlinAdapter, update AndroidAdapter to fetch android.jar, update the configuration-files-fetch logic to fetch JAVA_RUNTIME files

* lots of changes, so bump the minor version

* remove conditional default for enableJdkDocumentationLink - it seems to result in the wrong Java version in the KotlinMultiplatformExample test...?
  • Loading branch information
aSemy committed Apr 27, 2023
1 parent c74dd56 commit 4e2dbef
Show file tree
Hide file tree
Showing 22 changed files with 509 additions and 193 deletions.
5 changes: 1 addition & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ import buildsrc.utils.initIdeProjectLogo

plugins {
buildsrc.conventions.base

idea
}

group = "dev.adamko.dokkatoo"
version = "1.2.1-SNAPSHOT"
version = "1.3.0-SNAPSHOT"


idea {
module {
isDownloadSources = true
isDownloadJavadoc = false
excludeGeneratedGradleDsl(layout)

excludeDirs.apply {
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-format-example/dokkatoo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dev.adamko.dokkatoo.dokka.plugins.DokkaHtmlPluginParameters

plugins {
kotlin("jvm") version "1.8.10"
id("dev.adamko.dokkatoo") version "1.2.1-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.3.0-SNAPSHOT"
}

dokkatoo {
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle-example/dokkatoo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm") version "1.8.10"
id("dev.adamko.dokkatoo") version "1.2.1-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.3.0-SNAPSHOT"
}

dokkatoo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm") version "1.7.20" apply false
id("dev.adamko.dokkatoo") version "1.2.1-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.3.0-SNAPSHOT"
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm")
id("dev.adamko.dokkatoo") version "1.2.1-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.3.0-SNAPSHOT"
}

dokkatoo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm")
id("dev.adamko.dokkatoo") version "1.2.1-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.3.0-SNAPSHOT"
}

dokkatoo {
Expand Down
3 changes: 1 addition & 2 deletions examples/multiplatform-example/dokkatoo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("multiplatform") version "1.8.10"
id("dev.adamko.dokkatoo") version "1.2.1-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.3.0-SNAPSHOT"
}

group = "org.dokka.example"
Expand All @@ -23,7 +23,6 @@ kotlin {
}

dokkatoo {

// Create a custom source set not known to the Kotlin Gradle Plugin
dokkatooSourceSets.register("customSourceSet") {
jdkVersion.set(9)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]

kotlin = "1.7.20"
kotlin = "1.7.10" # should match Gradle's embedded Kotlin version https://docs.gradle.org/current/userguide/compatibility.html#kotlin
kotlin-dokka = "1.8.10"
kotlinx-serialization = "1.5.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dev.adamko.dokkatoo.dokka.plugins.DokkaHtmlPluginParameters

plugins {
kotlin("jvm") version "1.8.10"
id("dev.adamko.dokkatoo") version "1.2.1-SNAPSHOT"
id("dev.adamko.dokkatoo") version "1.3.0-SNAPSHOT"
}

version = "1.7.20-SNAPSHOT"
Expand Down
12 changes: 9 additions & 3 deletions modules/dokkatoo-plugin/api/dokkatoo-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ public abstract class dev/adamko/dokkatoo/DokkatooExtension : java/io/Serializab
}

public abstract interface class dev/adamko/dokkatoo/DokkatooExtension$Versions {
public static final field Companion Ldev/adamko/dokkatoo/DokkatooExtension$Versions$Companion;
public static final field VERSIONS_EXTENSION_NAME Ljava/lang/String;
public abstract fun getFreemarker ()Lorg/gradle/api/provider/Property;
public abstract fun getJetbrainsDokka ()Lorg/gradle/api/provider/Property;
public abstract fun getJetbrainsMarkdown ()Lorg/gradle/api/provider/Property;
public abstract fun getKotlinxCoroutines ()Lorg/gradle/api/provider/Property;
public abstract fun getKotlinxHtml ()Lorg/gradle/api/provider/Property;
}

public final class dev/adamko/dokkatoo/DokkatooExtension$Versions$Companion {
public static final field VERSIONS_EXTENSION_NAME Ljava/lang/String;
}

public abstract class dev/adamko/dokkatoo/DokkatooPlugin : org/gradle/api/Plugin {
public synthetic fun apply (Ljava/lang/Object;)V
public fun apply (Lorg/gradle/api/Project;)V
}

public final class dev/adamko/dokkatoo/adapters/DokkatooKotlinAdapter$Companion {
}

public abstract class dev/adamko/dokkatoo/dokka/DokkaPublication : java/io/Serializable, org/gradle/api/Named {
public abstract fun getCacheRoot ()Lorg/gradle/api/file/DirectoryProperty;
protected final fun getCacheRootPath ()Lorg/gradle/api/provider/Provider;
Expand Down Expand Up @@ -218,6 +222,7 @@ public abstract class dev/adamko/dokkatoo/dokka/parameters/DokkaSourceSetIdSpec
public final fun getScopeId ()Ljava/lang/String;
public abstract fun getSourceSetName ()Ljava/lang/String;
public abstract fun setSourceSetName (Ljava/lang/String;)V
public fun toString ()Ljava/lang/String;
}

public final class dev/adamko/dokkatoo/dokka/parameters/DokkaSourceSetIdSpec$Companion {
Expand Down Expand Up @@ -265,6 +270,7 @@ public abstract class dev/adamko/dokkatoo/dokka/parameters/DokkaSourceSetSpec :
}

public final class dev/adamko/dokkatoo/dokka/parameters/KotlinPlatform : java/lang/Enum {
public static final field AndroidJVM Ldev/adamko/dokkatoo/dokka/parameters/KotlinPlatform;
public static final field Common Ldev/adamko/dokkatoo/dokka/parameters/KotlinPlatform;
public static final field Companion Ldev/adamko/dokkatoo/dokka/parameters/KotlinPlatform$Companion;
public static final field JS Ldev/adamko/dokkatoo/dokka/parameters/KotlinPlatform;
Expand Down
10 changes: 7 additions & 3 deletions modules/dokkatoo-plugin/src/main/kotlin/DokkatooBasePlugin.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.adamko.dokkatoo

import dev.adamko.dokkatoo.DokkatooExtension.Versions.Companion.VERSIONS_EXTENSION_NAME
import dev.adamko.dokkatoo.distibutions.DokkatooConfigurationAttributes
import dev.adamko.dokkatoo.distibutions.DokkatooConfigurationAttributes.Companion.DOKKATOO_BASE_ATTRIBUTE
import dev.adamko.dokkatoo.distibutions.DokkatooConfigurationAttributes.Companion.DOKKATOO_CATEGORY_ATTRIBUTE
Expand Down Expand Up @@ -118,11 +119,12 @@ constructor(
dokkatooModuleDirectory.convention(layout.buildDirectory.dir("dokka-module"))
dokkatooConfigurationsDirectory.convention(layout.buildDirectory.dir("dokka-config"))

extensions.create<DokkatooExtension.Versions>("versions").apply {
extensions.create<DokkatooExtension.Versions>(VERSIONS_EXTENSION_NAME).apply {
jetbrainsDokka.convention(DokkatooConstants.DOKKA_VERSION)
jetbrainsMarkdown.convention("0.3.1")
freemarker.convention("2.3.31")
kotlinxHtml.convention("0.8.0")
kotlinxCoroutines.convention("1.6.4")
}
}
}
Expand Down Expand Up @@ -160,7 +162,7 @@ constructor(
name.endsWith("Main") -> name.substringBeforeLast("Main")

// indeterminate source sets should be named by the Kotlin platform
else -> platform.key
else -> platform.displayName
}
}
)
Expand All @@ -176,7 +178,9 @@ constructor(

enableKotlinStdLibDocumentationLink.convention(true)
enableJdkDocumentationLink.convention(true)
enableAndroidDocumentationLink.convention(false)
enableAndroidDocumentationLink.convention(
analysisPlatform.map { it == KotlinPlatform.AndroidJVM }
)

reportUndocumented.convention(false)
skipDeprecated.convention(false)
Expand Down
5 changes: 5 additions & 0 deletions modules/dokkatoo-plugin/src/main/kotlin/DokkatooExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,10 @@ constructor(
val jetbrainsMarkdown: Property<String>
val freemarker: Property<String>
val kotlinxHtml: Property<String>
val kotlinxCoroutines: Property<String>

companion object {
const val VERSIONS_EXTENSION_NAME = "versions"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package dev.adamko.dokkatoo.adapters

import com.android.build.gradle.internal.dependency.VariantDependencies
import com.android.build.gradle.internal.publishing.AndroidArtifacts
import dev.adamko.dokkatoo.DokkatooBasePlugin
import dev.adamko.dokkatoo.DokkatooExtension
import dev.adamko.dokkatoo.dokka.parameters.KotlinPlatform
import dev.adamko.dokkatoo.internal.DokkatooInternalApi
import dev.adamko.dokkatoo.internal.collectIncomingFiles
import javax.inject.Inject
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.api.logging.Logging
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.*

@DokkatooInternalApi
abstract class DokkatooAndroidAdapter @Inject constructor(
private val objects: ObjectFactory,
) : Plugin<Project> {

override fun apply(project: Project) {
logger.info("applied DokkatooAndroidAdapter to ${project.path}")

project.plugins.withType<DokkatooBasePlugin>().configureEach {
project.pluginManager.apply {
withPlugin("com.android.base") { configure(project) }
withPlugin("com.android.application") { configure(project) }
withPlugin("com.android.library") { configure(project) }
}
}
}

protected fun configure(project: Project) {
val dokkatooExtension = project.extensions.getByType<DokkatooExtension>()

dokkatooExtension.dokkatooSourceSets.configureEach {

val androidClasspath: Provider<FileCollection> =
analysisPlatform.map {
val compilationClasspath = objects.fileCollection()
if (it == KotlinPlatform.AndroidJVM) {

fun collectConfiguration(named: String) {
project.configurations.collectIncomingFiles(named, compilationClasspath)
// need to fetch JARs explicitly, because Android Gradle Plugin is weird
// and doesn't seem to register the attributes properly
@Suppress("UnstableApiUsage")
project.configurations.collectIncomingFiles(named, compilationClasspath) {
withVariantReselection()
attributes {
attribute(AndroidArtifacts.ARTIFACT_TYPE, AndroidArtifacts.ArtifactType.JAR.type)
}
lenient(true)
}
}

// fetch android.jar
collectConfiguration(named = VariantDependencies.CONFIG_NAME_ANDROID_APIS)
}

compilationClasspath
}

classpath.from(androidClasspath)
}
}

@DokkatooInternalApi
companion object {
private val logger = Logging.getLogger(DokkatooAndroidAdapter::class.java)
}
}

0 comments on commit 4e2dbef

Please sign in to comment.