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;
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class MockBundleContextTest method testBundleListener.
@Test
public void testBundleListener() throws Exception {
BundleListener bundleListener = mock(BundleListener.class);
BundleEvent bundleEvent = mock(BundleEvent.class);
bundleContext.addBundleListener(bundleListener);
MockOsgi.sendBundleEvent(bundleContext, bundleEvent);
verify(bundleListener).bundleChanged(bundleEvent);
bundleContext.removeBundleListener(bundleListener);
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class ModelAdapterFactoryUtil method addModelsForPackages.
/**
* Search classpath for given java package names (and sub packages) to scan for and
* register all classes with @Model annotation.
* @param bundleContext Bundle context
* @param packageNames Java package names
*/
public static void addModelsForPackages(BundleContext bundleContext, String... packageNames) {
Bundle bundle = new RegisterModelsBundle(bundleContext, Bundle.ACTIVE, packageNames, null);
BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
MockOsgi.sendBundleEvent(bundleContext, event);
}
Aggregations