@Override public void afterLibraryRemoved(Library removedLibrary) { AppEngineStandardMavenLibrary.getLibraryByMavenDisplayName(removedLibrary.getName()) .ifPresent( library -> appEngineStandardLibraryPanel.toggleLibrary(library, false /* select */)); }
@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; }
/** * 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()); }
/** * 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(); }); } }
@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 */); }); }