From 7d6012d06abfbd97a83c779538460d5e7c55eb71 Mon Sep 17 00:00:00 2001 From: Jakub Chrzanowski Date: Mon, 10 Jun 2024 13:51:07 +0200 Subject: [PATCH] Customizing the `sandboxDirectory` and `sandboxSuffix` when configuring `SandboxAware` tasks --- CHANGELOG.md | 1 + .../intellij/platform/gradle/tasks/tasks.kt | 7 +-- .../gradle/tasks/PrepareSandboxTaskTest.kt | 56 ++++++++++++++++++- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2aa483e61..60c883c534 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Replace base archive file of the `Jar` task with `ComposedJarTask` archive file in all configuration artifact sets - Redundant whitespace when parsing plugin dependency IDs - Plugin Verifier: introduce partial configuration for resolving IntelliJ Platform dependencies with same coordinates but different versions +- Customizing the `sandboxDirectory` and `sandboxSuffix` when configuring `SandboxAware` tasks ## [2.0.0-beta5] - 2024-05-30 diff --git a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/tasks.kt b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/tasks.kt index 6abe80c459..b819fbd6e8 100644 --- a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/tasks.kt +++ b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/tasks.kt @@ -260,13 +260,12 @@ internal fun Project.preconfigureTask(task: T) { SplitModeTarget.BACKEND -> "" SplitModeTarget.BOTH -> "" } + sandboxSuffix.convention("-$taskSubject".lowercase().trimEnd('-') + suffix) val taskName = "prepare" + taskSubject + splitModeVariant + "Sandbox" + suffix return tasks.maybeCreate(taskName).also { task -> - val taskSubjectSuffix = "-$taskSubject".lowercase().trimEnd('-') + suffix - task.sandboxSuffix.convention(taskSubjectSuffix) - sandboxSuffix.convention(taskSubjectSuffix) - sandboxDirectory.convention(task.sandboxDirectory) + task.sandboxSuffix.convention(sandboxSuffix) + task.sandboxDirectory.set(sandboxDirectory) if (this is CustomIntelliJPlatformVersionAware) { task.disabledPlugins = the().disabled diff --git a/src/test/kotlin/org/jetbrains/intellij/platform/gradle/tasks/PrepareSandboxTaskTest.kt b/src/test/kotlin/org/jetbrains/intellij/platform/gradle/tasks/PrepareSandboxTaskTest.kt index 7bbbacb47f..b56dd42a5d 100644 --- a/src/test/kotlin/org/jetbrains/intellij/platform/gradle/tasks/PrepareSandboxTaskTest.kt +++ b/src/test/kotlin/org/jetbrains/intellij/platform/gradle/tasks/PrepareSandboxTaskTest.kt @@ -6,7 +6,6 @@ import org.jetbrains.intellij.platform.gradle.* import org.jetbrains.intellij.platform.gradle.Constants.Sandbox import org.jetbrains.intellij.platform.gradle.Constants.Tasks import org.jetbrains.intellij.platform.gradle.tasks.aware.SplitModeAware -import java.nio.file.Path import kotlin.io.path.* import kotlin.test.Ignore import kotlin.test.Test @@ -925,4 +924,59 @@ class PrepareSandboxTaskTest : IntelliJPluginTestBase() { collectPaths(sandbox), ) } + + @Test + fun `create sandbox in a custom location`() { + val taskName = "customRunIde" + + buildFile write //language=kotlin + """ + val $taskName by tasks.registering(CustomRunIdeTask::class) { + sandboxDirectory = project.layout.buildDirectory.dir("custom-sandbox") + enabled = false + } + """.trimIndent() + + build(taskName) + + assertExists(buildDirectory.resolve("custom-sandbox/config_$taskName")) + assertExists(buildDirectory.resolve("custom-sandbox/plugins_$taskName")) + assertExists(buildDirectory.resolve("custom-sandbox/log_$taskName")) + assertExists(buildDirectory.resolve("custom-sandbox/system_$taskName")) + } + + @Test + fun `create test sandbox in a custom location`() { + val taskName = "customTest" + + buildFile write //language=kotlin + """ + val $taskName by tasks.registering(CustomTestIdeTask::class) { + sandboxDirectory = project.layout.buildDirectory.dir("custom-sandbox") + } + """.trimIndent() + + build(taskName) + + assertExists(buildDirectory.resolve("custom-sandbox/config-test_$taskName")) + assertExists(buildDirectory.resolve("custom-sandbox/plugins-test_$taskName")) + assertExists(buildDirectory.resolve("custom-sandbox/log-test_$taskName")) + assertExists(buildDirectory.resolve("custom-sandbox/system-test_$taskName")) + + buildFile write //language=kotlin + """ + tasks { + $taskName { + sandboxSuffix = "-foo" + } + } + """.trimIndent() + + build(taskName) + + assertExists(buildDirectory.resolve("custom-sandbox/config-foo")) + assertExists(buildDirectory.resolve("custom-sandbox/plugins-foo")) + assertExists(buildDirectory.resolve("custom-sandbox/log-foo")) + assertExists(buildDirectory.resolve("custom-sandbox/system-foo")) + } }