private ResumeImportStatistic apply()

in src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java [204:265]


  private ResumeImportStatistic apply(LockFile lockFile, Input input, ImportProjectInfo info)
      throws RestApiException, OrmException, IOException, GitAPIException, NoSuchChangeException,
          NoSuchAccountException, UpdateException, ConfigInvalidException,
          PermissionBackendException, PatchListNotAvailableException {
    boolean resume = info != null;
    api = apiFactory.create(input.from, input.user, input.pass);

    if (copy) {
      input.validateCopy();
    } else {
      input.validateImport();
      Version v = api.getVersion();
      if (v.compareTo(v2_11_2) < 0) {
        throw new BadRequestException(
            String.format(
                "The version of the source Gerrit server %s is too old. "
                    + "Its version is %s, but required is a version >= %s.",
                input.from, v.formatted, v2_11_2));
      }
    }

    ProgressMonitor pm = err != null ? new TextProgressMonitor(err) : NullProgressMonitor.INSTANCE;

    ResumeImportStatistic statistic = new ResumeImportStatistic();
    try {
      srcProject =
          !Strings.isNullOrEmpty(input.name) ? new Project.NameKey(input.name) : targetProject;
      checkProjectInSource(pm);
      setParentProjectName(input, pm);
      checkPreconditions(pm);
      try (Repository repo = openRepoStep.open(targetProject, resume, pm, parent)) {
        ImportJson.persist(lockFile, importJson.format(input, info), pm);
        configRepoStep.configure(repo, srcProject, input.from, pm);
        gitFetchStep.fetch(input.user, input.pass, repo, pm);
        configProjectStep.configure(targetProject, parent, pm);
        replayChangesFactory
            .create(input.from, api, repo, srcProject, targetProject, force, resume, statistic, pm)
            .replay();
        if (!copy) {
          importGroupsStepFactory
              .create(input.from, input.user, input.pass, targetProject, pm)
              .importGroups();
        }
      }
      importLog.onImport((IdentifiedUser) currentUser.get(), srcProject, targetProject, input.from);
    } catch (BadRequestException e) {
      throw e;
    } catch (Exception e) {
      importLog.onImport(
          (IdentifiedUser) currentUser.get(), srcProject, targetProject, input.from, e);
      String msg =
          input.from != null
              ? format(
                  "Unable to transfer project '%s' from" + " source gerrit host '%s'.",
                  srcProject.get(), input.from)
              : format("Unable to copy project '%s'.", srcProject.get());
      log.error(msg, e);
      throw e;
    }

    return statistic;
  }