geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r329596 - in /geronimo/trunk/modules: assembly/maven.xml deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployTool.java deploy-tool/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java
Date Sun, 30 Oct 2005 18:42:22 GMT
Author: ammulder
Date: Sun Oct 30 10:42:15 2005
New Revision: 329596

URL: http://svn.apache.org/viewcvs?rev=329596&view=rev
Log:
Deploy tool now requires --offline in order to perform offline operations
  (GERONIMO-477)
Also changed verbose and logging options to not require an argument, and
  generally better support different general option styles

Modified:
    geronimo/trunk/modules/assembly/maven.xml
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployTool.java
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java

Modified: geronimo/trunk/modules/assembly/maven.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/maven.xml?rev=329596&r1=329595&r2=329596&view=diff
==============================================================================
--- geronimo/trunk/modules/assembly/maven.xml (original)
+++ geronimo/trunk/modules/assembly/maven.xml Sun Oct 30 10:42:15 2005
@@ -368,6 +368,7 @@
             <ant:jvmarg value="-Djava.compiler=NONE"/>
             <ant:jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>
 -->
+            <ant:arg value="--offline"/>
             <ant:arg value="package"/>
             <ant:arg value="--classPath"/>
             <ant:arg value="${server.classpath}"/>
@@ -393,6 +394,7 @@
         <ant:echo>Building RMI Naming configuration</ant:echo>
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="distribute"/>
             <ant:arg value="target/plan/naming-server-plan.xml"/>
         </ant:java>
@@ -401,6 +403,7 @@
         <ant:echo>Building server configuration</ant:echo>
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="distribute"/>
             <ant:arg value="target/plan/j2ee-server-plan.xml"/>
         </ant:java>
@@ -408,17 +411,20 @@
         <ant:echo>Building security configuration</ant:echo>
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="distribute"/>
             <ant:arg value="target/plan/j2ee-security-plan.xml"/>
         </ant:java>
 
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="distribute"/>
             <ant:arg value="target/plan/j2ee-jetty-plan.xml"/>
         </ant:java>
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="distribute"/>
             <ant:arg value="target/plan/j2ee-tomcat-plan.xml"/>
         </ant:java>
@@ -426,16 +432,19 @@
         <ant:echo>Building runtime deployer configuration</ant:echo>
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="distribute"/>
             <ant:arg value="target/plan/j2ee-runtime-deployer-plan.xml"/>
         </ant:java>
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="distribute"/>
             <ant:arg value="${basedir}/target/plan/j2ee-jetty-runtime-deployer-plan.xml"/>
         </ant:java>
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="distribute"/>
             <ant:arg value="${basedir}/target/plan/j2ee-tomcat-runtime-deployer-plan.xml"/>
         </ant:java>
@@ -446,6 +455,7 @@
         <ant:mkdir dir="${geronimo.assembly.dir}/bin"/>
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="package"/>
             <ant:arg value="--mainClass"/>
             <ant:arg value="org.apache.geronimo.system.main.ClientCommandLine"/>
@@ -460,6 +470,7 @@
 
         <ant:java fork="true" jar="${geronimo.assembly.dir}/bin/deployer.jar" failonerror="true">
             <ant:jvmarg value="-ea"/>
+            <ant:arg value="--offline"/>
             <ant:arg value="distribute"/>
             <ant:arg value="target/plan/j2ee-client-plan.xml"/>
         </ant:java>

Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployTool.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployTool.java?rev=329596&r1=329595&r2=329596&view=diff
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployTool.java
(original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployTool.java
Sun Oct 30 10:42:15 2005
@@ -81,18 +81,18 @@
         PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true);
         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
         String command;
