geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r430136 - in /geronimo/trunk: ./ configs/shutdown/ m2-assemblies/geronimo-jetty-j2ee/src/main/assembly/ m2-assemblies/geronimo-jetty-minimal/src/main/assembly/ m2-assemblies/geronimo-tomcat-j2ee/src/main/assembly/ m2-assemblies/geronimo-tom...
Date Wed, 09 Aug 2006 20:21:52 GMT
Author: jdillon
Date: Wed Aug  9 13:21:52 2006
New Revision: 430136

URL: http://svn.apache.org/viewvc?rev=430136&view=rev
Log:
(GERONIMO-2216) Use JLine API to get password interactively when using shutdown


Added:
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/InputPrompt.java
  (with props)
Modified:
    geronimo/trunk/configs/shutdown/pom.xml
    geronimo/trunk/m2-assemblies/geronimo-jetty-j2ee/src/main/assembly/bin.xml
    geronimo/trunk/m2-assemblies/geronimo-jetty-minimal/src/main/assembly/bin.xml
    geronimo/trunk/m2-assemblies/geronimo-tomcat-j2ee/src/main/assembly/bin.xml
    geronimo/trunk/m2-assemblies/geronimo-tomcat-minimal/src/main/assembly/bin.xml
    geronimo/trunk/modules/deploy-tool/pom.xml
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java
    geronimo/trunk/pom.xml

Modified: geronimo/trunk/configs/shutdown/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/trunk/configs/shutdown/pom.xml?rev=430136&r1=430135&r2=430136&view=diff
==============================================================================
--- geronimo/trunk/configs/shutdown/pom.xml (original)
+++ geronimo/trunk/configs/shutdown/pom.xml Wed Aug  9 13:21:52 2006
@@ -50,6 +50,7 @@
                         <element>../lib/log4j-${log4jVersion}.jar</element>
                         <element>../lib/mx4j-${mx4jVersion}.jar</element>
                         <element>../lib/mx4j-remote-${mx4jVersion}.jar</element>
+                        <element>../lib/jline-${jlineVersion}.jar</element>
                     </classPath>
                     <mainClass>org.apache.geronimo.deployment.cli.StopServer</mainClass>
                 </configuration>

Modified: geronimo/trunk/m2-assemblies/geronimo-jetty-j2ee/src/main/assembly/bin.xml
URL: http://svn.apache.org/viewvc/geronimo/trunk/m2-assemblies/geronimo-jetty-j2ee/src/main/assembly/bin.xml?rev=430136&r1=430135&r2=430136&view=diff
==============================================================================
--- geronimo/trunk/m2-assemblies/geronimo-jetty-j2ee/src/main/assembly/bin.xml (original)
+++ geronimo/trunk/m2-assemblies/geronimo-jetty-j2ee/src/main/assembly/bin.xml Wed Aug  9
13:21:52 2006
@@ -56,6 +56,7 @@
                 <include>mx4j:mx4j-remote</include>
                 <include>xpp3:xpp3</include>
                 <include>xstream:xstream</include>
+                <include>jline:jline</include>
             </includes>
         </dependencySet>
         

Modified: geronimo/trunk/m2-assemblies/geronimo-jetty-minimal/src/main/assembly/bin.xml
URL: http://svn.apache.org/viewvc/geronimo/trunk/m2-assemblies/geronimo-jetty-minimal/src/main/assembly/bin.xml?rev=430136&r1=430135&r2=430136&view=diff
==============================================================================
--- geronimo/trunk/m2-assemblies/geronimo-jetty-minimal/src/main/assembly/bin.xml (original)
+++ geronimo/trunk/m2-assemblies/geronimo-jetty-minimal/src/main/assembly/bin.xml Wed Aug
 9 13:21:52 2006
@@ -56,6 +56,7 @@
                 <include>mx4j:mx4j-remote</include>
                 <include>xpp3:xpp3</include>
                 <include>xstream:xstream</include>
+                <include>jline:jline</include>
             </includes>
         </dependencySet>
         

Modified: geronimo/trunk/m2-assemblies/geronimo-tomcat-j2ee/src/main/assembly/bin.xml
URL: http://svn.apache.org/viewvc/geronimo/trunk/m2-assemblies/geronimo-tomcat-j2ee/src/main/assembly/bin.xml?rev=430136&r1=430135&r2=430136&view=diff
==============================================================================
--- geronimo/trunk/m2-assemblies/geronimo-tomcat-j2ee/src/main/assembly/bin.xml (original)
+++ geronimo/trunk/m2-assemblies/geronimo-tomcat-j2ee/src/main/assembly/bin.xml Wed Aug  9
13:21:52 2006
@@ -56,6 +56,7 @@
                 <include>mx4j:mx4j-remote</include>
                 <include>xpp3:xpp3</include>
                 <include>xstream:xstream</include>
