diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-07-31 10:27:54 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-14 17:51:11 +0200 |
commit | 23827bed7b4877b15633e1924f7ee3864f8ebe2c (patch) | |
tree | a683a90ae5778c87900e9bbf44be502f4d62cea3 /runners/gradle-plugin/src/main/kotlin/org | |
parent | cba413d6102173bfb4f9e1a222941388fafcac62 (diff) | |
download | dokka-23827bed7b4877b15633e1924f7ee3864f8ebe2c.tar.gz dokka-23827bed7b4877b15633e1924f7ee3864f8ebe2c.tar.bz2 dokka-23827bed7b4877b15633e1924f7ee3864f8ebe2c.zip |
Cover GradleDokkaSourceSetBuilder with tests
Diffstat (limited to 'runners/gradle-plugin/src/main/kotlin/org')
5 files changed, 29 insertions, 52 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt index 8f0a166b..59c5e9f8 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt @@ -13,20 +13,17 @@ import org.gradle.api.provider.Property import org.gradle.api.provider.SetProperty import org.gradle.api.tasks.* import org.gradle.kotlin.dsl.listProperty -import org.gradle.kotlin.dsl.property import org.gradle.kotlin.dsl.setProperty import org.gradle.util.ConfigureUtil import org.jetbrains.dokka.* import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import java.io.File import java.net.URL -import org.jetbrains.kotlin.gradle.model.SourceSet as KotlinModelSourceSet internal fun Task.GradleDokkaSourceSetBuilderFactory(): (name: String) -> GradleDokkaSourceSetBuilder = { name -> GradleDokkaSourceSetBuilder(name, project) } -// TODO NOW: Cover with tests open class GradleDokkaSourceSetBuilder constructor( @Transient @get:Input val name: String, @Transient @get:Internal internal val project: Project @@ -98,34 +95,31 @@ open class GradleDokkaSourceSetBuilder constructor( @Input @Optional - val languageVersion: Property<String?> = project.objects.safeProperty<String>() + val languageVersion: Property<String?> = project.objects.safeProperty() @Input @Optional val apiVersion: Property<String?> = project.objects.safeProperty() @Input - val noStdlibLink: Property<Boolean> = project.objects.property<Boolean>() - .convention(DokkaDefaults.noStdlibLink) + val noStdlibLink: Property<Boolean> = project.objects.safeProperty<Boolean>() + .safeConvention(DokkaDefaults.noStdlibLink) @Input - val noJdkLink: Property<Boolean> = project.objects.property<Boolean>() - .convention(DokkaDefaults.noJdkLink) + val noJdkLink: Property<Boolean> = project.objects.safeProperty<Boolean>() + .safeConvention(DokkaDefaults.noJdkLink) @Input - val noAndroidSdkLink: Property<Boolean> = project.objects.property<Boolean>() - .convention(false) + val noAndroidSdkLink: Property<Boolean> = project.objects.safeProperty<Boolean>() + .safeConvention(false) @InputFiles val suppressedFiles: ConfigurableFileCollection = project.files() @Input @Optional - val analysisPlatform: Property<Platform?> = project.objects.safeProperty() - - @Input - @Optional - val platform: Property<String?> = project.objects.safeProperty() + val platform: Property<Platform> = project.objects.safeProperty<Platform>() + .safeConvention(Platform.DEFAULT) fun DokkaSourceSetID(sourceSetName: String): DokkaSourceSetID { return DokkaSourceSetID(project, sourceSetName) @@ -163,7 +157,7 @@ open class GradleDokkaSourceSetBuilder constructor( sourceRoot(project.file(path)) } - fun sourceLink(c: Closure<Unit>) { + fun sourceLink(c: Closure<in GradleSourceLinkBuilder>) { val configured = ConfigureUtil.configure(c, GradleSourceLinkBuilder(project)) sourceLinks.add(configured) } @@ -174,7 +168,7 @@ open class GradleDokkaSourceSetBuilder constructor( sourceLinks.add(sourceLink) } - fun perPackageOption(c: Closure<Unit>) { + fun perPackageOption(c: Closure<in GradlePackageOptionsBuilder>) { val configured = ConfigureUtil.configure(c, GradlePackageOptionsBuilder(project)) perPackageOptions.add(configured) } @@ -185,7 +179,7 @@ open class GradleDokkaSourceSetBuilder constructor( perPackageOptions.add(option) } - fun externalDocumentationLink(c: Closure<Unit>) { + fun externalDocumentationLink(c: Closure<in GradleExternalDocumentationLinkBuilder>) { val link = ConfigureUtil.configure(c, GradleExternalDocumentationLinkBuilder(project)) externalDocumentationLinks.add(link) } @@ -197,12 +191,7 @@ open class GradleDokkaSourceSetBuilder constructor( } fun externalDocumentationLink(url: String, packageListUrl: String? = null) { - externalDocumentationLinks.add( - GradleExternalDocumentationLinkBuilder(project).apply { - this.url by URL(url) - this.packageListUrl by URL(packageListUrl) - } - ) + externalDocumentationLink(URL(url), packageListUrl = packageListUrl?.let(::URL)) } fun externalDocumentationLink(url: URL, packageListUrl: URL? = null) { @@ -221,9 +210,6 @@ open class GradleDokkaSourceSetBuilder constructor( } } -fun GradleDokkaSourceSetBuilder.dependsOn(sourceSet: KotlinModelSourceSet) { - dependsOn(DokkaSourceSetID(sourceSet.name)) -} fun GradleDokkaSourceSetBuilder.dependsOn(sourceSet: KotlinSourceSet) { dependsOn(DokkaSourceSetID(sourceSet.name)) diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinSourceSetGist.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinSourceSetGist.kt index 86551153..f889b5e8 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinSourceSetGist.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/KotlinSourceSetGist.kt @@ -6,8 +6,6 @@ import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet -// TODO NOW: Test this all - internal data class KotlinSourceSetGist( val name: String, val platform: KotlinPlatformType, @@ -22,7 +20,7 @@ internal fun Project.gistOf(sourceSet: KotlinSourceSet): KotlinSourceSetGist { name = sourceSet.name, platform = platformOf(sourceSet), isMain = isMainSourceSet(sourceSet), - classpath = classpathOf(sourceSet), + classpath = classpathOf(sourceSet).filter { it.exists() }, // TODO: Needs to respect filters. // We probably need to change from "sourceRoots" to support "sourceFiles" // https://github.com/Kotlin/dokka/issues/1215 diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt index 4de499e9..8fec309a 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/kotlinCompilationUtils.kt @@ -20,7 +20,6 @@ internal fun Project.allCompilationsOf( } } -// TODO NOW: Better name, clarify distinction to allCompilationsOf internal fun Project.compilationsOf(sourceSet: KotlinSourceSet): List<KotlinCompilation> { return allCompilationsOf(sourceSet).filter { compilation -> sourceSet in compilation.kotlinSourceSets } } diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt index 409f645f..3162b614 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt @@ -1,15 +1,16 @@ +@file:Suppress("UnstableApiUsage") + package org.jetbrains.dokka.gradle +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.gradle.kotlin.KotlinSourceSetGist import org.jetbrains.dokka.gradle.kotlin.gistOf import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet -// TODO NOW: Test fun GradleDokkaSourceSetBuilder.configureWithKotlinSourceSet(sourceSet: KotlinSourceSet) { configureWithKotlinSourceSetGist(project.gistOf(sourceSet)) } -// TODO NOW: What about language version? internal fun GradleDokkaSourceSetBuilder.configureWithKotlinSourceSetGist(sourceSet: KotlinSourceSetGist) { val dependentSourceSetIds = sourceSet.dependentSourceSetNames.map { sourceSetNames -> sourceSetNames.map { sourceSetName -> DokkaSourceSetID(sourceSetName) } @@ -17,8 +18,11 @@ internal fun GradleDokkaSourceSetBuilder.configureWithKotlinSourceSetGist(source this.sourceRoots.from(sourceSet.sourceRoots) this.classpath.from(sourceSet.classpath) - this.platform by sourceSet.platform.name + this.platform by Platform.fromString(sourceSet.platform.name) this.dependentSourceSets.set(dependentSourceSetIds) + this.displayName by sourceSet.name.substringBeforeLast( + delimiter = "Main", + missingDelimiterValue = sourceSet.platform.name + ) } - diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/toDokkaSourceSetImpl.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/toDokkaSourceSetImpl.kt index 766f7e55..64d44157 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/toDokkaSourceSetImpl.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/toDokkaSourceSetImpl.kt @@ -3,9 +3,7 @@ package org.jetbrains.dokka.gradle import org.jetbrains.dokka.* import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink import java.io.File -import java.net.URL -// TODO NOW: Test internal fun GradleDokkaSourceSetBuilder.toDokkaSourceSetImpl(): DokkaSourceSetImpl { return DokkaSourceSetImpl( classpath = classpath.toSet(), @@ -29,7 +27,7 @@ internal fun GradleDokkaSourceSetBuilder.toDokkaSourceSetImpl(): DokkaSourceSetI noStdlibLink = noStdlibLink.getSafe(), noJdkLink = noJdkLink.getSafe(), suppressedFiles = suppressedFilesWithDefaults(), - analysisPlatform = analysisPlatformOrDefault() + analysisPlatform = platform.getSafe() ) } @@ -38,7 +36,12 @@ private fun GradleDokkaSourceSetBuilder.moduleNameOrDefault(): String { } private fun GradleDokkaSourceSetBuilder.displayNameOrDefault(): String { - return displayName.getSafe() ?: name.substringBeforeLast("Main", platform.getSafe().toString()) + displayName.getSafe()?.let { return it } + if (name.endsWith("Main") && name != "Main") { + return name.removeSuffix("Main") + } + + return name } private fun GradleDokkaSourceSetBuilder.externalDocumentationLinksWithDefaults(): Set<ExternalDocumentationLinkImpl> { @@ -60,19 +63,6 @@ private fun GradleDokkaSourceSetBuilder.externalDocumentationLinksWithDefaults() .toSet() } -private fun GradleDokkaSourceSetBuilder.analysisPlatformOrDefault(): Platform { - val analysisPlatform = analysisPlatform.getSafe() - if (analysisPlatform != null) return analysisPlatform - - platform.getSafe()?.let { platform -> - return when (platform.toLowerCase()) { - "androidjvm", "android" -> Platform.jvm - "metadata" -> Platform.common - else -> Platform.fromString(platform) - } - } - return Platform.DEFAULT -} private fun GradleDokkaSourceSetBuilder.suppressedFilesWithDefaults(): Set<File> { val suppressedFilesForAndroid = if (project.isAndroidProject()) { |