Merge "Fixes for 2.12 API"
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/PasswordUtil.java b/src/main/java/com/googlesource/gerrit/plugins/importer/PasswordUtil.java
new file mode 100644
index 0000000..6409e72
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/PasswordUtil.java
@@ -0,0 +1,42 @@
+// 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 static java.nio.charset.StandardCharsets.UTF_8;
+
+import com.google.common.base.Strings;
+import com.google.gerrit.sshd.BaseCommand.UnloggedFailure;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+
+class PasswordUtil {
+
+  static String readPassword(InputStream in, String pass)
+      throws UnsupportedEncodingException, IOException, UnloggedFailure {
+    if ("-".equals(pass)) {
+      BufferedReader br = new BufferedReader(
+          new InputStreamReader(in, UTF_8));
+      pass = Strings.nullToEmpty(br.readLine());
+      if (br.readLine() != null) {
+        throw new UnloggedFailure(1, "multi-line password not allowed");
+      }
+    }
+    return 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 abaa0e1..e041fb8 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java
@@ -14,8 +14,6 @@
 
 package com.googlesource.gerrit.plugins.importer;
 
-import static java.nio.charset.StandardCharsets.UTF_8;
-
 import com.google.common.base.Strings;
 import com.google.gerrit.common.errors.NoSuchAccountException;
 import com.google.gerrit.extensions.annotations.RequiresCapability;
@@ -33,10 +31,7 @@
 import org.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.Option;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 
 @RequiresCapability(ImportCapability.ID)
 @CommandMetaData(name = "project", description = "Imports a project")
@@ -80,7 +75,7 @@
     input.from = url;
     input.name = name;
     input.user = user;
-    input.pass = readPassword();
+    input.pass = PasswordUtil.readPassword(in, pass);
     if (!Strings.isNullOrEmpty(parent)) {
       input.parent = parent;
     }
@@ -96,16 +91,4 @@
       throw die(e.getMessage());
     }
   }
-
-  private String readPassword() throws UnsupportedEncodingException,
-      IOException, UnloggedFailure {
-    if ("-".equals(pass)) {
-      BufferedReader br = new BufferedReader(new InputStreamReader(in, UTF_8));
-      pass = Strings.nullToEmpty(br.readLine());
-      if (br.readLine() != null) {
-        throw die("multi-line password not allowed");
-      }
-    }
-    return pass;
-  }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectCommand.java
index 9104d91..fb2a4a4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectCommand.java
@@ -60,7 +60,7 @@
       }
       ResumeProjectImport.Input input = new ResumeProjectImport.Input();
       input.user = user;
-      input.pass = pass;
+      input.pass = PasswordUtil.readPassword(in, pass);
       input.force = force;
       ResumeImportStatistic stats = resume.apply(rsrc, input);
       stdout.print("Created Changes: " + stats.numChangesCreated + "\n");