1 17 18 package org.apache.geronimo.deployment.cli; 19 20 import org.apache.geronimo.common.DeploymentException; 21 22 import java.io.PrintWriter ; 23 import java.io.File ; 24 import java.util.List ; 25 import java.util.LinkedList ; 26 import java.util.Iterator ; 27 import java.util.Arrays ; 28 29 35 public class CommandPackage extends AbstractCommand { 36 public CommandPackage() { 37 super("package", "3. Use if you know what you're doing", "[--classPath path] [--mainClass class] [--install] [module] [plan] fileName", 38 "Creates a configuration JAR rather than installing into the server " + 39 "environment. The fileName argument specifies the JAR to create. The " + 40 "optional classPath argument specifies a Class-Path to include in the JAR " + 41 "manifest. The optional mainClass argument specifies the Main-Class to include in " + 42 "the JAR manifest. The install option specifies that the " + 43 "configuration should be build into a JAR and also installed into " + 44 "the server configuration (otherwise it is packaged but not installed).\n" + 45 "The standard arguments may not be used with this command -- it " + 46 "never connects to a remote server."); 47 } 48 49 public boolean isLocalOnly() { 50 return true; 51 } 52 53 public void execute(PrintWriter out, ServerConnection connection, String [] argArray) throws DeploymentException { 54 if(connection.isOnline()) { 55 throw new DeploymentException("This command cannot be run when the server is running. Make sure the server is shut down first."); 56 } 57 58 String classPath = null; 59 String mainClass = null; 60 String endorsedDirs = null; 61 boolean install = false; 62 63 LinkedList args = new LinkedList (Arrays.asList(argArray)); 65 for (Iterator iterator = args.iterator(); iterator.hasNext();) { 66 String arg = (String ) iterator.next(); 67 if(arg.equals("--classPath")) { 68 iterator.remove(); 69 classPath = (String ) iterator.next(); 70 iterator.remove(); 71 } else if(arg.equals("--mainClass")) { 72 iterator.remove(); 73 mainClass = (String ) iterator.next(); 74 iterator.remove(); 75 } else if(arg.equals("--endorsedDirs")) { 76 iterator.remove(); 77 endorsedDirs = (String ) iterator.next(); 78 iterator.remove(); 79 } else if(arg.equals("--install")) { 80 iterator.remove(); 81 install = true; 82 } else if(arg.startsWith("--")) { 83 throw new DeploymentSyntaxException("Invalid option '" + arg + "'"); 84 } else { 85 break; 86 } 87 } 88 89 for (Iterator iterator = args.iterator(); iterator.hasNext();) { 91 String arg = (String ) iterator.next(); 92 if(arg.startsWith("--")) { 93 throw new DeploymentSyntaxException("All command line options must appear before module, plan or packageFile: " + arg); 94 } 95 } 96 97 if(args.isEmpty()) { 98 throw new DeploymentSyntaxException("No fileName specified for package command"); 99 } 100 101 File packageFile; 103 packageFile = new File ((String ) args.removeLast()); 104 File parent = packageFile.getAbsoluteFile().getParentFile(); 105 if(!parent.exists() || !parent.canWrite()) { 106 throw new DeploymentSyntaxException("Cannot write to output file "+packageFile.getAbsolutePath()); 107 } 108 109 File module = null; 111 File plan = null; 112 if(!args.isEmpty()) { 113 File test = new File ((String ) args.removeLast()).getAbsoluteFile(); 115 if(DeployUtils.isJarFile(test) || test.isDirectory()) { 116 module = test; 117 } else { 118 plan = test; 119 } 120 } 121 if(!args.isEmpty()) { 122 File test = new File ((String ) args.removeLast()).getAbsoluteFile(); 123 if(DeployUtils.isJarFile(test) || test.isDirectory()) { 124 if(module != null) { 125 throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!"); 126 } 127 module = test; 128 } else { 129 if(plan != null) { 130 throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!"); 131 } 132 plan = test; 133 } 134 } 135 136 if(!args.isEmpty()) { 138 throw new DeploymentSyntaxException("Too many arguments for package command"); 139 } 140 141 List list = (List ) connection.invokeOfflineDeployer( 143 new Object []{ 144 plan, 145 module, 146 packageFile, 147 install ? Boolean.TRUE : Boolean.FALSE, 148 mainClass, 149 classPath, 150 endorsedDirs}, 151 new String []{ 152 File .class.getName(), 153 File .class.getName(), 154 File .class.getName(), 155 boolean.class.getName(), 156 String .class.getName(), 157 String .class.getName(), 158 String .class.getName()}); 159 160 for (int j = 0; j < list.size(); j++) { 162 out.println("Packaged configuration "+list.get(j)+" to "+packageFile); 163 } 164 } 165 } 166 | Popular Tags |