+                <include>jline:jline</include>
             </includes>
         </dependencySet>
         

Modified: geronimo/trunk/m2-assemblies/geronimo-tomcat-minimal/src/main/assembly/bin.xml
URL: http://svn.apache.org/viewvc/geronimo/trunk/m2-assemblies/geronimo-tomcat-minimal/src/main/assembly/bin.xml?rev=430136&r1=430135&r2=430136&view=diff
==============================================================================
--- geronimo/trunk/m2-assemblies/geronimo-tomcat-minimal/src/main/assembly/bin.xml (original)
+++ geronimo/trunk/m2-assemblies/geronimo-tomcat-minimal/src/main/assembly/bin.xml Wed Aug
 9 13:21:52 2006
@@ -56,6 +56,7 @@
                 <include>mx4j:mx4j-remote</include>
                 <include>xpp3:xpp3</include>
                 <include>xstream:xstream</include>
+                <include>jline:jline</include>
             </includes>
         </dependencySet>
         

Modified: geronimo/trunk/modules/deploy-tool/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/trunk/modules/deploy-tool/pom.xml?rev=430136&r1=430135&r2=430136&view=diff
==============================================================================
--- geronimo/trunk/modules/deploy-tool/pom.xml (original)
+++ geronimo/trunk/modules/deploy-tool/pom.xml Wed Aug  9 13:21:52 2006
@@ -46,6 +46,7 @@
     </scm>
     
     <dependencies>
+        
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-j2ee-deployment_1.1_spec</artifactId>
@@ -86,6 +87,14 @@
             <artifactId>geronimo-deploy-jsr88</artifactId>
             <version>${pom.version}</version>
         </dependency>
+        
+        <!-- Thirdparty Dependencies -->
+        
+        <dependency>
+            <groupId>jline</groupId>
+            <artifactId>jline</artifactId>
+        </dependency>
+        
     </dependencies>
     
 </project>

Added: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/InputPrompt.java
URL: http://svn.apache.org/viewvc/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/InputPrompt.java?rev=430136&view=auto
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/InputPrompt.java
(added)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/InputPrompt.java
Wed Aug  9 13:21:52 2006
@@ -0,0 +1,74 @@
+/**
+ *  Copyright 2003-2006 The Apache Software Foundation
+ *
+ *  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 org.apache.geronimo.deployment.cli;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
+
+import jline.ConsoleReader;
+
+/**
+ * Prompts a user for input; optionally masking.
+ *
+ * <p>
+ * Uses the <a href="http://jline.sf.net">JLine</a> library to provide a rich
user experence.
+ *
+ * @version $Rev$ $Date$
+ */
+public class InputPrompt
+{
+    private ConsoleReader reader;
+
+    public InputPrompt(final InputStream in, final Writer out) throws IOException {
+        this.reader = new ConsoleReader(in, out);
+    }
+
+    public InputPrompt(final InputStream in, final OutputStream out) throws IOException {
+        this(in, new PrintWriter(new OutputStreamWriter(out), true));
+    }
+
+    /**
+     * Displays the prompt, grabs the input.
+     */
+    public String getInput(final String prompt, final Character mask) throws IOException
{
+        if (mask == null) {
+            return reader.readLine(prompt);
+        }
+        else {
+            return reader.readLine(prompt, mask);
+        }
+    }
+
+    public String getInput(final String prompt, final char mask) throws IOException {
+        return getInput(prompt, new Character(mask));
+    }
+
+    public String getInput(final String prompt) throws IOException {
+        return getInput(prompt, null);
+    }
+
+    /**
+     * Displays the prompt, grabs the input masking with '*'.
+     */
+    public String getPassword(final String prompt) throws IOException {
+        return getInput(prompt, '*');
+    }
+}
\ No newline at end of file

Propchange: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/InputPrompt.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/InputPrompt.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/InputPrompt.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java
URL: http://svn.apache.org/viewvc/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java?rev=430136&r1=430135&r2=430136&view=diff
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java
(original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java
Wed Aug  9 13:21:52 2006
@@ -18,7 +18,6 @@
 package org.apache.geronimo.deployment.cli;
 
 import java.io.BufferedInputStream;
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -109,12 +108,12 @@
 
     private DeploymentManager manager;
     private PrintWriter out;
-    private BufferedReader in;
+    private InputStream in;
     private SavedAuthentication auth;
     private boolean logToSysErr;
     private boolean verboseMessages;
 
-    public ServerConnection(String[] args, PrintWriter out, BufferedReader in) throws DeploymentException
{
+    public ServerConnection(String[] args, PrintWriter out, InputStream in) throws DeploymentException
{
         String uri = null, driver = null, user = null, password = null, host = null;
         Integer port = null;
         this.out = out;
@@ -248,6 +247,7 @@
                     try {
                         in = new BufferedInputStream(new FileInputStream(authFile));
                     } catch (FileNotFoundException e) {
+                        // ignore
                     }
                 }
             }
@@ -277,6 +277,7 @@
                     try {
                         in.close();
                     } catch (IOException e) {
+                        // ingore
                     }
                 }
             }
