1 17 18 package org.apache.geronimo.deployment; 19 20 import java.io.File ; 21 import java.util.jar.Attributes ; 22 import java.util.jar.Manifest ; 23 24 import org.apache.geronimo.deployment.service.ServiceConfigBuilder; 25 import org.apache.geronimo.deployment.util.DeploymentUtil; 26 import org.apache.geronimo.deployment.xbeans.ConfigurationDocument; 27 import org.apache.geronimo.deployment.xbeans.ConfigurationType; 28 import org.apache.geronimo.kernel.config.ConfigurationData; 29 import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil; 30 import org.apache.geronimo.system.configuration.LocalConfigStore; 31 import org.apache.geronimo.system.main.CommandLineManifest; 32 import org.apache.geronimo.system.repository.ReadOnlyRepository; 33 34 39 public class Bootstrap { 40 private String deployerJar; 41 private String storeDir; 42 private String repositoryDir; 43 private String deployerSystemPlan; 44 private String j2eeDeployerPlan; 45 private String deployerClassPath; 46 private String deployerEndorsedDirs; 47 private String deployerGBean; 48 private String deploymentFactory; 49 50 public String getDeployerJar() { 51 return deployerJar; 52 } 53 54 public void setDeployerJar(String deployerJar) { 55 this.deployerJar = deployerJar; 56 } 57 58 public String getStoreDir() { 59 return storeDir; 60 } 61 62 public void setStoreDir(String storeDir) { 63 this.storeDir = storeDir; 64 } 65 66 public String getRepositoryDir() { 67 return repositoryDir; 68 } 69 70 public void setRepositoryDir(String repositoryDir) { 71 this.repositoryDir = repositoryDir; 72 } 73 74 public String getDeployerSystemPlan() { 75 return deployerSystemPlan; 76 } 77 78 public void setDeployerSystemPlan(String deployerSystemPlan) { 79 this.deployerSystemPlan = deployerSystemPlan; 80 } 81 82 public String getJ2eeDeployerPlan() { 83 return j2eeDeployerPlan; 84 } 85 86 public void setJ2eeDeployerPlan(String j2eeDeployerPlan) { 87 this.j2eeDeployerPlan = j2eeDeployerPlan; 88 } 89 90 public String getDeployerClassPath() { 91 return deployerClassPath; 92 } 93 94 public void setDeployerClassPath(String deployerClassPath) { 95 this.deployerClassPath = deployerClassPath; 96 } 97 98 public String getDeployerEndorsedDirs() { 99 return deployerEndorsedDirs; 100 } 101 102 public void setDeployerEndorsedDirs(String deployerEndorsedDirs) { 103 this.deployerEndorsedDirs = deployerEndorsedDirs; 104 } 105 106 public String getDeployerGBean() { 107 return deployerGBean; 108 } 109 110 public void setDeployerGBean(String deployerGBean) { 111 this.deployerGBean = deployerGBean; 112 } 113 114 public String getDeploymentFactory() { 115 return deploymentFactory; 116 } 117 118 public void setDeploymentFactory(String deploymentFactory) { 119 this.deploymentFactory = deploymentFactory; 120 } 121 122 public void bootstrap() throws Exception { 123 ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); 124 Thread.currentThread().setContextClassLoader(Bootstrap.class.getClassLoader()); 125 try { 126 ConfigurationType deployerSystemConfig = ConfigurationDocument.Factory.parse(new File (deployerSystemPlan)).getConfiguration(); 128 ConfigurationType j2eeDeployerConfig = ConfigurationDocument.Factory.parse(new File (j2eeDeployerPlan)).getConfiguration(); 129 130 LocalConfigStore configStore = new LocalConfigStore(new File (storeDir)); 132 ReadOnlyRepository repository = new ReadOnlyRepository(new File (repositoryDir)); 133 134 ServiceConfigBuilder builder = new ServiceConfigBuilder(null, repository); 136 137 Manifest manifest = new Manifest (); 139 Attributes mainAttributes = manifest.getMainAttributes(); 140 mainAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); 141 mainAttributes.putValue(Attributes.Name.MAIN_CLASS.toString(), "org.apache.geronimo.deployment.cli.DeployTool"); 142 mainAttributes.putValue(Attributes.Name.CLASS_PATH.toString(), deployerClassPath); 143 mainAttributes.putValue(CommandLineManifest.MAIN_GBEAN.toString(), deployerGBean); 144 mainAttributes.putValue(CommandLineManifest.MAIN_METHOD.toString(), "deploy"); 145 mainAttributes.putValue(CommandLineManifest.CONFIGURATIONS.toString(), j2eeDeployerConfig.getConfigId()); 146 mainAttributes.putValue(CommandLineManifest.ENDORSED_DIRS.toString(), deployerEndorsedDirs); 147 148 mainAttributes.putValue("J2EE-DeploymentFactory-Implementation-Class", deploymentFactory); 150 151 153 File configurationDir = null; 155 try { 156 configurationDir = configStore.createNewConfigurationDir(); 157 158 ConfigurationData configurationData = builder.buildConfiguration(deployerSystemConfig, null, configurationDir); 160 161 ExecutableConfigurationUtil.createExecutableConfiguration(configurationData, manifest, configurationDir, new File (deployerJar)); 162 163 configStore.install(configurationData, configurationDir); 165 } catch (Throwable e) { 166 DeploymentUtil.recursiveDelete(configurationDir); 167 if (e instanceof Error ) { 168 throw (Error ) e; 169 } else if (e instanceof Exception ) { 170 throw (Exception ) e; 171 } 172 throw new Error (e); 173 } 174 175 String domain = deployerSystemConfig.getDomain(); 177 String server = deployerSystemConfig.getServer(); 178 179 try { 181 configurationDir = configStore.createNewConfigurationDir(); 182 183 ConfigurationData configurationData = builder.buildConfiguration(j2eeDeployerConfig, domain, server, configurationDir); 185 186 configStore.install(configurationData, configurationDir); 188 } catch (Throwable e) { 189 DeploymentUtil.recursiveDelete(configurationDir); 190 if (e instanceof Error ) { 191 throw (Error ) e; 192 } else if (e instanceof Exception ) { 193 throw (Exception ) e; 194 } 195 throw new Error (e); 196 } 197 } finally { 198 Thread.currentThread().setContextClassLoader(oldCL); 199 } 200 } 201 } 202 | Popular Tags |