1 17 18 package org.apache.geronimo.deployment; 19 20 import java.io.File ; 21 import java.io.FileOutputStream ; 22 import java.io.IOException ; 23 import java.util.Collections ; 24 import java.util.jar.JarOutputStream ; 25 26 import org.apache.geronimo.deployment.service.ServiceConfigBuilder; 27 import org.apache.geronimo.deployment.service.GBeanBuilder; 28 import org.apache.geronimo.deployment.xbeans.ModuleDocument; 29 import org.apache.geronimo.deployment.xbeans.ModuleType; 30 import org.apache.geronimo.kernel.Jsr77Naming; 31 import org.apache.geronimo.kernel.config.ConfigurationAlreadyExistsException; 32 import org.apache.geronimo.kernel.config.ConfigurationData; 33 import org.apache.geronimo.kernel.config.ConfigurationStore; 34 import org.apache.geronimo.kernel.config.NullConfigurationStore; 35 import org.apache.geronimo.kernel.repository.Artifact; 36 import org.apache.geronimo.kernel.repository.ArtifactManager; 37 import org.apache.geronimo.kernel.repository.DefaultArtifactManager; 38 import org.apache.geronimo.kernel.repository.ArtifactResolver; 39 import org.apache.geronimo.kernel.repository.DefaultArtifactResolver; 40 import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil; 41 import org.apache.geronimo.system.repository.Maven2Repository; 42 43 46 public class PluginBootstrap2 { 47 private File localRepo; 48 private File plan; 49 private File buildDir; 50 private File carFile; 51 private boolean expanded; 52 53 public void setLocalRepo(File localRepo) { 54 this.localRepo = localRepo; 55 } 56 57 public void setPlan(File plan) { 58 this.plan = plan; 59 } 60 61 public void setBuildDir(File buildDir) { 62 this.buildDir = buildDir; 63 } 64 65 public void setCarFile(File carFile) { 66 this.carFile = carFile; 67 } 68 69 public void setExpanded(final boolean expanded) { 70 this.expanded = expanded; 71 } 72 73 public void bootstrap() throws Exception { 74 System.out.println("Packaging module configuration: " + plan); 75 76 ModuleType config = ModuleDocument.Factory.parse(plan).getModule(); 77 78 Maven2Repository repository = new Maven2Repository(localRepo); 79 GBeanBuilder gBeanBuilder = new GBeanBuilder(null, null); 80 ServiceConfigBuilder builder = new ServiceConfigBuilder(null, Collections.singleton(repository), Collections.singleton(gBeanBuilder), new Jsr77Naming()); 81 ConfigurationStore targetConfigurationStore = new NullConfigurationStore() { 82 public File createNewConfigurationDir(Artifact configId) throws ConfigurationAlreadyExistsException { 83 return buildDir; 84 } 85 }; 86 87 ArtifactManager artifactManager = new DefaultArtifactManager(); 88 ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager, Collections.singleton(repository), null); 89 DeploymentContext context = builder.buildConfiguration( 90 false, 91 builder.getConfigurationID(config, null, new ModuleIDBuilder()), 92 config, 93 null, 94 Collections.singleton(targetConfigurationStore), 95 artifactResolver, 96 targetConfigurationStore); 97 98 ConfigurationData configurationData = context.getConfigurationData(); 99 100 try { 101 writeConfiguration(configurationData); 102 } 103 finally { 104 context.close(); 105 } 106 } 107 108 private void writeConfiguration(final ConfigurationData configurationData) throws IOException { 109 if (expanded) { 110 ExecutableConfigurationUtil.writeConfiguration(configurationData, carFile); 111 } 112 else { 113 JarOutputStream out = null; 114 try { 115 out = new JarOutputStream (new FileOutputStream (carFile)); 116 ExecutableConfigurationUtil.writeConfiguration(configurationData, out); 117 out.flush(); 118 } 119 finally { 120 if (out != null) { 121 try { 122 out.close(); 123 } 124 catch (IOException ignored) { 125 } 127 } 128 } 129 } 130 } 131 } 132 | Popular Tags |