@@ -332,13 +333,12 @@
 
     private void doAuthPromptAndRetry(String uri, String user, String password) throws DeploymentException
{
         try {
+            InputPrompt prompt = new InputPrompt(in, out);
             if (user == null) {
-                out.print("Username: ");
-                out.flush();
-                user = in.readLine();
+                user = prompt.getInput("Username: ");
             }
             if (password == null) {
-                password = new PasswordPrompt("Password: ", out).getPassword(in);
+                password = prompt.getPassword("Password: ");
             }
         } catch (IOException e) {
             throw new DeploymentException("Unable to prompt for login", e);
@@ -352,75 +352,6 @@
 
     public boolean isGeronimo() {
         return manager.getClass().getName().startsWith("org.apache.geronimo.");
-    }
-
-
-    /**
-     * Prompts for and grabs a password, trying to suppress any console output
-     * along the way.  Kind of heavy-handed, but we don't have access to any
-     * platform-specific APIs that might make this nicer.
-     */
-    public static class PasswordPrompt implements Runnable {
-        private volatile boolean done = false;
-        private String prompt;
-        private PrintWriter out;
-
-        public PasswordPrompt(String prompt, PrintWriter out) {
-            this.prompt = prompt;
-            this.out = out;
-        }
-
-        /**
-         * Don't call this directly.
-         */
-        public void run() {
-            int priority = Thread.currentThread().getPriority();
-            try {
-                Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
-                String fullPrompt = "\r" + prompt + "          " + "\r" + prompt;
-                StringBuffer clearline = new StringBuffer();
-                clearline.append('\r');
-                for (int i = prompt.length() + 10; i >= 0; i--) {
-                    clearline.append(' ');
-                }
-                while (!done) {
-                    out.print(fullPrompt);
-                    out.flush();
-                    Thread.sleep(1);
-                }
-                out.print(clearline.toString());
-                out.flush();
-                out.println();
-                out.flush();
-            } catch (InterruptedException e) {
-            } finally {
-                Thread.currentThread().setPriority(priority);
-            }
-            prompt = null;
-            out = null;
-        }
-
-        /**
-         * Displays the prompt, grabs the password, cleans up, and returns
-         * the entered password.  For this to make sense, the input reader
-         * here must be part of the same console as the output writer passed
-         * to the constructor.
-         * <p/>
-         * For higher security, should return a char[], but that will just
-         * be defeated by the JSR-88 call that takes a String anyway, so
-         * why bother?
-         */
-        public String getPassword(BufferedReader in) throws IOException {
-            Thread t = new Thread(this, "Password hiding thread");
-            t.start();
-            String password = in.readLine();
-            done = true;
-            try {
-                t.join();
-            } catch (InterruptedException e) {
-            }
-            return password;
-        }
     }
 
     private final static class SavedAuthentication implements Serializable {

Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java
URL: http://svn.apache.org/viewvc/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java?rev=430136&r1=430135&r2=430136&view=diff
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java
(original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java
Wed Aug  9 13:21:52 2006
@@ -1,6 +1,5 @@
 /**
- *
- * Copyright 2005 The Apache Software Foundation
+ *  Copyright 2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -14,13 +13,10 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
+
 package org.apache.geronimo.deployment.cli;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
 import java.net.MalformedURLException;
 import java.util.HashMap;
 import java.util.Map;
@@ -30,7 +26,6 @@
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 
-import org.apache.geronimo.deployment.cli.ServerConnection.PasswordPrompt;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.system.jmx.KernelDelegate;
 
@@ -51,76 +46,69 @@
 
 	private String[] args;
 
-	public static void main(String[] args) {
+	public static void main(String[] args) throws Exception {
 		StopServer cmd = new StopServer();
 		cmd.execute(args);
 	}
 
-	public void execute(String args[]) {
+	public void execute(String args[]) throws IOException {
+        this.args = args;
 
-		this.args = args;
-
-		int i = 0;
-		while (i < args.length && args[i].startsWith("--")) {
-			if (setParam(i++)) {
-				i++;
-			}
-		}
-
-		if (i < args.length) {
-			// There was an argument error somewhere.
-			printUsage();
-		}
-
-		try {
-			if (port != null) {
-				Integer.parseInt(port);
-			}
-		} catch (NumberFormatException e) {
-			System.out.println("Invalid port number specified.");
-			System.exit(1);
-		}
-
-		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out),
-				true);
-		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
-		try {
-			if (user == null) {
-				out.print("Username: ");
-				out.flush();
-				user = in.readLine();
-			}
-			if (password == null) {
-				password = new PasswordPrompt("Password: ", out)
-						.getPassword(in);
-			}
-		} catch (IOException e) {
-			System.out.println("Unable to prompt for login.");
-			System.exit(1);
-		}
-
-		try {
-			if (port == null) {
-				port = DEFAULT_PORT;
-			}
-			System.out.print("Locating server on port " + port + "... ");
-			Kernel kernel = null;
-			try {
-				kernel = getRunningKernel();
-			} catch (IOException e) {
-				System.out
-						.println("\nCould not communicate with the server.  The server may not be running or
the port number may be incorrect.");
-			}
-			if (kernel != null) {
-				System.out.println("Server found.");
-				System.out.println("Server shutdown begun");
-				kernel.shutdown();
-				System.out.println("Server shutdown completed");
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-	}
+        int i = 0;
+        while (i < args.length && args[i].startsWith("--")) {
+            if (setParam(i++)) {
+                i++;
+            }
+        }
+
+        if (i < args.length) {
+            // There was an argument error somewhere.
+            printUsage();
+        }
+
+        try {
+            if (port != null) {
+                Integer.parseInt(port);
+            }
+        } catch (NumberFormatException e) {
+            System.out.println("Invalid port number specified.");
+            System.exit(1);
+        }
+
+        InputPrompt prompt = new InputPrompt(System.in, System.out);
+        try {
+            if (user == null) {
+                user = prompt.getInput("Username: ");
+            }
+            if (password == null) {
+                password = prompt.getPassword("Password: ");
+            }
+        } catch (IOException e) {
+            System.out.println("Unable to prompt for login.");
+            System.exit(1);
+        }
+
+        try {
+            if (port == null) {
+                port = DEFAULT_PORT;
+            }
+            System.out.print("Locating server on port " + port + "... ");
+            Kernel kernel = null;
+            try {
+                kernel = getRunningKernel();
+            } catch (IOException e) {
+                System.out.println("\nCould not communicate with the server.  The server
may not be running or the port number may be incorrect.");
+            }
+            if (kernel != null) {
+                System.out.println("Server found.");
+                System.out.println("Server shutdown begun");
+                kernel.shutdown();
+                System.out.println("Server shutdown completed");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
 	private boolean argumentHasValue(int i) {
 		return i + 1 < args.length && !args[i + 1].startsWith("--");
@@ -150,14 +138,10 @@
 		Kernel kernel = null;
 		try {
 			JMXServiceURL address = new JMXServiceURL(
-					"service:jmx:rmi:///jndi/rmi://localhost" + ":" + port
-							+ "/JMXConnector");
-			JMXConnector jmxConnector = JMXConnectorFactory.connect(address,
-					map);
-			MBeanServerConnection mbServerConnection = jmxConnector
-					.getMBeanServerConnection();
+					"service:jmx:rmi:///jndi/rmi://localhost" + ":" + port + "/JMXConnector");
+			JMXConnector jmxConnector = JMXConnectorFactory.connect(address, map);
+			MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection();
 			kernel = new KernelDelegate(mbServerConnection);
-
 		} catch (MalformedURLException e) {
 			e.printStackTrace();
 		}

Modified: geronimo/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/trunk/pom.xml?rev=430136&r1=430135&r2=430136&view=diff
==============================================================================
--- geronimo/trunk/pom.xml (original)
+++ geronimo/trunk/pom.xml Wed Aug  9 13:21:52 2006
@@ -83,6 +83,7 @@
         <geronimoSpecJ2eeDeploymentVersion>1.0.1</geronimoSpecJ2eeDeploymentVersion>
         <geronimoSpecJmsVersion>1.0.1</geronimoSpecJmsVersion>
         <concurrentVersion>1.3.4</concurrentVersion>
+        <jlineVersion>0.9.9</jlineVersion>
     </properties>
     
     <dependencyManagement>
@@ -200,6 +201,13 @@
             </dependency>
             
             <!-- External dependency versions -->
+            
+            <dependency>
+                <groupId>jline</groupId>
+                <artifactId>jline</artifactId>
+                <version>${jlineVersion}</version>
+                <type>jar</type>
+            </dependency>
             
             <dependency>
                 <groupId>axis</groupId>



Mime
View raw message