use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class RootsChangedTest method testModuleJdkEditing.
public void testModuleJdkEditing() throws Exception {
final File tempDirectory = createTempDirectory();
ApplicationManager.getApplication().runWriteAction(() -> {
final Module moduleA = createModule("a.iml");
final Module moduleB = createModule("b.iml");
assertEventsCount(2);
final Sdk jdk;
try {
jdk = (Sdk) IdeaTestUtil.getMockJdk17().clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
ProjectJdkTable.getInstance().addJdk(jdk);
assertEventsCount(0);
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
rootModelA.setSdk(jdk);
rootModelB.setSdk(jdk);
ModifiableRootModel[] rootModels = { rootModelA, rootModelB };
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
assertEventsCount(1);
final SdkModificator sdkModificator = jdk.getSdkModificator();
sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
sdkModificator.commitChanges();
assertEventsCount(1);
ProjectJdkTable.getInstance().removeJdk(jdk);
assertEventsCount(1);
});
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class RootsChangedTest method testInheritedJdkEditing.
public void testInheritedJdkEditing() throws Exception {
final File tempDirectory = createTempDirectory();
ApplicationManager.getApplication().runWriteAction(() -> {
final Module moduleA = createModule("a.iml");
final Module moduleB = createModule("b.iml");
assertEventsCount(2);
final Sdk jdk;
final Sdk jdkBBB;
try {
jdk = (Sdk) IdeaTestUtil.getMockJdk17("AAA").clone();
ProjectJdkTable.getInstance().addJdk(jdk);
assertEventsCount(0);
jdkBBB = (Sdk) IdeaTestUtil.getMockJdk17("BBB").clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
ProjectJdkTable.getInstance().addJdk(jdk);
assertEventsCount(0);
ProjectRootManager.getInstance(myProject).setProjectSdk(jdkBBB);
assertEventsCount(0);
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
rootModelA.inheritSdk();
rootModelB.inheritSdk();
ModifiableRootModel[] rootModels = { rootModelA, rootModelB };
if (rootModels.length > 0) {
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
}
assertEventsCount(1);
ProjectRootManager.getInstance(myProject).setProjectSdk(jdk);
assertEventsCount(1);
final SdkModificator sdkModificator = jdk.getSdkModificator();
sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
sdkModificator.commitChanges();
assertEventsCount(1);
ProjectJdkTable.getInstance().removeJdk(jdk);
assertEventsCount(1);
});
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-plugins by JetBrains.
the class ActionScriptHighlightingTest method testBadResolveOfSuperclass.
public void testBadResolveOfSuperclass() throws Exception {
final Module module2 = doCreateRealModuleIn("module2", myProject, FlexModuleType.getInstance());
final Ref<VirtualFile> fileFromModule2 = new Ref<>();
final Ref<Sdk> sdk1 = new Ref<>();
final Ref<Sdk> sdk2 = new Ref<>();
myAfterCommitRunnable = () -> {
sdk1.set(FlexTestUtils.createSdk(getTestDataPath() + BASE_PATH + "fake_sdk", "4.0.0"));
{
SdkModificator m = sdk1.get().getSdkModificator();
m.removeAllRoots();
m.addRoot(sdk1.get().getHomeDirectory().findChild("common_root"), OrderRootType.CLASSES);
m.addRoot(sdk1.get().getHomeDirectory().findChild("flex_root"), OrderRootType.CLASSES);
m.commitChanges();
}
sdk2.set(FlexTestUtils.createSdk(getTestDataPath() + BASE_PATH + "fake_sdk", "4.0.0"));
{
SdkModificator m = sdk2.get().getSdkModificator();
m.removeAllRoots();
m.addRoot(sdk2.get().getHomeDirectory().findChild("common_root"), OrderRootType.CLASSES);
m.addRoot(sdk2.get().getHomeDirectory().findChild("air_root"), OrderRootType.CLASSES);
m.commitChanges();
}
fileFromModule2.set(copyFileToModule(module2, getTestDataPath() + BASE_PATH + getTestName(false) + "2.as"));
};
configureByFile(BASE_PATH + getTestName(false) + "1.as");
FlexTestUtils.modifyConfigs(myProject, e -> {
FlexTestUtils.setSdk(e.getConfigurations(myModule)[0], sdk1.get());
FlexTestUtils.setSdk(e.getConfigurations(module2)[0], sdk2.get());
});
checkHighlighting(new ExpectedHighlightingData(myEditor.getDocument(), true, true, false, myFile));
myFile = PsiManager.getInstance(myProject).findFile(fileFromModule2.get());
myEditor = createEditor(fileFromModule2.get());
checkHighlighting(new ExpectedHighlightingData(myEditor.getDocument(), true, true, false, myFile));
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-plugins by JetBrains.
the class DesignerApplicationManager method setVersionString.
private static void setVersionString(Sdk sdk, String version) {
WriteAction.run(() -> {
SdkModificator modificator = sdk.getSdkModificator();
modificator.setVersionString(version);
modificator.commitChanges();
});
}
use of com.intellij.openapi.projectRoots.SdkModificator in project android by JetBrains.
the class ExternalAnnotationsSupport method checkAnnotationsJarAttached.
// Based on similar code in MagicConstantInspection
@SuppressWarnings("ALL")
private static void checkAnnotationsJarAttached(@NotNull PsiFile file, @NotNull ProblemsHolder holder) {
// Not yet used
if (false) {
final Project project = file.getProject();
PsiClass actionBar = JavaPsiFacade.getInstance(project).findClass("android.app.ActionBar", GlobalSearchScope.allScope(project));
if (actionBar == null) {
// no sdk to attach
return;
}
PsiMethod[] methods = actionBar.findMethodsByName("getNavigationMode", false);
if (methods.length != 1) {
// no sdk to attach
return;
}
PsiMethod getModifiers = methods[0];
ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project);
PsiAnnotation annotation = annotationsManager.findExternalAnnotation(getModifiers, MagicConstant.class.getName());
if (annotation != null) {
return;
}
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(getModifiers);
if (virtualFile == null) {
// no sdk to attach
return;
}
final List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(virtualFile);
Sdk sdk = null;
for (OrderEntry orderEntry : entries) {
if (orderEntry instanceof JdkOrderEntry) {
sdk = ((JdkOrderEntry) orderEntry).getJdk();
if (sdk != null) {
break;
}
}
}
if (sdk == null) {
// no sdk to attach
return;
}
final Sdk finalSdk = sdk;
String path = finalSdk.getHomePath();
String text = "No IDEA annotations attached to the Android SDK " + finalSdk.getName() + (path == null ? "" : " (" + FileUtil.toSystemDependentName(path) + ")") + ", some issues will not be found";
holder.registerProblem(file, text, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new LocalQuickFix() {
@NotNull
@Override
public String getName() {
return "Attach annotations";
}
@NotNull
@Override
public String getFamilyName() {
return getName();
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
SdkModificator modifier = finalSdk.getSdkModificator();
attachJdkAnnotations(modifier);
modifier.commitChanges();
}
});
}
});
}
}
Aggregations