1 /**
2 *
3 * Copyright 2005 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.plugin.car;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.kernel.config.ConfigurationData;
27 import org.apache.geronimo.kernel.config.InvalidConfigException;
28 import org.apache.geronimo.kernel.config.NoSuchConfigException;
29 import org.apache.geronimo.kernel.repository.Artifact;
30 import org.apache.geronimo.kernel.repository.WritableListableRepository;
31 import org.apache.geronimo.kernel.Kernel;
32 import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
33 import org.apache.geronimo.system.configuration.RepositoryConfigurationStore;
34
35 /**
36 * Implementation of ConfigurationStore that loads Configurations from a repository.
37 * This implementation is read-only on the assumption that a separate maven task will
38 * handle installation of a built package into the repository.
39 *
40 * @version $Rev: 428888 $ $Date: 2006-08-04 23:21:54 +0200 (ven., 04 août 2006) $
41 */
42 public class MavenConfigStore
43 extends RepositoryConfigurationStore
44 {
45 public MavenConfigStore(Kernel kernel, String objectName, WritableListableRepository repository) {
46 super(kernel, objectName, repository);
47 }
48
49 public MavenConfigStore(WritableListableRepository repository) {
50 super(repository);
51 }
52
53 public File createNewConfigurationDir(Artifact configId) {
54 try {
55 File tmpFile = File.createTempFile("package", ".tmpdir");
56 tmpFile.delete();
57 tmpFile.mkdir();
58 if (!tmpFile.isDirectory()) {
59 return null;
60 }
61
62 File metaInf = new File(tmpFile, "META-INF");
63 metaInf.mkdirs();
64 return tmpFile;
65 }
66 catch (IOException e) {
67
68 return null;
69 }
70 }
71
72 public void install(ConfigurationData configurationData) throws IOException, InvalidConfigException {
73 File source = configurationData.getConfigurationDir();
74 if (!source.isDirectory()) {
75 throw new InvalidConfigException("Source must be a directory: source=" + source);
76 }
77 Artifact configId = configurationData.getId();
78 File targetFile = repository.getLocation(configId);
79 ExecutableConfigurationUtil.createExecutableConfiguration(configurationData, null, targetFile);
80 }
81
82 public void uninstall(Artifact configID) throws NoSuchConfigException, IOException {
83 File targetFile = repository.getLocation(configID);
84 targetFile.delete();
85 }
86
87 public List listConfigurations() {
88 throw new UnsupportedOperationException();
89 }
90
91 public static final GBeanInfo GBEAN_INFO;
92
93 public static GBeanInfo getGBeanInfo() {
94 return GBEAN_INFO;
95 }
96
97 static {
98 GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(MavenConfigStore.class, "ConfigurationStore");
99 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 }