You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2007/12/10 21:54:11 UTC

svn commit: r603044 - in /geronimo/server/trunk: assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/ framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ framework/modules/geronimo-deploy-tool/src/main/java/org/a...

Author: gawor
Date: Mon Dec 10 12:54:10 2007
New Revision: 603044

URL: http://svn.apache.org/viewvc?rev=603044&view=rev
Log:
gshell command for install-plugin. also improved list-plugins ghsell command and related code

Added:
    geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/InstallPluginCommand.groovy
Modified:
    geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml
    geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ListConfigurationsCommand.groovy
    geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallCAR.java
    geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java

Modified: geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml?rev=603044&r1=603043&r2=603044&view=diff
==============================================================================
--- geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml (original)
+++ geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml Mon Dec 10 12:54:10 2007
@@ -215,6 +215,11 @@
                     <name>deploy</name>
                     <id>geronimo-commands:deploy-module</id>
                 </command>
+
+                <command>
+                    <name>install-plugin</name>
+                    <id>geronimo-commands:install-plugin</id>
+                </command>
             </nodes>
         </group>
 

Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/InstallPluginCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/InstallPluginCommand.groovy?rev=603044&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/InstallPluginCommand.groovy (added)
+++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/InstallPluginCommand.groovy Mon Dec 10 12:54:10 2007
@@ -0,0 +1,52 @@
+/*
+ * 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.geronimo.commands
+
+import jline.ConsoleReader
+
+import org.apache.geronimo.gshell.clp.Argument
+import org.apache.geronimo.gshell.command.annotation.CommandComponent
+import org.apache.geronimo.cli.deployer.BaseCommandArgs
+import org.apache.geronimo.deployment.cli.CommandInstallCAR
+
+/**
+ * Install a plugin.
+ *
+ * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $
+ */
+@CommandComponent(id='geronimo-commands:install-plugin', description="Install a plugin")
+class InstallPluginCommand extends ConnectCommand {
+     
+    @Argument(metaVar="PLUGIN_FILE", required=true, description="Plugin file")
+    String pluginFile
+    
+    protected Object doExecute() throws Exception {
+        def connection = variables.get("ServerConnection")
+        if (!connection) {
+            connection = super.doExecute()
+        }
+        
+        def command = new CommandInstallCAR()
+        def consoleReader = new ConsoleReader(io.inputStream, io.out)
+        def args = new BaseCommandArgs( (String[]) [ pluginFile ] )
+        
+        command.execute(consoleReader, connection, args)
+    }
+}
\ No newline at end of file

Modified: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ListConfigurationsCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ListConfigurationsCommand.groovy?rev=603044&r1=603043&r2=603044&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ListConfigurationsCommand.groovy (original)
+++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ListConfigurationsCommand.groovy Mon Dec 10 12:54:10 2007
@@ -21,6 +21,7 @@
 
 import jline.ConsoleReader
 
+import org.apache.geronimo.gshell.clp.Argument
 import org.apache.geronimo.gshell.clp.Option
 import org.apache.geronimo.gshell.command.annotation.CommandComponent
 import org.apache.geronimo.gshell.command.CommandSupport
@@ -42,28 +43,38 @@
 
     @Option(name='-l', aliases=['--list'], description='refresh plugin list')
     boolean refreshList = false
