Adapt to recent gerrit changes that broke compilation

The gerrit commits

  85f0487714e005b478eee5b28efab22bf5b7a5e2 (getCurrentUser -> User)
  bce0e922c429c819f30d1d8c86a8858bb661fa2a (Set Hashtag via BatchUpdate.Op)

broke the compilation of this plugin [1]. Hence, we follow gerrit's
changes to make it compile against latest master again.

[1] For example:
  [...]/AddHashtagsStep.java:76: error: cannot find symbol
          hashtagsUtil.setHashtags(ctrl, input, false, false);
                      ^
See

  http://builds.quelltextlich.at/gerrit/nightly/master/2015-10-20/importer.jar.build.stderr.txt

for full build log.

Bug: Issue 3622
Change-Id: Ie604b6e2beab8288274598a02ed59aa2557945b9
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/AddHashtagsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/AddHashtagsStep.java
index cf91b66..a8de4a2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/AddHashtagsStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/AddHashtagsStep.java
@@ -14,24 +14,28 @@
 
 package com.googlesource.gerrit.plugins.importer;
 
+import com.google.gerrit.common.TimeUtil;
 import com.google.gerrit.extensions.api.changes.HashtagsInput;
 import com.google.gerrit.extensions.common.ChangeInfo;
 import com.google.gerrit.extensions.restapi.AuthException;
+import com.google.gerrit.extensions.restapi.RestApiException;
 import com.google.gerrit.reviewdb.client.Change;
+import com.google.gerrit.reviewdb.server.ReviewDb;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.change.ChangeTriplet;
-import com.google.gerrit.server.change.HashtagsUtil;
+import com.google.gerrit.server.change.SetHashtagsOp;
+import com.google.gerrit.server.git.BatchUpdate;
+import com.google.gerrit.server.git.UpdateException;
 import com.google.gerrit.server.project.ChangeControl;
 import com.google.gerrit.server.project.NoSuchChangeException;
