]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/OsgiProfile.java
Generalize ArchiveWrapper and deprecates ImportBundlesZip
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / osgi / OsgiProfile.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.repo.osgi;
17
18 import java.io.InputStream;
19 import java.net.URL;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Properties;
24
25 import org.apache.commons.io.IOUtils;
26 import org.argeo.slc.SlcException;
27
28 /**
29 * Wraps an OSGi profile, simplifying access to its values such as system
30 * packages, etc.
31 */
32 public class OsgiProfile {
33 public final static String PROP_SYSTEM_PACKAGES = "org.osgi.framework.system.packages";
34
35 public final static OsgiProfile PROFILE_JAVA_SE_1_6 = new OsgiProfile(
36 "JavaSE-1.6.profile");
37
38 private final URL url;
39 private final Properties properties;
40
41 public OsgiProfile(URL url) {
42 this.url = url;
43 properties = new Properties();
44 InputStream in = null;
45 try {
46 properties.load(this.url.openStream());
47 } catch (Exception e) {
48 throw new SlcException("Cannot initalize OSGi profile " + url, e);
49 } finally {
50 IOUtils.closeQuietly(in);
51 }
52 }
53
54 public OsgiProfile(String name) {
55 this(OsgiProfile.class.getClassLoader().getResource(
56 '/'
57 + OsgiProfile.class.getPackage().getName()
58 .replace('.', '/') + '/' + name));
59 }
60
61 public List<String> getSystemPackages() {
62 String[] splitted = properties.getProperty(PROP_SYSTEM_PACKAGES).split(
63 ",");
64 List<String> res = new ArrayList<String>();
65 for (String pkg : splitted) {
66 res.add(pkg.trim());
67 }
68 return Collections.unmodifiableList(res);
69 }
70 }