in components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/CamelBlueprintHelper.java [136:196]
public static BundleContext createBundleContext(String name, String bundleFilter,
TinyBundle bundle, TinyBundle configAdminInitBundle,
ClassLoader loader) throws Exception {
// ensure felix-connect stores bundles in an unique target directory
String uid = "" + System.currentTimeMillis();
String tempDir = "target/bundles/" + uid;
System.setProperty("org.osgi.framework.storage", tempDir);
createDirectory(tempDir);
// use another directory for the jar of the bundle as it cannot be in the same directory
// as it has a file lock during running the tests which will cause the temp dir to not be
// fully deleted between tests
createDirectory("target/test-bundles");
List<BundleDescriptor> bundles = new LinkedList<>();
if (configAdminInitBundle != null) {
String jarName = "configAdminInitBundle-" + uid + ".jar";
bundles.add(getBundleDescriptor("target/test-bundles/" + jarName, configAdminInitBundle));
}
if (bundle != null) {
String jarName = name.toLowerCase(Locale.ENGLISH) + "-" + uid + ".jar";
bundles.add(getBundleDescriptor("target/test-bundles/" + jarName, bundle));
}
List<BundleDescriptor> bundleDescriptors = getBundleDescriptors(bundleFilter, loader);
// let's put configadmin before blueprint.core
int idx1 = -1;
int idx2 = -1;
for (int i = 0; i < bundleDescriptors.size(); i++) {
BundleDescriptor bd = bundleDescriptors.get(i);
if ("org.apache.felix.configadmin".equals(bd.getHeaders().get("Bundle-SymbolicName"))) {
idx1 = i;
}
if ("org.apache.aries.blueprint.core".equals(bd.getHeaders().get("Bundle-SymbolicName"))) {
idx2 = i;
}
}
if (idx1 >= 0 && idx2 >= 0 && idx1 > idx2) {
bundleDescriptors.add(idx2, bundleDescriptors.remove(idx1));
}
// get the bundles
bundles.addAll(bundleDescriptors);
if (LOG.isDebugEnabled()) {
for (int i = 0; i < bundles.size(); i++) {
BundleDescriptor desc = bundles.get(i);
LOG.debug("Bundle #{} -> {}", i, desc);
}
}
// setup felix-connect to use our bundles
Map<String, Object> config = new HashMap<>();
config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
// create pojorsr osgi service registry
PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
return reg.getBundleContext();
}