Repository: activemq-artemis
Updated Branches:
  refs/heads/master a2a88625d -> 879f4a6bb


Fixing silent-input over password

--silent-input was being ignored on password. This is a little fix
I have also moved an abstract just for InputAbstract


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/14cb3a07
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/14cb3a07
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/14cb3a07

Branch: refs/heads/master
Commit: 14cb3a07a031d4ef7056f4d9f1232d806802e078
Parents: a2a8862
Author: Clebert Suconic <clebertsuco...@apache.org>
Authored: Wed May 20 15:42:07 2015 -0400
Committer: Clebert Suconic <clebertsuco...@apache.org>
Committed: Wed May 20 22:42:39 2015 -0400

----------------------------------------------------------------------
 .../artemis/cli/commands/ActionAbstract.java    |  71 ------------
 .../activemq/artemis/cli/commands/Create.java   |  10 +-
 .../artemis/cli/commands/InputAbstract.java     | 111 +++++++++++++++++++
 3 files changed, 112 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/14cb3a07/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java
----------------------------------------------------------------------
diff --git 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java
 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java
index 6b3b3a6..d00f4ac 100644
--- 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java
+++ 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java
@@ -16,86 +16,15 @@
  */
 package org.apache.activemq.artemis.cli.commands;
 
-import java.util.Scanner;
-
 public abstract class ActionAbstract implements Action
 {
 
    protected ActionContext context;
 
-   private Scanner scanner;
-
-   private boolean noInput = false;
-
-   protected void disableInputs()
-   {
-      noInput = true;
-
-   }
-
-   protected String input(String propertyName, String prompt, String 
silentDefault)
-   {
-      if (noInput)
-      {
-         return silentDefault;
-      }
-      String inputStr;
-      boolean valid = false;
-      System.out.println();
-      do
-      {
-         context.out.println(propertyName + ": is mandatory with this 
configuration:");
-         context.out.println(prompt);
-         inputStr = scanner.nextLine();
-         if (inputStr.trim().equals(""))
-         {
-            System.out.println("Invalid Entry!");
-         }
-         else
-         {
-            valid = true;
-         }
-      }
-      while (!valid);
-
-      return inputStr.trim();
-   }
-
-   protected String inputPassword(String propertyName, String prompt, String 
silentDefault)
-   {
-      if (noInput)
-      {
-         return silentDefault;
-      }
-      String inputStr;
-      boolean valid = false;
-      System.out.println();
-      do
-      {
-         context.out.println(propertyName + ": is mandatory with this 
configuration:");
-         context.out.println(prompt);
-         inputStr = new String(System.console().readPassword());
-
-         if (inputStr.trim().equals(""))
-         {
-            System.out.println("Invalid Entry!");
-         }
-         else
-         {
-            valid = true;
-         }
-      }
-      while (!valid);
-
-      return inputStr.trim();
-   }
-
    public Object execute(ActionContext context) throws Exception
    {
       this.context = context;
 
-      scanner = new Scanner(context.in);
-
       return null;
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/14cb3a07/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
----------------------------------------------------------------------
diff --git 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
index d99f287..9fae68b 100644
--- 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
+++ 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
@@ -51,7 +51,7 @@ import static 
java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
  * CLI action that creates a broker instance directory.
  */
 @Command(name = "create", description = "creates a new broker instance")
-public class Create extends ActionAbstract
+public class Create extends InputAbstract
 {
    private static final Integer DEFAULT_PORT = 61616;
 
@@ -132,9 +132,6 @@ public class Create extends ActionAbstract
    @Option(name = "--role", description = "The name for the role created 
(Default: amq)")
    String role;
 
-   @Option(name = "--silent-input", description = "It will disable all the 
inputs, and it would make a best guess for any required input")
-   boolean silentInput;
-
    boolean IS_WINDOWS;
 
    boolean IS_CYGWIN;
@@ -359,11 +356,6 @@ public class Create extends ActionAbstract
    {
       super.execute(context);
 
-      if (silentInput)
-      {
-         this.disableInputs();
-      }
-
       try
       {
          return run(context);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/14cb3a07/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java
----------------------------------------------------------------------
diff --git 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java
 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java
new file mode 100644
index 0000000..7578aad
--- /dev/null
+++ 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.activemq.artemis.cli.commands;
+
+import java.util.Scanner;
+
+import io.airlift.airline.Option;
+
+public class InputAbstract extends ActionAbstract
+{
+
+   private Scanner scanner;
+
+   @Option(name = "--silent-input", description = "It will disable all the 
inputs, and it would make a best guess for any required input")
+   private boolean silentInput = false;
+
+   public boolean isSilentInput()
+   {
+      return silentInput;
+   }
+
+   public void setSilentInput(boolean silentInput)
+   {
+      this.silentInput = silentInput;
+   }
+
+   protected String input(String propertyName, String prompt, String 
silentDefault)
+   {
+      if (silentInput)
+      {
+         return silentDefault;
+      }
+
+      String inputStr;
+      boolean valid = false;
+      System.out.println();
+      do
+      {
+         context.out.println(propertyName + ": is mandatory with this 
configuration:");
+         context.out.println(prompt);
+         inputStr = scanner.nextLine();
+         if (inputStr.trim().equals(""))
+         {
+            System.out.println("Invalid Entry!");
+         }
+         else
+         {
+            valid = true;
+         }
+      }
+      while (!valid);
+
+      return inputStr.trim();
+   }
+
+   protected String inputPassword(String propertyName, String prompt, String 
silentDefault)
+   {
+      if (silentInput)
+      {
+         return silentDefault;
+      }
+
+      String inputStr;
+      boolean valid = false;
+      System.out.println();
+      do
+      {
+         context.out.println(propertyName + ": is mandatory with this 
configuration:");
+         context.out.println(prompt);
+         inputStr = new String(System.console().readPassword());
+
+         if (inputStr.trim().equals(""))
+         {
+            System.out.println("Invalid Entry!");
+         }
+         else
+         {
+            valid = true;
+         }
+      }
+      while (!valid);
+
+      return inputStr.trim();
+   }
+
+   @Override
+   public Object execute(ActionContext context) throws Exception
+   {
+      super.execute(context);
+
+      this.scanner = new Scanner(context.in);
+
+      return null;
+   }
+
+}

Reply via email to