001 /**
002 *
003 * Copyright 2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * 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 */
017
018 package org.apache.geronimo.plugin.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.repository.Artifact;
030 import org.apache.geronimo.kernel.repository.WritableListableRepository;
031 import org.apache.geronimo.kernel.Kernel;
032 import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
033 import org.apache.geronimo.system.configuration.RepositoryConfigurationStore;
034
035 /**
036 * Implementation of ConfigurationStore that loads Configurations from a repository.
037 * This implementation is read-only on the assumption that a separate maven task will
038 * handle installation of a built package into the repository.
039 *
040 * @version $Rev: 428888 $ $Date: 2006-08-04 23:21:54 +0200 (ven., 04 août 2006) $
041 */
042 public class MavenConfigStore
043 extends RepositoryConfigurationStore
044 {
045 public MavenConfigStore(Kernel kernel, String objectName, WritableListableRepository repository) {
046 super(kernel, objectName, 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 }
066 catch (IOException e) {
067 // doh why can't I throw this?
068 return null;
069 }
070 }
071
072 public void install(ConfigurationData configurationData) throws IOException, InvalidConfigException {
073 File source = configurationData.getConfigurationDir();
074 if (!source.isDirectory()) {
075 throw new InvalidConfigException("Source must be a directory: source=" + source);
076 }
077 Artifact configId = configurationData.getId();
078 File targetFile = repository.getLocation(configId);
079 ExecutableConfigurationUtil.createExecutableConfiguration(configurationData, null, targetFile);
080 }
081
082 public void uninstall(Artifact configID) throws NoSuchConfigException, IOException {
083 File targetFile = repository.getLocation(configID);
084 targetFile.delete();
085 }
086
087 public List listConfigurations() {
088 throw new UnsupportedOperationException();
089 }
090
091 public static final GBeanInfo GBEAN_INFO;
092
093 public static GBeanInfo getGBeanInfo() {
094 return GBEAN_INFO;
095 }
096
097 static {
098 GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(MavenConfigStore.class, "ConfigurationStore");
099 builder.addAttribute("kernel", Kernel.class, false);
100 builder.addAttribute("objectName", String.class, false);
101 builder.addReference("Repository", WritableListableRepository.class, "Repository");
102 builder.setConstructor(new String[]{"kernel", "objectName", "Repository"});
103 GBEAN_INFO = builder.getBeanInfo();
104 }
105 }