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 */
019
020 package org.apache.geronimo.mavenplugins.car;
021
022 import java.io.File;
023 import java.io.IOException;
024 import java.util.List;
025
026 import org.apache.geronimo.gbean.GBeanInfo;
027 import org.apache.geronimo.gbean.GBeanInfoBuilder;
028 import org.apache.geronimo.kernel.config.ConfigurationData;
029 import org.apache.geronimo.kernel.config.InvalidConfigException;
030 import org.apache.geronimo.kernel.config.NoSuchConfigException;
031 import org.apache.geronimo.kernel.config.ConfigurationInfo;
032 import org.apache.geronimo.kernel.repository.Artifact;
033 import org.apache.geronimo.kernel.repository.WritableListableRepository;
034 import org.apache.geronimo.kernel.Kernel;
035 import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
036 import org.apache.geronimo.system.configuration.RepositoryConfigurationStore;
037
038 /**
039 * Implementation of ConfigurationStore that loads Configurations from a repository.
040 * This implementation is read-only on the assumption that a separate maven task will
041 * handle installation of a built package into the repository.
042 *
043 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
044 */
045 public class MavenConfigStore
046 extends RepositoryConfigurationStore
047 {
048 public MavenConfigStore(Kernel kernel, String objectName, WritableListableRepository repository) {
049 super(kernel, objectName, null, repository);
050 }
051
052 public MavenConfigStore(WritableListableRepository repository) {
053 super(repository);
054 }
055
056 public File createNewConfigurationDir(Artifact configId) {
057 try {
058 File tmpFile = File.createTempFile("package", ".tmpdir");
059 tmpFile.delete();
060 tmpFile.mkdir();
061 if (!tmpFile.isDirectory()) {
062 return null;
063 }
064 // create the meta-inf dir
065 File metaInf = new File(tmpFile, "META-INF");
066 metaInf.mkdirs();
067 return tmpFile;
068 }
069 catch (IOException e) {
070 // doh why can't I throw this?
071 return null;
072 }
073 }
074
075 public void install(ConfigurationData configurationData) throws IOException, InvalidConfigException {
076 File source = configurationData.getConfigurationDir();
077 if (!source.isDirectory()) {
078 throw new InvalidConfigException("Source must be a directory: " + source);
079 }
080
081 Artifact configId = configurationData.getId();
082 File targetFile = repository.getLocation(configId);
083 ExecutableConfigurationUtil.createExecutableConfiguration(configurationData, null, targetFile);
084 }
085
086 public void uninstall(Artifact configID) 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(MavenConfigStore.class, "ConfigurationStore");
103 builder.addAttribute("kernel", Kernel.class, false);
104 builder.addAttribute("objectName", String.class, false);
105 builder.addReference("Repository", WritableListableRepository.class, "Repository");
106 builder.setConstructor(new String[]{"kernel", "objectName", "Repository"});
107 GBEAN_INFO = builder.getBeanInfo();
108 }
109 }