use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class CreateLibraryFromFilesDialog method addLibrary.
private void addLibrary() {
final LibrariesContainer.LibraryLevel level = myNameAndLevelPanel.getLibraryLevel();
WriteAction.run(() -> {
final Module module = myModulesComboBox.getSelectedModule();
final String libraryName = myNameAndLevelPanel.getLibraryName();
if (level == LibrariesContainer.LibraryLevel.MODULE) {
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(libraryName, level, myRoots);
modifiableModel.commit();
} else {
final Library library = LibrariesContainerFactory.createContainer(myProject).createLibrary(libraryName, level, myRoots);
if (module != null) {
ModuleRootModificationUtil.addDependency(module, library);
}
}
});
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class AddModuleDependencyAction method getNotAddedModules.
private List<Module> getNotAddedModules() {
final ModifiableRootModel rootModel = myClasspathPanel.getRootModel();
Set<Module> addedModules = new HashSet<>(Arrays.asList(rootModel.getModuleDependencies(true)));
addedModules.add(rootModel.getModule());
final Module[] modules = myClasspathPanel.getModuleConfigurationState().getModulesProvider().getModules();
final List<Module> elements = new ArrayList<>();
for (final Module module : modules) {
if (!addedModules.contains(module)) {
elements.add(module);
}
}
return elements;
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class SuppressExternalTest method addAnnotationsModuleRoot.
private void addAnnotationsModuleRoot() throws IOException {
myFixture.copyDirectoryToProject("content/anno/suppressed", "content/anno/suppressed");
ApplicationManager.getApplication().runWriteAction(() -> {
final Module module = myFixture.getModule();
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
final String url = VfsUtilCore.pathToUrl(myFixture.getTempDirPath() + "/content/anno");
model.getModuleExtension(JavaModuleExternalPaths.class).setExternalAnnotationUrls(new String[] { url });
model.commit();
});
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class AddAnnotationFixTest method addLibrary.
private void addLibrary(@NotNull final String... annotationsDirs) {
ApplicationManager.getApplication().runWriteAction(() -> {
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
final LibraryTable libraryTable = model.getModuleLibraryTable();
final Library library = libraryTable.createLibrary("test");
final Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addRoot(VfsUtilCore.pathToUrl(myFixture.getTempDirPath() + "/lib"), OrderRootType.SOURCES);
for (String annotationsDir : annotationsDirs) {
libraryModel.addRoot(VfsUtilCore.pathToUrl(myFixture.getTempDirPath() + annotationsDir), AnnotationOrderRootType.getInstance());
}
libraryModel.commit();
model.commit();
});
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class ModuleLoadingStressTest method createModule.
private void createModule(String name, File contentRoot, String path) {
Module module = createModuleAt(name, myProject, JavaModuleType.getModuleType(), path);
assertTrue(contentRoot.mkdir());
VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(contentRoot);
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
model.addContentEntry(root);
ApplicationManager.getApplication().runWriteAction(() -> model.commit());
}
Aggregations