in testing/support/src/main/java/org/apache/servicemix/platform/testing/support/SmxPlatform.java [110:159]
public void start() throws Exception {
Set<String> jars = getJars(Felix.class);
ClassLoader classLoader = new GuardClassLoader(toURLs(jars.toArray(new String[jars.size()])), null);
BundleActivator activator = new BundleActivator() {
private ServiceRegistration registration;
public void start(BundleContext context) {
registration = context.registerService(MainService.class.getName(), new MainService() {
public String[] getArgs() {
return new String[0];
}
public int getExitCode() {
return 0;
}
public void setExitCode(int exitCode) {
}
}, null);
}
public void stop(BundleContext context) {
registration.unregister();
}
};
List<BundleActivator> activations = new ArrayList<BundleActivator>();
activations.add(activator);
Properties props = getConfigurationProperties();
props.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, activations);
Thread.currentThread().setContextClassLoader(classLoader);
Class cl = classLoader.loadClass(Felix.class.getName());
Constructor cns = cl.getConstructor(Map.class);
platform = cns.newInstance(props);
platform.getClass().getMethod("start").invoke(platform);
Bundle systemBundle = (Bundle) platform;
// call getBundleContext
final Method getContext = systemBundle.getClass().getMethod("getBundleContext");
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
getContext.setAccessible(true);
return null;
}
});
context = (BundleContext) getContext.invoke(systemBundle);
}