001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.deployment;
017:
018: import java.io.File;
019: import java.io.FileOutputStream;
020: import java.io.IOException;
021: import java.util.Collections;
022: import java.util.jar.JarOutputStream;
023:
024: import org.apache.geronimo.deployment.service.ServiceConfigBuilder;
025: import org.apache.geronimo.deployment.service.GBeanBuilder;
026: import org.apache.geronimo.deployment.xbeans.ModuleDocument;
027: import org.apache.geronimo.deployment.xbeans.ModuleType;
028: import org.apache.geronimo.kernel.Jsr77Naming;
029: import org.apache.geronimo.kernel.config.ConfigurationAlreadyExistsException;
030: import org.apache.geronimo.kernel.config.ConfigurationData;
031: import org.apache.geronimo.kernel.config.ConfigurationStore;
032: import org.apache.geronimo.kernel.config.NullConfigurationStore;
033: import org.apache.geronimo.kernel.repository.Artifact;
034: import org.apache.geronimo.kernel.repository.ArtifactManager;
035: import org.apache.geronimo.kernel.repository.DefaultArtifactManager;
036: import org.apache.geronimo.kernel.repository.ArtifactResolver;
037: import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
038: import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
039: import org.apache.geronimo.system.repository.Maven2Repository;
040:
041: /**
042: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
043: */
044: public class PluginBootstrap2 {
045: private File localRepo;
046: private File plan;
047: private File buildDir;
048: private File carFile;
049: private boolean expanded;
050:
051: public void setLocalRepo(File localRepo) {
052: this .localRepo = localRepo;
053: }
054:
055: public void setPlan(File plan) {
056: this .plan = plan;
057: }
058:
059: public void setBuildDir(File buildDir) {
060: this .buildDir = buildDir;
061: }
062:
063: public void setCarFile(File carFile) {
064: this .carFile = carFile;
065: }
066:
067: public void setExpanded(final boolean expanded) {
068: this .expanded = expanded;
069: }
070:
071: public void bootstrap() throws Exception {
072: System.out.println("Packaging module configuration: " + plan);
073:
074: ModuleType config = ModuleDocument.Factory.parse(plan)
075: .getModule();
076:
077: Maven2Repository repository = new Maven2Repository(localRepo);
078: GBeanBuilder gBeanBuilder = new GBeanBuilder(null, null);
079: ServiceConfigBuilder builder = new ServiceConfigBuilder(null,
080: Collections.singleton(repository), Collections
081: .singleton(gBeanBuilder), new Jsr77Naming());
082: ConfigurationStore targetConfigurationStore = new NullConfigurationStore() {
083: public File createNewConfigurationDir(Artifact configId)
084: throws ConfigurationAlreadyExistsException {
085: return buildDir;
086: }
087: };
088:
089: ArtifactManager artifactManager = new DefaultArtifactManager();
090: ArtifactResolver artifactResolver = new DefaultArtifactResolver(
091: artifactManager, Collections.singleton(repository),
092: null);
093: DeploymentContext context = builder.buildConfiguration(false,
094: builder.getConfigurationID(config, null,
095: new ModuleIDBuilder()), config, null,
096: Collections.singleton(targetConfigurationStore),
097: artifactResolver, targetConfigurationStore);
098:
099: ConfigurationData configurationData = context
100: .getConfigurationData();
101:
102: try {
103: writeConfiguration(configurationData);
104: } finally {
105: context.close();
106: }
107: }
108:
109: private void writeConfiguration(
110: final ConfigurationData configurationData)
111: throws IOException {
112: if (expanded) {
113: ExecutableConfigurationUtil.writeConfiguration(
114: configurationData, carFile);
115: } else {
116: JarOutputStream out = null;
117: try {
118: out = new JarOutputStream(new FileOutputStream(carFile));
119: ExecutableConfigurationUtil.writeConfiguration(
120: configurationData, out);
121: out.flush();
122: } finally {
123: if (out != null) {
124: try {
125: out.close();
126: } catch (IOException ignored) {
127: // ignored
128: }
129: }
130: }
131: }
132: }
133: }
|