[jboss-cvs] JBossAS SVN: r88567 - in branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient: command and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 8 19:18:57 EDT 2009


Author: ispringer
Date: 2009-05-08 19:18:57 -0400 (Fri, 08 May 2009)
New Revision: 88567

Removed:
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/RefreshCommand.java
Modified:
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/HelpCommand.java
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListComponentsCommand.java
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListDeploymentsCommand.java
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/LoadCommand.java
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/QuitCommand.java
   branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ReloadCommand.java
Log:
various minor improvements



Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -29,9 +29,9 @@
 import java.io.StreamTokenizer;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
 import jline.ArgumentCompletor;
 import jline.Completor;
@@ -66,7 +66,8 @@
             QuitCommand.class,
             ReloadCommand.class
     };
-    private static final Map<String, ClientCommand> COMMANDS = new HashMap<String, ClientCommand>();
+    // Use a TreeMap, so the commands will be sorted by name (e.g. for display by the help command).
+    private static final Map<String, ClientCommand> COMMANDS = new TreeMap<String, ClientCommand>();
 
     static
     {
@@ -76,7 +77,7 @@
             try
             {
                 command = (ClientCommand)commandClass.newInstance();
-                COMMANDS.put(command.getPromptCommandString(), command);
+                COMMANDS.put(command.getName(), command);
             }
             catch (Exception e)
             {
@@ -157,30 +158,17 @@
 
     public String getUserInput(String prompt)
     {
-
         String inputString = "";
         boolean useDefaultPrompt = (prompt == null);
 
         while ((inputString != null) && (inputString.trim().length() == 0))
         {
             if (prompt == null)
-            {
-                if (!isConnected())
-                {
-                    prompt = "unconnected> ";
-                }
-                else
-                {
-                    prompt = host + ":" + port + "> ";
-                }
-            }
-//            outputWriter.print(prompt);
-
+                prompt = isConnected() ? (this.host + ":" + this.port + "> ") : "disconnected> ";
             try
             {
-                outputWriter.flush();
-                inputString = consoleReader.readLine(prompt);
-                //inputReader.readLine();
+                this.outputWriter.flush();
+                inputString = this.consoleReader.readLine(prompt);
             }
             catch (Exception e)
             {
@@ -272,8 +260,7 @@
     {
         boolean continueRunning;
         try
-                    {
-                        // parse the command into separate arguments and execute it
+        {
             String[] cmdArgs = parseCommandLine(cmd);
             continueRunning = executeCommand(cmdArgs);
         }
@@ -293,7 +280,8 @@
             ClientCommand command = COMMANDS.get(commandName);
             if (command.isConnectionRequired() && !isConnected())
             {
-                outputWriter.println("The '" + commandName + "' command requires a connection. Please run the 'connect' command first.");
+                outputWriter.println("The '" + commandName
+                        + "' command requires a connection. Please run the 'connect' command first.");
                 return true;
             }
             String[] params = new String[args.length - 1];
@@ -345,7 +333,7 @@
         ByteArrayInputStream in = new ByteArrayInputStream(cmdLine.getBytes());
         StreamTokenizer strtok = new StreamTokenizer(new InputStreamReader(in));
         List<String> args = new ArrayList<String>();
-        boolean keep_going = true;
+        boolean keepGoing = true;
 
         // we don't want to parse numbers and we want ' to be a normal word character
         strtok.ordinaryChars('0', '9');
@@ -356,7 +344,7 @@
         strtok.quoteChar('\"');
 
         // parse the command line
-        while (keep_going)
+        while (keepGoing)
         {
             int nextToken;
 
@@ -379,7 +367,7 @@
             }
             else if ((nextToken == java.io.StreamTokenizer.TT_EOF) || (nextToken == java.io.StreamTokenizer.TT_EOL))
             {
-                keep_going = false;
+                keepGoing = false;
             }
         }
 
@@ -427,10 +415,11 @@
 
         String execute = (String)options.valueOf("execute");
         if (execute != null) {
-            String[] commands = execute.split(";");
-            for (String command : commands)
+            String[] tokens = execute.split(";");
+            for (String token : tokens)
             {
-                if (!executeCommand(command))
+                String commandName = token.trim();
+                if (!executeCommand(commandName))
                     System.exit(0);
             }
         }

Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -32,13 +32,13 @@
 public interface ClientCommand
 {
     /**
-     * All implementations must indicate what the prompt command is that will trigger its execution. This method returns
-     * the prompt command name.
+     * All implementations must indicate what the prompt command name is that will trigger its execution. This method
+     * returns that name.
      *
-     * @return the prompt command string - if the first prompt argument is this value, then this prompt command will be
+     * @return the prompt command name - if the first prompt argument is this value, then this command will be
      *         executed.
      */
-    String getPromptCommandString();
+    String getName();
 
     /**
      * Executes the agent prompt command with the given arguments.

Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -36,7 +36,7 @@
 {
     public static final String COMMAND_NAME = "connect";
 
-    public String getPromptCommandString()
+    public String getName()
     {
         return COMMAND_NAME;
     }
@@ -61,7 +61,7 @@
     public boolean execute(AdminClientMain client, OptionSet options)
     {
         if (!options.nonOptionArguments().isEmpty())
-            throw new IllegalArgumentException("Usage: " + getPromptCommandString() + " ...");
+            throw new IllegalArgumentException("Usage: " + getName() + " ...");
         String host = options.has("host") ? (String)options.valueOf("host") : "127.0.0.1";
         int port = options.has("port") ? (Integer)options.valueOf("port") : 1099;
         String username = (String)options.valueOf("username");

Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -31,7 +31,7 @@
  */
 public class DisconnectCommand extends AbstractClientCommand
 {
-    public String getPromptCommandString()
+    public String getName()
     {
         return "disconnect";
     }
@@ -44,7 +44,7 @@
     public boolean execute(AdminClientMain client, OptionSet options)
     {
         if (!options.nonOptionArguments().isEmpty())
-            throw new IllegalArgumentException("Usage: " + getPromptCommandString());
+            throw new IllegalArgumentException("Usage: " + getName());
         if (client.getConnection() != null)
             client.getConnection().getConnectionProvider().disconnect();
         client.getPrintWriter().println("Disconnected.");

Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/HelpCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/HelpCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/HelpCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -31,7 +31,7 @@
  */
 public class HelpCommand extends AbstractClientCommand
 {
-    public String getPromptCommandString()
+    public String getName()
     {
         return "help";
     }
@@ -45,24 +45,24 @@
     {
         List<String> nonOptionArgs = options.nonOptionArguments();
         if (nonOptionArgs.size() > 1)
-            throw new IllegalArgumentException("Usage: " + getPromptCommandString() + " [command]");
+            throw new IllegalArgumentException("Usage: " + getName() + " [command]");
         if (nonOptionArgs.isEmpty()) {
             client.getPrintWriter().println("The following commands are available:\n");
             for (ClientCommand command : client.getCommands().values()) {
                 if (!command.isUndocumented())
-                    client.getPrintWriter().println("    " + command.getPromptCommandString() + "\t" + command.getHelp());
+                    client.getPrintWriter().printf("  %-16s  %s\n", command.getName(), command.getHelp());
             }
             client.getPrintWriter().println("\nEnter 'help <command>' to display detailed help for a command.");
         } else {
             String commandName = nonOptionArgs.get(0);
             ClientCommand command = client.getCommands().get(commandName);
             if (command != null) {
-                client.getPrintWriter().println("Command: " + command.getPromptCommandString());
+                client.getPrintWriter().println("Command: " + command.getName());
                 String detailedHelp = (command.getDetailedHelp() != null) ? command.getDetailedHelp() :
                         command.getHelp();
                 client.getPrintWriter().println("\n" + detailedHelp);
                 String syntax = "TODO";
-                client.getPrintWriter().println("Usage: " + command.getPromptCommandString() + "\t" + syntax);
+                client.getPrintWriter().println("Usage: " + command.getName() + "\t" + syntax);
                 try
                 {
                     command.getOptionParser().printHelpOn(client.getPrintWriter());
@@ -80,7 +80,7 @@
 
     public String getHelp()
     {
-        return "Refresh the Profile Service management view.";
+        return "Display a list of available commands or the syntax for a specific command.";
     }
 
     public String getDetailedHelp()

Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListComponentsCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListComponentsCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListComponentsCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -37,7 +37,7 @@
  */
 public class ListComponentsCommand extends AbstractClientCommand
 {
-    public String getPromptCommandString()
+    public String getName()
     {
         return "listcomponents";
     }
@@ -51,7 +51,7 @@
     {
         List<String> nonOptionArgs = options.nonOptionArguments();
         if (nonOptionArgs.size() != 2)
-            throw new IllegalArgumentException("Usage: " + getPromptCommandString() + " <type> <subtype>");
+            throw new IllegalArgumentException("Usage: " + getName() + " <type> <subtype>");
         String type = nonOptionArgs.get(0);
         String subtype = nonOptionArgs.get(1);
         ManagementView managementView = client.getConnection().getManagementView();

Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListDeploymentsCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListDeploymentsCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListDeploymentsCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -34,7 +34,7 @@
  */
 public class ListDeploymentsCommand extends AbstractClientCommand
 {
-    public String getPromptCommandString()
+    public String getName()
     {
         return "listdeployments";
     }
@@ -53,7 +53,7 @@
     public boolean execute(AdminClientMain client, OptionSet options)
     {
         if (!options.nonOptionArguments().isEmpty())
-            throw new IllegalArgumentException("Usage: " + getPromptCommandString() + " [--type <type>]");
+            throw new IllegalArgumentException("Usage: " + getName() + " [--type <type>]");
         String type = (String)options.valueOf("type");
         ManagementView managementView = client.getConnection().getManagementView();
         Set<String> deploymentNames;

Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/LoadCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/LoadCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/LoadCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -29,7 +29,7 @@
  */
 public class LoadCommand extends AbstractClientCommand
 {
-    public String getPromptCommandString()
+    public String getName()
     {
         return "load";
     }
@@ -42,7 +42,7 @@
     public boolean execute(AdminClientMain client, OptionSet options)
     {
         if (!options.nonOptionArguments().isEmpty())
-            throw new IllegalArgumentException("Usage: " + getPromptCommandString());
+            throw new IllegalArgumentException("Usage: " + getName());
         ManagementView managementView = client.getConnection().getManagementView();
         boolean wasReloaded = managementView.load();
         if (wasReloaded)

Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/QuitCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/QuitCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/QuitCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -31,7 +31,7 @@
  */
 public class QuitCommand extends AbstractClientCommand
 {
-    public String getPromptCommandString()
+    public String getName()
     {
         return "quit";
     }
@@ -44,7 +44,7 @@
     public boolean execute(AdminClientMain client, OptionSet options)
     {
         if (!options.nonOptionArguments().isEmpty())
-            throw new IllegalArgumentException("Usage: " + getPromptCommandString());
+            throw new IllegalArgumentException("Usage: " + getName());
         client.getPrintWriter().println("Goodbye.");
         return false;
     }

Deleted: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/RefreshCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/RefreshCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/RefreshCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -1,74 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.jboss.adminclient.command;
-
-import joptsimple.OptionParser;
-import joptsimple.OptionSet;
-
-import org.jboss.adminclient.AdminClientMain;
-import org.jboss.deployers.spi.management.ManagementView;
-
-/**
- * @author Ian Springer
- */
-public class RefreshCommand extends AbstractClientCommand
-{
-    public String getPromptCommandString()
-    {
-        return "refresh";
-    }
-
-    public OptionParser getOptionParser()
-    {
-        return new OptionParser();
-    }
-
-    public boolean execute(AdminClientMain client, OptionSet options)
-    {
-        if (!options.nonOptionArguments().isEmpty())
-            throw new IllegalArgumentException("Usage: " + getPromptCommandString());
-        try
-        {
-            ManagementView managementView = client.getConnection().getManagementView();
-            managementView.load();
-            client.getPrintWriter().println(managementView.getDeploymentNames());
-            client.getPrintWriter().println("Refreshed management view.");
-        }
-        catch (Exception e)
-        {
-            client.getPrintWriter().println("Failed to refresh management view: " + e);
-        }
-        return true;
-    }
-
-    public String getHelp()
-    {
-        return "Refresh the Profile Service management view.";
-    }
-
-    public String getDetailedHelp()
-    {
-        return null;
-    }
-
-    public boolean isConnectionRequired()
-    {
-        return true;
-    }
-}
\ No newline at end of file

Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ReloadCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ReloadCommand.java	2009-05-08 23:11:24 UTC (rev 88566)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ReloadCommand.java	2009-05-08 23:18:57 UTC (rev 88567)
@@ -29,7 +29,7 @@
  */
 public class ReloadCommand extends AbstractClientCommand
 {
-    public String getPromptCommandString()
+    public String getName()
     {
         return "reload";
     }
@@ -42,7 +42,7 @@
     public boolean execute(AdminClientMain client, OptionSet options)
     {
         if (!options.nonOptionArguments().isEmpty())
-            throw new IllegalArgumentException("Usage: " + getPromptCommandString());
+            throw new IllegalArgumentException("Usage: " + getName());
         ManagementView managementView = client.getConnection().getManagementView();
         managementView.reload();
         client.getPrintWriter().println("Reloaded management view.");




More information about the jboss-cvs-commits mailing list