use of org.osgi.framework.BundleEvent in project aries by apache.
the class JndiExtensionTests method testDisableExtensionAndCDIContainerWaits.
public void testDisableExtensionAndCDIContainerWaits() throws Exception {
BundleTracker<Bundle> bt = new BundleTracker<>(bundle.getBundleContext(), Bundle.RESOLVED | Bundle.ACTIVE, new BundleTrackerCustomizer<Bundle>() {
@Override
public Bundle addingBundle(Bundle bundle, BundleEvent arg1) {
List<BundleCapability> capabilities = bundle.adapt(BundleWiring.class).getCapabilities(CdiConstants.CDI_EXTENSION_NAMESPACE);
if (capabilities.isEmpty()) {
return null;
}
for (Capability capability : capabilities) {
if (capability.getAttributes().containsValue("jndi")) {
return bundle;
}
}
return null;
}
@Override
public void modifiedBundle(Bundle bundle, BundleEvent arg1, Bundle arg2) {
}
@Override
public void removedBundle(Bundle bundle, BundleEvent arg1, Bundle arg2) {
}
});
bt.open();
assertFalse(bt.isEmpty());
Bundle extensionBundle = bt.getBundles()[0];
Collection<ServiceReference<CdiContainer>> serviceReferences = bundleContext.getServiceReferences(CdiContainer.class, "(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + cdiBundle.getBundleId() + "))");
assertNotNull(serviceReferences);
assertFalse(serviceReferences.isEmpty());
ServiceReference<CdiContainer> serviceReference = serviceReferences.iterator().next();
CdiEvent.Type state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.CREATED, state);
extensionBundle.stop();
state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.WAITING_FOR_EXTENSIONS, state);
extensionBundle.start();
state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.CREATED, state);
}
use of org.osgi.framework.BundleEvent in project bnd by bndtools.
the class GC method start.
@Override
public void start(BundleContext context) throws Exception {
this.context = context;
context.addBundleListener(new BundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.UNINSTALLED) {
Bundle b = event.getBundle();
String embedded = b.getHeaders().get("Bnd-Embedded");
if (embedded != null) {
uninstalled(b);
}
}
}
});
}
use of org.osgi.framework.BundleEvent in project bnd by bndtools.
the class Activator method automatic.
void automatic(File reportDir) throws IOException {
final List<Bundle> queue = new Vector<Bundle>();
if (!reportDir.exists() && !reportDir.mkdirs()) {
throw new IOException("Could not create directory " + reportDir);
}
trace("using %s", reportDir);
trace("adding Bundle Listener for getting test bundle events");
context.addBundleListener(new SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.STARTED) {
checkBundle(queue, event.getBundle());
}
}
});
for (Bundle b : context.getBundles()) {
checkBundle(queue, b);
}
trace("starting queue");
int result = 0;
outer: while (active) {
Bundle bundle;
synchronized (queue) {
while (queue.isEmpty() && active) {
try {
queue.wait();
} catch (InterruptedException e) {
trace("tests bundle queue interrupted");
thread.interrupt();
break outer;
}
}
}
try {
bundle = queue.remove(0);
trace("received bundle to test: %s", bundle.getLocation());
try (Writer report = getReportWriter(reportDir, bundle)) {
trace("test will run");
result += test(bundle, (String) bundle.getHeaders().get(aQute.bnd.osgi.Constants.TESTCASES), report);
trace("test ran");
if (queue.isEmpty() && !continuous) {
trace("queue " + queue);
System.exit(result);
}
}
} catch (Exception e) {
error("Not sure what happened anymore %s", e);
System.exit(-2);
}
}
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class ConfigurationMetadataUtil method registerAnnotationClasses.
/**
* Search classpath for given class names to scan for and register all classes with @Configuration annotation.
* @param bundleContext Bundle context
* @param classNames Java class names
*/
public static void registerAnnotationClasses(BundleContext bundleContext, String... classNames) {
Bundle bundle = new RegisterConfigurationMetadataBundle(bundleContext, Bundle.ACTIVE, classNames);
BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
MockOsgi.sendBundleEvent(bundleContext, event);
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class BundleEventUtil method startDummyBundle.
/**
* Simulate a bundle STARTED event with a given set of classes simulated to be found in the bundle's classpath.
*/
public static Bundle startDummyBundle(BundleContext bundleContext, Class... classes) {
DummyBundle bundle = new DummyBundle(bundleContext, classes);
bundle.setState(Bundle.ACTIVE);
BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
MockOsgi.sendBundleEvent(bundleContext, event);
return bundle;
}
Aggregations