1 package org
.argeo
.osgi
.a2
;
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
;
9 /** A running OSGi bundle context seen as a {@link AbstractProvisioningSource}. */
10 class OsgiContext
extends AbstractProvisioningSource
{
11 private final BundleContext bc
;
13 public OsgiContext(BundleContext bc
) {
18 public OsgiContext() {
19 Bundle bundle
= FrameworkUtil
.getBundle(OsgiContext
.class);
21 throw new IllegalArgumentException(
22 "OSGi Boot bundle must be started or a bundle context must be specified");
23 this.bc
= bundle
.getBundleContext();
27 A2Contribution runtimeContribution
= getOrAddContribution( A2Contribution
.RUNTIME
);
28 for (Bundle bundle
: bc
.getBundles()) {
29 // OsgiBootUtils.debug(bundle.getDataFile("/"));
30 String componentId
= bundle
.getSymbolicName();
31 Version version
= bundle
.getVersion();
32 A2Component component
= runtimeContribution
.getOrAddComponent(componentId
);
33 A2Module module
= component
.getOrAddModule(version
, bundle
);
34 if (OsgiBootUtils
.isDebug())
35 OsgiBootUtils
.debug("Registered " + module
+ " (location id: " + bundle
.getLocation() + ")");