public static ContentEntry addContentRoot(Module module, VirtualFile vDir) { ModuleRootModificationUtil.updateModel(module, model -> model.addContentEntry(vDir)); for (ContentEntry entry : ModuleRootManager.getInstance(module).getContentEntries()) { if (Comparing.equal(entry.getFile(), vDir)) { Assert.assertFalse(((ContentEntryImpl) entry).isDisposed()); return entry; } } return null; }
@Nullable public static ContentEntry findContentEntryForRoot( @NotNull ModifiableRootModel model, @NotNull VirtualFile root) { ContentEntry contentEntry = null; for (ContentEntry candidate : model.getContentEntries()) { VirtualFile contentRoot = candidate.getFile(); if (contentRoot != null && VfsUtilCore.isAncestor(contentRoot, root, false)) { contentEntry = candidate; } } return contentEntry; }