-        String[] commonArgs = new String[0];
+        String[] generalArgs = new String[0];
         String[] commandArgs = new String[0];
         if(args.length == 0) {
             command = "help";
         } else {
             String[] temp = getCommonArgsAndCommand(args);
-            if(temp == null) {
+            if(temp == null || temp.length == 0) {
                 command = "help";
             } else {
                 command = temp[temp.length-1];
-                commonArgs = new String[temp.length-1];
-                System.arraycopy(temp, 0, commonArgs, 0, temp.length-1);
+                generalArgs = new String[temp.length-1];
+                System.arraycopy(temp, 0, generalArgs, 0, temp.length-1);
                 commandArgs = new String[args.length - temp.length];
                 System.arraycopy(args, temp.length, commandArgs, 0, commandArgs.length);
             }
@@ -108,7 +108,7 @@
             } else {
                 ServerConnection con = null;
                 try {
-                    con = new ServerConnection(commonArgs, dc.isLocalOnly(), out, in);
+                    con = new ServerConnection(generalArgs, dc.isLocalOnly(), out, in);
                     try {
                         dc.execute(out, con, commandArgs);
                     } catch (DeploymentSyntaxException e) {
@@ -230,22 +230,12 @@
 
     private String[] getCommonArgsAndCommand(String[] all) {
         List list = new ArrayList();
-        boolean prefix = false;
         for (int i = 0; i < all.length; i++) {
             String s = all[i];
+            boolean option = ServerConnection.isGeneralOption(list, s);
             list.add(s);
-            if(s.startsWith("-")) {
-                if(prefix) {
-                    return null;
-                } else {
-                    prefix = true;
-                }
-            } else {
-                if(prefix) {
-                    prefix = false;
-                } else {
-                    break;
-                }
+            if(!option) {
+                break;
             }
         }
         return (String[]) list.toArray(new String[list.size()]);

Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java?rev=329596&r1=329595&r2=329596&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
Sun Oct 30 10:42:15 2005
@@ -47,12 +47,17 @@
     private final static Map OPTION_HELP = new LinkedHashMap(4);
     static {
         OPTION_HELP.put("--uri", "A URI to contact the server.  The server must be running
for this " +
-                "to work.  If not specified, the deployer default to operating on a " +
-                "Geronimo server running on the standard port on localhost, or if nothing
" +
-                "is available there, then the Geronimo server installation that the " +
-                "deployer JAR is part of.\n" +
+                "to work.  If not specified, the deployer defaults to operating on a " +
+                "Geronimo server running on the standard port on localhost.\n" +
                 "A URI to connect to Geronimo (including optional host and port parameters)
has the form: " +
                 "deployer:geronimo:jmx:rmi:///jndi/rmi:[//host[:port]]/JMXConnector");
+        OPTION_HELP.put("--offline", "Indicates that you don't want the deployer to try to
connect to " +
+                "a Geronimo server over the network.  If you're running on the same machine
as the " +
+                "Geronimo installation, using this option means that you're asserting that
the" +
+                "Geronimo server is not running.  WARNING: do not use this option if there's
a Geronimo " +
+                "server running out of the same Geronimo installation as the deploy tool
is from --" +
+                "the results may be unexpected.  Further, only a small number of commands
may be" +
+                "run in offline mode.");
         OPTION_HELP.put("--driver", "If you want to use this tool with a server other than
Geronimo, " +
                 "then you must provide the path to its driver JAR.  Currently, manifest "
+
                 "Class-Path entries in that JAR are ignored.");
@@ -61,15 +66,40 @@
                 "deployer will attempt to connect to the server with no password, and if
" +
                 "that fails, will prompt you for a password.");
         OPTION_HELP.put("--password", "Specifies a password to use to authenticate to the
server.");
-        OPTION_HELP.put("--syserr", "Log errors to syserr. Can be either true or false."
+
-                " The default value is false.");
-        OPTION_HELP.put("--verbose", "Verbose execution mode. Can be either true or false."
+
-                " The default value is false.");
+        OPTION_HELP.put("--syserr", "Enables error logging to syserr.  Disabled by default.");
+        OPTION_HELP.put("--verbose", "Enables verbose execution mode.  Disabled by default.");
     }
     public static Map getOptionHelp() {
         return OPTION_HELP;
     }
 
+    /**
+     * Checks whether the stated command-line argument is a general argument (which
+     * may be the general argument itself, or a required parameter after the general
+     * argument).  For example, if the arguments were "--user bob --offline foo" then
+     * this should return true for "--user" "bob" and "--offline" and false for "foo"
+     * (since --offline does not expect a parameter).
+     *
+     * @param args The previous arguments on the command line
+     * @param option The argument we're checking at the moment
+     *
+     * @return True if the argument we're checking is part of a general argument
+     */
+    public static boolean isGeneralOption(List args, String option) {
+        if(OPTION_HELP.containsKey(option) || option.equals("--url")) {
+            return true;
+        }
+        if(args.size() == 0) {
+            return false;
+        }
+        String last = (String) args.get(args.size()-1);
+        if(last.equals("--uri") || last.equals("--url") || last.equals("--driver") || last.equals("--user")
||
+                last.equals("--password")) {
+            return true;
+        }
+        return false;
+    }
+
     private final static String DEFAULT_URI = "deployer:geronimo:jmx:rmi:///jndi/rmi://localhost:1099/JMXConnector";
     
     private DeploymentManager manager;
@@ -79,6 +109,7 @@
 
     public ServerConnection(String[] args, boolean forceLocal, PrintWriter out, BufferedReader
in) throws DeploymentException {
         String uri = null, driver = null, user = null, password = null;
+        boolean offline = false;
         JMXDeploymentManager.CommandContext commandContext = new JMXDeploymentManager.CommandContext();
         this.out = out;
         this.in = in;
@@ -90,6 +121,9 @@
                 } else if(i >= args.length-1) {
                     throw new DeploymentSyntaxException("Must specify a URI (--uri deployer:...)");
                 }
+                if(offline) {
+                    throw new DeploymentSyntaxException("Cannot specify a URI in offline
mode");
+                }
                 uri = args[++i];
             } else if(arg.equals("--driver")) {
                 if(driver != null) {
@@ -97,13 +131,33 @@
                 } else if(i >= args.length-1) {
                     throw new DeploymentSyntaxException("Must specify a driver JAR (--driver
jarfile)");
                 }
+                if(offline) {
+                    throw new DeploymentSyntaxException("Cannot specify a driver in offline
mode");
+                }
                 driver = args[++i];
+            } else if(arg.equals("--offline")) {
+                if(uri != null) {
+                    throw new DeploymentSyntaxException("Cannot specify a URI in offline
mode");
+                }
+                if(driver != null) {
+                    throw new DeploymentSyntaxException("Cannot specify a driver in offline
mode");
+                }
+                if(user != null) {
+                    throw new DeploymentSyntaxException("Cannot specify a username in offline
mode");
+                }
+                if(password != null) {
+                    throw new DeploymentSyntaxException("Cannot specify a password in offline
mode");
+                }
+                offline = true;
             } else if(arg.equals("--user")) {
                 if(user != null) {
                     throw new DeploymentSyntaxException("Cannot specify more than one user
name");
                 } else if(i >= args.length-1) {
                     throw new DeploymentSyntaxException("Must specify a username (--user
username)");
                 }
+                if(offline) {
+                    throw new DeploymentSyntaxException("Cannot specify a username in offline
mode");
+                }
                 user = args[++i];
             } else if(arg.equals("--password")) {
                 if(password != null) {
@@ -111,25 +165,14 @@
                 } else if(i >= args.length-1) {
                     throw new DeploymentSyntaxException("Must specify a password (--password
password)");
                 }
+                if(offline) {
+                    throw new DeploymentSyntaxException("Cannot specify a password in offline
mode");
+                }
                 password = args[++i];
             } else if (arg.equals("--verbose")) {
-                String value = args[++i];
-                if (value.equals("true")) {
-                    commandContext.setVerbose(true);
-                } else if (value.equals("false")) {
-                    commandContext.setVerbose(false);
-                } else {
-                    throw new DeploymentSyntaxException("--quiet must be either true or false.");
-                }
+                commandContext.setVerbose(true);
             } else if (arg.equals("--syserr")) {
-                String value = args[++i];
-                if (value.equals("true")) {
-                    commandContext.setLogErrors(true);
-                } else if (value.equals("false")) {
-                    commandContext.setLogErrors(false);
-                } else {
-                    throw new DeploymentSyntaxException("--syserr must be either true or
false.");
-                }
+                commandContext.setLogErrors(true);
             } else {
                 throw new DeploymentException("Invalid option "+arg);
             }
@@ -137,16 +180,19 @@
         if((driver != null) && uri == null) {
             throw new DeploymentSyntaxException("A custom driver requires a custom URI");
         }
+        if(forceLocal && !offline) {
+            throw new DeploymentSyntaxException("This command may only be run offline.  Make
sure the server is not running and use the --offline option.");
+        }
         if(forceLocal && (uri != null || driver != null || user != null || password
!= null)) {
             throw new DeploymentSyntaxException("This command does not use normal server
connectivity.  No standard options are allowed.");
         }
-        if(!forceLocal) {
+        if(forceLocal || offline) {
+            initializeKernel();
+        } else {
             tryToConnect(uri, commandContext, driver, user, password, true);
-            if(manager == null) { // uri must be null too or we'd have thrown an exception
-                initializeKernel();
+            if(manager == null) {
+                throw new DeploymentException("Unexpected error; connection failed.");
             }
-        } else {
-            initializeKernel();
         }
     }
 
@@ -184,9 +230,7 @@
                 throw new DeploymentException("Login Failed");
             }
         } catch(DeploymentManagerCreationException e) {
-            if(uri != null) {
-                throw new DeploymentException("Unable to connect to server at "+uri+" --
"+e.getMessage());
-            } //else, fall through and try local access
+            throw new DeploymentException("Unable to connect to server at "+(uri == null
? DEFAULT_URI : uri)+" -- "+e.getMessage());
         }
         
         if (manager instanceof JMXDeploymentManager) {



Mime
View raw message