@VisibleForTesting
  public static void patchProject(Project project,
                                  Map<Pattern, Set<Pattern>> excludePatterns,
                                  Map<Pattern, Set<Pattern>> includePatterns) {
    final ModifiableModuleModel modulesModel = ModuleManager.getInstance(project).getModifiableModel();
    final Module[] modules = modulesModel.getModules();
    final ModifiableRootModel[] models = new ModifiableRootModel[modules.length];
    for (int i = 0; i < modules.length; i++) {
      ModuleRootManager rootManager = ModuleRootManager.getInstance(modules[i]);
      models[i] = rootManager.getModifiableModel();
      String moduleName = modules[i].getName();
      final ContentEntry[] contentEntries = models[i].getContentEntries();
      for (final ContentEntry contentEntry : contentEntries) {
        final VirtualFile contentRoot = contentEntry.getFile();
        if (contentRoot == null) continue;
        final Set<VirtualFile> included = new HashSet<>();
        VfsUtilCore.visitChildrenRecursively(contentRoot, new VirtualFileVisitor<Void>() {
          @Override
          public @NotNull Result visitFileEx(@NotNull VirtualFile fileOrDir) {
            String relativeName = VfsUtilCore.getRelativePath(fileOrDir, contentRoot, '/');

            for (Pattern module : excludePatterns.keySet()) {
              if (module == null || module.matcher(moduleName).matches()) {
                final Set<Pattern> dirPatterns = excludePatterns.get(module);
                for (Pattern pattern : dirPatterns) {
                  if (pattern.matcher(relativeName).matches()) {
                    contentEntry.addExcludeFolder(fileOrDir);
                    return relativeName.isEmpty() ? CONTINUE : SKIP_CHILDREN;
                  }
                }
              }
            }
            if (includePatterns.isEmpty()) return CONTINUE;
            for (Pattern module : includePatterns.keySet()) {
              if (module == null || module.matcher(moduleName).matches()) {
                final Set<Pattern> dirPatterns = includePatterns.get(module);
                for (Pattern pattern : dirPatterns) {
                  if (pattern.matcher(relativeName).matches()) {
                    included.add(fileOrDir);
                    return CONTINUE;
                  }
                }
              }
            }
            return CONTINUE;
          }
        });
        processIncluded(contentEntry, included);
      }
    }

    ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(models, modulesModel));
  }
@VisibleForTesting
  public static void patchProject(Project project,
                                  Map<Pattern, Set<Pattern>> excludePatterns,
                                  Map<Pattern, Set<Pattern>> includePatterns)