From aa9fe3556c8aae523614344a464576267e8c892b Mon Sep 17 00:00:00 2001 From: Jakub Chrzanowski Date: Tue, 19 Nov 2024 14:04:49 +0100 Subject: [PATCH] Custom `runIde` task do not find the right runtime, if `useInstaller` is `false`. #1827 --- CHANGELOG.md | 1 + .../IntelliJPlatformDependenciesHelper.kt | 6 +++-- .../IntelliJPlatformTestingExtension.kt | 22 ++++++++++++++++++- .../gradle/tasks/aware/RuntimeAware.kt | 15 +++++++++---- .../intellij/platform/gradle/tasks/tasks.kt | 4 +++- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b01ad5b4b..7f87d082e0 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - Rework how the IDEs from Plugin Verification are resolved. JetBrains/intellij-platform-gradle-plugin#1784 - Exclude `kotlin-stdlib` and `kotlinx-coroutines` transitive dependencies in various variants from IntelliJ Platform dependencies. JetBrains/intellij-platform-gradle-plugin#1817 - Can't find `performanceTesting.jar` when building against Android Studio 242+. JetBrains/intellij-platform-gradle-plugin#1738 +- Custom `runIde` task do not find the right runtime, if `useInstaller` is `false`. JetBrains/intellij-platform-gradle-plugin#1827 ## [2.1.0] diff --git a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesHelper.kt b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesHelper.kt index 9214a77a8d..da183669b7 100644 --- a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesHelper.kt +++ b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesHelper.kt @@ -1040,10 +1040,12 @@ class IntelliJPlatformDependenciesHelper( /** * Creates a [Provider] that holds a JetBrains Runtime version obtained using the currently used IntelliJ Platform. + * + * @param platformPathProvider The path to the IntelliJ Platform to be used for resolving JetBrains Runtime version. */ - internal fun obtainJetBrainsRuntimeVersion() = cachedProvider { + internal fun obtainJetBrainsRuntimeVersion(platformPathProvider: Provider = platformPath) = cachedProvider { val dependencies = runCatching { - platformPath.get().resolve("dependencies.txt").takeIf { it.exists() } + platformPathProvider.get().resolve("dependencies.txt").takeIf { it.exists() } }.getOrNull() ?: return@cachedProvider null val version = FileReader(dependencies.toFile()).use { reader -> diff --git a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformTestingExtension.kt b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformTestingExtension.kt index d3d7e904de..19345ca6d5 100644 --- a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformTestingExtension.kt +++ b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformTestingExtension.kt @@ -19,10 +19,12 @@ import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType import org.jetbrains.intellij.platform.gradle.plugins.configureExtension import org.jetbrains.intellij.platform.gradle.tasks.* import org.jetbrains.intellij.platform.gradle.tasks.aware.IntelliJPlatformVersionAware +import org.jetbrains.intellij.platform.gradle.tasks.aware.RuntimeAware import org.jetbrains.intellij.platform.gradle.tasks.aware.SandboxAware import org.jetbrains.intellij.platform.gradle.tasks.aware.SplitModeAware.SplitModeTarget import org.jetbrains.intellij.platform.gradle.utils.create import org.jetbrains.intellij.platform.gradle.utils.isModule +import org.jetbrains.intellij.platform.gradle.utils.platformPath import javax.inject.Inject @IntelliJPlatform @@ -36,7 +38,7 @@ abstract class IntelliJPlatformTestingExtension @Inject constructor( val testIdeUi = register() val testIdePerformance = register() - private inline fun , reified T> register() where T : Task, T : IntelliJPlatformVersionAware, T : SandboxAware = + private inline fun , reified T> register() where T : Task, T : IntelliJPlatformVersionAware, T : RuntimeAware, T : SandboxAware = project.objects.domainObjectContainer( elementType = C::class, factory = { project.objects.newInstance(it, project) }, @@ -104,6 +106,23 @@ abstract class IntelliJPlatformTestingExtension @Inject constructor( }) } } + val customJetBrainsRuntimeConfiguration = project.configurations.create( + name = Configurations.JETBRAINS_RUNTIME.withSuffix, + description = "Custom JetBrains Runtime", + ) { + attributes { + attribute(Attributes.extracted, true) + } + + defaultDependencies { + val customPlatformPath = project.provider { + customIntelliJPlatformConfiguration.platformPath() + } + addLater(dependenciesHelper.obtainJetBrainsRuntimeVersion(customPlatformPath).map { version -> + dependenciesHelper.createJetBrainsRuntime(version) + }) + } + } val customIntellijPlatformPluginDependencyConfiguration = project.configurations.create( name = Configurations.INTELLIJ_PLATFORM_PLUGIN_DEPENDENCY.withSuffix, @@ -159,6 +178,7 @@ abstract class IntelliJPlatformTestingExtension @Inject constructor( intelliJPlatformConfiguration = customIntelliJPlatformConfiguration intelliJPlatformPluginConfiguration = customIntellijPlatformPluginConfiguration + jetbrainsRuntimeConfiguration = customJetBrainsRuntimeConfiguration applySandboxFrom(prepareSandboxTask) } diff --git a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/aware/RuntimeAware.kt b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/aware/RuntimeAware.kt index 39c0602bef..63f19654e3 100644 --- a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/aware/RuntimeAware.kt +++ b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/aware/RuntimeAware.kt @@ -2,14 +2,13 @@ package org.jetbrains.intellij.platform.gradle.tasks.aware +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.PathSensitive -import org.gradle.api.tasks.PathSensitivity +import org.gradle.api.tasks.* import org.gradle.jvm.toolchain.JavaLauncher +import org.jetbrains.intellij.platform.gradle.Constants.Configurations import org.jetbrains.intellij.platform.gradle.resolvers.path.JavaRuntimePathResolver /** @@ -19,6 +18,14 @@ import org.jetbrains.intellij.platform.gradle.resolvers.path.JavaRuntimePathReso */ interface RuntimeAware : IntelliJPlatformVersionAware { + /** + * Holds the [Configurations.JETBRAINS_RUNTIME] configuration with the JetBrains Runtime dependency added. + * It should not be directly accessed. + */ + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) + val jetbrainsRuntimeConfiguration: ConfigurableFileCollection + /** * Java Runtime parent directory. */ 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 3f84c9218c..2c114d5090 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 @@ -109,8 +109,10 @@ internal fun Project.preconfigureTask(task: T) { * This configuration picks relevant Java Runtime using the [JavaRuntimePathResolver] and [RuntimeAware.runtimeMetadata]. */ if (this is RuntimeAware) { + jetbrainsRuntimeConfiguration = configurations.maybeCreate(Configurations.JETBRAINS_RUNTIME) + val javaRuntimePathResolver = JavaRuntimePathResolver( - jetbrainsRuntime = configurations[Configurations.JETBRAINS_RUNTIME].asLenient, + jetbrainsRuntime = jetbrainsRuntimeConfiguration, intellijPlatform = intelliJPlatformConfiguration, javaToolchainSpec = project.the().toolchain, javaToolchainService = project.serviceOf(),