aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicCachingIntegrationTest.kt35
-rw-r--r--integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/GradleRelocatedCachingIntegrationTest.kt6
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt17
3 files changed, 50 insertions, 8 deletions
diff --git a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicCachingIntegrationTest.kt b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicCachingIntegrationTest.kt
index f47f7e2a..ada6c26c 100644
--- a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicCachingIntegrationTest.kt
+++ b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicCachingIntegrationTest.kt
@@ -20,8 +20,39 @@ class BasicCachingIntegrationTest(override val versions: BuildVersions) : Abstra
@Test
fun execute() {
+ runAndAssertOutcomeAndContents(TaskOutcome.SUCCESS)
+ runAndAssertOutcomeAndContents(TaskOutcome.FROM_CACHE)
+ }
+
+ @Test
+ fun localDirectoryPointingToRoot() {
+ fun String.findAndReplace(oldValue: String, newValue: String): String {
+ assertTrue(oldValue in this, "Expected to replace '$oldValue'")
+ return replace(oldValue, newValue)
+ }
+ val projectKts = projectDir.resolve("build.gradle.kts")
+
+ projectKts.readText()
+ .findAndReplace("localDirectory.set(file(\"src/main\"))", "localDirectory.set(projectDir)")
+ .findAndReplace("integration-tests/gradle/projects/it-basic/src/main", "integration-tests/gradle/projects/it-basic")
+ .also { projectKts.writeText(it) }
+
+ runAndAssertOutcomeAndContents(TaskOutcome.SUCCESS)
+ projectDir.resolve("unrelated.txt").writeText("modified")
+ // despite projectDir is used as an input in localDirectory, changing its contents shouldn't invalidate the cache
+ runAndAssertOutcomeAndContents(TaskOutcome.FROM_CACHE)
+
+ projectKts.readText()
+ .findAndReplace("localDirectory.set(projectDir)", "localDirectory.set(file(\"src\"))")
+ .also { projectKts.writeText(it) }
+ // changing localDirectory path invalidates cached task results
runAndAssertOutcome(TaskOutcome.SUCCESS)
- runAndAssertOutcome(TaskOutcome.FROM_CACHE)
+ }
+
+
+ private fun runAndAssertOutcomeAndContents(expectedOutcome: TaskOutcome) {
+ runAndAssertOutcome(expectedOutcome)
+ File(projectDir, "build/dokka/html").assertHtmlOutputDir()
}
private fun runAndAssertOutcome(expectedOutcome: TaskOutcome) {
@@ -35,7 +66,5 @@ class BasicCachingIntegrationTest(override val versions: BuildVersions) : Abstra
).buildRelaxed()
assertEquals(expectedOutcome, assertNotNull(result.task(":dokkaHtml")).outcome)
-
- File(projectDir, "build/dokka/html").assertHtmlOutputDir()
}
}
diff --git a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/GradleRelocatedCachingIntegrationTest.kt b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/GradleRelocatedCachingIntegrationTest.kt
index 28b8d22c..2ac129af 100644
--- a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/GradleRelocatedCachingIntegrationTest.kt
+++ b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/GradleRelocatedCachingIntegrationTest.kt
@@ -21,11 +21,11 @@ class GradleRelocatedCachingIntegrationTest(override val versions: BuildVersions
@Test
fun execute() {
- runAndAssertOutcome(projectFolder(1), TaskOutcome.SUCCESS)
- runAndAssertOutcome(projectFolder(2), TaskOutcome.FROM_CACHE)
+ runAndAssertOutcomeAndContents(projectFolder(1), TaskOutcome.SUCCESS)
+ runAndAssertOutcomeAndContents(projectFolder(2), TaskOutcome.FROM_CACHE)
}
- private fun runAndAssertOutcome(project: File, expectedOutcome: TaskOutcome) {
+ private fun runAndAssertOutcomeAndContents(project: File, expectedOutcome: TaskOutcome) {
val result = createGradleRunner("clean", "dokkaHtml", "-i", "-s", "-Dorg.gradle.caching.debug=true", "--build-cache")
.withProjectDir(project)
.buildRelaxed()
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt
index 4a0c1333..b307796d 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt
@@ -2,6 +2,7 @@ package org.jetbrains.dokka.gradle
import org.gradle.api.Project
import org.gradle.api.provider.Property
+import org.gradle.api.provider.Provider
import org.gradle.api.tasks.*
import org.jetbrains.dokka.DokkaConfigurationBuilder
import org.jetbrains.dokka.SourceLinkDefinitionImpl
@@ -30,15 +31,27 @@ class GradleSourceLinkBuilder(
/**
* Path to the local source directory. The path must be relative to the root of current project.
*
+ * This path is used to find relative paths of the source files from which the documentation is built.
+ * These relative paths are then combined with the base url of a source code hosting service specified with
+ * the [remoteUrl] property to create source links for each declaration.
+ *
* Example:
*
* ```kotlin
* projectDir.resolve("src")
* ```
*/
- @InputDirectory
- @PathSensitive(PathSensitivity.RELATIVE)
+ @Internal // changing contents of the directory should not invalidate the task
val localDirectory: Property<File?> = project.objects.safeProperty()
+
+ /**
+ * The relative path to [localDirectory] from the project directory. Declared as an input to invalidate the task if that path changes.
+ * Should not be used anywhere directly.
+ */
+ @Suppress("unused")
+ @get:Input
+ internal val localDirectoryPath: Provider<String?> =
+ localDirectory.map { it.relativeToOrSelf(project.projectDir).invariantSeparatorsPath }
/**
* URL of source code hosting service that can be accessed by documentation readers,