Merge branch 'stable-2.14' into stable-2.15
* stable-2.14:
Move the UNKNOWN constant from interface to class
RenameProject: Replace generic Exception with thrown types
Change-Id: Ic99cc6911a50f17da9bbf5f22cc8acb4220ebd17
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java
index 208d103..b28d47c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java
@@ -16,9 +16,7 @@
import static com.googlesource.gerrit.plugins.renameproject.RenameProject.WARNING_LIMIT;
-import com.google.gerrit.extensions.restapi.AuthException;
-import com.google.gerrit.extensions.restapi.ResourceConflictException;
-import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
+import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.project.ProjectResource;
@@ -70,12 +68,7 @@
stdout.flush();
}
}
- } catch (CannotRenameProjectException
- | AuthException
- | ResourceNotFoundException
- | ResourceConflictException
- | OrmException
- | IOException e) {
+ } catch (RestApiException | OrmException | IOException e) {
throw die(e);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameProject.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameProject.java
index c33f849..8bc3828 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameProject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameProject.java
@@ -41,7 +41,9 @@
import com.googlesource.gerrit.plugins.renameproject.database.IndexUpdateHandler;
import com.googlesource.gerrit.plugins.renameproject.fs.FilesystemRenameHandler;
import com.googlesource.gerrit.plugins.renameproject.monitor.ProgressMonitor;
+import java.io.IOException;
import java.util.List;
+import org.eclipse.jgit.errors.ConfigInvalidException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -116,7 +118,7 @@
void assertCanRename(ProjectResource rsrc, Input input, ProgressMonitor pm)
throws ResourceConflictException, BadRequestException, AuthException {
try {
- pm.beginTask("Checking preconditions", ProgressMonitor.UNKNOWN);
+ pm.beginTask("Checking preconditions");
assertNewNameNotNull(input);
assertRenamePermission(rsrc);
renamePreconditions.assertCanRename(rsrc, new Project.NameKey(input.name));
@@ -127,7 +129,7 @@
}
void doRename(List<Change.Id> changeIds, ProjectResource rsrc, Input input, ProgressMonitor pm)
- throws Exception {
+ throws InterruptedException, OrmException, ConfigInvalidException, IOException {
Project.NameKey oldProjectKey = rsrc.getControl().getProject().getNameKey();
Project.NameKey newProjectKey = new Project.NameKey(input.name);
Exception ex = null;
@@ -157,7 +159,7 @@
}
List<Change.Id> getChanges(ProjectResource rsrc, ProgressMonitor pm) throws OrmException {
- pm.beginTask("Retrieving the list of changes from DB", ProgressMonitor.UNKNOWN);
+ pm.beginTask("Retrieving the list of changes from DB");
Project.NameKey oldProjectKey = rsrc.getControl().getProject().getNameKey();
return dbHandler.getChangeIds(oldProjectKey);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/database/DatabaseRenameHandler.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/database/DatabaseRenameHandler.java
index 2c59f8e..3215c42 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/database/DatabaseRenameHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/database/DatabaseRenameHandler.java
@@ -88,7 +88,7 @@
Project.NameKey newProjectKey,
ProgressMonitor pm)
throws OrmException {
- pm.beginTask("Updating changes in the database", ProgressMonitor.UNKNOWN);
+ pm.beginTask("Updating changes in the database");
Connection conn = ((JdbcSchema) schemaFactory.open()).getConnection();
try (Statement stmt = conn.createStatement()) {
conn.setAutoCommit(false);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/fs/FilesystemRenameHandler.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/fs/FilesystemRenameHandler.java
index 9663be4..29a76d8 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/fs/FilesystemRenameHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/fs/FilesystemRenameHandler.java
@@ -50,7 +50,7 @@
Repository repository = repoManager.openRepository(oldProjectKey);
File repoFile = repository.getDirectory();
RepositoryCache.close(repository);
- pm.beginTask("Renaming git repository", ProgressMonitor.UNKNOWN);
+ pm.beginTask("Renaming git repository");
renameGitRepository(repoFile, newProjectKey, oldProjectKey);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/CommandProgressMonitor.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/CommandProgressMonitor.java
index 25e8451..d614986 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/CommandProgressMonitor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/CommandProgressMonitor.java
@@ -28,6 +28,9 @@
private boolean write = true;
private Task task;
+ // Constant indicating the total work units cannot be predicted in advance.
+ private static final int UNKNOWN = 0;
+
public CommandProgressMonitor(Writer out) {
this.out = out;
}
@@ -35,7 +38,7 @@
@Override
public synchronized void beginTask(String taskName, int work) {
endTask();
- if (work == ProgressMonitor.UNKNOWN) {
+ if (work == UNKNOWN) {
task = new UnknownTask(taskName);
} else {
task = new Task(taskName, work);
@@ -43,6 +46,11 @@
}
@Override
+ public synchronized void beginTask(String taskName) {
+ beginTask(taskName, UNKNOWN);
+ }
+
+ @Override
public synchronized void update(int completed) {
if (task != null) {
task.update(completed);
@@ -137,7 +145,7 @@
private int animationCounter;
UnknownTask(String taskName) {
- super(taskName, ProgressMonitor.UNKNOWN);
+ super(taskName, UNKNOWN);
executor =
new ScheduledThreadPoolExecutor(
1, new ThreadFactoryBuilder().setNameFormat("Rename-Monitoring-%d").build());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/NoopMonitor.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/NoopMonitor.java
index fac2d11..a03d907 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/NoopMonitor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/NoopMonitor.java
@@ -29,6 +29,11 @@
}
@Override
+ public void beginTask(String title) {
+ // Do not report.
+ }
+
+ @Override
public void update(int completed) {
// Do not report.
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/ProgressMonitor.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/ProgressMonitor.java
index d7a0916..d857e67 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/ProgressMonitor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/monitor/ProgressMonitor.java
@@ -16,19 +16,22 @@
public interface ProgressMonitor {
- /** Constant indicating the total work units cannot be predicted. */
- int UNKNOWN = 0;
-
/**
* Begin processing a single task.
*
* @param title title to describe the task.
- * @param totalWork total number of work units the application will perform; {@link #UNKNOWN} if
- * it cannot be predicted in advance.
+ * @param totalWork total number of work units the application will perform.
*/
void beginTask(String title, int totalWork);
/**
+ * Begin processing a single task of unknown work units.
+ *
+ * @param title title to describe the task.
+ */
+ void beginTask(String title);
+
+ /**
* Denote that some work units have been completed.
*
* <p>This is an incremental update; if invoked once per work unit the correct value for our