Library get = table.getLibraryByName(GoSmallIDEsSdkService.LIBRARY_NAME); Library lib = get != null ? get : table.createLibrary(GoSmallIDEsSdkService.LIBRARY_NAME); table.removeLibrary(lib); table.getModifiableModel().commit();
ApplicationManager.getApplication().runWriteAction(() -> { LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(); LibraryTable.ModifiableModel modifiableModel = libraryTable.getModifiableModel(); globalLibrary = libraryTable.getLibraryByName(LIB_NAME); if (globalLibrary == null) { globalLibrary = libraryTable.createLibrary(LIB_NAME); Library.ModifiableModel libraryModel = globalLibrary.getModifiableModel(); libraryModel.addRoot(sourceRoot, ORDER_ROOT_TYPE);
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(); } }
@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(); } });
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); } }
/** * 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 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)); } }
public AppEngineStandardFacetEditor( AppEngineStandardFacetConfiguration facetConfiguration, FacetEditorContext context) { this.facetConfiguration = facetConfiguration; this.context = context; libraryListener = new LibraryModificationListener(); LibraryTablesRegistrar.getInstance() .getLibraryTable(context.getProject()) .addListener(libraryListener); }
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(); } }
@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(); } } } });
@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 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)); } }
Library get = table.getLibraryByName(BallerinaSmallIDEsSdkService.LIBRARY_NAME); Library lib = get != null ? get : table.createLibrary(BallerinaSmallIDEsSdkService.LIBRARY_NAME); table.removeLibrary(lib); table.getModifiableModel().commit();
private void addClassesToModuleLibs( @NotNull final ModifiableRootModel modifiableRootModel, @NotNull final IdeModifiableModelsProvider modifiableModelsProvider, @Nullable final VirtualFile sourceCodeRoot, @NotNull final JavaLibraryDescriptor javaLibraryDescriptor ) { final Library library = modifiableRootModel.getModuleLibraryTable().createLibrary(); final Library.ModifiableModel libraryModifiableModel = modifiableModelsProvider .getModifiableLibraryModel(library); libraryModifiableModel.addRoot( VfsUtil.getUrlForLibraryRoot(javaLibraryDescriptor.getLibraryFile()), OrderRootType.CLASSES ); boolean sourceDirAttached = false; if (null != javaLibraryDescriptor.getSourcesFile()) { final VirtualFile srcDirVF = VfsUtil.findFileByIoFile(javaLibraryDescriptor.getSourcesFile(), true); if (null != srcDirVF) { libraryModifiableModel.addRoot(srcDirVF, OrderRootType.SOURCES); sourceDirAttached = true; } } if (sourceCodeRoot != null && !sourceDirAttached && javaLibraryDescriptor.getLibraryFile().getName().endsWith(HYBRIS_PLATFORM_CODE_SERVER_JAR_SUFFIX)) { libraryModifiableModel.addRoot(sourceCodeRoot, OrderRootType.SOURCES); } if (javaLibraryDescriptor.isExported()) { this.setLibraryEntryExported(modifiableRootModel, library); } setLibraryEntryScope(modifiableRootModel, library, javaLibraryDescriptor.getScope()); }
private void addJarFolderToModuleLibs( @NotNull final ModifiableRootModel modifiableRootModel, @NotNull final IdeModifiableModelsProvider modifiableModelsProvider, @Nullable final VirtualFile sourceCodeRoot, @NotNull final JavaLibraryDescriptor javaLibraryDescriptor ) { final LibraryTable projectLibraryTable = modifiableRootModel.getModuleLibraryTable(); final Library library = projectLibraryTable.createLibrary(); final Library.ModifiableModel libraryModifiableModel = modifiableModelsProvider .getModifiableLibraryModel(library); libraryModifiableModel.addJarDirectory( VfsUtil.getUrlForLibraryRoot(javaLibraryDescriptor.getLibraryFile()), true ); if (null != javaLibraryDescriptor.getSourcesFile()) { final VirtualFile srcDirVF = VfsUtil.findFileByIoFile(javaLibraryDescriptor.getSourcesFile(), true); if (null != srcDirVF) { libraryModifiableModel.addRoot(srcDirVF, OrderRootType.SOURCES); } } if (javaLibraryDescriptor.isExported()) { this.setLibraryEntryExported(modifiableRootModel, library); } setLibraryEntryScope(modifiableRootModel, library, javaLibraryDescriptor.getScope()); }
final String moduleLibraryPath = libInfo.first; final String sourceLibraryPath = libInfo.second; Library library = libraryTable.createLibrary(); Library.ModifiableModel modifiableModel = library.getModifiableModel(); modifiableModel.addRoot(getUrlByPath(moduleLibraryPath), OrderRootType.CLASSES);