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(); }
LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject); Library get = table.getLibraryByName(GoSmallIDEsSdkService.LIBRARY_NAME); Library lib = get != null ? get : table.createLibrary(GoSmallIDEsSdkService.LIBRARY_NAME); Library.ModifiableModel libraryModel = lib.getModifiableModel(); String libUrl = ArrayUtil.getFirstElement(lib.getUrls(OrderRootType.CLASSES)); if (libUrl != null) { libraryModel.removeRoot(libUrl, OrderRootType.CLASSES); libraryModel.addRoot(file, OrderRootType.CLASSES); libraryModel.commit(); table.removeLibrary(lib); table.getModifiableModel().commit();
private static VirtualFile[] libraryRootsFor(final Module module) { return LibraryUtil.getLibraryRoots(new Module[]{module}, false, false); }
@Override public void run() { final LibraryTable table = LibraryTablesRegistrar.getInstance() .getLibraryTableByLevel( LibraryTablesRegistrar.APPLICATION_LEVEL, myModule.getProject()); assert table != null; final LibraryTable.ModifiableModel tableModel = table.getModifiableModel(); final Library library = tableModel.createLibrary("endpoints-lib"); final Library.ModifiableModel libraryModel = library.getModifiableModel(); libraryModel.addJarDirectory(pluginsDir, true); libraryModel.commit(); tableModel.commit(); ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel(); Library jar = table.getLibraries()[0]; rootModel.addLibraryEntry(jar); // Endpoint is the only jar added rootModel.commit(); } });
/** * Looks up the user's configured libraries for the project and returns a set of {@link * AppEngineStandardMavenLibrary} for each configured library matching one of the AE standard * managed libraries. * * <p>The lookup is performed based on the maven display id consisting of groupId, artifactName, * and version. If the configured lib doesn't entirely match this strategy, then it will not be * returned and therefore not considered to be "managed". */ public Set<AppEngineStandardMavenLibrary> getLibraries(@NotNull Project project) { return Arrays.stream( LibraryTablesRegistrar.getInstance().getLibraryTable(project).getLibraries()) .map( library -> AppEngineStandardMavenLibrary.getLibraryByMavenDisplayName(library.getName())) .filter(Optional::isPresent) .map(Optional::get) .collect(toSet()); }
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(); }
@Override public void run() { LibraryTable table = LibraryTablesRegistrar.getInstance() .getLibraryTableByLevel( LibraryTablesRegistrar.APPLICATION_LEVEL, myModule.getProject()); if (table != null) { LibraryTable.ModifiableModel tableModel = table.getModifiableModel(); Library library = tableModel.getLibraryByName("endpoints-lib"); if (library != null) { tableModel.removeLibrary(library); tableModel.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 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(); } }
@Nullable private Library findGlobalProtobufLibrary(Project project, VirtualFile libraryBundle) { LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project); Library library = libraryTable.getLibraryByName(LIB_NAME); if (library != null) { // check library - update if needed if (Arrays.stream(library.getFiles(ORDER_ROOT_TYPE)) .anyMatch(file -> file.getName().equals(libraryBundle.getName()))) { return library; } } return null; }
@Override public void disposeUIResources() { if (libraryListener != null) { LibraryTablesRegistrar.getInstance() .getLibraryTable(context.getProject()) .removeListener(libraryListener); } }
public AppEngineStandardFacetEditor( AppEngineStandardFacetConfiguration facetConfiguration, FacetEditorContext context) { this.facetConfiguration = facetConfiguration; this.context = context; libraryListener = new LibraryModificationListener(); LibraryTablesRegistrar.getInstance() .getLibraryTable(context.getProject()) .addListener(libraryListener); }
private void clear(Library.ModifiableModel libraryModel) { String[] urls = libraryModel.getUrls(ORDER_ROOT_TYPE); for (String url : urls) { libraryModel.removeRoot(url, ORDER_ROOT_TYPE); } }
private void removeLibraryIfNeeded() { ApplicationManager.getApplication().assertIsDispatchThread(); ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance(); ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule); LibraryOrderEntry goLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (goLibraryEntry != null) { ApplicationManager.getApplication().runWriteAction(() -> { Library library = goLibraryEntry.getLibrary(); if (library != null) { LibraryTable table = library.getTable(); if (table != null) { table.removeLibrary(library); model.removeOrderEntry(goLibraryEntry); modelsProvider.commitModuleModifiableModel(model); } } else { modelsProvider.disposeModuleModifiableModel(model); } }); } else { ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model)); } }
private static Collection<VirtualFile> getLibraryEntries(@Nullable Library lib) { if (lib == null) { return Collections.emptyList(); } return Arrays.asList(lib.getFiles(OrderRootType.CLASSES)); }
@NotNull @Override public DummyLibraryProperties createDefaultProperties() { return new DummyLibraryProperties(); } };
LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject); Library get = table.getLibraryByName(BallerinaSmallIDEsSdkService.LIBRARY_NAME); Library lib = get != null ? get : table.createLibrary(BallerinaSmallIDEsSdkService.LIBRARY_NAME); Library.ModifiableModel libraryModel = lib.getModifiableModel(); String libUrl = ArrayUtil.getFirstElement(lib.getUrls(OrderRootType.CLASSES)); if (libUrl != null) { libraryModel.removeRoot(libUrl, OrderRootType.CLASSES); libraryModel.addRoot(file, OrderRootType.CLASSES); libraryModel.commit(); table.removeLibrary(lib); table.getModifiableModel().commit();
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(); }
@Nullable private String getDUnitPath() { final LibraryTable projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project); final Optional<Library> dunit = Arrays.stream(projectLibraryTable.getLibraries()) .filter(lib -> StringUtil.isNotEmpty(lib.getName()) && lib.getName().contains("d-unit-")) // todo: also check for "dunit-" ?? .findFirst(); // it's possible for a dependency to be found multiple times if(dunit.isPresent()) { final VirtualFile[] files = dunit.get().getFiles(OrderRootType.CLASSES); if (files.length > 0) { return dubImportPath(files[0].getCanonicalPath()); } } return null; }
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(); } }
private void removeLibraryIfNeeded() { ApplicationManager.getApplication().assertIsDispatchThread(); ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance(); ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule); LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (ballerinaLibraryEntry != null) { ApplicationManager.getApplication().runWriteAction(() -> { Library library = ballerinaLibraryEntry.getLibrary(); if (library != null) { LibraryTable table = library.getTable(); if (table != null) { table.removeLibrary(library); model.removeOrderEntry(ballerinaLibraryEntry); modelsProvider.commitModuleModifiableModel(model); } } else { modelsProvider.disposeModuleModifiableModel(model); } }); } else { ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model)); } }