private static void addSourceRoot(Project project, final VirtualFile baseDir, final VirtualFile root, final boolean unique) {
    final Module[] modules = ModuleManager.getInstance(project).getModules();
    if (modules.length > 0 && root != null) {
      ApplicationManager.getApplication().runWriteAction(() -> {
        final ModifiableRootModel model = ModuleRootManager.getInstance(modules[0]).getModifiableModel();
        final ContentEntry[] contentEntries = model.getContentEntries();
        for (ContentEntry contentEntry : contentEntries) {
          if (Comparing.equal(contentEntry.getFile(), baseDir)) {
            final SourceFolder[] sourceFolders = contentEntry.getSourceFolders();
            if (!unique || sourceFolders.length == 0) {
              contentEntry.addSourceFolder(root, false);
            }
          }
        }
        model.commit();
      });
    }
  }
private static void addSourceRoot(Project project, final VirtualFile baseDir, final VirtualFile root, final boolean unique)