]> git.argeo.org Git - lgpl/argeo-commons.git/blob - a2/OsgiContext.java
Prepare next development cycle
[lgpl/argeo-commons.git] / a2 / OsgiContext.java
1 package org.argeo.osgi.boot.a2;
2
3 import org.argeo.osgi.boot.OsgiBootUtils;
4 import org.osgi.framework.Bundle;
5 import org.osgi.framework.BundleContext;
6 import org.osgi.framework.FrameworkUtil;
7 import org.osgi.framework.Version;
8
9 class OsgiContext extends ProvisioningSource {
10 private final BundleContext bc;
11
12 public OsgiContext(BundleContext bc) {
13 super();
14 this.bc = bc;
15 }
16
17 public OsgiContext() {
18 Bundle bundle = FrameworkUtil.getBundle(OsgiContext.class);
19 if (bundle == null)
20 throw new IllegalArgumentException(
21 "OSGi Boot bundle must be started or a bundle context must be specified");
22 this.bc = bundle.getBundleContext();
23 }
24
25 void load() {
26 A2Contribution runtimeContribution = new A2Contribution(this, A2Contribution.RUNTIME);
27 for (Bundle bundle : bc.getBundles()) {
28 // OsgiBootUtils.debug(bundle.getDataFile("/"));
29 String componentId = bundle.getSymbolicName();
30 Version version = bundle.getVersion();
31 A2Component component = runtimeContribution.getOrAddComponent(componentId);
32 A2Module module = component.getOrAddModule(version, bundle);
33 if (OsgiBootUtils.isDebug())
34 OsgiBootUtils.debug("Registered " + module + " (location id: " + bundle.getLocation() + ")");
35 }
36
37 }
38 }