001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.geronimo.mavenplugins.car;
019:
020: import java.io.File;
021: import java.io.IOException;
022: import java.util.List;
023:
024: import org.apache.geronimo.gbean.GBeanInfo;
025: import org.apache.geronimo.gbean.GBeanInfoBuilder;
026: import org.apache.geronimo.kernel.config.ConfigurationData;
027: import org.apache.geronimo.kernel.config.InvalidConfigException;
028: import org.apache.geronimo.kernel.config.NoSuchConfigException;
029: import org.apache.geronimo.kernel.config.ConfigurationInfo;
030: import org.apache.geronimo.kernel.repository.Artifact;
031: import org.apache.geronimo.kernel.repository.WritableListableRepository;
032: import org.apache.geronimo.kernel.Kernel;
033: import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
034: import org.apache.geronimo.system.configuration.RepositoryConfigurationStore;
035:
036: /**
037: * Implementation of ConfigurationStore that loads Configurations from a repository.
038: * This implementation is read-only on the assumption that a separate maven task will
039: * handle installation of a built package into the repository.
040: *
041: * @version $Rev: 604483 $ $Date: 2007-12-15 10:28:19 -0800 (Sat, 15 Dec 2007) $
042: */
043: public class MavenConfigStore extends RepositoryConfigurationStore {
044: public MavenConfigStore(Kernel kernel, String objectName,
045: WritableListableRepository repository) {
046: super (kernel, objectName, null, repository);
047: }
048:
049: public MavenConfigStore(WritableListableRepository repository) {
050: super (repository);
051: }
052:
053: public File createNewConfigurationDir(Artifact configId) {
054: try {
055: File tmpFile = File.createTempFile("package", ".tmpdir");
056: tmpFile.delete();
057: tmpFile.mkdir();
058: if (!tmpFile.isDirectory()) {
059: return null;
060: }
061: // create the meta-inf dir
062: File metaInf = new File(tmpFile, "META-INF");
063: metaInf.mkdirs();
064: return tmpFile;
065: } catch (IOException e) {
066: // doh why can't I throw this?
067: return null;
068: }
069: }
070:
071: public void install(ConfigurationData configurationData)
072: throws IOException, InvalidConfigException {
073: File source = configurationData.getConfigurationDir();
074: if (!source.isDirectory()) {
075: throw new InvalidConfigException(
076: "Source must be a directory: " + source);
077: }
078:
079: Artifact configId = configurationData.getId();
080: File targetFile = repository.getLocation(configId);
081: ExecutableConfigurationUtil.createExecutableConfiguration(
082: configurationData, null, targetFile);
083: }
084:
085: public void uninstall(Artifact configID)
086: throws NoSuchConfigException, IOException {
087: File targetFile = repository.getLocation(configID);
088: targetFile.delete();
089: }
090:
091: public List<ConfigurationInfo> listConfigurations() {
092: throw new UnsupportedOperationException();
093: }
094:
095: public static final GBeanInfo GBEAN_INFO;
096:
097: public static GBeanInfo getGBeanInfo() {
098: return GBEAN_INFO;
099: }
100:
101: static {
102: GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(
103: MavenConfigStore.class, "ConfigurationStore");
104: builder.addAttribute("kernel", Kernel.class, false);
105: builder.addAttribute("objectName", String.class, false);
106: builder.addReference("Repository",
107: WritableListableRepository.class, "Repository");
108: builder.setConstructor(new String[] { "kernel", "objectName",
109: "Repository" });
110: GBEAN_INFO = builder.getBeanInfo();
111: }
112: }
|