From 8c0344e682fc4ba0e44fc740269c7ba308c47c35 Mon Sep 17 00:00:00 2001 From: aSemy <897017+aSemy@users.noreply.github.com> Date: Tue, 21 Feb 2023 18:51:11 +0100 Subject: Move Gradle plugin tasks into a separate directory (#2705) --- .../dokka/gradle/AbstractDokkaLeafTask.kt | 35 --- .../dokka/gradle/AbstractDokkaParentTask.kt | 102 --------- .../jetbrains/dokka/gradle/AbstractDokkaTask.kt | 241 -------------------- .../jetbrains/dokka/gradle/DokkaCollectorTask.kt | 35 --- .../jetbrains/dokka/gradle/DokkaMultiModuleTask.kt | 103 --------- .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 23 -- .../org/jetbrains/dokka/gradle/DokkaTaskPartial.kt | 26 --- .../dokka/gradle/tasks/AbstractDokkaLeafTask.kt | 37 ++++ .../dokka/gradle/tasks/AbstractDokkaParentTask.kt | 103 +++++++++ .../dokka/gradle/tasks/AbstractDokkaTask.kt | 243 +++++++++++++++++++++ .../dokka/gradle/tasks/DokkaCollectorTask.kt | 37 ++++ .../dokka/gradle/tasks/DokkaMultiModuleTask.kt | 104 +++++++++ .../org/jetbrains/dokka/gradle/tasks/DokkaTask.kt | 25 +++ .../dokka/gradle/tasks/DokkaTaskPartial.kt | 28 +++ 14 files changed, 577 insertions(+), 565 deletions(-) delete mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaLeafTask.kt delete mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTask.kt delete mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt delete mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt delete mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt delete mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt delete mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTaskPartial.kt create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaLeafTask.kt create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaParentTask.kt create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaTask.kt create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaCollectorTask.kt create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTask.kt create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTask.kt create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTaskPartial.kt (limited to 'runners/gradle-plugin/src/main/kotlin') diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaLeafTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaLeafTask.kt deleted file mode 100644 index 6e34676c..00000000 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaLeafTask.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.jetbrains.dokka.gradle - -import org.gradle.api.NamedDomainObjectContainer -import org.gradle.api.internal.plugins.DslObject -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.Nested -import org.gradle.kotlin.dsl.container -import org.gradle.work.DisableCachingByDefault - -@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly") -abstract class AbstractDokkaLeafTask : AbstractDokkaTask() { - - @get:Internal - val dokkaSourceSets: NamedDomainObjectContainer = - project.container(GradleDokkaSourceSetBuilder::class, gradleDokkaSourceSetBuilderFactory()).also { container -> - DslObject(this).extensions.add("dokkaSourceSets", container) - project.kotlinOrNull?.sourceSets?.all sourceSet@{ - container.register(name) { - configureWithKotlinSourceSet(this@sourceSet) - } - } - } - - /** - * Only contains source sets that are marked with `isDocumented`. - * Non documented source sets are not relevant for Gradle's UP-TO-DATE mechanism, as well - * as task dependency graph. - */ - @get:Nested - protected val unsuppressedSourceSets: List - get() = dokkaSourceSets - .toList() - .also(::checkSourceSetDependencies) - .filterNot { it.suppress.getSafe() } -} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTask.kt deleted file mode 100644 index e912b083..00000000 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTask.kt +++ /dev/null @@ -1,102 +0,0 @@ -package org.jetbrains.dokka.gradle - -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.Nested -import org.gradle.work.DisableCachingByDefault - -private const val DEPRECATION_MESSAGE = """ - It is an anti-pattern to declare cross-project dependencies as it leads to various build problems. - For this reason, this API wil be removed with the introduction of project isolation. - When it happens, we will provide a migration guide. In the meantime, you can keep using this API - if you have to, but please don't rely on it if possible. If you don't want to document a certain project, - don't apply the Dokka plugin for it, or disable individual project tasks using the Gradle API . -""" - -@Suppress("DEPRECATION") -@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly") -abstract class AbstractDokkaParentTask : AbstractDokkaTask() { - - @get:Internal - internal var childDokkaTaskPaths: Set = emptySet() - private set - - @get:Nested - internal val childDokkaTasks: Set - get() = childDokkaTaskPaths - .mapNotNull { path -> project.tasks.findByPath(path) } - .map(::checkIsAbstractDokkaTask) - .toSet() - - /* By task reference */ - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun addChildTask(task: AbstractDokkaTask) { - childDokkaTaskPaths = childDokkaTaskPaths + task.path - } - - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun removeChildTask(task: AbstractDokkaTask) { - childDokkaTaskPaths = childDokkaTaskPaths - task.path - } - - /* By path */ - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun addChildTask(path: String) { - childDokkaTaskPaths = childDokkaTaskPaths + project.absoluteProjectPath(path) - } - - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun removeChildTask(path: String) { - childDokkaTaskPaths = childDokkaTaskPaths - project.absoluteProjectPath(path) - } - - /* By project reference and name */ - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun addChildTasks(projects: Iterable, childTasksName: String) { - projects.forEach { project -> - addChildTask(project.absoluteProjectPath(childTasksName)) - } - } - - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun removeChildTasks(projects: Iterable, childTasksName: String) { - projects.forEach { project -> - removeChildTask(project.absoluteProjectPath(childTasksName)) - } - } - - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun addSubprojectChildTasks(childTasksName: String) { - addChildTasks(project.subprojects, childTasksName) - } - - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun removeSubprojectChildTasks(childTasksName: String) { - removeChildTasks(project.subprojects, childTasksName) - } - - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun removeChildTasks(project: Project) { - childDokkaTaskPaths = childDokkaTaskPaths.filter { path -> - parsePath(path).parent != parsePath(project.path) - }.toSet() - } - - @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) - fun removeChildTasks(projects: Iterable) { - projects.forEach { project -> removeChildTasks(project) } - } - - private fun checkIsAbstractDokkaTask(task: Task): AbstractDokkaTask { - if (task is AbstractDokkaTask) { - return task - } - throw IllegalArgumentException( - "Only tasks of type ${AbstractDokkaTask::class.java.name} can be added as child for " + - "${AbstractDokkaParentTask::class.java.name} tasks.\n" + - "Found task ${task.path} of type ${task::class.java.name} added to $path" - ) - } -} - diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt deleted file mode 100644 index d7ddfc93..00000000 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaTask.kt +++ /dev/null @@ -1,241 +0,0 @@ -package org.jetbrains.dokka.gradle - -import groovy.lang.Closure -import org.gradle.api.Action -import org.gradle.api.DefaultTask -import org.gradle.api.Task -import org.gradle.api.artifacts.Configuration -import org.gradle.api.plugins.JavaBasePlugin -import org.gradle.api.provider.ListProperty -import org.gradle.api.provider.MapProperty -import org.gradle.api.provider.Property -import org.gradle.api.tasks.* -import org.gradle.kotlin.dsl.listProperty -import org.gradle.kotlin.dsl.mapProperty -import org.gradle.work.DisableCachingByDefault -import org.jetbrains.dokka.* -import org.jetbrains.dokka.plugability.ConfigurableBlock -import org.jetbrains.dokka.plugability.DokkaPlugin -import java.io.File -import java.util.function.BiConsumer -import kotlin.reflect.full.createInstance - -@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly") -abstract class AbstractDokkaTask : DefaultTask() { - - /** - * Display name used to refer to the module. Used for ToC, navigation, logging, etc. - * - * If set for a single-project build or a MultiModule task, will be used as project name. - * - * Default is Gradle project name. - */ - @Input - val moduleName: Property = project.objects.safeProperty() - .safeConvention(project.name) - - /** - * Module version. - * - * If set for a single-project build or a MultiModule task, will be used - * as project version by the versioning plugin. - * - * Default is Gradle project version. - */ - @Input - val moduleVersion: Property = project.objects.safeProperty() - .safeConvention(project.provider { project.version.toString() }) - - /** - * Directory to which documentation will be generated, regardless of format. - * Can be set on per-task basis. - * - * Default is `project/buildDir/taskName.removePrefix("dokka").decapitalize()`, so - * for `dokkaHtmlMultiModule` task it will be `project/buildDir/htmlMultiModule` - */ - @OutputDirectory - val outputDirectory: Property = project.objects.safeProperty() - .safeConvention(project.provider { defaultDokkaOutputDirectory() }) - - /** - * Configuration for Dokka plugins. This property is not expected to be used directly - if possible, use - * [pluginConfiguration] blocks (preferred) or [pluginsMapConfiguration] instead. - */ - @Input - val pluginsConfiguration: ListProperty = project.objects.listProperty() - - /** - * JSON configuration of Dokka plugins. - * - * Key is fully qualified Dokka plugin name, value is its configuration in JSON. - * - * Example: - * - * ```kotlin - * tasks.dokkaHtml { - * val dokkaBaseConfiguration = """ - * { - * "customAssets": ["${file("assets/my-image.png")}"], - * "customStyleSheets": ["${file("assets/my-styles.css")}"], - * "footerMessage": "(c) 2022 MyOrg" - * } - * """ - * pluginsMapConfiguration.set( - * mapOf("org.jetbrains.dokka.base.DokkaBase" to dokkaBaseConfiguration) - * ) - * } - * ``` - */ - @Input - val pluginsMapConfiguration: MapProperty = project.objects.mapProperty() - - /** - * Whether to suppress obvious functions. - * - * A function is considered to be obvious if it is: - * - Inherited from `kotlin.Any`, `Kotlin.Enum`, `java.lang.Object` or `java.lang.Enum`, - * such as `equals`, `hashCode`, `toString`. - * - Synthetic (generated by the compiler) and does not have any documentation, such as - * `dataClass.componentN` or `dataClass.copy`. - * - * Default is `true` - */ - @Input - val suppressObviousFunctions: Property = project.objects.safeProperty() - .safeConvention(DokkaDefaults.suppressObviousFunctions) - - /** - * Whether to suppress inherited members that aren't explicitly overridden in a given class. - * - * Note: this can suppress functions such as `equals`/`hashCode`/`toString`, but cannot suppress - * synthetic functions such as `dataClass.componentN` and `dataClass.copy`. Use [suppressObviousFunctions] - * for that. - * - * Default is `false`. - */ - @Input - val suppressInheritedMembers: Property = project.objects.safeProperty() - .safeConvention(DokkaDefaults.suppressInheritedMembers) - - /** - * Whether to resolve remote files/links over network. - * - * This includes package-lists used for generating external documentation links: - * for instance, to make classes from standard library clickable. - * - * Setting this to `true` can significantly speed up build times in certain cases, - * but can also worsen documentation quality and user experience, for instance by - * not resolving some dependency's class/member links. - * - * When using offline mode, you can cache fetched files locally and provide them to - * Dokka as local paths. For instance, see [GradleExternalDocumentationLinkBuilder]. - * - * Default is `false`. - */ - @Input - val offlineMode: Property = project.objects.safeProperty() - .safeConvention(DokkaDefaults.offlineMode) - - /** - * Whether to fail documentation generation if Dokka has emitted a warning or an error. - * Will wait until all errors and warnings have been emitted first. - * - * This setting works well with [GradleDokkaSourceSetBuilder.reportUndocumented] - * - * Default is `false`. - */ - @Input - val failOnWarning: Property = project.objects.safeProperty() - .safeConvention(DokkaDefaults.failOnWarning) - - @Optional - @InputDirectory - @PathSensitive(PathSensitivity.RELATIVE) - val cacheRoot: Property = project.objects.safeProperty() - - /** - * Type-safe configuration for a Dokka plugin. - * - * Note: this is available in Kotlin DSL only, if Dokka Gradle plugin was applied through `plugins` block - * and the configured plugin can be found on classpath, which may require adding a classpath dependency - * to `buildscript` block in case of external plugins. Some Dokka plugins, such as - * [org.jetbrains.dokka.base.DokkaBase], are on classpath by default. - * - * Example: - * - * ```kotlin - * import org.jetbrains.dokka.base.DokkaBase - * import org.jetbrains.dokka.base.DokkaBaseConfiguration - * - * tasks.dokkaHtml { - * pluginConfiguration { - * footerMessage = "Test" - * } - * } - * ``` - * - * @param P Plugin class that extends [DokkaPlugin] - * @param T Plugin configuration class that extends [ConfigurableBlock] - */ - inline fun pluginConfiguration(block: T.() -> Unit) { - val instance = T::class.createInstance().apply(block) - val pluginConfiguration = PluginConfigurationImpl( - fqPluginName = P::class.qualifiedName!!, - serializationFormat = DokkaConfiguration.SerializationFormat.JSON, - values = instance.toCompactJsonString() - ) - pluginsConfiguration.add(pluginConfiguration) - } - - @Classpath - val plugins: Configuration = project.maybeCreateDokkaPluginConfiguration(name) - - @Classpath - val runtime: Configuration = project.maybeCreateDokkaRuntimeConfiguration(name) - - final override fun doFirst(action: Action): Task = super.doFirst(action) - - final override fun doFirst(action: Closure<*>): Task = super.doFirst(action) - - @TaskAction - internal open fun generateDocumentation() { - DokkaBootstrap(runtime, DokkaBootstrapImpl::class).apply { - configure(buildDokkaConfiguration().toCompactJsonString(), createProxyLogger()) - /** - * Run in a new thread to avoid memory leaks that are related to ThreadLocal (that keeps `URLCLassLoader`) - * Currently, all `ThreadLocal`s leaking are in the compiler/IDE codebase. - */ - Thread { generate() }.apply { - start() - join() - } - } - } - - internal abstract fun buildDokkaConfiguration(): DokkaConfigurationImpl - - private fun createProxyLogger(): BiConsumer = BiConsumer { level, message -> - when (level) { - "debug" -> logger.debug(message) - "info" -> logger.info(message) - "progress" -> logger.lifecycle(message) - "warn" -> logger.warn(message) - "error" -> logger.error(message) - } - } - - init { - group = JavaBasePlugin.DOCUMENTATION_GROUP - } - - internal fun buildPluginsConfiguration(): List { - val manuallyConfigured = pluginsMapConfiguration.getSafe().entries.map { entry -> - PluginConfigurationImpl( - entry.key, - DokkaConfiguration.SerializationFormat.JSON, - entry.value - ) - } - return pluginsConfiguration.getSafe().mapNotNull { it as? PluginConfigurationImpl } + manuallyConfigured - } -} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt deleted file mode 100644 index 68c4181c..00000000 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.jetbrains.dokka.gradle - -import org.gradle.api.tasks.CacheableTask -import org.jetbrains.dokka.DokkaConfigurationImpl - -@CacheableTask -abstract class DokkaCollectorTask : AbstractDokkaParentTask() { - - override fun generateDocumentation() { - checkChildDokkaTasksIsNotEmpty() - super.generateDocumentation() - } - - override fun buildDokkaConfiguration(): DokkaConfigurationImpl { - val initialDokkaConfiguration = DokkaConfigurationImpl( - moduleName = moduleName.getSafe(), - outputDir = outputDirectory.getSafe(), - cacheRoot = cacheRoot.getSafe(), - failOnWarning = failOnWarning.getSafe(), - offlineMode = offlineMode.getSafe(), - pluginsClasspath = plugins.resolve().toList(), - pluginsConfiguration = buildPluginsConfiguration(), - suppressObviousFunctions = suppressObviousFunctions.getSafe(), - suppressInheritedMembers = suppressInheritedMembers.getSafe(), - ) - - val subprojectDokkaConfigurations = childDokkaTasks.map { dokkaTask -> dokkaTask.buildDokkaConfiguration() } - return subprojectDokkaConfigurations.fold(initialDokkaConfiguration) { acc, it: DokkaConfigurationImpl -> - acc.copy( - sourceSets = acc.sourceSets + it.sourceSets, - pluginsClasspath = acc.pluginsClasspath + it.pluginsClasspath - ) - } - } -} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt deleted file mode 100644 index db2a219c..00000000 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt +++ /dev/null @@ -1,103 +0,0 @@ -package org.jetbrains.dokka.gradle - -import org.gradle.api.file.ConfigurableFileCollection -import org.gradle.api.internal.tasks.TaskDependencyInternal -import org.gradle.api.provider.Property -import org.gradle.api.tasks.* -import org.jetbrains.dokka.DokkaConfigurationImpl -import org.jetbrains.dokka.DokkaModuleDescriptionImpl -import java.io.File - -@Suppress("unused") // Shall provide source compatibility if possible -@Deprecated("Use 'DokkaMultiModuleTask' instead", ReplaceWith("DokkaMultiModuleTask"), DeprecationLevel.ERROR) -typealias DokkaMultimoduleTask = DokkaMultiModuleTask - -private typealias TaskPath = String - -@CacheableTask -abstract class DokkaMultiModuleTask : AbstractDokkaParentTask() { - - /** - * List of Markdown files that contain - * [module and package documentation](https://kotlinlang.org/docs/reference/dokka-module-and-package-docs.html). - * - * Contents of specified files will be parsed and embedded into documentation as module and package descriptions. - * - * Example of such a file: - * - * ```markdown - * # Module kotlin-demo - * - * The module shows the Dokka usage. - * - * # Package org.jetbrains.kotlin.demo - * - * Contains assorted useful stuff. - * - * ## Level 2 heading - * - * Text after this heading is also part of documentation for `org.jetbrains.kotlin.demo` - * - * # Package org.jetbrains.kotlin.demo2 - * - * Useful stuff in another package. - * ``` - */ - @InputFiles - @Optional - @PathSensitive(PathSensitivity.RELATIVE) - val includes: ConfigurableFileCollection = project.files() - - @Internal - val fileLayout: Property = project.objects.safeProperty() - .safeConvention(DokkaMultiModuleFileLayout.CompactInParent) - - @get:InputFiles - @get:PathSensitive(PathSensitivity.RELATIVE) - internal val sourceChildOutputDirectories: Iterable - get() = childDokkaTasks.map { task -> task.outputDirectory.getSafe() } - - @get:OutputDirectories - internal val targetChildOutputDirectories: Iterable - get() = childDokkaTasks.map { task -> targetChildOutputDirectory(task) } - - @get:Input - internal val childDokkaTaskIncludes: Map> - get() = childDokkaTasks.filterIsInstance().associate { task -> - task.path to task.dokkaSourceSets.flatMap { it.includes }.toSet() - } - - // The method contains a reference to internal Gradle API that is nice not to use. - // There was an attempt to get rid of it, but it was not successful - // See: https://github.com/Kotlin/dokka/pull/2835 - @Internal - override fun getTaskDependencies(): TaskDependencyInternal = - super.getTaskDependencies() + childDokkaTasks - - - override fun generateDocumentation() { - checkChildDokkaTasksIsNotEmpty() - super.generateDocumentation() - } - - override fun buildDokkaConfiguration(): DokkaConfigurationImpl = DokkaConfigurationImpl( - moduleName = moduleName.getSafe(), - moduleVersion = moduleVersion.getValidVersionOrNull(), - outputDir = outputDirectory.getSafe(), - cacheRoot = cacheRoot.getSafe(), - pluginsConfiguration = buildPluginsConfiguration(), - failOnWarning = failOnWarning.getSafe(), - offlineMode = offlineMode.getSafe(), - pluginsClasspath = plugins.resolve().toList(), - modules = childDokkaTasks.map { dokkaTask -> - DokkaModuleDescriptionImpl( - name = dokkaTask.moduleName.getSafe(), - relativePathToOutputDirectory = targetChildOutputDirectory(dokkaTask).relativeTo(outputDirectory.getSafe()), - includes = childDokkaTaskIncludes[dokkaTask.path].orEmpty(), - sourceOutputDirectory = dokkaTask.outputDirectory.getSafe() - ) - }, - includes = includes.toSet(), - ) -} - diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt deleted file mode 100644 index af2d3b1b..00000000 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.jetbrains.dokka.gradle - -import org.jetbrains.dokka.DokkaConfigurationImpl -import org.jetbrains.dokka.build -import org.gradle.api.tasks.* - -@CacheableTask -abstract class DokkaTask : AbstractDokkaLeafTask() { - override fun buildDokkaConfiguration(): DokkaConfigurationImpl = - DokkaConfigurationImpl( - moduleName = moduleName.getSafe(), - moduleVersion = moduleVersion.getValidVersionOrNull(), - outputDir = outputDirectory.getSafe(), - cacheRoot = cacheRoot.getSafe(), - offlineMode = offlineMode.getSafe(), - failOnWarning = failOnWarning.getSafe(), - sourceSets = unsuppressedSourceSets.build(), - pluginsConfiguration = buildPluginsConfiguration(), - pluginsClasspath = plugins.resolve().toList(), - suppressObviousFunctions = suppressObviousFunctions.getSafe(), - suppressInheritedMembers = suppressInheritedMembers.getSafe(), - ) -} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTaskPartial.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTaskPartial.kt deleted file mode 100644 index eaee68a2..00000000 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTaskPartial.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.jetbrains.dokka.gradle - -import org.jetbrains.dokka.DokkaConfigurationImpl -import org.jetbrains.dokka.build -import org.gradle.api.tasks.* - -@CacheableTask -abstract class DokkaTaskPartial : AbstractDokkaLeafTask() { - - override fun buildDokkaConfiguration(): DokkaConfigurationImpl { - return DokkaConfigurationImpl( - moduleName = moduleName.getSafe(), - moduleVersion = moduleVersion.orNull, - outputDir = outputDirectory.getSafe(), - cacheRoot = cacheRoot.getSafe(), - offlineMode = offlineMode.getSafe(), - failOnWarning = failOnWarning.getSafe(), - sourceSets = unsuppressedSourceSets.build(), - pluginsConfiguration = buildPluginsConfiguration(), - pluginsClasspath = plugins.resolve().toList(), - delayTemplateSubstitution = true, - suppressObviousFunctions = suppressObviousFunctions.getSafe(), - suppressInheritedMembers = suppressInheritedMembers.getSafe(), - ) - } -} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaLeafTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaLeafTask.kt new file mode 100644 index 00000000..f24df017 --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaLeafTask.kt @@ -0,0 +1,37 @@ +@file:Suppress("PackageDirectoryMismatch") + +package org.jetbrains.dokka.gradle + +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.internal.plugins.DslObject +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.Nested +import org.gradle.kotlin.dsl.container +import org.gradle.work.DisableCachingByDefault + +@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly") +abstract class AbstractDokkaLeafTask : AbstractDokkaTask() { + + @get:Internal + val dokkaSourceSets: NamedDomainObjectContainer = + project.container(GradleDokkaSourceSetBuilder::class, gradleDokkaSourceSetBuilderFactory()).also { container -> + DslObject(this).extensions.add("dokkaSourceSets", container) + project.kotlinOrNull?.sourceSets?.all sourceSet@{ + container.register(name) { + configureWithKotlinSourceSet(this@sourceSet) + } + } + } + + /** + * Only contains source sets that are marked with `isDocumented`. + * Non documented source sets are not relevant for Gradle's UP-TO-DATE mechanism, as well + * as task dependency graph. + */ + @get:Nested + protected val unsuppressedSourceSets: List + get() = dokkaSourceSets + .toList() + .also(::checkSourceSetDependencies) + .filterNot { it.suppress.getSafe() } +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaParentTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaParentTask.kt new file mode 100644 index 00000000..e3a1a732 --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaParentTask.kt @@ -0,0 +1,103 @@ +@file:Suppress("PackageDirectoryMismatch") + +package org.jetbrains.dokka.gradle + +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.Nested +import org.gradle.work.DisableCachingByDefault + +private const val DEPRECATION_MESSAGE = """ + It is an anti-pattern to declare cross-project dependencies as it leads to various build problems. + For this reason, this API wil be removed with the introduction of project isolation. + When it happens, we will provide a migration guide. In the meantime, you can keep using this API + if you have to, but please don't rely on it if possible. If you don't want to document a certain project, + don't apply the Dokka plugin for it, or disable individual project tasks using the Gradle API . +""" + +@Suppress("DEPRECATION") +@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly") +abstract class AbstractDokkaParentTask : AbstractDokkaTask() { + + @get:Internal + internal var childDokkaTaskPaths: Set = emptySet() + private set + + @get:Nested + internal val childDokkaTasks: Set + get() = childDokkaTaskPaths + .mapNotNull { path -> project.tasks.findByPath(path) } + .map(::checkIsAbstractDokkaTask) + .toSet() + + /* By task reference */ + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun addChildTask(task: AbstractDokkaTask) { + childDokkaTaskPaths = childDokkaTaskPaths + task.path + } + + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun removeChildTask(task: AbstractDokkaTask) { + childDokkaTaskPaths = childDokkaTaskPaths - task.path + } + + /* By path */ + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun addChildTask(path: String) { + childDokkaTaskPaths = childDokkaTaskPaths + project.absoluteProjectPath(path) + } + + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun removeChildTask(path: String) { + childDokkaTaskPaths = childDokkaTaskPaths - project.absoluteProjectPath(path) + } + + /* By project reference and name */ + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun addChildTasks(projects: Iterable, childTasksName: String) { + projects.forEach { project -> + addChildTask(project.absoluteProjectPath(childTasksName)) + } + } + + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun removeChildTasks(projects: Iterable, childTasksName: String) { + projects.forEach { project -> + removeChildTask(project.absoluteProjectPath(childTasksName)) + } + } + + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun addSubprojectChildTasks(childTasksName: String) { + addChildTasks(project.subprojects, childTasksName) + } + + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun removeSubprojectChildTasks(childTasksName: String) { + removeChildTasks(project.subprojects, childTasksName) + } + + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun removeChildTasks(project: Project) { + childDokkaTaskPaths = childDokkaTaskPaths.filter { path -> + parsePath(path).parent != parsePath(project.path) + }.toSet() + } + + @Deprecated(message = DEPRECATION_MESSAGE, level = DeprecationLevel.WARNING) + fun removeChildTasks(projects: Iterable) { + projects.forEach { project -> removeChildTasks(project) } + } + + private fun checkIsAbstractDokkaTask(task: Task): AbstractDokkaTask { + if (task is AbstractDokkaTask) { + return task + } + throw IllegalArgumentException( + "Only tasks of type ${AbstractDokkaTask::class.java.name} can be added as child for " + + "${AbstractDokkaParentTask::class.java.name} tasks.\n" + + "Found task ${task.path} of type ${task::class.java.name} added to $path" + ) + } +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaTask.kt new file mode 100644 index 00000000..e5d42ffa --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/AbstractDokkaTask.kt @@ -0,0 +1,243 @@ +@file:Suppress("PackageDirectoryMismatch") + +package org.jetbrains.dokka.gradle + +import groovy.lang.Closure +import org.gradle.api.Action +import org.gradle.api.DefaultTask +import org.gradle.api.Task +import org.gradle.api.artifacts.Configuration +import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.provider.ListProperty +import org.gradle.api.provider.MapProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.* +import org.gradle.kotlin.dsl.listProperty +import org.gradle.kotlin.dsl.mapProperty +import org.gradle.work.DisableCachingByDefault +import org.jetbrains.dokka.* +import org.jetbrains.dokka.plugability.ConfigurableBlock +import org.jetbrains.dokka.plugability.DokkaPlugin +import java.io.File +import java.util.function.BiConsumer +import kotlin.reflect.full.createInstance + +@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly") +abstract class AbstractDokkaTask : DefaultTask() { + + /** + * Display name used to refer to the module. Used for ToC, navigation, logging, etc. + * + * If set for a single-project build or a MultiModule task, will be used as project name. + * + * Default is Gradle project name. + */ + @Input + val moduleName: Property = project.objects.safeProperty() + .safeConvention(project.name) + + /** + * Module version. + * + * If set for a single-project build or a MultiModule task, will be used + * as project version by the versioning plugin. + * + * Default is Gradle project version. + */ + @Input + val moduleVersion: Property = project.objects.safeProperty() + .safeConvention(project.provider { project.version.toString() }) + + /** + * Directory to which documentation will be generated, regardless of format. + * Can be set on per-task basis. + * + * Default is `project/buildDir/taskName.removePrefix("dokka").decapitalize()`, so + * for `dokkaHtmlMultiModule` task it will be `project/buildDir/htmlMultiModule` + */ + @OutputDirectory + val outputDirectory: Property = project.objects.safeProperty() + .safeConvention(project.provider { defaultDokkaOutputDirectory() }) + + /** + * Configuration for Dokka plugins. This property is not expected to be used directly - if possible, use + * [pluginConfiguration] blocks (preferred) or [pluginsMapConfiguration] instead. + */ + @Input + val pluginsConfiguration: ListProperty = project.objects.listProperty() + + /** + * JSON configuration of Dokka plugins. + * + * Key is fully qualified Dokka plugin name, value is its configuration in JSON. + * + * Example: + * + * ```kotlin + * tasks.dokkaHtml { + * val dokkaBaseConfiguration = """ + * { + * "customAssets": ["${file("assets/my-image.png")}"], + * "customStyleSheets": ["${file("assets/my-styles.css")}"], + * "footerMessage": "(c) 2022 MyOrg" + * } + * """ + * pluginsMapConfiguration.set( + * mapOf("org.jetbrains.dokka.base.DokkaBase" to dokkaBaseConfiguration) + * ) + * } + * ``` + */ + @Input + val pluginsMapConfiguration: MapProperty = project.objects.mapProperty() + + /** + * Whether to suppress obvious functions. + * + * A function is considered to be obvious if it is: + * - Inherited from `kotlin.Any`, `Kotlin.Enum`, `java.lang.Object` or `java.lang.Enum`, + * such as `equals`, `hashCode`, `toString`. + * - Synthetic (generated by the compiler) and does not have any documentation, such as + * `dataClass.componentN` or `dataClass.copy`. + * + * Default is `true` + */ + @Input + val suppressObviousFunctions: Property = project.objects.safeProperty() + .safeConvention(DokkaDefaults.suppressObviousFunctions) + + /** + * Whether to suppress inherited members that aren't explicitly overridden in a given class. + * + * Note: this can suppress functions such as `equals`/`hashCode`/`toString`, but cannot suppress + * synthetic functions such as `dataClass.componentN` and `dataClass.copy`. Use [suppressObviousFunctions] + * for that. + * + * Default is `false`. + */ + @Input + val suppressInheritedMembers: Property = project.objects.safeProperty() + .safeConvention(DokkaDefaults.suppressInheritedMembers) + + /** + * Whether to resolve remote files/links over network. + * + * This includes package-lists used for generating external documentation links: + * for instance, to make classes from standard library clickable. + * + * Setting this to `true` can significantly speed up build times in certain cases, + * but can also worsen documentation quality and user experience, for instance by + * not resolving some dependency's class/member links. + * + * When using offline mode, you can cache fetched files locally and provide them to + * Dokka as local paths. For instance, see [GradleExternalDocumentationLinkBuilder]. + * + * Default is `false`. + */ + @Input + val offlineMode: Property = project.objects.safeProperty() + .safeConvention(DokkaDefaults.offlineMode) + + /** + * Whether to fail documentation generation if Dokka has emitted a warning or an error. + * Will wait until all errors and warnings have been emitted first. + * + * This setting works well with [GradleDokkaSourceSetBuilder.reportUndocumented] + * + * Default is `false`. + */ + @Input + val failOnWarning: Property = project.objects.safeProperty() + .safeConvention(DokkaDefaults.failOnWarning) + + @Optional + @InputDirectory + @PathSensitive(PathSensitivity.RELATIVE) + val cacheRoot: Property = project.objects.safeProperty() + + /** + * Type-safe configuration for a Dokka plugin. + * + * Note: this is available in Kotlin DSL only, if Dokka Gradle plugin was applied through `plugins` block + * and the configured plugin can be found on classpath, which may require adding a classpath dependency + * to `buildscript` block in case of external plugins. Some Dokka plugins, such as + * [org.jetbrains.dokka.base.DokkaBase], are on classpath by default. + * + * Example: + * + * ```kotlin + * import org.jetbrains.dokka.base.DokkaBase + * import org.jetbrains.dokka.base.DokkaBaseConfiguration + * + * tasks.dokkaHtml { + * pluginConfiguration { + * footerMessage = "Test" + * } + * } + * ``` + * + * @param P Plugin class that extends [DokkaPlugin] + * @param T Plugin configuration class that extends [ConfigurableBlock] + */ + inline fun pluginConfiguration(block: T.() -> Unit) { + val instance = T::class.createInstance().apply(block) + val pluginConfiguration = PluginConfigurationImpl( + fqPluginName = P::class.qualifiedName!!, + serializationFormat = DokkaConfiguration.SerializationFormat.JSON, + values = instance.toCompactJsonString() + ) + pluginsConfiguration.add(pluginConfiguration) + } + + @Classpath + val plugins: Configuration = project.maybeCreateDokkaPluginConfiguration(name) + + @Classpath + val runtime: Configuration = project.maybeCreateDokkaRuntimeConfiguration(name) + + final override fun doFirst(action: Action): Task = super.doFirst(action) + + final override fun doFirst(action: Closure<*>): Task = super.doFirst(action) + + @TaskAction + internal open fun generateDocumentation() { + DokkaBootstrap(runtime, DokkaBootstrapImpl::class).apply { + configure(buildDokkaConfiguration().toCompactJsonString(), createProxyLogger()) + /** + * Run in a new thread to avoid memory leaks that are related to ThreadLocal (that keeps `URLCLassLoader`) + * Currently, all `ThreadLocal`s leaking are in the compiler/IDE codebase. + */ + Thread { generate() }.apply { + start() + join() + } + } + } + + internal abstract fun buildDokkaConfiguration(): DokkaConfigurationImpl + + private fun createProxyLogger(): BiConsumer = BiConsumer { level, message -> + when (level) { + "debug" -> logger.debug(message) + "info" -> logger.info(message) + "progress" -> logger.lifecycle(message) + "warn" -> logger.warn(message) + "error" -> logger.error(message) + } + } + + init { + group = JavaBasePlugin.DOCUMENTATION_GROUP + } + + internal fun buildPluginsConfiguration(): List { + val manuallyConfigured = pluginsMapConfiguration.getSafe().entries.map { entry -> + PluginConfigurationImpl( + entry.key, + DokkaConfiguration.SerializationFormat.JSON, + entry.value + ) + } + return pluginsConfiguration.getSafe().mapNotNull { it as? PluginConfigurationImpl } + manuallyConfigured + } +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaCollectorTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaCollectorTask.kt new file mode 100644 index 00000000..38f4017a --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaCollectorTask.kt @@ -0,0 +1,37 @@ +@file:Suppress("PackageDirectoryMismatch") + +package org.jetbrains.dokka.gradle + +import org.gradle.api.tasks.CacheableTask +import org.jetbrains.dokka.DokkaConfigurationImpl + +@CacheableTask +abstract class DokkaCollectorTask : AbstractDokkaParentTask() { + + override fun generateDocumentation() { + checkChildDokkaTasksIsNotEmpty() + super.generateDocumentation() + } + + override fun buildDokkaConfiguration(): DokkaConfigurationImpl { + val initialDokkaConfiguration = DokkaConfigurationImpl( + moduleName = moduleName.getSafe(), + outputDir = outputDirectory.getSafe(), + cacheRoot = cacheRoot.getSafe(), + failOnWarning = failOnWarning.getSafe(), + offlineMode = offlineMode.getSafe(), + pluginsClasspath = plugins.resolve().toList(), + pluginsConfiguration = buildPluginsConfiguration(), + suppressObviousFunctions = suppressObviousFunctions.getSafe(), + suppressInheritedMembers = suppressInheritedMembers.getSafe(), + ) + + val subprojectDokkaConfigurations = childDokkaTasks.map { dokkaTask -> dokkaTask.buildDokkaConfiguration() } + return subprojectDokkaConfigurations.fold(initialDokkaConfiguration) { acc, it: DokkaConfigurationImpl -> + acc.copy( + sourceSets = acc.sourceSets + it.sourceSets, + pluginsClasspath = acc.pluginsClasspath + it.pluginsClasspath + ) + } + } +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTask.kt new file mode 100644 index 00000000..190dc6df --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTask.kt @@ -0,0 +1,104 @@ +@file:Suppress("PackageDirectoryMismatch") + +package org.jetbrains.dokka.gradle + +import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.internal.tasks.TaskDependencyInternal +import org.gradle.api.provider.Property +import org.gradle.api.tasks.* +import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.DokkaModuleDescriptionImpl +import java.io.File + +@Suppress("unused") // Shall provide source compatibility if possible +@Deprecated("Use 'DokkaMultiModuleTask' instead", ReplaceWith("DokkaMultiModuleTask"), DeprecationLevel.ERROR) +typealias DokkaMultimoduleTask = DokkaMultiModuleTask + +private typealias TaskPath = String + +@CacheableTask +abstract class DokkaMultiModuleTask : AbstractDokkaParentTask() { + + /** + * List of Markdown files that contain + * [module and package documentation](https://kotlinlang.org/docs/reference/dokka-module-and-package-docs.html). + * + * Contents of specified files will be parsed and embedded into documentation as module and package descriptions. + * + * Example of such a file: + * + * ```markdown + * # Module kotlin-demo + * + * The module shows the Dokka usage. + * + * # Package org.jetbrains.kotlin.demo + * + * Contains assorted useful stuff. + * + * ## Level 2 heading + * + * Text after this heading is also part of documentation for `org.jetbrains.kotlin.demo` + * + * # Package org.jetbrains.kotlin.demo2 + * + * Useful stuff in another package. + * ``` + */ + @InputFiles + @Optional + @PathSensitive(PathSensitivity.RELATIVE) + val includes: ConfigurableFileCollection = project.files() + + @Internal + val fileLayout: Property = project.objects.safeProperty() + .safeConvention(DokkaMultiModuleFileLayout.CompactInParent) + + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) + internal val sourceChildOutputDirectories: Iterable + get() = childDokkaTasks.map { task -> task.outputDirectory.getSafe() } + + @get:OutputDirectories + internal val targetChildOutputDirectories: Iterable + get() = childDokkaTasks.map { task -> targetChildOutputDirectory(task) } + + @get:Input + internal val childDokkaTaskIncludes: Map> + get() = childDokkaTasks.filterIsInstance().associate { task -> + task.path to task.dokkaSourceSets.flatMap { it.includes }.toSet() + } + + // The method contains a reference to internal Gradle API that is nice not to use. + // There was an attempt to get rid of it, but it was not successful + // See: https://github.com/Kotlin/dokka/pull/2835 + @Internal + override fun getTaskDependencies(): TaskDependencyInternal = + super.getTaskDependencies() + childDokkaTasks + + + override fun generateDocumentation() { + checkChildDokkaTasksIsNotEmpty() + super.generateDocumentation() + } + + override fun buildDokkaConfiguration(): DokkaConfigurationImpl = DokkaConfigurationImpl( + moduleName = moduleName.getSafe(), + moduleVersion = moduleVersion.getValidVersionOrNull(), + outputDir = outputDirectory.getSafe(), + cacheRoot = cacheRoot.getSafe(), + pluginsConfiguration = buildPluginsConfiguration(), + failOnWarning = failOnWarning.getSafe(), + offlineMode = offlineMode.getSafe(), + pluginsClasspath = plugins.resolve().toList(), + modules = childDokkaTasks.map { dokkaTask -> + DokkaModuleDescriptionImpl( + name = dokkaTask.moduleName.getSafe(), + relativePathToOutputDirectory = targetChildOutputDirectory(dokkaTask).relativeTo(outputDirectory.getSafe()), + includes = childDokkaTaskIncludes[dokkaTask.path].orEmpty(), + sourceOutputDirectory = dokkaTask.outputDirectory.getSafe() + ) + }, + includes = includes.toSet(), + ) +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTask.kt new file mode 100644 index 00000000..102ae336 --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTask.kt @@ -0,0 +1,25 @@ +@file:Suppress("PackageDirectoryMismatch") + +package org.jetbrains.dokka.gradle + +import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.build +import org.gradle.api.tasks.* + +@CacheableTask +abstract class DokkaTask : AbstractDokkaLeafTask() { + override fun buildDokkaConfiguration(): DokkaConfigurationImpl = + DokkaConfigurationImpl( + moduleName = moduleName.getSafe(), + moduleVersion = moduleVersion.getValidVersionOrNull(), + outputDir = outputDirectory.getSafe(), + cacheRoot = cacheRoot.getSafe(), + offlineMode = offlineMode.getSafe(), + failOnWarning = failOnWarning.getSafe(), + sourceSets = unsuppressedSourceSets.build(), + pluginsConfiguration = buildPluginsConfiguration(), + pluginsClasspath = plugins.resolve().toList(), + suppressObviousFunctions = suppressObviousFunctions.getSafe(), + suppressInheritedMembers = suppressInheritedMembers.getSafe(), + ) +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTaskPartial.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTaskPartial.kt new file mode 100644 index 00000000..14c6576c --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTaskPartial.kt @@ -0,0 +1,28 @@ +@file:Suppress("PackageDirectoryMismatch") + +package org.jetbrains.dokka.gradle + +import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.build +import org.gradle.api.tasks.* + +@CacheableTask +abstract class DokkaTaskPartial : AbstractDokkaLeafTask() { + + override fun buildDokkaConfiguration(): DokkaConfigurationImpl { + return DokkaConfigurationImpl( + moduleName = moduleName.getSafe(), + moduleVersion = moduleVersion.orNull, + outputDir = outputDirectory.getSafe(), + cacheRoot = cacheRoot.getSafe(), + offlineMode = offlineMode.getSafe(), + failOnWarning = failOnWarning.getSafe(), + sourceSets = unsuppressedSourceSets.build(), + pluginsConfiguration = buildPluginsConfiguration(), + pluginsClasspath = plugins.resolve().toList(), + delayTemplateSubstitution = true, + suppressObviousFunctions = suppressObviousFunctions.getSafe(), + suppressInheritedMembers = suppressInheritedMembers.getSafe(), + ) + } +} -- cgit