@Nullable private static Sdk moduleSdk(@NotNull Module module) { return sdk(ModuleRootManager.getInstance(module).getSdk()); }
@Override public void actionPerformed(@NotNull AnActionEvent e) { Project project = e.getProject(); assert project != null; FileDocumentManager.getInstance().saveAllDocuments(); for (Module module : GoSdkUtil.getGoModules(project)) { for (VirtualFile file : ModuleRootManager.getInstance(module).getContentRoots()) { fmt(project, module, "go fmt " + file.getPath(), file); } } }
private static void updateModules(@NotNull Project project, @NotNull Library lib, boolean remove) { Module[] modules = ModuleManager.getInstance(project).getModules(); for (Module module : modules) { ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); if (!remove) { if (model.findLibraryOrderEntry(lib) == null) { LibraryOrderEntry entry = model.addLibraryEntry(lib); entry.setScope(DependencyScope.PROVIDED); } } else { LibraryOrderEntry entry = model.findLibraryOrderEntry(lib); if (entry != null) { model.removeOrderEntry(entry); } } model.commit(); } }
private VirtualFile getSourceRoot(final Module module) { if (module != null) { final VirtualFile[] sourcesRoots = ModuleRootManager.getInstance(module).getSourceRoots(); if (sourcesRoots.length >= 1) { return sourcesRoots[0]; } } return null; } }
/** * Returns an instance of the extension for a module. Always use this and not the constructor of the implementing * class. * * @param module The module you want the extension for * * @return Instance that can be accessed and changed */ public static MathematicaLanguageLevelModuleExtension getInstance(Module module) { return ModuleRootManager.getInstance(module).getModuleExtension(MathematicaLanguageLevelModuleExtension.class); }
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 collectModuleDependencies (@NotNull Module start, @NotNull Set<Module> modules) { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(start); if (moduleRootManager != null) { for (Module module : moduleRootManager.getDependencies()) { if (!modules.contains(module)) { modules.add(module); collectModuleDependencies(module, modules); } } } }
@Override public VirtualFile[] getSourceRoots(Module module, ProtoPsiFileRoot psiFileRoot) { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); return moduleRootManager.orderEntries().getAllSourceRoots(); } }
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); if (scope == ScanScope.Everything) { moduleFiles = moduleRootManager.getContentRoots(); } else { moduleFiles = moduleRootManager.getSourceRoots(scope.includeTestClasses());
private static boolean isTestClass(final PsiElement element) { final VirtualFile elementFile = element.getContainingFile().getVirtualFile(); if (elementFile == null) { return false; } final Module module = ModuleUtil.findModuleForPsiElement(element); if (module == null) { return false; } final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); return moduleRootManager != null && moduleRootManager.getFileIndex().isInTestSourceContent(elementFile); }
private File checkModuleContentRoots(final Module module, final String fileName) { ModuleRootManager rootManager = ModuleRootManager.getInstance(module); if (rootManager.getContentEntries().length > 0) { for (final ContentEntry contentEntry : rootManager.getContentEntries()) { if (contentEntry.getFile() == null) { continue; } final File contentEntryPath = new File(contentEntry.getFile().getPath(), fileName); if (contentEntryPath.exists()) { return contentEntryPath; } } } return null; }
private File relativePathToModuleContentRoots(final @NotNull PsiFile file, final @NotNull Module module, final @NotNull File baseTmpDir) { if (file.getParent() != null) { final String parentUrl = file.getParent().getVirtualFile().getUrl(); for (String moduleSourceRoot : ModuleRootManager.getInstance(module).getContentRootUrls()) { if (parentUrl.startsWith(moduleSourceRoot)) { return new File(baseTmpDir.getAbsolutePath() + parentUrl.substring(moduleSourceRoot.length())); } } } return null; }
private static VirtualFile[] getExcludedRoots(final Module module) { if (module != null) { return ModuleRootManager.getInstance(module).getExcludeRoots(); } return null; }
private static List<VirtualFile> getProjectClasspath(@Nullable final Module module) { if (module == null) { return Collections.emptyList(); } final List<VirtualFile> found = new ArrayList<>(); final ModuleRootManager mrm = ModuleRootManager.getInstance(module); final OrderEntry[] orderEntries = mrm.getOrderEntries(); for (final OrderEntry entry : orderEntries) { if (entry instanceof ModuleOrderEntry) { // Add dependent module output dir as library Module dependentModule = ((ModuleOrderEntry) entry).getModule(); found.addAll(getModuleEntries(dependentModule)); } else if (entry instanceof LibraryOrderEntry) { Library lib = ((LibraryOrderEntry) entry).getLibrary(); found.addAll(getLibraryEntries(lib)); } } return found; }
private void createModuleRoot() { ModuleRootManager moduleRootManager = mock(ModuleRootManager.class); root = mock(VirtualFile.class); when(root.getCanonicalPath()).thenReturn("/src"); when(root.getPath()).thenReturn("/src"); VirtualFile[] roots = {root}; when(moduleRootManager.getContentRoots()).thenReturn(roots); register(module, ModuleRootManager.class, moduleRootManager); }
@Nullable private VirtualFile getSourceRoot(@Nullable final Module module) { if (module != null) { final VirtualFile[] sourcesRoots = ModuleRootManager.getInstance(module).getSourceRoots(); if (sourcesRoots.length >= 1) { return sourcesRoots[0]; } } return null; }
public static TargetDeviceModuleExtension getInstance(final Module module) { return ModuleRootManager.getInstance(module).getModuleExtension(TargetDeviceModuleExtension.class); }
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(); } }
.flatMap(module -> Arrays.stream(ModuleRootManager.getInstance(module).getDependencies())) .filter(this::isOotbOrPlatformExtension) .collect(Collectors.toList()); .stream(allModules) .filter(module -> Arrays .stream(ModuleRootManager.getInstance(module).getDependencies()) .anyMatch(this::isCustomExtension)) .filter(this::isOotbOrPlatformExtension)
@Override public VirtualFile[] getSourceRoots(Module module, ProtoPsiFileRoot psiFileRoot) { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); return moduleRootManager.orderEntries().getAllLibrariesAndSdkClassesRoots(); } }