private static void fillLibrary(@NotNull Library library, @NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) { ApplicationManager.getApplication().assertWriteAccessAllowed(); Library.ModifiableModel libraryModel = library.getModifiableModel(); for (String root : libraryModel.getUrls(OrderRootType.CLASSES)) { libraryModel.removeRoot(root, OrderRootType.CLASSES); } for (String root : libraryModel.getUrls(OrderRootType.SOURCES)) { libraryModel.removeRoot(root, OrderRootType.SOURCES); } for (VirtualFile libraryRoot : libraryRoots) { libraryModel.addRoot(libraryRoot, OrderRootType.CLASSES); // in order to consider GOPATH as library and show it in Ext. Libraries libraryModel.addRoot(libraryRoot, OrderRootType.SOURCES); // in order to find usages inside GOPATH } for (VirtualFile root : exclusions) { ((LibraryEx.ModifiableModelEx)libraryModel).addExcludedRoot(root.getUrl()); } libraryModel.commit(); }
private void assertLibrary(@NotNull Collection<String> libUrls, String... exclusionUrls) { UIUtil.dispatchAllInvocationEvents(); GoModuleLibrariesInitializer initializer = myModule.getComponent(GoModuleLibrariesInitializer.class); ModuleRootManager model = ModuleRootManager.getInstance(myModule); LibraryOrderEntry libraryOrderEntry = OrderEntryUtil.findLibraryOrderEntry(model, initializer.getLibraryName()); if (libUrls.isEmpty()) { assertNull(libraryOrderEntry); return; } LibraryEx library = (LibraryEx)libraryOrderEntry.getLibrary(); assertNotNull(library); assertSameElements(Arrays.asList(library.getUrls(OrderRootType.CLASSES)), libUrls); assertSameElements(library.getExcludedRootUrls(), exclusionUrls); }
private void attachLibraries(@NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!libraryRoots.isEmpty()) { ApplicationManager.getApplication().runWriteAction(() -> { ModuleRootManager model = ModuleRootManager.getInstance(myModule); LibraryOrderEntry goLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (goLibraryEntry != null && goLibraryEntry.isValid()) { Library library = goLibraryEntry.getLibrary(); if (library != null && !((LibraryEx)library).isDisposed()) { fillLibrary(library, libraryRoots, exclusions); } } else { LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myModule.getProject()); Library library = libraryTable.createLibrary(getLibraryName()); fillLibrary(library, libraryRoots, exclusions); ModuleRootModificationUtil.addDependency(myModule, library); } }); showNotification(myModule.getProject()); } else { removeLibraryIfNeeded(); } }
public void testAppEngine_defaultManagedLibrariesSelected() { AppEngineStandardLibraryPanel libraryPanel = new AppEngineStandardLibraryPanel(true /*enabled*/); LibraryEx library = mock(LibraryEx.class); when(library.getTable()).thenReturn(ProjectLibraryTable.getInstance(myModule.getProject())); when(library.getExcludedRoots()).thenReturn(new VirtualFile[0]); when(library.getName()).thenReturn("javax.servlet:servlet-api:2.5"); setupAppEngine(libraryPanel, library); addSupport(); assertNull(FacetManager.getInstance(myModule).getFacetByType(WebFacet.ID)); final String moduleName = myModule.getName(); ArtifactsTestUtil.assertLayout( myProject, moduleName, "<root>\n" + " WEB-INF/\n" + " classes/\n" + " module:" + moduleName + "\n" + " lib/\n" + " lib:javax.servlet:servlet-api:2.5(project)\n"); }
static void removeMavenLibraries( final Set<AppEngineStandardMavenLibrary> librariesToRemove, final Module module) { final ModuleRootManager manager = ModuleRootManager.getInstance(module); final ModifiableRootModel model = manager.getModifiableModel(); final LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject()); ApplicationManager.getApplication() .invokeLater( () -> { new WriteAction() { @Override protected void run(@NotNull Result result) throws Throwable { for (AppEngineStandardMavenLibrary libraryToRemove : librariesToRemove) { final String displayName = libraryToRemove.toMavenDisplayVersion(); final Library library = libraryTable.getLibraryByName(displayName); if (library != null) { libraryTable.removeLibrary(library); for (OrderEntry orderEntry : model.getOrderEntries()) { if (orderEntry.getPresentableName().equals(library.getName())) { model.removeOrderEntry(orderEntry); } } } } model.commit(); } }.execute(); }, ModalityState.NON_MODAL); }
private static void createOrUpdateLibrary(@NotNull String libraryName, @NotNull List<Pair<VirtualFile, DownloadableFileDescription>> pairs) { ApplicationManager.getApplication().assertWriteAccessAllowed(); Library library = ApplicationLibraryTable.getApplicationTable().getLibraryByName(libraryName); if (library == null) { LibraryTable.ModifiableModel modifiableModel = ApplicationLibraryTable.getApplicationTable().getModifiableModel(); library = modifiableModel.createLibrary(libraryName); modifiableModel.commit(); } Library.ModifiableModel modifiableModel = library.getModifiableModel(); for (Pair<VirtualFile, DownloadableFileDescription> pair : pairs) { modifiableModel.addRoot(pair.first, OrderRootType.CLASSES); } modifiableModel.commit(); }
private static boolean findExistingLibrary(@NotNull List<File> result, String... urls) { for (Library library : ApplicationLibraryTable.getApplicationTable().getLibraries()) { if (collectFiles(result, Arrays.asList(library.getUrls(OrderRootType.CLASSES)), urls)) return true; } return false; }
private static void removeOldProjectData(@NotNull final Project project) { final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : moduleModel.getModules()) { moduleModel.disposeModule(module); } final LibraryTable.ModifiableModel libraryModel = ProjectLibraryTable.getInstance(project).getModifiableModel(); for (Library library : libraryModel.getLibraries()) { libraryModel.removeLibrary(library); } ApplicationManager.getApplication().runWriteAction(() -> { moduleModel.commit(); libraryModel.commit(); }); final GradleSupport gradleSupport = GradleSupport.getInstance(); if (gradleSupport != null) { gradleSupport.clearLinkedProjectSettings(project); } final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(project); for (AntBuildFile antBuildFile : antConfiguration.getBuildFiles()) { antConfiguration.removeBuildFile(antBuildFile); } }
private static void fillLibrary(@NotNull Library library, @NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) { ApplicationManager.getApplication().assertWriteAccessAllowed(); Library.ModifiableModel libraryModel = library.getModifiableModel(); for (String root : libraryModel.getUrls(OrderRootType.CLASSES)) { libraryModel.removeRoot(root, OrderRootType.CLASSES); } for (String root : libraryModel.getUrls(OrderRootType.SOURCES)) { libraryModel.removeRoot(root, OrderRootType.SOURCES); } for (VirtualFile libraryRoot : libraryRoots) { // in order to consider BALLERINA_REPOSITORY as library and show it in Ext. Libraries libraryModel.addRoot(libraryRoot, OrderRootType.CLASSES); // In order to find usages inside BALLERINA_REPOSITORY. libraryModel.addRoot(libraryRoot, OrderRootType.SOURCES); } for (VirtualFile root : exclusions) { ((LibraryEx.ModifiableModelEx) libraryModel).addExcludedRoot(root.getUrl()); } libraryModel.commit(); }
private void attachLibraries(@NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!libraryRoots.isEmpty()) { ApplicationManager.getApplication().runWriteAction(() -> { ModuleRootManager model = ModuleRootManager.getInstance(myModule); LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (ballerinaLibraryEntry != null && ballerinaLibraryEntry.isValid()) { Library library = ballerinaLibraryEntry.getLibrary(); if (library != null && !((LibraryEx) library).isDisposed()) { fillLibrary(library, libraryRoots, exclusions); } } else { LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myModule .getProject()); Library library = libraryTable.createLibrary(getLibraryName()); fillLibrary(library, libraryRoots, exclusions); ModuleRootModificationUtil.addDependency(myModule, library); } }); showNotification(myModule.getProject()); } else { removeLibraryIfNeeded(); } }