aboutsummaryrefslogtreecommitdiff
path: root/runners/gradle-plugin/src
diff options
context:
space:
mode:
Diffstat (limited to 'runners/gradle-plugin/src')
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt7
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt5
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt9
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt7
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/sourceSetKotlinGistConfiguration.kt2
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AndroidAutoConfigurationTest.kt79
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/CheckSourceSetDependenciesTest.kt67
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt44
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt27
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/IsMainSourceSetTest.kt15
10 files changed, 247 insertions, 15 deletions
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 08ed7d70..e63863b3 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
@@ -22,18 +22,17 @@ open class DokkaTask : AbstractDokkaTask(DokkaBootstrapImpl::class) {
}
}
- // TODO NOW: Test
/**
* 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 documentedDokkaSourceSets: List<GradleDokkaSourceSetBuilder>
+ protected val unsuppressedSourceSets: List<GradleDokkaSourceSetBuilder>
get() = dokkaSourceSets
.toList()
.also(::checkSourceSetDependencies)
- .filter { it.isDocumented.getSafe() }
+ .filterNot { it.suppress.getSafe() }
override fun buildDokkaConfiguration(): DokkaConfigurationImpl {
return DokkaConfigurationImpl(
@@ -41,7 +40,7 @@ open class DokkaTask : AbstractDokkaTask(DokkaBootstrapImpl::class) {
cacheRoot = cacheRoot.getSafe(),
offlineMode = offlineMode.getSafe(),
failOnWarning = failOnWarning.getSafe(),
- sourceSets = documentedDokkaSourceSets.build(),
+ sourceSets = unsuppressedSourceSets.build(),
pluginsConfiguration = pluginsConfiguration.getSafe(),
pluginsClasspath = plugins.resolve().toList()
)
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 b0686011..3b26e1e9 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
@@ -33,9 +33,8 @@ open class GradleDokkaSourceSetBuilder constructor(
val sourceSetID: DokkaSourceSetID = DokkaSourceSetID(project, name)
@Input
- @get:JvmName("getIsDocumented")
- val isDocumented: Property<Boolean> = project.objects.safeProperty<Boolean>()
- .safeConvention(true)
+ val suppress: Property<Boolean> = project.objects.safeProperty<Boolean>()
+ .safeConvention(false)
@Classpath
@Optional
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt
index 8d2f70fd..989ad10a 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/checkDependentSourceSets.kt
@@ -2,7 +2,6 @@ package org.jetbrains.dokka.gradle
import org.jetbrains.dokka.DokkaSourceSetID
-// TODO NOW: Test
internal fun checkSourceSetDependencies(sourceSets: List<GradleDokkaSourceSetBuilder>) {
checkSourceSetDependencies(sourceSets.associateBy { it.sourceSetID })
}
@@ -11,13 +10,13 @@ private fun checkSourceSetDependencies(sourceSets: Map<DokkaSourceSetID, GradleD
sourceSets.values.forEach { sourceSet ->
sourceSet.dependentSourceSets.getSafe().forEach { dependentSourceSetID ->
val dependentSourceSet = requireNotNull(sourceSets[dependentSourceSetID]) {
- "Dokka source set ${sourceSet.name}: Cannot find dependent source set $dependentSourceSetID"
+ "Dokka source set \"${sourceSet.name}\": Cannot find dependent source set \"$dependentSourceSetID\""
}
- if (sourceSet.isDocumented.getSafe() && dependentSourceSet.isDocumented.getSafe().not()) {
+ if (sourceSet.suppress.getSafe().not() && dependentSourceSet.suppress.getSafe()) {
throw IllegalArgumentException(
- "Dokka source set: ${sourceSet.name}: " +
- "Documented source set cannot depend on undocumented source set $dependentSourceSetID"
+ "Dokka source set: \"${sourceSet.name}\": " +
+ "Unsuppressed source set cannot depend on suppressed source set \"$dependentSourceSetID\""
)
}
}
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt
index 2c1eba5b..15989217 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt
@@ -7,7 +7,12 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
internal fun Project.isMainSourceSet(sourceSet: KotlinSourceSet): Boolean {
- return allCompilationsOf(sourceSet).any { compilation -> isMainCompilation(compilation) }
+ return isMainSourceSet(allCompilationsOf(sourceSet))
+}
+
+internal fun isMainSourceSet(compilations: List<KotlinCompilation>): Boolean {
+ if (compilations.isEmpty()) return true
+ return compilations.any { compilation -> isMainCompilation(compilation) }
}
private fun isMainCompilation(compilation: KotlinCompilation): Boolean {
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 fee86094..a7231f04 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
@@ -14,7 +14,7 @@ internal fun GradleDokkaSourceSetBuilder.configureWithKotlinSourceSetGist(source
sourceSetNames.map { sourceSetName -> DokkaSourceSetID(sourceSetName) }
}
- this.isDocumented by sourceSet.isMain
+ this.suppress by sourceSet.isMain.map { !it }
this.sourceRoots.from(sourceSet.sourceRoots)
this.classpath.from(sourceSet.classpath)
this.platform by sourceSet.platform.map { Platform.fromString(it.name) }
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AndroidAutoConfigurationTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AndroidAutoConfigurationTest.kt
new file mode 100644
index 00000000..76215762
--- /dev/null
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AndroidAutoConfigurationTest.kt
@@ -0,0 +1,79 @@
+package org.jetbrains.dokka.gradle
+
+import com.android.build.gradle.LibraryExtension
+import org.gradle.api.artifacts.ResolveException
+import org.gradle.api.internal.project.ProjectInternal
+import org.gradle.kotlin.dsl.configure
+import org.gradle.kotlin.dsl.withType
+import org.gradle.testfixtures.ProjectBuilder
+import kotlin.test.*
+
+class AndroidAutoConfigurationTest {
+
+ private val project = ProjectBuilder.builder().build().also { project ->
+ project.plugins.apply("com.android.library")
+ project.plugins.apply("org.jetbrains.kotlin.android")
+ project.plugins.apply("org.jetbrains.dokka")
+ project.extensions.configure<LibraryExtension> {
+ compileSdkVersion(28)
+ }
+ }
+
+ @Test
+ fun `at least one dokka task created`() {
+ val dokkaTasks = project.tasks.withType<DokkaTask>().toList()
+ assertTrue(dokkaTasks.isNotEmpty(), "Expected at least one dokka task")
+ }
+
+ @Test
+ fun `all default source sets are present in dokka`() {
+ val dokkaTasks = project.tasks.withType<DokkaTask>().toList()
+ dokkaTasks.forEach { task ->
+ val sourceSets = task.dokkaSourceSets.toList()
+ assertEquals(
+ listOf(
+ "androidTest", "androidTestDebug", "debug", "main",
+ "release", "test", "testDebug", "testRelease"
+ ).sorted(),
+ sourceSets.map { it.name }.sorted(),
+ "Expected all default source sets being registered"
+ )
+ }
+ }
+
+ @Test
+ fun `test source sets are suppressed`() {
+ val dokkaTasks = project.tasks.withType<DokkaTask>().toList()
+ project as ProjectInternal
+ project.evaluate()
+ dokkaTasks.flatMap { it.dokkaSourceSets }.forEach { sourceSet ->
+ if ("test" in sourceSet.name.toLowerCase()) {
+ assertTrue(
+ sourceSet.suppress.getSafe(),
+ "Expected source set `${sourceSet.name}` to be suppressed by default"
+ )
+ } else {
+ assertFalse(
+ sourceSet.suppress.getSafe(),
+ "Expected source set `${sourceSet.name}`to not be suppressed by default"
+ )
+ }
+ }
+ }
+
+ @Test
+ fun `source sets have non-empty classpath`() {
+ val dokkaTasks = project.tasks.withType<DokkaTask>().toList()
+ project as ProjectInternal
+ project.evaluate()
+
+ dokkaTasks.flatMap { it.dokkaSourceSets }.forEach { sourceSet ->
+ /*
+ There is no better way of checking for empty classpath at the moment (without resolving dependencies).
+ We assume, that an empty classpath can be resolved
+ We assume, that a non-empty classpath will not be able to resolve (no repositories defined)
+ */
+ assertFailsWith<ResolveException> { sourceSet.classpath.files }
+ }
+ }
+}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/CheckSourceSetDependenciesTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/CheckSourceSetDependenciesTest.kt
new file mode 100644
index 00000000..cc0efea4
--- /dev/null
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/CheckSourceSetDependenciesTest.kt
@@ -0,0 +1,67 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.testfixtures.ProjectBuilder
+import java.lang.IllegalArgumentException
+import kotlin.test.Test
+import kotlin.test.assertFailsWith
+import kotlin.test.assertTrue
+
+class CheckSourceSetDependenciesTest {
+
+ private val project = ProjectBuilder.builder().build()
+
+ @Test
+ fun `passes when properly configured`() {
+ val sourceSets = listOf(
+ GradleDokkaSourceSetBuilder("common", project),
+ GradleDokkaSourceSetBuilder("jvmAndJsCommon", project).apply {
+ dependsOn("common")
+ },
+ GradleDokkaSourceSetBuilder("jvm", project).apply {
+ dependsOn("jvmAndJsCommon")
+ },
+ GradleDokkaSourceSetBuilder("js", project).apply {
+ dependsOn("jvmAndJsCommon")
+ }
+ )
+ checkSourceSetDependencies(sourceSets)
+ }
+
+ @Test
+ fun `throws exception when dependent source set id cant be found`() {
+ val sourceSets = listOf(
+ GradleDokkaSourceSetBuilder("main", project),
+ GradleDokkaSourceSetBuilder("bad", project).apply {
+ dependsOn("missing")
+ }
+ )
+
+ val exception = assertFailsWith<IllegalArgumentException> {
+ checkSourceSetDependencies(sourceSets)
+ }
+
+ assertTrue("bad" in exception.message.orEmpty(), "Expected name of source set mentioned")
+ assertTrue("missing" in exception.message.orEmpty(), "Expected name of missing source set mentioned")
+ }
+
+ @Test
+ fun `throws exception when documented source set depends on suppressed source set`() {
+ val sourceSets = listOf(
+ GradleDokkaSourceSetBuilder("common", project),
+ GradleDokkaSourceSetBuilder("intermediate", project).apply {
+ dependsOn("common")
+ suppress by true
+ },
+ GradleDokkaSourceSetBuilder("jvm", project).apply {
+ dependsOn("intermediate")
+ }
+ )
+
+ val exception = assertFailsWith<IllegalArgumentException> {
+ checkSourceSetDependencies(sourceSets)
+ }
+
+ assertTrue("intermediate" in exception.message.orEmpty())
+ assertTrue("jvm" in exception.message.orEmpty())
+ }
+}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt
index c4525f72..efe03c56 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt
@@ -1,7 +1,9 @@
package org.jetbrains.dokka.gradle
import org.gradle.api.artifacts.FileCollectionDependency
+import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.kotlin.dsl.get
+import org.gradle.kotlin.dsl.property
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.gradle.kotlin.KotlinSourceSetGist
@@ -27,7 +29,6 @@ class ConfigureWithKotlinSourceSetGistTest {
name = "customName",
platform = project.provider { KotlinPlatformType.common },
isMain = project.provider { true },
- // TODO NOW: Test if it changes
classpath = project.provider { project.files(f1Jar, f2Jar) },
sourceRoots = project.files(customSourceRoot),
dependentSourceSetNames = project.provider { setOf("customRootSourceSet") }
@@ -121,4 +122,45 @@ class ConfigureWithKotlinSourceSetGistTest {
"Expected customRoot being added to source roots in dokkaSourceSet"
)
}
+
+ @Test
+ fun `changing classpath`() {
+ val project = ProjectBuilder.builder().build()
+ val dokkaSourceSet = GradleDokkaSourceSetBuilder("main", project)
+ var classpath = project.files()
+
+ dokkaSourceSet.configureWithKotlinSourceSetGist(
+ KotlinSourceSetGist(
+ name = "gist",
+ platform = project.provider { KotlinPlatformType.common },
+ isMain = project.provider { true },
+ dependentSourceSetNames = project.provider { emptySet() },
+ sourceRoots = project.files(),
+ classpath = project.provider { classpath }
+ )
+ )
+
+ dokkaSourceSet.classpath.from("base.jar")
+ classpath.from("f1.jar")
+ classpath.from("f2.jar")
+ assertEquals(
+ setOf(project.file("f1.jar"), project.file("f2.jar"), project.file("base.jar")),
+ dokkaSourceSet.classpath.files,
+ "Expected files from initial gist classpath and manually added file base.jar to be present in classpath"
+ )
+
+ /*
+ Swapping the original file collection in favour of a new one.
+ We expect that the base.jar is still present, as it was configured on the dokka source set.
+ We also expect, that the new files from the new file collection are replacing old ones
+ */
+ classpath = project.files("f3.jar", "f4.jar")
+ assertEquals(
+ setOf(project.file("f3.jar"), project.file("f4.jar"), project.file("base.jar")),
+ dokkaSourceSet.classpath.files,
+ "Expected files from changed gist classpath and manually added file base.jar to be present in classpath"
+ )
+ }
+
+
}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt
new file mode 100644
index 00000000..139ebd3a
--- /dev/null
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt
@@ -0,0 +1,27 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.kotlin.dsl.create
+import org.gradle.testfixtures.ProjectBuilder
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class DokkaTaskTest {
+ @Test
+ fun `no suppressed source sets are present after in built configuration`() {
+ val project = ProjectBuilder.builder().build()
+ val task = project.tasks.create<DokkaTask>("dokkaTask")
+ project.configurations.all { configuration -> configuration.withDependencies { it.clear() } }
+
+ task.dokkaSourceSets.register("main")
+ task.dokkaSourceSets.register("jvm")
+ task.dokkaSourceSets.register("test") {
+ it.suppress by true
+ }
+
+ assertEquals(
+ listOf("main", "jvm").sorted(),
+ task.buildDokkaConfiguration().sourceSets.map { it.sourceSetID.sourceSetName }.sorted(),
+ "Expected only unsuppressed source sets `main` and `test` to be present in built configuration"
+ )
+ }
+}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/IsMainSourceSetTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/IsMainSourceSetTest.kt
new file mode 100644
index 00000000..c354c62f
--- /dev/null
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/IsMainSourceSetTest.kt
@@ -0,0 +1,15 @@
+package org.jetbrains.dokka.gradle
+
+import org.jetbrains.dokka.gradle.kotlin.isMainSourceSet
+import kotlin.test.Test
+import kotlin.test.assertTrue
+
+class IsMainSourceSetTest {
+ @Test
+ fun `missing compilations will return true`() {
+ assertTrue(
+ isMainSourceSet(emptyList()),
+ "Expected 'isMainSourceSet' to return 'true' when no compilations are found"
+ )
+ }
+}