aboutsummaryrefslogtreecommitdiff
path: root/runners/gradle-plugin
diff options
context:
space:
mode:
Diffstat (limited to 'runners/gradle-plugin')
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayout.kt18
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt24
2 files changed, 39 insertions, 3 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayout.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayout.kt
index bb48ba2a..e3b82e7c 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayout.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayout.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.gradle
+import org.jetbrains.dokka.DokkaException
import java.io.File
/**
@@ -59,14 +60,25 @@ internal fun DokkaMultiModuleTask.copyChildOutputDirectory(child: AbstractDokkaT
val targetChildOutputDirectory = project.file(fileLayout.targetChildOutputDirectory(this, child))
val sourceChildOutputDirectory = child.outputDirectory.getSafe()
- if (!sourceChildOutputDirectory.exists()) {
+ /* Pointing to the same directory -> No copy necessary */
+ if (sourceChildOutputDirectory.absoluteFile == targetChildOutputDirectory.absoluteFile) {
return
}
- if (sourceChildOutputDirectory.absoluteFile == targetChildOutputDirectory.absoluteFile) {
+ /* Cannot target *inside* the original folder */
+ if (targetChildOutputDirectory.absoluteFile.startsWith(sourceChildOutputDirectory.absoluteFile)) {
+ throw DokkaException(
+ "Cannot re-locate output directory into itself.\n" +
+ "sourceChildOutputDirectory=${sourceChildOutputDirectory.path}\n" +
+ "targetChildOutputDirectory=${targetChildOutputDirectory.path}"
+ )
+ }
+
+ /* Source output directory is empty -> No copy necessary */
+ if (!sourceChildOutputDirectory.exists()) {
return
}
- sourceChildOutputDirectory.copyRecursively(targetChildOutputDirectory, overwrite = false)
+ sourceChildOutputDirectory.copyRecursively(targetChildOutputDirectory, overwrite = true)
}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt
index 951e292f..6ec3dd57 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt
@@ -2,11 +2,13 @@ package org.jetbrains.dokka.gradle
import org.gradle.kotlin.dsl.create
import org.gradle.testfixtures.ProjectBuilder
+import org.jetbrains.dokka.DokkaException
import org.jetbrains.dokka.gradle.DokkaMultiModuleFileLayout.CompactInParent
import org.jetbrains.dokka.gradle.DokkaMultiModuleFileLayout.NoCopy
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
class DokkaMultiModuleFileLayoutTest {
@@ -97,4 +99,26 @@ class DokkaMultiModuleFileLayoutTest {
"Expected content to be written into 'other.file'"
)
}
+
+ @Test
+ fun `copyChildOutputDirectory target output directory within itself throws DokkaException`() {
+ val project = ProjectBuilder.builder().build()
+ val childTask = project.tasks.create<DokkaTask>("child")
+ val parentTask = project.tasks.create<DokkaMultiModuleTask>("parent")
+ parentTask.fileLayout = object : DokkaMultiModuleFileLayout {
+ override fun targetChildOutputDirectory(parent: DokkaMultiModuleTask, child: AbstractDokkaTask): File {
+ return child.outputDirectory.getSafe().resolve("subfolder")
+ }
+ }
+ assertFailsWith<DokkaException> { parentTask.copyChildOutputDirectory(childTask) }
+ }
+
+ @Test
+ fun `copyChildOutputDirectory NoCopy`() {
+ val project = ProjectBuilder.builder().build()
+ val childTask = project.tasks.create<DokkaTask>("child")
+ val parentTask = project.tasks.create<DokkaMultiModuleTask>("parent")
+ parentTask.fileLayout = NoCopy
+ parentTask.copyChildOutputDirectory(childTask)
+ }
}