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