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.plugin.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.repository.Artifact; 032 import org.apache.geronimo.kernel.repository.WritableListableRepository; 033 import org.apache.geronimo.kernel.Kernel; 034 import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil; 035 import org.apache.geronimo.system.configuration.RepositoryConfigurationStore; 036 037 /** 038 * Implementation of ConfigurationStore that loads Configurations from a repository. 039 * This implementation is read-only on the assumption that a separate maven task will 040 * handle installation of a built package into the repository. 041 * 042 * @version $Rev: 451661 $ $Date: 2006-09-30 13:45:53 -0700 (Sat, 30 Sep 2006) $ 043 */ 044 public class MavenConfigStore 045 extends RepositoryConfigurationStore 046 { 047 public MavenConfigStore(Kernel kernel, String objectName, WritableListableRepository repository) { 048 super(kernel, objectName, repository); 049 } 050 051 public MavenConfigStore(WritableListableRepository repository) { 052 super(repository); 053 } 054 055 public File createNewConfigurationDir(Artifact configId) { 056 try { 057 File tmpFile = File.createTempFile("package", ".tmpdir"); 058 tmpFile.delete(); 059 tmpFile.mkdir(); 060 if (!tmpFile.isDirectory()) { 061 return null; 062 } 063 // create the meta-inf dir 064 File metaInf = new File(tmpFile, "META-INF"); 065 metaInf.mkdirs(); 066 return tmpFile; 067 } 068 catch (IOException e) { 069 // doh why can't I throw this? 070 return null; 071 } 072 } 073 074 public void install(ConfigurationData configurationData) throws IOException, InvalidConfigException { 075 File source = configurationData.getConfigurationDir(); 076 if (!source.isDirectory()) { 077 throw new InvalidConfigException("Source must be a directory: source=" + source); 078 } 079 Artifact configId = configurationData.getId(); 080 File targetFile = repository.getLocation(configId); 081 ExecutableConfigurationUtil.createExecutableConfiguration(configurationData, null, targetFile); 082 } 083 084 public void uninstall(Artifact configID) throws NoSuchConfigException, IOException { 085 File targetFile = repository.getLocation(configID); 086 targetFile.delete(); 087 } 088 089 public List listConfigurations() { 090 throw new UnsupportedOperationException(); 091 } 092 093 public static final GBeanInfo GBEAN_INFO; 094 095 public static GBeanInfo getGBeanInfo() { 096 return GBEAN_INFO; 097 } 098 099 static { 100 GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(MavenConfigStore.class, "ConfigurationStore"); 101 builder.addAttribute("kernel", Kernel.class, false); 102 builder.addAttribute("objectName", String.class, false); 103 builder.addReference("Repository", WritableListableRepository.class, "Repository"); 104 builder.setConstructor(new String[]{"kernel", "objectName", "Repository"}); 105 GBEAN_INFO = builder.getBeanInfo(); 106 } 107 }