]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/OsgiProfile.java
Adapt to changes in Argeo Commons
[gpl/argeo-slc.git] / org.argeo.slc.repo / src / org / argeo / slc / repo / osgi / OsgiProfile.java
1 package org.argeo.slc.repo.osgi;
2
3 import java.io.InputStream;
4 import java.net.URL;
5 import java.util.ArrayList;
6 import java.util.Collections;
7 import java.util.List;
8 import java.util.Properties;
9
10 import org.apache.commons.io.IOUtils;
11 import org.argeo.slc.SlcException;
12
13 /**
14 * Wraps an OSGi profile, simplifying access to its values such as system
15 * packages, etc.
16 */
17 public class OsgiProfile {
18 public final static String PROP_SYSTEM_PACKAGES = "org.osgi.framework.system.packages";
19
20 public final static OsgiProfile PROFILE_JAVA_SE_1_6 = new OsgiProfile("JavaSE-1.6.profile");
21
22 private final URL url;
23 private final Properties properties;
24
25 public OsgiProfile(URL url) {
26 this.url = url;
27 properties = new Properties();
28 InputStream in = null;
29 try {
30 properties.load(this.url.openStream());
31 } catch (Exception e) {
32 throw new SlcException("Cannot initalize OSGi profile " + url, e);
33 } finally {
34 IOUtils.closeQuietly(in);
35 }
36 }
37
38 public OsgiProfile(String name) {
39 this(OsgiProfile.class.getClassLoader()
40 .getResource('/' + OsgiProfile.class.getPackage().getName().replace('.', '/') + '/' + name));
41 }
42
43 public List<String> getSystemPackages() {
44 String[] splitted = properties.getProperty(PROP_SYSTEM_PACKAGES).split(",");
45 List<String> res = new ArrayList<String>();
46 for (String pkg : splitted) {
47 res.add(pkg.trim());
48 }
49 return Collections.unmodifiableList(res);
50 }
51 }