Merge "SSH command complete-project to complete project import"
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImportCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImportCommand.java
new file mode 100644
index 0000000..4a7ea73
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImportCommand.java
@@ -0,0 +1,51 @@
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.importer;
+
+import com.google.gerrit.extensions.annotations.RequiresCapability;
+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.sshd.CommandMetaData;
+import com.google.gerrit.sshd.SshCommand;
+import com.google.inject.Inject;
+
+import org.kohsuke.args4j.Argument;
+
+@RequiresCapability(ImportCapability.ID)
+@CommandMetaData(name = "complete-project", description = "Completes project import")
+class CompleteProjectImportCommand extends SshCommand {
+
+  @Argument(index = 0, required = true, metaVar = "NAME",
+      usage = "name of the project in target system")
+  private String project;
+
+  @Inject
+  private CompleteProjectImport completeProjectImport;
+
+  @Inject
+  private ProjectsCollection projects;
+
+  @Override
+  protected void run() throws ResourceConflictException,
+      ResourceNotFoundException, UnloggedFailure {
+    try {
+      ImportProjectResource rsrc = projects.parse(project);
+      completeProjectImport.apply(rsrc, new CompleteProjectImport.Input());
+    } catch (RestApiException e) {
+      throw die(e.getMessage());
+    }
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/SshModule.java b/src/main/java/com/googlesource/gerrit/plugins/importer/SshModule.java
index 466643a..29a452d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/SshModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/SshModule.java
@@ -23,6 +23,7 @@
     command(ListProjectImportsCommand.class);
     command(ResumeProjectCommand.class);
     command(CopyProjectCommand.class);
+    command(CompleteProjectImportCommand.class);
 
     command(GroupCommand.class);
   }
diff --git a/src/main/resources/Documentation/cmd-complete-project.md b/src/main/resources/Documentation/cmd-complete-project.md
new file mode 100644
index 0000000..4d470fd
--- /dev/null
+++ b/src/main/resources/Documentation/cmd-complete-project.md
@@ -0,0 +1,34 @@
+@PLUGIN@ complete-project
+=========================
+
+NAME
+----
+@PLUGIN@ complete-project - Completes a project import
+
+SYNOPSIS
+--------
+```
+ssh -p @SSH_PORT@ @SSH_HOST@ @PLUGIN@ complete-project <NAME>
+```
+
+DESCRIPTION
+-----------
+Completes a project import.
+
+ACCESS
+------
+Caller must be a member of a group that is granted the 'Import'
+capability (provided by this plugin) or the 'Administrate Server'
+capability.
+
+SCRIPTING
+---------
+This command is intended to be used in scripts.
+
+EXAMPLES
+--------
+Complete the import of the myProject project:
+
+```
+  $ ssh -p @SSH_PORT@ @SSH_HOST@ @PLUGIN@ complete-project myProject
+```