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(); }
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);
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)); } }
Library.ModifiableModel libraryModel = globalLibrary.getModifiableModel(); libraryModel.addRoot(sourceRoot, ORDER_ROOT_TYPE); libraryModel.commit(); } else { Optional<VirtualFile> libraryFile = Arrays.stream(globalLibrary.getFiles(ORDER_ROOT_TYPE)) .filter(file -> file.getName().equals(sourceRoot.getName())) .findAny(); if (!libraryFile.isPresent()) { Library.ModifiableModel libraryModel = globalLibrary.getModifiableModel(); clear(libraryModel); libraryModel.addRoot(sourceRoot, ORDER_ROOT_TYPE);
@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; }
@Override public void afterLibraryRemoved(Library removedLibrary) { AppEngineStandardMavenLibrary.getLibraryByMavenDisplayName(removedLibrary.getName()) .ifPresent( library -> appEngineStandardLibraryPanel.toggleLibrary(library, false /* select */)); }
private static Collection<VirtualFile> getLibraryEntries(@Nullable Library lib) { if (lib == null) { return Collections.emptyList(); } return Arrays.asList(lib.getFiles(OrderRootType.CLASSES)); }
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; }
/** * 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()); }
@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; }
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(); }
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);
/** * Add global protobuf library to given module. Visible for testing. */ public void addLibrary(Module module) { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); ModifiableRootModel modifiableRootModel = moduleRootManager.getModifiableModel(); AtomicBoolean found = new AtomicBoolean(false); OrderEnumerator.orderEntries(module).forEachLibrary(library1 -> { if (LIB_NAME.equals(library1.getName())) { found.set(true); return false; } return true; }); if (!found.get()) { ApplicationManager.getApplication().runWriteAction(() -> { modifiableRootModel.addLibraryEntry(globalLibrary); modifiableRootModel.commit(); }); } }
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)); } }
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 afterLibraryAdded(final Library addedLibrary) { Optional<AppEngineStandardMavenLibrary> libraryOptional = AppEngineStandardMavenLibrary.getLibraryByMavenDisplayName(addedLibrary.getName()); libraryOptional.ifPresent( library -> { final DependencyScope scope = library.getScope(); ApplicationManager.getApplication() .runWriteAction( () -> { ModifiableRootModel model = ModuleRootManager.getInstance(context.getModule()).getModifiableModel(); model.addLibraryEntry(addedLibrary); Arrays.stream(model.getOrderEntries()) .filter( orderEntry -> orderEntry.getPresentableName().equals(addedLibrary.getName())) .forEach( orderEntry -> ((ExportableOrderEntry) orderEntry).setScope(scope)); model.commit(); }); Artifact artifact = AppEngineStandardSupportProvider.findOrCreateWebArtifact( (AppEngineStandardFacet) context.getFacet()); AppEngineStandardWebIntegration.getInstance() .addLibraryToArtifact(addedLibrary, artifact, context.getProject()); appEngineStandardLibraryPanel.toggleLibrary(library, true /* select */); }); }
final String sourceLibraryPath = libInfo.second; Library library = libraryTable.createLibrary(); Library.ModifiableModel modifiableModel = library.getModifiableModel(); modifiableModel.addRoot(getUrlByPath(moduleLibraryPath), OrderRootType.CLASSES); if (sourceLibraryPath != null) {
@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(); } });