void (Module module) { final ModuleRootManager rootManager = ModuleRootManager.getInstance(module); final ModifiableRootModel rootModel = rootManager.getModifiableModel(); try { for (String contentRoot : myContentRoots) { final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(contentRoot); Assert.assertNotNull("cannot find content root: " + contentRoot, virtualFile); final ContentEntry contentEntry = rootModel.addContentEntry(virtualFile); for (String sourceRoot: mySourceRoots) { String s = UriUtil.trimTrailingSlashes(contentRoot + "/" + sourceRoot); VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByPath(s); if (vf == null) { final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(sourceRoot); if (file != null && VfsUtilCore.isAncestor(virtualFile, file, false)) vf = file; } // assert vf != null : "cannot find source root: " + sourceRoot; if (vf != null) { VirtualFile finalVf = vf; if (!ContainerUtil.exists(contentEntry.getSourceFolders(), folder -> finalVf.equals(folder.getFile()))) { contentEntry.addSourceFolder(finalVf, false); } } else { // files are not created yet String url = VfsUtilCore.pathToUrl(s); if (!ContainerUtil.exists(contentEntry.getSourceFolders(), folder -> url.equals(folder.getUrl()))) { contentEntry.addSourceFolder(url, false); } } } } setupRootModel(rootModel); } catch (Throwable e) { rootModel.dispose(); throw e; } rootModel.commit(); }