-
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.
Implement different build issues for Daemon toolchain related exceptions
- Loading branch information
Showing
9 changed files
with
340 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
...ains/kotlin/idea/gradleJava/issues/checkers/GradleInvalidDaemonJvmCriteriaIssueChecker.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,52 @@ | ||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package org.jetbrains.kotlin.idea.gradleJava.issues.checkers | ||
|
||
import com.intellij.build.FilePosition | ||
import com.intellij.build.events.BuildEvent | ||
import com.intellij.build.issue.BuildIssue | ||
import org.gradle.internal.buildconfiguration.DaemonJvmPropertiesConfigurator | ||
import org.jetbrains.kotlin.idea.gradleJava.issues.quickfix.GradleOpenDaemonJvmSettingsQuickFix | ||
import org.jetbrains.plugins.gradle.issue.ConfigurableGradleBuildIssue | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueChecker | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueData | ||
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionErrorHandler.getRootCauseAndLocation | ||
import org.jetbrains.plugins.gradle.util.GradleBundle | ||
import java.util.function.Consumer | ||
|
||
/** | ||
* An [GradleIssueChecker] handling Daemon JVM criteria exceptions like: | ||
* "Value 'invalid version' given for toolchainVersion is an invalid Java version" | ||
*/ | ||
class GradleInvalidDaemonJvmCriteriaIssueChecker : GradleIssueChecker { | ||
|
||
override fun check(issueData: GradleIssueData): BuildIssue? { | ||
val rootCause = getRootCauseAndLocation(issueData.error).first | ||
if (rootCause?.toString()?.endsWith("toolchainVersion is an invalid Java version") == true) { | ||
return GradleInvalidDaemonJvmCriteriaBuildIssue(rootCause) | ||
} | ||
return null | ||
} | ||
|
||
override fun consumeBuildOutputFailureMessage( | ||
message: String, | ||
failureCause: String, | ||
stacktrace: String?, | ||
location: FilePosition?, | ||
parentEventId: Any, | ||
messageConsumer: Consumer<in BuildEvent> | ||
): Boolean { | ||
return parentEventId == ":${DaemonJvmPropertiesConfigurator.TASK_NAME}" | ||
} | ||
} | ||
|
||
private class GradleInvalidDaemonJvmCriteriaBuildIssue( | ||
cause: Throwable | ||
) : ConfigurableGradleBuildIssue() { | ||
init { | ||
setTitle(GradleBundle.message("gradle.build.issue.daemon.toolchain.invalid.criteria.title")) | ||
addDescription(cause.message ?: title) | ||
addQuickFixes( | ||
mapOf(GradleOpenDaemonJvmSettingsQuickFix to GradleBundle.message("gradle.build.quick.fix.modify.gradle.jvm.criteria")) | ||
) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
.../idea/gradleJava/issues/checkers/GradleToolchainDownloadedMismatchCriteriaIssueChecker.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,57 @@ | ||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package org.jetbrains.kotlin.idea.gradleJava.issues.checkers | ||
|
||
import com.intellij.build.FilePosition | ||
import com.intellij.build.events.BuildEvent | ||
import com.intellij.build.issue.BuildIssue | ||
import org.gradle.internal.buildconfiguration.DaemonJvmPropertiesConfigurator | ||
import org.jetbrains.kotlin.idea.gradleJava.issues.quickfix.GradleOpenDaemonJvmSettingsQuickFix | ||
import org.jetbrains.kotlin.idea.gradleJava.issues.quickfix.GradleRecreateToolchainDownloadUrlsQuickFix | ||
import org.jetbrains.plugins.gradle.issue.ConfigurableGradleBuildIssue | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueChecker | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueData | ||
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionErrorHandler.getRootCauseAndLocation | ||
import org.jetbrains.plugins.gradle.util.GradleBundle | ||
import java.util.function.Consumer | ||
|
||
/** | ||
* An [GradleIssueChecker] handling Daemon JVM criteria exceptions like: | ||
* "Toolchain provisioned from '<URL>' doesn't satisfy the specification: {languageVersion=11, vendor=any, implementation=vendor-specific}" | ||
*/ | ||
class GradleToolchainDownloadedMismatchCriteriaIssueChecker : GradleIssueChecker { | ||
|
||
override fun check(issueData: GradleIssueData): BuildIssue? { | ||
val rootCause = getRootCauseAndLocation(issueData.error).first | ||
if (rootCause.message?.startsWith("Toolchain provisioned from") == true) { | ||
return GradleToolchainDownloadedMismatchCriteriaBuildIssue(rootCause, issueData.projectPath) | ||
} | ||
return null | ||
} | ||
|
||
override fun consumeBuildOutputFailureMessage( | ||
message: String, | ||
failureCause: String, | ||
stacktrace: String?, | ||
location: FilePosition?, | ||
parentEventId: Any, | ||
messageConsumer: Consumer<in BuildEvent> | ||
): Boolean { | ||
return parentEventId == ":${DaemonJvmPropertiesConfigurator.TASK_NAME}" | ||
} | ||
} | ||
|
||
private class GradleToolchainDownloadedMismatchCriteriaBuildIssue( | ||
cause: Throwable, | ||
externalProjectPath: String | ||
) : ConfigurableGradleBuildIssue() { | ||
init { | ||
setTitle(GradleBundle.message("gradle.build.issue.daemon.toolchain.downloaded.mismatch.criteria.title")) | ||
addDescription(cause.message ?: title) | ||
addQuickFixes( | ||
mapOf( | ||
GradleRecreateToolchainDownloadUrlsQuickFix(externalProjectPath) to GradleBundle.message("gradle.build.quick.fix.recreate.download.urls"), | ||
GradleOpenDaemonJvmSettingsQuickFix to GradleBundle.message("gradle.build.quick.fix.modify.gradle.jvm.criteria") | ||
) | ||
) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ins/kotlin/idea/gradleJava/issues/checkers/GradleToolchainDownloadingErrorIssueChecker.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,58 @@ | ||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package org.jetbrains.kotlin.idea.gradleJava.issues.checkers | ||
|
||
import com.intellij.build.FilePosition | ||
import com.intellij.build.events.BuildEvent | ||
import com.intellij.build.issue.BuildIssue | ||
import org.gradle.internal.buildconfiguration.DaemonJvmPropertiesConfigurator | ||
import org.jetbrains.kotlin.idea.gradleJava.issues.quickfix.GradleDownloadToolchainQuickFix | ||
import org.jetbrains.kotlin.idea.gradleJava.issues.quickfix.GradleOpenDaemonJvmSettingsQuickFix | ||
import org.jetbrains.plugins.gradle.issue.ConfigurableGradleBuildIssue | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueChecker | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueData | ||
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionErrorHandler.getRootCauseAndLocation | ||
import org.jetbrains.plugins.gradle.util.GradleBundle | ||
import java.util.function.Consumer | ||
|
||
/** | ||
* An [GradleIssueChecker] handling Daemon JVM criteria exceptions like: | ||
* "Unable to download toolchain matching the requirements ({languageVersion=1.1, vendor=any vendor, implementation=vendor-specific}) | ||
* from '<URL>', due to: No defined toolchain download url for MAC_OS on aarch64 architecture." | ||
*/ | ||
class GradleToolchainDownloadingErrorIssueChecker : GradleIssueChecker { | ||
|
||
override fun check(issueData: GradleIssueData): BuildIssue? { | ||
val rootCause = getRootCauseAndLocation(issueData.error).first | ||
if (rootCause.message?.startsWith("Unable to download toolchain matching the requirements") == true) { | ||
return GradleToolchainDownloadingErrorBuildIssue(rootCause, issueData.projectPath) | ||
} | ||
return null | ||
} | ||
|
||
override fun consumeBuildOutputFailureMessage( | ||
message: String, | ||
failureCause: String, | ||
stacktrace: String?, | ||
location: FilePosition?, | ||
parentEventId: Any, | ||
messageConsumer: Consumer<in BuildEvent> | ||
): Boolean { | ||
return parentEventId == ":${DaemonJvmPropertiesConfigurator.TASK_NAME}" | ||
} | ||
} | ||
|
||
private class GradleToolchainDownloadingErrorBuildIssue( | ||
cause: Throwable, | ||
externalProjectPath: String | ||
) : ConfigurableGradleBuildIssue() { | ||
init { | ||
setTitle(GradleBundle.message("gradle.build.issue.daemon.toolchain.download.error.title")) | ||
addDescription(cause.message ?: title) | ||
addQuickFixes( | ||
mapOf( | ||
GradleDownloadToolchainQuickFix(externalProjectPath) to GradleBundle.message("gradle.build.quick.fix.install.missing.toolchain"), | ||
GradleOpenDaemonJvmSettingsQuickFix to GradleBundle.message("gradle.build.quick.fix.modify.gradle.jvm.criteria") | ||
) | ||
) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...radleJava/issues/checkers/GradleToolchainInstalledNotFoundMatchingCriteriaIssueChecker.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,58 @@ | ||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package org.jetbrains.kotlin.idea.gradleJava.issues.checkers | ||
|
||
import com.intellij.build.FilePosition | ||
import com.intellij.build.events.BuildEvent | ||
import com.intellij.build.issue.BuildIssue | ||
import org.gradle.internal.buildconfiguration.DaemonJvmPropertiesConfigurator | ||
import org.jetbrains.kotlin.idea.gradleJava.issues.quickfix.GradleDownloadToolchainQuickFix | ||
import org.jetbrains.kotlin.idea.gradleJava.issues.quickfix.GradleOpenDaemonJvmSettingsQuickFix | ||
import org.jetbrains.plugins.gradle.issue.ConfigurableGradleBuildIssue | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueChecker | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueData | ||
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionErrorHandler.getRootCauseAndLocation | ||
import org.jetbrains.plugins.gradle.util.GradleBundle | ||
import java.util.function.Consumer | ||
|
||
/** | ||
* An [GradleIssueChecker] handling Daemon JVM criteria exceptions like: | ||
* "Cannot find a Java installation on your machine (Mac OS X 14.7.1 aarch64) matching: Compatible with Java 20, | ||
* vendor matching('dasdsada') (from gradle/gradle-daemon-jvm.properties)." | ||
*/ | ||
class GradleToolchainInstalledNotFoundMatchingCriteriaIssueChecker : GradleIssueChecker { | ||
|
||
override fun check(issueData: GradleIssueData): BuildIssue? { | ||
val rootCause = getRootCauseAndLocation(issueData.error).first | ||
if (rootCause.message?.startsWith("Cannot find a Java installation on your machine") == true) { | ||
return GradleToolchainInstalledNotFoundMatchingCriteriaBuildIssue(rootCause, issueData.projectPath) | ||
} | ||
return null | ||
} | ||
|
||
override fun consumeBuildOutputFailureMessage( | ||
message: String, | ||
failureCause: String, | ||
stacktrace: String?, | ||
location: FilePosition?, | ||
parentEventId: Any, | ||
messageConsumer: Consumer<in BuildEvent> | ||
): Boolean { | ||
return parentEventId == ":${DaemonJvmPropertiesConfigurator.TASK_NAME}" | ||
} | ||
} | ||
|
||
private class GradleToolchainInstalledNotFoundMatchingCriteriaBuildIssue( | ||
cause: Throwable, | ||
externalProjectPath: String | ||
) : ConfigurableGradleBuildIssue() { | ||
init { | ||
setTitle(GradleBundle.message("gradle.build.issue.daemon.toolchain.not.found.title")) | ||
addDescription(cause.message ?: title) | ||
addQuickFixes( | ||
mapOf( | ||
GradleDownloadToolchainQuickFix(externalProjectPath) to GradleBundle.message("gradle.build.quick.fix.install.missing.toolchain"), | ||
GradleOpenDaemonJvmSettingsQuickFix to GradleBundle.message("gradle.build.quick.fix.modify.gradle.jvm.criteria") | ||
) | ||
) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ns/kotlin/idea/gradleJava/issues/checkers/GradleUndefinedDaemonJvmCriteriaIssueChecker.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,39 @@ | ||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package org.jetbrains.kotlin.idea.gradleJava.issues.checkers | ||
|
||
import com.intellij.build.issue.BuildIssue | ||
import org.jetbrains.kotlin.idea.gradleJava.issues.quickfix.GradleAddDaemonToolchainCriteriaQuickFix | ||
import org.jetbrains.plugins.gradle.issue.ConfigurableGradleBuildIssue | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueChecker | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueData | ||
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionErrorHandler.getRootCauseAndLocation | ||
import org.jetbrains.plugins.gradle.util.GradleBundle | ||
|
||
/** | ||
* An [GradleIssueChecker] handling Daemon JVM criteria exception when isn't defined for the project | ||
*/ | ||
class GradleUndefinedDaemonJvmCriteriaIssueChecker : GradleIssueChecker { | ||
|
||
override fun check(issueData: GradleIssueData): BuildIssue? { | ||
val rootCause = getRootCauseAndLocation(issueData.error).first | ||
if (false) { // TODO: No known exception since right now is an opt-in feature | ||
return GradleUndefinedDaemonJvmCriteriaBuildIssue(rootCause, issueData.projectPath) | ||
} | ||
return null | ||
} | ||
} | ||
|
||
private class GradleUndefinedDaemonJvmCriteriaBuildIssue( | ||
cause: Throwable, | ||
externalProjectPath: String | ||
) : ConfigurableGradleBuildIssue() { | ||
init { | ||
setTitle(GradleBundle.message("gradle.build.issue.daemon.toolchain.undefined.criteria.title")) | ||
addDescription(cause.message ?: title) | ||
addQuickFixes( | ||
mapOf( | ||
GradleAddDaemonToolchainCriteriaQuickFix(externalProjectPath) to GradleBundle.message("gradle.build.quick.fix.add.toolchain.criteria") | ||
) | ||
) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...otlin/idea/gradleJava/issues/checkers/GradleUndefinedToolchainRepositoriesIssueChecker.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,55 @@ | ||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package org.jetbrains.kotlin.idea.gradleJava.issues.checkers | ||
|
||
import com.intellij.build.FilePosition | ||
import com.intellij.build.events.BuildEvent | ||
import com.intellij.build.issue.BuildIssue | ||
import org.gradle.internal.buildconfiguration.DaemonJvmPropertiesConfigurator | ||
import org.jetbrains.kotlin.idea.gradleJava.issues.quickfix.GradleAddDownloadToolchainRepositoryQuickFix | ||
import org.jetbrains.plugins.gradle.issue.ConfigurableGradleBuildIssue | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueChecker | ||
import org.jetbrains.plugins.gradle.issue.GradleIssueData | ||
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionErrorHandler.getRootCauseAndLocation | ||
import org.jetbrains.plugins.gradle.util.GradleBundle | ||
import java.util.function.Consumer | ||
|
||
/** | ||
* An [GradleIssueChecker] handling Daemon JVM criteria exceptions like: | ||
* "Cannot find a Java installation on your machine (Mac OS X 14.7.1 aarch64) matching: {languageVersion=99, vendor=any vendor, | ||
* implementation=vendor-specific}. Toolchain download repositories have not been configured." | ||
*/ | ||
class GradleUndefinedToolchainRepositoriesIssueChecker : GradleIssueChecker { | ||
|
||
override fun check(issueData: GradleIssueData): BuildIssue? { | ||
val rootCause = getRootCauseAndLocation(issueData.error).first | ||
if (rootCause.message?.contains("Toolchain download repositories have not been configured.") == true) { | ||
return GradleUndefinedToolchainRepositoriesBuildIssue(rootCause) | ||
} | ||
return null | ||
} | ||
|
||
override fun consumeBuildOutputFailureMessage( | ||
message: String, | ||
failureCause: String, | ||
stacktrace: String?, | ||
location: FilePosition?, | ||
parentEventId: Any, | ||
messageConsumer: Consumer<in BuildEvent> | ||
): Boolean { | ||
return parentEventId == ":${DaemonJvmPropertiesConfigurator.TASK_NAME}" | ||
} | ||
} | ||
|
||
private class GradleUndefinedToolchainRepositoriesBuildIssue( | ||
cause: Throwable, | ||
) : ConfigurableGradleBuildIssue() { | ||
init { | ||
setTitle(GradleBundle.message("gradle.build.issue.daemon.toolchain.repositories.undefined.title")) | ||
addDescription(cause.message ?: title) | ||
addQuickFixes( | ||
mapOf( | ||
GradleAddDownloadToolchainRepositoryQuickFix to GradleBundle.message("gradle.build.quick.fix.add.toolchain.repository") | ||
) | ||
) | ||
} | ||
} |