JetBrains / intellij-platform-gradle-plugin

Gradle plugin for building plugins for IntelliJ-based IDEs
https://plugins.jetbrains.com/docs/intellij/gradle-prerequisites.html
Apache License 2.0
1.42k stars 270 forks source link

`sandboxSuffix` is empty string when copying files inside the `prepareSandbox {}` task #1735

Open mkurnikov opened 1 month ago

mkurnikov commented 1 month ago

What happened?

sandboxSuffix is an empty string in the prepareSandbox { } body, independent of the actual task name at the time of execution.

Relevant log output or stack trace

No response

Steps to reproduce

I'm trying to copy binary files into the plugin zip archive to bundle them together. Migration of my old code to the new version of the Gradle Plugin yields this

        prepareSandbox {
            dependsOn("downloadAptosBinaries")
            from("$rootDir/bin") {
                into(sandboxPluginsDirectory.dir("$pluginName/bin").get())
                include("**")
            }
        }

In the new version, configuration of the runIde is performed with the custom task

    val runIdeWithPlugins by intellijPlatformTesting.runIde.registering {
        plugins {
            plugin("com.google.ide-perf:1.3.1")
        }
    }

When called, that runIdeWithPlugins task generates and calls the prepareSandbox_runIdeWithPlugins task, and that _runIdeWithPlugins suffix is supposed to be stored in the sandboxSuffix variable.

But at the point of my from { into {} } call in the prepareSandbox, the sandboxSuffix variable is always an empty string.

Gradle IntelliJ Plugin version

2.0.1

Gradle version

8.9

Operating System

Linux

Link to build, i.e. failing GitHub Action job

No response

hsz commented 1 month ago

It is possible to achieve it with:

val runIdeWithPlugins by intellijPlatformTesting.runIde.registering {
    plugins {
        plugin("com.google.ide-perf:1.3.1")
    }

    prepareSandboxTask {
        dependsOn("downloadAptosBinaries")
        from("${rootDir}/cert") {
            into(intellijPlatform.projectName.map { "$it/bin" })
            include("**")
        }
    }
}

To make it more transparent, I've introduced the projectName property (https://github.com/JetBrains/intellij-platform-gradle-plugin/commit/39161c028cd3612ad6e838fe111281b8281163a9), so with the next release, you'll be able to:

val runIdeWithPlugins by intellijPlatformTesting.runIde.registering {
    // ...

    prepareSandboxTask {
        // ...

        from("${rootDir}/cert") {
            into(pluginName.map { "$it/bin" })
        }
    }
}
mkurnikov commented 4 weeks ago

I tried to specify prepareSandboxTask {} configuration inside the runIdeWithPlugins task, and this indeed works, there's no need for the intellijPlatform.projectName (sandboxSuffix has the expected value of _runIdeWithPlugins, and the pluginName exists in my environment anyway). I'm going to extract the common copying code into the function and call it twice from inside the runIdeWithPlugins and from the general prepareSandboxTask checking for the existence of the directory.

I want to clarify that my problem is not fixed with the intellijPlatform.projectName. I need to patch prepareSandboxTask both for buildPlugin and for runIde, so in general case patching it inside the custom task does not work.

My understanding is that there's some special case code inside the gradle plugin, that creates the prepareSandboxTask_runIdeWithPlugins custom task specifically for my runIdeWithPlugins custom task, and it executes the body of the

    prepareSandboxTask {
        from("${rootDir}/cert") {
            into(intellijPlatform.projectName.map { "$it/bin" })
            include("**")
        }
    }

(which is defined outside the custom task as it's shared for the deployment and for testing). And the bug report is that sandboxSuffix (or sandboxPluginsDirectory for that matter) is not populated correctly at the time of execution of the body of that prepareSandboxTask_runIdeWithPlugins.

UPD. Ok, I think I just might be doing it incorrectly. It seems I can't really patch generated prepareSandboxTask_runIdeWithPlugins with the root level

tasks {
    prepareSandboxTask {

    }
}

at all, it's never called. So to provide binaries both to the buildPlugin and to runIde I need to use two blocks of prepareSandboxTask. Is that right?