1 17 18 package org.apache.geronimo.deployment.cli; 19 20 import org.apache.geronimo.common.DeploymentException; 21 22 import javax.enterprise.deploy.spi.TargetModuleID ; 23 import javax.enterprise.deploy.spi.Target ; 24 import javax.enterprise.deploy.spi.DeploymentManager ; 25 import javax.enterprise.deploy.spi.exceptions.TargetException ; 26 import java.io.PrintWriter ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 35 public class CommandListModules extends AbstractCommand { 36 public CommandListModules() { 37 super("list-modules", "2. Other Commands", "[--all|--started|--stopped] [target*]", 38 "Lists the modules available on the specified targets. If " + 39 "--started or --stopped is specified, only started or stopped modules will " + 40 "be listed; otherwise all modules will be listed. If no targets are " + 41 "specified, then modules on all targets will be listed; otherwise only " + 42 "modules on the specified targets."); 43 } 44 45 public void execute(PrintWriter out, ServerConnection connection, String [] args) throws DeploymentException { 46 List targets = new ArrayList (); 47 Boolean started = null; 48 for (int i = 0; i < args.length; i++) { 49 String arg = args[i]; 50 if(arg.startsWith("--")) { 51 if(arg.equals("--all")) { 52 if(started != null) { 53 throw new DeploymentSyntaxException("Cannot specify more than one of --all, --started, --stopped"); 54 } 55 } else if(arg.equals("--started")) { 56 if(started != null) { 57 throw new DeploymentSyntaxException("Cannot specify more than one of --all, --started, --stopped"); 58 } 59 started = Boolean.TRUE; 60 } else if(arg.equals("--stopped")) { 61 if(started != null) { 62 throw new DeploymentSyntaxException("Cannot specify more than one of --all, --started, --stopped"); 63 } 64 started = Boolean.FALSE; 65 } else { 66 throw new DeploymentSyntaxException("Unrecognized option '"+arg+"'"); 67 } 68 } else { 69 targets.add(arg); 70 } 71 } 72 final DeploymentManager mgr = connection.getDeploymentManager(); 73 TargetModuleID [] running = null, notrunning = null; 74 Target [] tlist = identifyTargets(targets, mgr); 75 if(tlist.length == 0) { 76 tlist = mgr.getTargets(); 77 } 78 try { 79 if(started == null || started.booleanValue()) { 80 running = mgr.getRunningModules(null, tlist); 81 } 82 if(started == null || !started.booleanValue()) { 83 notrunning = mgr.getNonRunningModules(null, tlist); 84 } 85 } catch (TargetException e) { 86 throw new DeploymentException("Unable to query modules", e); 87 } catch (IllegalStateException e) { 88 throw new DeploymentSyntaxException(e.getMessage()); 89 } 90 if(running == null) { 91 running = new TargetModuleID [0]; 92 } 93 if(notrunning == null) { 94 notrunning = new TargetModuleID [0]; 95 } 96 97 int total = running.length+notrunning.length; 98 out.println("Found "+total+" module"+(total != 1 ? "s" : "")); 99 for (int i = 0; i < running.length; i++) { 100 TargetModuleID result = running[i]; 101 out.println(" + "+result.getModuleID()+(tlist.length > 1 ? " on "+result.getTarget().getName(): "")+(result.getWebURL() == null ? "" : " @ "+result.getWebURL())); 102 if(result.getChildTargetModuleID() != null) { 103 for (int j = 0; j < result.getChildTargetModuleID().length; j++) { 104 TargetModuleID child = result.getChildTargetModuleID()[j]; 105 out.println(" `-> "+child.getModuleID()+(child.getWebURL() == null ? "" : " @ "+child.getWebURL())); 106 } 107 } 108 } 109 for (int i = 0; i < notrunning.length; i++) { 110 TargetModuleID result = notrunning[i]; 111 out.println(" "+result.getModuleID()+(tlist.length > 1 ? " on "+result.getTarget().getName(): "")); 112 if(result.getChildTargetModuleID() != null) { 113 for (int j = 0; j < result.getChildTargetModuleID().length; j++) { 114 TargetModuleID child = result.getChildTargetModuleID()[j]; 115 out.println(" `-> "+child.getModuleID()); 116 } 117 } 118 } 119 } 120 } 121 | Popular Tags |