Search in sources :

Example 1 with ExternalSystemJdkException

use of com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkException in project intellij-community by JetBrains.

the class GradleInstallationManager method doGetGradleJdk.

@Nullable
private Sdk doGetGradleJdk(@Nullable Project project, String linkedProjectPath) {
    if (project == null) {
        return null;
    }
    final GradleProjectSettings settings = GradleSettings.getInstance(project).getLinkedProjectSettings(linkedProjectPath);
    if (settings == null) {
        return null;
    }
    final String gradleJvm = settings.getGradleJvm();
    final Sdk sdk;
    try {
        sdk = ExternalSystemJdkUtil.getJdk(project, gradleJvm);
    } catch (ExternalSystemJdkException e) {
        throw new ExternalSystemJdkException(String.format("Invalid Gradle JDK configuration found. <a href='%s'>Open Gradle Settings</a> \n", OpenExternalSystemSettingsCallback.ID), linkedProjectPath, e, OpenExternalSystemSettingsCallback.ID);
    }
    if (sdk == null && gradleJvm != null) {
        throw new ExternalSystemJdkException(String.format("Invalid Gradle JDK configuration found. <a href='%s'>Open Gradle Settings</a> \n", OpenExternalSystemSettingsCallback.ID), linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
    }
    final File sdkHomePath = sdk != null && sdk.getHomePath() != null ? new File(sdk.getHomePath()) : null;
    if (sdkHomePath != null && JdkUtil.checkForJre(sdkHomePath.getPath()) && !JdkUtil.checkForJdk(sdkHomePath)) {
        throw new ExternalSystemJdkException(String.format("Please, use JDK instead of JRE for Gradle importer. <a href='%s'>Open Gradle Settings</a> \n", OpenExternalSystemSettingsCallback.ID), linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
    }
    return sdk;
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) ExternalSystemJdkException(com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkException) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExternalSystemJdkException (com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkException)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 Nullable (org.jetbrains.annotations.Nullable)1 GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)1