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-community by JetBrains.
the class BytecodeAnalysisIntegrationTest method setUpExternalUpAnnotations.
private void setUpExternalUpAnnotations() {
String annotationsPath = PathManagerEx.getTestDataPath() + "/codeInspection/bytecodeAnalysis/annotations";
VirtualFile annotationsDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(annotationsPath);
assertNotNull(annotationsDir);
ModuleRootModificationUtil.updateModel(myModule, new AsynchConsumer<ModifiableRootModel>() {
@Override
public void finished() {
}
@Override
public void consume(ModifiableRootModel modifiableRootModel) {
LibraryTable libraryTable = modifiableRootModel.getModuleLibraryTable();
Library[] libs = libraryTable.getLibraries();
for (Library library : libs) {
Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
libraryModel.commit();
}
Sdk sdk = modifiableRootModel.getSdk();
if (sdk != null) {
Sdk clone;
try {
clone = (Sdk) sdk.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
SdkModificator sdkModificator = clone.getSdkModificator();
sdkModificator.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
sdkModificator.commitChanges();
modifiableRootModel.setSdk(clone);
}
}
});
VfsUtilCore.visitChildrenRecursively(annotationsDir, new VirtualFileVisitor() {
});
annotationsDir.refresh(false, true);
}
use of com.intellij.openapi.projectRoots.SdkModificator in project android by JetBrains.
the class AndroidSdks method setUpSdk.
public void setUpSdk(@NotNull Sdk androidSdk, @NotNull IAndroidTarget target, @NotNull String sdkName, @NotNull Collection<Sdk> allSdks, @Nullable Sdk jdk, boolean addRoots) {
SdkModificator sdkModificator = androidSdk.getSdkModificator();
setUpSdk(androidSdk, sdkModificator, target, sdkName, allSdks, jdk, addRoots);
sdkModificator.commitChanges();
}
use of com.intellij.openapi.projectRoots.SdkModificator in project android by JetBrains.
the class AndroidSdks method replaceLibraries.
@VisibleForTesting
void replaceLibraries(@NotNull Sdk sdk, @NotNull VirtualFile[] libraries) {
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.removeRoots(CLASSES);
for (VirtualFile library : libraries) {
sdkModificator.addRoot(library, CLASSES);
}
sdkModificator.commitChanges();
}
Aggregations