-import com.google.gerrit.server.validators.ValidationException;
 import com.google.gwtorm.server.OrmException;
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 import com.google.inject.assistedinject.Assisted;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
 import java.util.HashSet;
 
 class AddHashtagsStep {
@@ -43,42 +47,58 @@
   private static final Logger log = LoggerFactory
       .getLogger(AddHashtagsStep.class);
 
-  private final HashtagsUtil hashtagsUtil;
   private final CurrentUser currentUser;
   private final ChangeControl.GenericFactory changeControlFactory;
   private final Change change;
   private final ChangeInfo changeInfo;
   private final boolean resume;
+  private final Provider<ReviewDb> db;
+  private final BatchUpdate.Factory batchUpdateFactory;
+  private final SetHashtagsOp.Factory hashtagsFactory;
 
   @Inject
-  AddHashtagsStep(HashtagsUtil hashtagsUtil,
-      CurrentUser currentUser,
+  AddHashtagsStep(CurrentUser currentUser,
       ChangeControl.GenericFactory changeControlFactory,
+      Provider<ReviewDb> db,
+      BatchUpdate.Factory batchUpdateFactory,
+      SetHashtagsOp.Factory hashtagsFactory,
       @Assisted Change change,
       @Assisted ChangeInfo changeInfo,
       @Assisted boolean resume) {
-    this.hashtagsUtil = hashtagsUtil;
     this.currentUser = currentUser;
     this.changeControlFactory = changeControlFactory;
+    this.db = db;
+    this.batchUpdateFactory = batchUpdateFactory;
+    this.hashtagsFactory = hashtagsFactory;
     this.change = change;
     this.changeInfo = changeInfo;
     this.resume = resume;
   }
 
-  void add() throws IllegalArgumentException, IOException,
-      ValidationException, OrmException, NoSuchChangeException {
+  void add() throws IllegalArgumentException, OrmException,
+      NoSuchChangeException, UpdateException, RestApiException {
     ChangeControl ctrl = changeControlFactory.controlFor(change, currentUser);
 
     try {
       if (resume) {
         HashtagsInput input = new HashtagsInput();
         input.remove = ctrl.getNotes().load().getHashtags();
-        hashtagsUtil.setHashtags(ctrl, input, false, false);
+        try (BatchUpdate bu = batchUpdateFactory.create(db.get(),
+            change.getProject(), currentUser, TimeUtil.nowTs())) {
+                  SetHashtagsOp op = hashtagsFactory.create(input);
+                  bu.addOp(change.getId(), op);
+                  bu.execute();
+        }
       }
 
       HashtagsInput input = new HashtagsInput();
       input.add = new HashSet<>(changeInfo.hashtags);
-      hashtagsUtil.setHashtags(ctrl, input, false, false);
+      try (BatchUpdate bu = batchUpdateFactory.create(db.get(),
+          change.getProject(), currentUser, TimeUtil.nowTs())) {
+                SetHashtagsOp op = hashtagsFactory.create(input);
+                bu.addOp(change.getId(), op);
+                bu.execute();
+      }
     } catch (AuthException e) {
       log.warn(String.format(
           "Hashtags cannot be set on change %s because the importing"
@@ -88,4 +108,4 @@
           ChangeTriplet.format(change), currentUser.getUserName()));
     }
   }
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java
index 1f6a641..6598f30 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java
@@ -26,6 +26,7 @@
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.account.CapabilityControl;
 import com.google.gerrit.server.config.ConfigResource;
+import com.google.gerrit.server.git.UpdateException;
 import com.google.gerrit.server.project.NoSuchChangeException;
 import com.google.gerrit.server.project.ProjectResource;
 import com.google.gerrit.server.validators.ValidationException;
@@ -69,7 +70,8 @@
   @Override
   public ImportStatistic apply(ProjectResource rsrc, Input input)
       throws RestApiException, OrmException, IOException, ValidationException,
-      GitAPIException, NoSuchChangeException, NoSuchAccountException {
+      GitAPIException, NoSuchChangeException, NoSuchAccountException,
+      UpdateException {
     if (Strings.isNullOrEmpty(input.name)) {
       throw new BadRequestException("name is required");
     }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java
index 4e90374..39d1868 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java
@@ -28,6 +28,7 @@
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.config.ConfigResource;
+import com.google.gerrit.server.git.UpdateException;
 import com.google.gerrit.server.project.NoSuchChangeException;
 import com.google.gerrit.server.project.ProjectCache;
 import com.google.gerrit.server.project.ProjectState;
@@ -164,7 +165,8 @@
   @Override
   public ImportStatistic apply(ConfigResource rsrc, Input input)
       throws RestApiException, OrmException, IOException, ValidationException,
-      GitAPIException, NoSuchChangeException, NoSuchAccountException {
+      GitAPIException, NoSuchChangeException, NoSuchAccountException,
+      UpdateException {
     if (input == null) {
       input = new Input();
     }
@@ -179,8 +181,8 @@
 
   public ResumeImportStatistic resume(String user, String pass, boolean force,
       File importStatus) throws RestApiException, OrmException, IOException,
-      ValidationException, GitAPIException, NoSuchChangeException,
-      NoSuchAccountException {
+      GitAPIException, NoSuchChangeException, NoSuchAccountException,
+      UpdateException {
     LockFile lockFile = lockForImport();
     try {
       ImportProjectInfo info = ImportJson.parse(importStatus);
@@ -202,8 +204,8 @@
 
   private ResumeImportStatistic apply(LockFile lockFile, Input input,
       ImportProjectInfo info) throws RestApiException, OrmException,
-      IOException, ValidationException, GitAPIException, NoSuchChangeException,
-      NoSuchAccountException {
+      IOException, GitAPIException, NoSuchChangeException,
+      NoSuchAccountException, UpdateException {
     boolean resume = info != null;
     api = apiFactory.create(input.from, input.user, input.pass);
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java
index e041fb8..f31e160 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java
@@ -20,6 +20,7 @@
 import com.google.gerrit.extensions.restapi.RestApiException;
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.config.ConfigResource;
+import com.google.gerrit.server.git.UpdateException;
 import com.google.gerrit.server.project.NoSuchChangeException;
 import com.google.gerrit.server.validators.ValidationException;
 import com.google.gerrit.sshd.CommandMetaData;
@@ -70,7 +71,7 @@
   @Override
   protected void run() throws OrmException, IOException, UnloggedFailure,
       ValidationException, GitAPIException, NoSuchChangeException,
-      NoSuchAccountException {
+      NoSuchAccountException, UpdateException {
     ImportProject.Input input = new ImportProject.Input();
     input.from = url;
     input.name = name;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java
index ce4b2a0..3322dfc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java
@@ -26,11 +26,11 @@
 import com.google.gerrit.reviewdb.client.Change;
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.reviewdb.server.ReviewDb;
+import com.google.gerrit.server.git.UpdateException;
 import com.google.gerrit.server.index.ChangeIndexer;
 import com.google.gerrit.server.project.NoSuchChangeException;
 import com.google.gerrit.server.query.change.ChangeData;
 import com.google.gerrit.server.query.change.InternalChangeQuery;
-import com.google.gerrit.server.validators.ValidationException;
 import com.google.gwtorm.server.OrmException;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
@@ -128,7 +128,7 @@
 
   void replay() throws IOException, OrmException,
       NoSuchAccountException, NoSuchChangeException, RestApiException,
-      ValidationException {
+      UpdateException {
     int start = 0;
     int limit = GlobalCapability.DEFAULT_MAX_QUERY_LIMIT;
     pm.beginTask("Replay Changes", ProgressMonitor.UNKNOWN);
@@ -162,7 +162,7 @@
 
   private void replayChange(RevWalk rw, ChangeInfo c)
       throws IOException, OrmException, NoSuchAccountException,
-      NoSuchChangeException, RestApiException, ValidationException {
+      NoSuchChangeException, RestApiException, IllegalArgumentException, UpdateException {
     if (c.status == ChangeStatus.DRAFT) {
       // no import of draft changes
       return;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
index 0dda6e6..0df6a89 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
@@ -211,7 +211,7 @@
       PatchSet ps) throws OrmException {
     Map<String, PatchLineComment> drafts = Maps.newHashMap();
     for (PatchLineComment c : plcUtil.draftByPatchSetAuthor(db, ps.getId(),
-        ((IdentifiedUser) ctrl.getCurrentUser()).getAccountId(),
+        ((IdentifiedUser) ctrl.getUser()).getAccountId(),
         ctrl.getNotes())) {
       drafts.put(c.getKey().get(), c);
     }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java
index d0fbc85..e040133 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java
@@ -26,6 +26,7 @@
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.account.CapabilityControl;
 import com.google.gerrit.server.config.ConfigResource;
+import com.google.gerrit.server.git.UpdateException;
 import com.google.gerrit.server.project.NoSuchChangeException;
 import com.google.gerrit.server.project.ProjectCache;
 import com.google.gerrit.server.project.ProjectResource;
@@ -78,7 +79,8 @@
   @Override
   public ResumeImportStatistic apply(ProjectResource rsrc, Input input)
       throws RestApiException, IOException, OrmException, ValidationException,
-      GitAPIException, NoSuchChangeException, NoSuchAccountException {
+      GitAPIException, NoSuchChangeException, NoSuchAccountException,
+      UpdateException {
     ImportProjectResource projectResource =
         projectsCollection.parse(new ConfigResource(),
             IdString.fromDecoded(rsrc.getName()));
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
index 457d8f1..b5793b5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
@@ -27,6 +27,7 @@
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.account.CapabilityControl;
 import com.google.gerrit.server.config.ConfigResource;
+import com.google.gerrit.server.git.UpdateException;
 import com.google.gerrit.server.project.NoSuchChangeException;
 import com.google.gerrit.server.project.ProjectResource;
 import com.google.gerrit.server.validators.ValidationException;
@@ -92,7 +93,8 @@
   @Override
   public ResumeImportStatistic apply(ImportProjectResource rsrc, Input input)
       throws RestApiException, IOException, OrmException, ValidationException,
-      GitAPIException, NoSuchChangeException, NoSuchAccountException {
+      GitAPIException, NoSuchChangeException, NoSuchAccountException,
+      UpdateException {
     if (copy) {
       input.validateResumeCopy();
     } else {
@@ -129,7 +131,7 @@
     public ResumeImportStatistic apply(ProjectResource rsrc, Input input)
         throws RestApiException, IOException, OrmException,
         ValidationException, GitAPIException, NoSuchChangeException,
-        NoSuchAccountException {
+        NoSuchAccountException, UpdateException {
       ImportProjectResource projectResource =
           projectsCollection.parse(new ConfigResource(),
               IdString.fromDecoded(rsrc.getName()));