-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bypass Jvm validations for Gradle execution when project uses Daemon …
…toolchain
- Loading branch information
Showing
11 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...stSources/org/jetbrains/plugins/gradle/service/execution/LocalGradleExecutionAwareTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.jetbrains.plugins.gradle.service.execution | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.externalSystem.model.ProjectSystemId | ||
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId | ||
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener | ||
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkException | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkProvider | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkUtil.USE_INTERNAL_JAVA | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkUtil.USE_JAVA_HOME | ||
import com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.roots.ui.configuration.SdkLookupProvider | ||
import com.intellij.testFramework.LightPlatformTestCase | ||
import com.intellij.testFramework.VfsTestUtil | ||
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings | ||
import org.jetbrains.plugins.gradle.settings.GradleSettings | ||
|
||
class LocalGradleExecutionAwareTest : LightPlatformTestCase() { | ||
|
||
fun `test Project without linked projectSettings When prepare JVM execution Then any validation is skipped`() { | ||
prepareJvmForExecution().run { | ||
assertNull(this) | ||
} | ||
} | ||
|
||
fun `test Given project using valid JAVA_INTERNAL When prepare JVM execution Then SDK info is returned as resolved`() { | ||
GradleSettings.getInstance(project).linkedProjectsSettings = listOf(GradleProjectSettings().apply { | ||
this.externalProjectPath = project.basePath | ||
this.gradleJvm = USE_INTERNAL_JAVA | ||
}) | ||
(prepareJvmForExecution() as SdkLookupProvider.SdkInfo.Resolved).run { | ||
assertEquals(ExternalSystemJdkProvider.getInstance().getInternalJdk().name, name) | ||
assertEquals(ExternalSystemJdkProvider.getInstance().getInternalJdk().homePath, homePath) | ||
} | ||
} | ||
|
||
fun `test Given project using Daemon toolchain When prepare JVM execution Then throws expected exception`() { | ||
GradleSettings.getInstance(project).linkedProjectsSettings = listOf(GradleProjectSettings().apply { | ||
this.externalProjectPath = project.basePath | ||
this.gradleJvm = "Invalid jdk.table entry" | ||
}) | ||
|
||
assertThrows(ExternalSystemJdkException::class.java) { | ||
ApplicationManager.getApplication().executeOnPooledThread { | ||
prepareJvmForExecution() | ||
} | ||
} | ||
} | ||
|
||
fun `test Given project using Daemon toolchain When prepare JVM execution Then any validation is skipped`() { | ||
VfsTestUtil.createFile(project.baseDir, "gradle/gradle-daemon-jvm.properties", "toolchainVersion=17") | ||
GradleSettings.getInstance(project).linkedProjectsSettings = listOf(GradleProjectSettings().apply { | ||
this.externalProjectPath = project.basePath | ||
this.gradleJvm = USE_JAVA_HOME | ||
}) | ||
prepareJvmForExecution().run { | ||
assertNull(this) | ||
} | ||
} | ||
|
||
private fun prepareJvmForExecution() = | ||
LocalGradleExecutionAware().prepareJvmForExecution(DummyTask(project), project.basePath!!, DummyTaskNotificationListener(), project) | ||
|
||
private class DummyTask(project: Project) : AbstractExternalSystemTask( | ||
ProjectSystemId.IDE, ExternalSystemTaskType.EXECUTE_TASK, project, "" | ||
) { | ||
override fun doCancel(): Boolean = true | ||
|
||
override fun doExecute() {} | ||
} | ||
|
||
private class DummyTaskNotificationListener : ExternalSystemTaskNotificationListener { | ||
override fun onStart(id: ExternalSystemTaskId, workingDir: String?) {} | ||
|
||
override fun onEnd(id: ExternalSystemTaskId) {} | ||
} | ||
} |