mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
UnknownSdkTracker - handle unset SDKs, fix more tests
GitOrigin-RevId: 95f42e222bf7411535046ca59027452d244d553c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fcbf5a8013
commit
8fcbb0f1f3
+29
-36
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
@@ -14,6 +15,8 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -45,9 +48,7 @@ public class SdkSetupNotificationTest extends JavaCodeInsightFixtureTestCase {
|
||||
final List<SdkFixInfo> fixes = detectMissingSdks();
|
||||
assertThat(fixes)
|
||||
.withFailMessage(String.valueOf(fixes))
|
||||
.hasSize(1)
|
||||
.first()
|
||||
.returns("missingSDK", SdkFixInfo::getSdkName);
|
||||
.hasSize(1);
|
||||
}
|
||||
|
||||
public void testMissingModuleJdk() {
|
||||
@@ -60,9 +61,7 @@ public class SdkSetupNotificationTest extends JavaCodeInsightFixtureTestCase {
|
||||
final List<SdkFixInfo> fixes = detectMissingSdks();
|
||||
assertThat(fixes)
|
||||
.withFailMessage(String.valueOf(fixes))
|
||||
.hasSize(1)
|
||||
.first()
|
||||
.returns("missingSDK", SdkFixInfo::getSdkName);
|
||||
.hasSize(1);
|
||||
}
|
||||
|
||||
public void testNoProjectSdk() {
|
||||
@@ -73,20 +72,10 @@ public class SdkSetupNotificationTest extends JavaCodeInsightFixtureTestCase {
|
||||
assertThat(fixes)
|
||||
.withFailMessage(String.valueOf(fixes))
|
||||
.isNotEmpty();
|
||||
|
||||
/*
|
||||
final IntentionActionWithOptions action = fixes.getIntentionAction();
|
||||
assertThat(action).isNotNull();
|
||||
final String text = action.getText();
|
||||
assertThat(text).isNotNull();
|
||||
if (!text.startsWith("Setup SDK")) {
|
||||
final int length = Math.min(text.length(), "Setup SDK".length());
|
||||
assertThat(text.substring(0, length)).isEqualTo("Setup SDK");
|
||||
}*/
|
||||
}
|
||||
|
||||
public void testModuleSdk() {
|
||||
Sdk sdk = IdeaTestUtil.getMockJdk18();
|
||||
Sdk sdk = addSdkIfNeeded(IdeaTestUtil.getMockJdk18());
|
||||
ModuleRootModificationUtil.setModuleSdk(getModule(), sdk);
|
||||
|
||||
final List<SdkFixInfo> fixes = detectMissingSdks();
|
||||
@@ -102,15 +91,6 @@ public class SdkSetupNotificationTest extends JavaCodeInsightFixtureTestCase {
|
||||
assertThat(fixes)
|
||||
.withFailMessage(String.valueOf(fixes))
|
||||
.isNotEmpty();
|
||||
|
||||
/*final IntentionActionWithOptions action = panel.getIntentionAction();
|
||||
assertThat(action).isNotNull();
|
||||
final String text = action.getText();
|
||||
assertThat(text).isNotNull();
|
||||
if (!text.startsWith("Setup SDK")) {
|
||||
final int length = Math.min(text.length(), "Setup SDK".length());
|
||||
assertThat(text.substring(0, length)).isEqualTo("Setup SDK");
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,16 +109,29 @@ public class SdkSetupNotificationTest extends JavaCodeInsightFixtureTestCase {
|
||||
|
||||
private void setProjectSdk(@Nullable Sdk sdk) {
|
||||
WriteAction.run(() -> {
|
||||
ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
|
||||
|
||||
if (sdk != null) {
|
||||
final Sdk foundJdk = jdkTable.findJdk(sdk.getName());
|
||||
if (foundJdk == null) {
|
||||
jdkTable.addJdk(sdk, myFixture.getProjectDisposable());
|
||||
}
|
||||
}
|
||||
|
||||
ProjectRootManager.getInstance(getProject()).setProjectSdk(sdk);
|
||||
ProjectRootManager.getInstance(getProject()).setProjectSdk(addSdkIfNeeded(sdk));
|
||||
});
|
||||
}
|
||||
|
||||
@Contract("null->null;!null->!null")
|
||||
private Sdk addSdkIfNeeded(Sdk sdk) {
|
||||
if (sdk == null) return null;
|
||||
|
||||
ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
|
||||
|
||||
final Sdk foundJdk = jdkTable.findJdk(sdk.getName());
|
||||
if (foundJdk != null) return sdk;
|
||||
|
||||
ThrowableRunnable<RuntimeException> addSdk = () -> {
|
||||
jdkTable.addJdk(sdk, myFixture.getProjectDisposable());
|
||||
};
|
||||
|
||||
if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
|
||||
addSdk.run();
|
||||
} else {
|
||||
WriteAction.run(addSdk);
|
||||
}
|
||||
|
||||
return sdk;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user