aboutsummaryrefslogtreecommitdiff
path: root/runners
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-03-13 10:46:33 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2020-03-23 13:57:07 +0100
commitc09bde34ff729ef9b1f3bea602fb53cd4e6dca42 (patch)
tree3a744a16c133b813ab1849761aef1ec3544f401f /runners
parentcedf8b7594deef2cd26e981865daa8aae0155520 (diff)
downloaddokka-c09bde34ff729ef9b1f3bea602fb53cd4e6dca42.tar.gz
dokka-c09bde34ff729ef9b1f3bea602fb53cd4e6dca42.tar.bz2
dokka-c09bde34ff729ef9b1f3bea602fb53cd4e6dca42.zip
Gradle Task supporting multimodular projects
Diffstat (limited to 'runners')
-rw-r--r--runners/cli/src/main/kotlin/cli/main.kt16
-rw-r--r--runners/gradle-plugin/build.gradle.kts1
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt56
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt37
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt36
-rw-r--r--runners/maven-plugin/src/main/kotlin/DokkaMojo.kt9
6 files changed, 123 insertions, 32 deletions
diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt
index e9329c38..644ecee4 100644
--- a/runners/cli/src/main/kotlin/cli/main.kt
+++ b/runners/cli/src/main/kotlin/cli/main.kt
@@ -52,7 +52,7 @@ open class GlobalArguments(parser: DokkaArgumentsParser) : DokkaConfiguration {
listOf("-pass"),
"Single dokka pass"
) {
- Arguments(parser)
+ Arguments(parser).also { if(it.moduleName.isEmpty()) DokkaConsoleLogger.warn("Not specified module name. It can result in unexpected behaviour while including documentation for module") }
}
}
@@ -260,14 +260,18 @@ object MainKt {
listOf("-globalPackageOptions"),
"List of package passConfiguration in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" "
) { link ->
- configuration.passesConfigurations.all { it.perPackageOptions.addAll(parsePerPackageOptions(link)) }
+ configuration.passesConfigurations.all {
+ it.perPackageOptions.toMutableList().addAll(parsePerPackageOptions(link))
+ }
}
parseContext.cli.singleAction(
listOf("-globalLinks"),
"External documentation links in format url^packageListUrl^^url2..."
) { link ->
- configuration.passesConfigurations.all { it.externalDocumentationLinks.addAll(parseLinks(link)) }
+ configuration.passesConfigurations.all {
+ it.externalDocumentationLinks.toMutableList().addAll(parseLinks(link))
+ }
}
parseContext.cli.repeatingAction(
@@ -278,12 +282,14 @@ object MainKt {
listOf(SourceLinkDefinitionImpl.parseSourceLinkDefinition(it))
else {
if (it.isNotEmpty()) {
- println("Warning: Invalid -srcLink syntax. Expected: <path>=<url>[#lineSuffix]. No source links will be generated.")
+ DokkaConsoleLogger.warn("Invalid -srcLink syntax. Expected: <path>=<url>[#lineSuffix]. No source links will be generated.")
}
listOf()
}
- configuration.passesConfigurations.all { it.sourceLinks.addAll(newSourceLinks) }
+ configuration.passesConfigurations.all {
+ it.sourceLinks.toMutableList().addAll(newSourceLinks)
+ }
}
parser.parseInto(configuration)
diff --git a/runners/gradle-plugin/build.gradle.kts b/runners/gradle-plugin/build.gradle.kts
index 0d68a525..df4a8738 100644
--- a/runners/gradle-plugin/build.gradle.kts
+++ b/runners/gradle-plugin/build.gradle.kts
@@ -15,6 +15,7 @@ dependencies {
compileOnly("com.android.tools.build:gradle-core:3.0.0")
compileOnly("com.android.tools.build:builder-model:3.0.0")
compileOnly(gradleApi())
+ compileOnly(gradleKotlinDsl())
constraints {
val kotlin_version: String by project
compileOnly("org.jetbrains.kotlin:kotlin-reflect:${kotlin_version}") {
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
new file mode 100644
index 00000000..f4fa7aaa
--- /dev/null
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt
@@ -0,0 +1,56 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.Project
+import org.gradle.api.UnknownTaskException
+import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.TaskAction
+import org.gradle.kotlin.dsl.getByName
+import java.lang.IllegalStateException
+
+open class DokkaCollectorTask : DefaultTask() {
+
+ @Input
+ var modules: List<String> = emptyList()
+
+ @Input
+ var outputDirectory: String = ""
+
+ private lateinit var configuration: GradleDokkaConfigurationImpl
+
+ @TaskAction
+ fun collect() {
+ val passesConfigurations = getProjects(project).filter { it.name in modules }.map {
+ val task = try {
+ it.tasks.getByName(DOKKA_TASK_NAME, DokkaTask::class)
+ } catch (e: UnknownTaskException) {
+ throw IllegalStateException("No dokka task declared in module ${it.name}")
+ }
+ task.getConfiguration()
+ }
+
+ val initial = GradleDokkaConfigurationImpl().apply {
+ outputDir = outputDirectory
+ cacheRoot = passesConfigurations.first().cacheRoot
+ format = passesConfigurations.first().format
+ generateIndexPages = passesConfigurations.first().generateIndexPages
+ }
+
+ configuration = passesConfigurations.fold(initial) { acc, it: GradleDokkaConfigurationImpl ->
+ if(acc.format != it.format || acc.generateIndexPages != it.generateIndexPages || acc.cacheRoot != it.cacheRoot)
+ throw IllegalStateException("Dokka task configurations differ on core arguments (format, generateIndexPages, cacheRoot)")
+ acc.passesConfigurations = acc.passesConfigurations + it.passesConfigurations
+ acc.pluginsClasspath = (acc.pluginsClasspath + it.pluginsClasspath).distinct()
+ acc
+ }
+ project.tasks.getByName(DOKKA_TASK_NAME).setProperty("config", configuration)
+ }
+
+ init {
+ finalizedBy(project.tasks.getByName(DOKKA_TASK_NAME))
+ }
+
+ private fun getProjects(project: Project): Set<Project> =
+ project.subprojects + project.subprojects.flatMap { getProjects(it) }
+
+} \ No newline at end of file
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
index 65b0f4b3..4f7b88c4 100644
--- 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
@@ -8,7 +8,6 @@ import org.gradle.api.internal.plugins.DslObject
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.tasks.*
import org.jetbrains.dokka.DokkaBootstrap
-import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder
import org.jetbrains.dokka.DokkaConfiguration.SourceRoot
import org.jetbrains.dokka.Platform
@@ -76,10 +75,11 @@ open class DokkaTask : DefaultTask() {
@Nested get() = DslObject(this).extensions.getByType(GradlePassConfigurationImpl::class.java)
internal set(value) = DslObject(this).extensions.add(CONFIGURATION_EXTENSION_NAME, value)
+ var config: GradleDokkaConfigurationImpl? = null
+
// Configure Dokka with closure in Gradle Kotlin DSL
fun configuration(action: Action<in GradlePassConfigurationImpl>) = action.execute(configuration)
-
private val kotlinTasks: List<Task> by lazy { extractKotlinCompileTasks(configuration.collectKotlinTasks ?: { defaultKotlinTasks() }) }
private val configExtractor = ConfigurationExtractor(project)
@@ -133,6 +133,10 @@ open class DokkaTask : DefaultTask() {
@TaskAction
fun generate() {
+ generateForConfig(config ?: getConfiguration())
+ }
+
+ internal fun generateForConfig(configuration: GradleDokkaConfigurationImpl) {
outputDiagnosticInfo = true
val kotlinColorsEnabledBefore = System.getProperty(COLORS_ENABLED_PROPERTY) ?: "false"
System.setProperty(COLORS_ENABLED_PROPERTY, "false")
@@ -146,20 +150,6 @@ open class DokkaTask : DefaultTask() {
val gson = GsonBuilder().setPrettyPrinting().create()
- val globalConfig = multiplatform.toList().find { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME }
- val passConfigurationList = collectConfigurations()
- .map { defaultPassConfiguration(it, globalConfig) }
-
- val configuration = GradleDokkaConfigurationImpl().apply {
- outputDir = outputDirectory
- format = outputFormat
- generateIndexPages = true
- cacheRoot = cacheRoot
- impliedPlatforms = impliedPlatforms
- passesConfigurations = passConfigurationList
- pluginsClasspath = pluginsConfiguration.resolve().toList()
- }
-
bootstrapProxy.configure(
BiConsumer { level, message ->
when (level) {
@@ -180,6 +170,21 @@ open class DokkaTask : DefaultTask() {
}
}
+ internal fun getConfiguration(): GradleDokkaConfigurationImpl {
+ val globalConfig = multiplatform.toList().find { it.name.toLowerCase() == GLOBAL_PLATFORM_NAME }
+ val defaultModulesConfiguration = collectConfigurations()
+ .map { defaultPassConfiguration(it, globalConfig) }
+ return GradleDokkaConfigurationImpl().apply {
+ outputDir = outputDirectory
+ format = outputFormat
+ generateIndexPages = true
+ cacheRoot = cacheRoot
+ impliedPlatforms = impliedPlatforms
+ passesConfigurations = defaultModulesConfiguration
+ pluginsClasspath = pluginsConfiguration.resolve().toList()
+ }
+ }
+
private fun collectConfigurations() =
if (this.isMultiplatformProject()) collectMultiplatform() else listOf(collectSinglePlatform(configuration))
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt
index f4ffdab6..4efc5010 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt
@@ -10,9 +10,10 @@ import java.util.*
internal const val CONFIGURATION_EXTENSION_NAME = "configuration"
internal const val MULTIPLATFORM_EXTENSION_NAME = "multiplatform"
+internal const val DOKKA_TASK_NAME = "dokka"
+internal const val DOKKA_COLLECTOR_TASK_NAME = "dokkaCollector"
open class DokkaPlugin : Plugin<Project> {
- private val taskName = "dokka"
override fun apply(project: Project) {
loadDokkaVersion()
@@ -20,33 +21,50 @@ open class DokkaPlugin : Plugin<Project> {
val pluginsConfiguration = project.configurations.create("dokkaPlugins").apply {
defaultDependencies { it.add(project.dependencies.create("org.jetbrains.dokka:dokka-base:${DokkaVersion.version}")) }
}
- addTasks(project, dokkaRuntimeConfiguration, pluginsConfiguration, DokkaTask::class.java)
+ addDokkaTasks(project, dokkaRuntimeConfiguration, pluginsConfiguration, DokkaTask::class.java)
+ addDokkaCollectorTasks(project, DokkaCollectorTask::class.java)
}
- private fun loadDokkaVersion() = DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties"))
+ private fun loadDokkaVersion() =
+ DokkaVersion.loadFrom(javaClass.getResourceAsStream("/META-INF/gradle-plugins/org.jetbrains.dokka.properties"))
private fun addConfiguration(project: Project) =
project.configurations.create("dokkaRuntime").apply {
- defaultDependencies{ dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-core:${DokkaVersion.version}")) }
+ defaultDependencies { dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-core:${DokkaVersion.version}")) }
}
- private fun addTasks(
+ private fun addDokkaTasks(
project: Project,
runtimeConfiguration: Configuration,
pluginsConfiguration: Configuration,
taskClass: Class<out DokkaTask>
) {
- if(GradleVersion.current() >= GradleVersion.version("4.10")) {
- project.tasks.register(taskName, taskClass)
+ if (GradleVersion.current() >= GradleVersion.version("4.10")) {
+ project.tasks.register(DOKKA_TASK_NAME, taskClass)
} else {
- project.tasks.create(taskName, taskClass)
+ project.tasks.create(DOKKA_TASK_NAME, taskClass)
}
project.tasks.withType(taskClass) { task ->
task.multiplatform = project.container(GradlePassConfigurationImpl::class.java)
task.configuration = GradlePassConfigurationImpl()
task.dokkaRuntime = runtimeConfiguration
task.pluginsConfiguration = pluginsConfiguration
- task.outputDirectory = File(project.buildDir, taskName).absolutePath
+ task.outputDirectory = File(project.buildDir, DOKKA_TASK_NAME).absolutePath
+ }
+ }
+
+ private fun addDokkaCollectorTasks(
+ project: Project,
+ taskClass: Class<out DokkaCollectorTask>
+ ) {
+ if (GradleVersion.current() >= GradleVersion.version("4.10")) {
+ project.tasks.register(DOKKA_COLLECTOR_TASK_NAME, taskClass)
+ } else {
+ project.tasks.create(DOKKA_COLLECTOR_TASK_NAME, taskClass)
+ }
+ project.tasks.withType(taskClass) { task ->
+ task.modules = emptyList()
+ task.outputDirectory = File(project.buildDir, DOKKA_TASK_NAME).absolutePath
}
}
}
diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
index c84b97f4..cfe278ce 100644
--- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
+++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
@@ -29,6 +29,7 @@ import org.eclipse.aether.transport.file.FileTransporterFactory
import org.eclipse.aether.transport.http.HttpTransporterFactory
import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator
import org.jetbrains.dokka.*
+import org.jetbrains.dokka.utilities.DokkaConsoleLogger
import java.io.File
import java.net.URL
@@ -219,18 +220,22 @@ abstract class AbstractDokkaMojo : AbstractMojo() {
includeRootPackage = includeRootPackage
)
+ val logger = MavenDokkaLogger(log)
+
val configuration = DokkaConfigurationImpl(
outputDir = getOutDir(),
format = getOutFormat(),
impliedPlatforms = impliedPlatforms,
cacheRoot = cacheRoot,
- passesConfigurations = listOf(passConfiguration),
+ passesConfigurations = listOf(passConfiguration).also {
+ if(passConfiguration.moduleName.isEmpty()) logger.warn("Not specified module name. It can result in unexpected behaviour while including documentation for module")
+ },
generateIndexPages = generateIndexPages,
pluginsClasspath = getArtifactByAether("org.jetbrains.dokka", "dokka-base", dokkaVersion) +
dokkaPlugins.map { getArtifactByAether(it.groupId, it.artifactId, it.version) }.flatten()
)
- val gen = DokkaGenerator(configuration, MavenDokkaLogger(log))
+ val gen = DokkaGenerator(configuration, logger)
gen.generate()
}