+    
+    @Argument(metaVar="MAVEN-REPO-URL", description="Repository URL")
+    String mavenRepoURL
 
     protected Object doExecute() throws Exception {
-        io.out.println("Listing configurations from Geronimo server")
-
         def connection = variables.get("ServerConnection")
         if (!connection) {
-            //def connectCommand = new ConnectCommand()
-            //connectCommand.init(context)
             connection = super.doExecute()
         }
         def command = new CommandListConfigurations()
         def consoleReader = new ConsoleReader(io.inputStream, io.out)
-        def repo = variables.get("PluginRepository")
-        if (refreshRepo || !repo) {
-            repo = command.getRepository(consoleReader, connection.getDeploymentManager())
-            variables.parent.set("PluginRepository", repo)
-        }
-        def plugins = variables.get("AvailablePlugins")
-        if (refreshList || !plugins) {
-            plugins = command.getPluginCategories(repo, connection.getDeploymentManager(), consoleReader)
-            variables.parent.set("AvailablePlugins", plugins)
+        def repo = null
+        def plugins = null
+        
+        if (mavenRepoURL) {
+        	plugins = command.getPluginCategories(mavenRepoURL, connection.getDeploymentManager(), consoleReader)
+        } else {
+            io.out.println("Listing configurations from Geronimo server")
+            
+        	repo = variables.get("PluginRepository")
+        	if (refreshRepo || !repo) {
+            	repo = command.getRepository(consoleReader, connection.getDeploymentManager())
+            	variables.parent.set("PluginRepository", repo)
+        	}
+              
+       	 	plugins = variables.get("AvailablePlugins")
+        	if (refreshList || !plugins) {
+            	plugins = command.getPluginCategories(repo, connection.getDeploymentManager(), consoleReader)
+            	variables.parent.set("AvailablePlugins", plugins)
+        	}
         }
+        
         if (plugins) {
             def pluginsToInstall = command.getInstallList(plugins, consoleReader, repo)
             if (pluginsToInstall) {

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallCAR.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallCAR.java?rev=603044&r1=603043&r2=603044&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallCAR.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallCAR.java Mon Dec 10 12:54:10 2007
@@ -43,6 +43,9 @@
         if(dmgr instanceof GeronimoDeploymentManager) {
             try {
                 GeronimoDeploymentManager mgr = (GeronimoDeploymentManager) dmgr;
+                if (commandArgs.getArgs().length == 0) {
+                    throw new DeploymentException("Must specify Plugin CAR file");
+                }
                 File carFile = new File(commandArgs.getArgs()[0]);
                 carFile = carFile.getAbsoluteFile();
                 if(!carFile.exists() || !carFile.canRead()) {
@@ -51,24 +54,9 @@
                 //TODO figure out if there is a plausible default repo
                 Object key = mgr.startInstall(carFile, null, false, null, null);
                 long start = System.currentTimeMillis();
-                DownloadResults results = showProgress(mgr, key);
+                DownloadResults results = showProgress(consoleReader, mgr, key);
                 int time = (int)(System.currentTimeMillis() - start) / 1000;
-                consoleReader.printNewline();
-                if(!results.isFailed()) {
-                    consoleReader.printString(DeployUtils.reformat("**** Installation Complete!", 4, 72));
-                    for (int i = 0; i < results.getDependenciesPresent().length; i++) {
-                        Artifact uri = results.getDependenciesPresent()[i];
-                        consoleReader.printString(DeployUtils.reformat("Used existing: "+uri, 4, 72));
-                    }
-                    for (int i = 0; i < results.getDependenciesInstalled().length; i++) {
-                        Artifact uri = results.getDependenciesInstalled()[i];
-                        consoleReader.printString(DeployUtils.reformat("Installed new: "+uri, 4, 72));
-                    }
-                    if(results.getTotalDownloadBytes() > 0 && time > 0) {
-                        System.out.println();
-                        consoleReader.printString(DeployUtils.reformat("Downloaded "+(results.getTotalDownloadBytes()/1024)+" kB in "+time+"s ("+results.getTotalDownloadBytes()/(1024*time)+" kB/s)", 4, 72));
-                    }
-                }
+                printResults(consoleReader, results, time);            
                 if(results.isFinished() && !results.isFailed() && results.getInstalledConfigIDs().length == 1) {
                     Artifact target = results.getInstalledConfigIDs()[0];
                     consoleReader.printString(DeployUtils.reformat("Now starting "+target+"...", 4, 72));
@@ -83,8 +71,8 @@
         }
     }
 
-    static DownloadResults showProgress(GeronimoDeploymentManager mgr, Object key) {
-        System.out.println("Checking for status every 1000ms:");
+    static DownloadResults showProgress(ConsoleReader consoleReader, GeronimoDeploymentManager mgr, Object key) throws IOException {
+        DeployUtils.println("Checking for status every 1000ms:", 0, consoleReader);
         String last = null, status;
         while(true) {
             DownloadResults results = mgr.checkOnInstall(key);
@@ -96,12 +84,13 @@
                 }
                 if(last == null || !last.equals(status)) {
                     last = status;
-                    System.out.println(status);
+                    DeployUtils.println(status, 0, consoleReader);
+                    consoleReader.flushConsole();
                 }
             }
             if(results.isFinished()) {
                 if(results.isFailed()) {
-                    System.err.println("Installation FAILED: "+results.getFailure().getMessage());
+                    DeployUtils.println("Installation FAILED: "+results.getFailure().getMessage(), 0, consoleReader);
                 }
                 return results;
             }
@@ -109,6 +98,30 @@
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
                 return results;
+            }
+        }
+    }
+    
+    static void printResults(ConsoleReader consoleReader, DownloadResults results, int time) throws IOException, DeploymentException {
+        consoleReader.printNewline();
+        if (!results.isFailed()) {
+            DeployUtils.println("**** Installation Complete!", 0, consoleReader);
+
+            for (int i = 0; i < results.getDependenciesPresent().length; i++) {
+                Artifact uri = results.getDependenciesPresent()[i];
+                DeployUtils.println("Used existing: " + uri, 0, consoleReader);
+
+            }
+            for (int i = 0; i < results.getDependenciesInstalled().length; i++) {
+                Artifact uri = results.getDependenciesInstalled()[i];
+                DeployUtils.println("Installed new: " + uri, 0, consoleReader);
+
+            }
+            consoleReader.printNewline();
+            if (results.getTotalDownloadBytes() > 0 && time > 0) {
+                DeployUtils.println(
+                    "Downloaded " + (results.getTotalDownloadBytes() / 1024) + " kB in " + time + "s (" + results.getTotalDownloadBytes() / (1024 * time) + " kB/s)",
+                    0, consoleReader);
             }
         }
     }

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java?rev=603044&r1=603043&r2=603044&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java Mon Dec 10 12:54:10 2007
@@ -90,6 +90,15 @@
                     "URL on the command line, or go into the console Plugin page and update the list of available " +
                     "repositories.");
         }
+        // no need to ask for input if only one repo exists
+        if (all.length == 1) {
+            String repo = all[0].toString();
+            consoleReader.printNewline();
+            consoleReader.printString("Selected repository: " + repo);
+            consoleReader.printNewline();
+            return repo;
+        }
+        
         consoleReader.printNewline();
         consoleReader.printString("Select repository:");
         consoleReader.printNewline();
@@ -99,11 +108,23 @@
             DeployUtils.println(url.toString(), 0, consoleReader);
         }
         String entry = consoleReader.readLine("Enter Repository Number: ").trim();
-        int index = Integer.parseInt(entry);
-        return all[index - 1].toString();
+        if (entry.length() == 0) {
+            return null;
+        }
+        try {
+            int index = Integer.parseInt(entry);
+            return all[index - 1].toString();
+        } catch (NumberFormatException e) {
+            throw new DeploymentException("Invalid selection");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            throw new DeploymentException("Invalid selection");
+        }
     }
 
     public Map<String, Collection<PluginType>> getPluginCategories(String repo, GeronimoDeploymentManager mgr, ConsoleReader consoleReader) throws DeploymentException, IOException {
+        if (repo == null) {
+            return null;
+        }
         PluginListType data;
         URL repository;
         try {
@@ -200,9 +221,9 @@
     public void installPlugins(GeronimoDeploymentManager mgr, PluginListType list, String defaultRepository, ConsoleReader consoleReader, ServerConnection connection) throws IOException, DeploymentException {
         long start = System.currentTimeMillis();
         Object key = mgr.startInstall(list, defaultRepository, false, null, null);
-        DownloadResults results = CommandInstallCAR.showProgress(mgr, key);
+        DownloadResults results = CommandInstallCAR.showProgress(consoleReader, mgr, key);
         int time = (int) (System.currentTimeMillis() - start) / 1000;
-        printResults(consoleReader, results, time);
+        CommandInstallCAR.printResults(consoleReader, results, time);
         if (results.isFinished() && !results.isFailed()) {
             for (PluginType plugin : list.getPlugin()) {
                 for (PluginArtifactType targetInstance : plugin.getPluginArtifact()) {
@@ -214,38 +235,13 @@
             }
         }
     }
-
-    private void printResults(ConsoleReader consoleReader, DownloadResults results, int time) throws IOException, DeploymentException {
-        consoleReader.printNewline();
-        if (!results.isFailed()) {
-            DeployUtils.println("**** Installation Complete!", 0, consoleReader);
-
-            for (int i = 0; i < results.getDependenciesPresent().length; i++) {
-                Artifact uri = results.getDependenciesPresent()[i];
-                DeployUtils.println("Used existing: " + uri, 0, consoleReader);
-
-            }
-            for (int i = 0; i < results.getDependenciesInstalled().length; i++) {
-                Artifact uri = results.getDependenciesInstalled()[i];
-                DeployUtils.println("Installed new: " + uri, 0, consoleReader);
-
-            }
-            consoleReader.printNewline();
-            DeployUtils.println(
-                    "Downloaded " + (results.getTotalDownloadBytes() / 1024) + " kB in " + time + "s (" + results.getTotalDownloadBytes() / (1024 * time) + " kB/s)",
-                    0, consoleReader);
-
-        }
-    }
-
+    
     public void assembleServer(GeronimoDeploymentManager mgr, PluginListType list, String repositoryPath, String relativeServerPath, ConsoleReader consoleReader) throws Exception {
         DownloadResults results = new DownloadResults();
         long start = System.currentTimeMillis();
         mgr.installPluginList(repositoryPath, relativeServerPath, list, results);
         int time = (int) (System.currentTimeMillis() - start) / 1000;
-
-        printResults(consoleReader, results, time);
+        CommandInstallCAR.printResults(consoleReader, results, time);
     }
-
 
 }