1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
30
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 }