2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.repo
.osgi
;
18 import java
.io
.InputStream
;
20 import java
.util
.ArrayList
;
21 import java
.util
.Collections
;
22 import java
.util
.List
;
23 import java
.util
.Properties
;
25 import org
.apache
.commons
.io
.IOUtils
;
26 import org
.argeo
.slc
.SlcException
;
29 * Wraps an OSGi profile, simplifying access to its values such as system
32 public class OsgiProfile
{
33 public final static String PROP_SYSTEM_PACKAGES
= "org.osgi.framework.system.packages";
35 public final static OsgiProfile PROFILE_JAVA_SE_1_6
= new OsgiProfile(
36 "JavaSE-1.6.profile");
38 private final URL url
;
39 private final Properties properties
;
41 public OsgiProfile(URL url
) {
43 properties
= new Properties();
44 InputStream in
= null;
46 properties
.load(this.url
.openStream());
47 } catch (Exception e
) {
48 throw new SlcException("Cannot initalize OSGi profile " + url
, e
);
50 IOUtils
.closeQuietly(in
);
54 public OsgiProfile(String name
) {
55 this(OsgiProfile
.class.getClassLoader().getResource(
57 + OsgiProfile
.class.getPackage().getName()
58 .replace('.', '/') + '/' + name
));
61 public List
<String
> getSystemPackages() {
62 String
[] splitted
= properties
.getProperty(PROP_SYSTEM_PACKAGES
).split(
64 List
<String
> res
= new ArrayList
<String
>();
65 for (String pkg
: splitted
) {
68 return Collections
.unmodifiableList(res
);