1 17 package org.apache.geronimo.system.main; 18 19 import java.io.IOException ; 20 import java.net.JarURLConnection ; 21 import java.net.URI ; 22 import java.net.URISyntaxException ; 23 import java.net.URL ; 24 import java.util.ArrayList ; 25 import java.util.Collections ; 26 import java.util.List ; 27 import java.util.StringTokenizer ; 28 import java.util.jar.Attributes ; 29 import java.util.jar.Manifest ; 30 31 import org.apache.geronimo.gbean.AbstractNameQuery; 32 import org.apache.geronimo.kernel.repository.Artifact; 33 34 37 public class CommandLineManifest { 38 public static final Attributes.Name MAIN_GBEAN = new Attributes.Name ("Main-GBean"); 39 public static final Attributes.Name MAIN_METHOD = new Attributes.Name ("Main-Method"); 40 public static final Attributes.Name CONFIGURATIONS = new Attributes.Name ("Configurations"); 41 public static final Attributes.Name ENDORSED_DIRS = new Attributes.Name ("Endorsed-Dirs"); 42 public static final Attributes.Name EXTENSION_DIRS = new Attributes.Name ("Extension-Dirs"); 43 44 public static CommandLineManifest getManifestEntries() { 45 ClassLoader classLoader = CommandLine.class.getClassLoader(); 47 URL url = classLoader.getResource("META-INF/startup-jar"); 48 if (url == null) { 49 throw new IllegalArgumentException ("Unable to determine location of startup jar"); 50 } 51 52 Manifest manifest; 54 try { 55 JarURLConnection jarConnection = (JarURLConnection ) url.openConnection(); 56 manifest = jarConnection.getManifest(); 57 } catch (IOException e) { 58 System.err.println("Startup jar does not contain a manifest: " + url); 59 System.exit(1); 60 throw new AssertionError (); 61 } 62 Attributes mainAttributes = manifest.getMainAttributes(); 63 64 String mainGBeanString = mainAttributes.getValue(MAIN_GBEAN); 66 67 AbstractNameQuery mainGBean = null; 68 if (mainGBeanString != null) { 69 try { 70 mainGBean = new AbstractNameQuery(new URI (mainGBeanString)); 71 } catch (URISyntaxException e) { 72 System.err.println("Invalid Main-GBean name: " + mainGBeanString); 73 System.exit(1); 74 throw new AssertionError (); 75 } 76 } 77 78 String mainMethod = mainAttributes.getValue(MAIN_METHOD); 80 81 List configurations = new ArrayList (); 83 String configurationsString = mainAttributes.getValue(CONFIGURATIONS); 84 if (configurationsString != null) { 85 for (StringTokenizer tokenizer = new StringTokenizer (configurationsString, " "); tokenizer.hasMoreTokens();) 86 { 87 String configuration = tokenizer.nextToken(); 88 configurations.add(Artifact.create(configuration)); 89 } 90 } 91 92 List endorsedDirs = new ArrayList (); 94 String endorsedDirsString = mainAttributes.getValue(ENDORSED_DIRS); 95 if (endorsedDirsString != null) { 96 for (StringTokenizer tokenizer = new StringTokenizer (endorsedDirsString, " "); tokenizer.hasMoreTokens();) { 97 String directory = tokenizer.nextToken(); 98 endorsedDirs.add(directory); 99 } 100 } 101 102 List extensionDirs = new ArrayList (); 104 String extensionDirsString = mainAttributes.getValue(EXTENSION_DIRS); 105 if (extensionDirsString != null) { 106 for (StringTokenizer tokenizer = new StringTokenizer (extensionDirsString, " "); tokenizer.hasMoreTokens();) 107 { 108 String directory = tokenizer.nextToken(); 109 extensionDirs.add(directory); 110 } 111 } 112 113 CommandLineManifest commandLineManifest = new CommandLineManifest(mainGBean, mainMethod, configurations, endorsedDirs, extensionDirs); 114 return commandLineManifest; 115 } 116 117 private final AbstractNameQuery mainGBean; 118 private final String mainMethod; 119 private final List configurations; 120 private final List endorsedDirs; 121 private final List extensionDirs; 122 123 public CommandLineManifest(AbstractNameQuery mainGBean, String mainMethod, List configurations, List endorsedDirs, List extensionDirs) { 124 this.mainGBean = mainGBean; 125 this.mainMethod = mainMethod; 126 this.configurations = Collections.unmodifiableList(configurations); 127 this.endorsedDirs = endorsedDirs; 128 this.extensionDirs = extensionDirs; 129 } 130 131 public AbstractNameQuery getMainGBeanQuery() { 132 return mainGBean; 133 } 134 135 public String getMainMethod() { 136 return mainMethod; 137 } 138 139 public List getConfigurations() { 140 return configurations; 141 } 142 143 public List getEndorsedDirs() { 144 return endorsedDirs; 145 } 146 147 public List getExtensionDirs() { 148 return extensionDirs; 149 } 150 } 151 | Popular Tags |