Skip to content

Commit

Permalink
Custom runIde task do not find the right runtime, if useInstaller
Browse files Browse the repository at this point in the history
… is `false`. #1827
  • Loading branch information
hsz committed Nov 19, 2024
1 parent b70d21c commit aa9fe35
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> = 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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +38,7 @@ abstract class IntelliJPlatformTestingExtension @Inject constructor(
val testIdeUi = register<TestIdeUiParameters, _>()
val testIdePerformance = register<TestIdePerformanceParameters, _>()

private inline fun <reified C : CommonParameters<T>, reified T> register() where T : Task, T : IntelliJPlatformVersionAware, T : SandboxAware =
private inline fun <reified C : CommonParameters<T>, reified T> register() where T : Task, T : IntelliJPlatformVersionAware, T : RuntimeAware, T : SandboxAware =
project.objects.domainObjectContainer(
elementType = C::class,
factory = { project.objects.newInstance<C>(it, project) },
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -159,6 +178,7 @@ abstract class IntelliJPlatformTestingExtension @Inject constructor(

intelliJPlatformConfiguration = customIntelliJPlatformConfiguration
intelliJPlatformPluginConfiguration = customIntellijPlatformPluginConfiguration
jetbrainsRuntimeConfiguration = customJetBrainsRuntimeConfiguration

applySandboxFrom(prepareSandboxTask)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ internal fun <T : Task> 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<JavaPluginExtension>().toolchain,
javaToolchainService = project.serviceOf<JavaToolchainService>(),
Expand Down

0 comments on commit aa9fe35

Please sign in to comment.