diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-06-22 13:15:39 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-06-29 14:01:56 +0200 |
commit | 862a23e3561942417a50e15a09a233f364a4a204 (patch) | |
tree | 72b38e96264ca30c2d5d69ba8a243c535ea7fa37 /runners/gradle-plugin/src/main/kotlin | |
parent | cae0ab0b5c9358f4b7d42209d59fad337c01d9be (diff) | |
download | dokka-862a23e3561942417a50e15a09a233f364a4a204.tar.gz dokka-862a23e3561942417a50e15a09a233f364a4a204.tar.bz2 dokka-862a23e3561942417a50e15a09a233f364a4a204.zip |
DokkaTask: Replace exitProcess with exception and helpful message if no source sets are configured
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin')
-rw-r--r-- | runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt | 5 | ||||
-rw-r--r-- | runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 45 |
2 files changed, 33 insertions, 17 deletions
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 index 8483cd60..ead0f90a 100644 --- 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 @@ -5,7 +5,6 @@ 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() { @@ -26,7 +25,7 @@ open class DokkaCollectorTask : DefaultTask() { } catch (e: UnknownTaskException) { throw IllegalStateException("No dokka task declared in module ${it.name}") } - tasks.map { it.getConfiguration() } + tasks.map { it.getConfigurationOrNull() } }.filterNotNull() val initial = GradleDokkaConfigurationImpl().apply { @@ -52,4 +51,4 @@ open class DokkaCollectorTask : DefaultTask() { 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 b6d71952..e27357c9 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 @@ -10,6 +10,7 @@ import org.gradle.api.tasks.* import org.jetbrains.dokka.DokkaBootstrap import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder import org.jetbrains.dokka.DokkaConfiguration.SourceRoot +import org.jetbrains.dokka.DokkaException import org.jetbrains.dokka.Platform import org.jetbrains.dokka.ReflectDsl import org.jetbrains.dokka.ReflectDsl.isNotInstance @@ -19,7 +20,6 @@ import java.io.File import java.net.URLClassLoader import java.util.concurrent.Callable import java.util.function.BiConsumer -import kotlin.system.exitProcess open class DokkaTask : DefaultTask(), Configurable { private val ANDROID_REFERENCE_URL = Builder("https://developer.android.com/reference/").build() @@ -143,7 +143,7 @@ open class DokkaTask : DefaultTask(), Configurable { } @TaskAction - fun generate() = config?.let { generate(it) } ?: getConfiguration()?.let { generate(it) } ?: exitProcess(0) + fun generate() = config?.let { generate(it) } ?: generate(getConfigurationOrThrow()) protected open fun generate(configuration: GradleDokkaConfigurationImpl) { outputDiagnosticInfo = true @@ -178,19 +178,18 @@ open class DokkaTask : DefaultTask(), Configurable { } } - internal open fun getConfiguration(): GradleDokkaConfigurationImpl? { + internal fun getConfigurationOrNull(): GradleDokkaConfigurationImpl? { val globalConfig = dokkaSourceSets.toList().find { it.name.toLowerCase() == GLOBAL_CONFIGURATION_NAME } - val defaultModulesConfiguration = passConfigurations - .map { defaultPassConfiguration(it, globalConfig) }.takeIf { it.isNotEmpty() } + val defaultModulesConfiguration = configuredDokkaSourceSets + .map { configureDefault(it, globalConfig) }.takeIf { it.isNotEmpty() } ?: listOf( - defaultPassConfiguration( - collectSinglePassConfiguration(GradleDokkaSourceSet("main")), + configureDefault( + configureDokkaSourceSet(GradleDokkaSourceSet("main")), null ) ).takeIf { project.isNotMultiplatformProject() } ?: emptyList() if (defaultModulesConfiguration.isEmpty()) { - logger.error("No source sets to document found, exiting") return null } @@ -206,13 +205,31 @@ open class DokkaTask : DefaultTask(), Configurable { } } + internal fun getConfigurationOrThrow(): GradleDokkaConfigurationImpl { + return getConfigurationOrNull() ?: throw DokkaException( + """ + No source sets to document found. + Make source to configure at least one source set e.g. + + dokka { + dokkaSourceSets { + create("commonMain") { + displayName = "common" + platform = "common" + } + } + } + """ + ) + } + - protected val passConfigurations: List<GradleDokkaSourceSet> + protected val configuredDokkaSourceSets: List<GradleDokkaSourceSet> get() = dokkaSourceSets .filterNot { it.name.toLowerCase() == GLOBAL_CONFIGURATION_NAME } - .map { collectSinglePassConfiguration(it) } + .map { configureDokkaSourceSet(it) } - protected fun collectSinglePassConfiguration(config: GradleDokkaSourceSet): GradleDokkaSourceSet { + protected fun configureDokkaSourceSet(config: GradleDokkaSourceSet): GradleDokkaSourceSet { val userConfig = config .apply { collectKotlinTasks?.let { @@ -280,7 +297,7 @@ open class DokkaTask : DefaultTask(), Configurable { platform = autoConfig.platform } - protected fun defaultPassConfiguration( + protected fun configureDefault( config: GradleDokkaSourceSet, globalConfig: GradleDokkaSourceSet? ): GradleDokkaSourceSet { @@ -328,7 +345,7 @@ open class DokkaTask : DefaultTask(), Configurable { // Needed for Gradle incremental build @InputFiles - fun getInputFiles(): FileCollection = passConfigurations.let { config -> + fun getInputFiles(): FileCollection = configuredDokkaSourceSets.let { config -> project.files(config.flatMap { it.sourceRoots }.map { project.fileTree(File(it.path)) }) + project.files(config.flatMap { it.includes }) + project.files(config.flatMap { it.samples }.map { project.fileTree(File(it)) }) @@ -336,7 +353,7 @@ open class DokkaTask : DefaultTask(), Configurable { @Classpath fun getInputClasspath(): FileCollection = - project.files((passConfigurations.flatMap { it.classpath } as List<Any>).map { project.fileTree(File(it.toString())) }) + project.files((configuredDokkaSourceSets.flatMap { it.classpath } as List<Any>).map { project.fileTree(File(it.toString())) }) companion object { const val COLORS_ENABLED_PROPERTY = "kotlin.colors.enabled" |