KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > PluginBootstrap


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.deployment;
18
19 import java.io.File JavaDoc;
20 import java.io.FileOutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.jar.JarOutputStream JavaDoc;
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 /**
43  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
44  */

45 public class PluginBootstrap {
46     private File JavaDoc localRepo;
47     private File JavaDoc plan;
48     private File JavaDoc buildDir;
49     private File JavaDoc carFile;
50
51     public void setLocalRepo(File JavaDoc localRepo) {
52         this.localRepo = localRepo;
53     }
54
55     public void setPlan(File JavaDoc plan) {
56         this.plan = plan;
57     }
58
59     public void setBuildDir(File JavaDoc buildDir) {
60         this.buildDir = buildDir;
61     }
62
63     public void setCarFile(File JavaDoc carFile) {
64         this.carFile = carFile;
65     }
66
67     public void bootstrap() throws Exception JavaDoc {
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 JavaDoc 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 JavaDoc out = null;
87         try {
88             ConfigurationData configurationData = context.getConfigurationData();
89             out = new JarOutputStream JavaDoc(new FileOutputStream JavaDoc(carFile));
90             ExecutableConfigurationUtil.writeConfiguration(configurationData, out);
91             out.flush();
92         } finally {
93             if (out != null)
94             {
95                 try {
96                     out.close();
97                 } catch (IOException JavaDoc ignored) {
98                     // ignored
99
}
100             }
101             if (context != null)
102                 context.close();
103         }
104     }
105 }
106
Popular Tags