use of org.apache.felix.connect.launch.BundleDescriptor in project camel by apache.
the class CamelBlueprintHelper method createBundleContext.
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<String, Object>();
config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
// create pojorsr osgi service registry
PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
return reg.getBundleContext();
}
use of org.apache.felix.connect.launch.BundleDescriptor in project felix by apache.
the class PojoSR method createSystemBundle.
public static BundleDescriptor createSystemBundle() {
final Map<String, String> headers = new HashMap<String, String>();
headers.put(Constants.BUNDLE_SYMBOLICNAME, "org.apache.felix.connect");
headers.put(Constants.BUNDLE_VERSION, "0.0.0");
headers.put(Constants.BUNDLE_NAME, "System Bundle");
headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
headers.put(Constants.BUNDLE_VENDOR, "Apache Software Foundation");
Revision revision = new Revision() {
final long lastModified = System.currentTimeMillis();
@Override
public long getLastModified() {
return lastModified;
}
@Override
public Enumeration<String> getEntries() {
return Collections.enumeration(Collections.EMPTY_LIST);
}
@Override
public URL getEntry(String entryName) {
return getClass().getClassLoader().getResource(entryName);
}
};
Map<Class, Object> services = new HashMap<Class, Object>();
services.put(FrameworkStartLevel.class, new FrameworkStartLevelImpl());
return new BundleDescriptor(PojoSR.class.getClassLoader(), "System Bundle", headers, revision, services);
}
use of org.apache.felix.connect.launch.BundleDescriptor in project karaf by apache.
the class EncryptablePropertyPlaceholderTest method setUp.
@Before
public void setUp() throws Exception {
StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
env.setAlgorithm("PBEWithMD5AndDES");
env.setPassword("password");
enc.setConfig(env);
String val = enc.encrypt("bar");
System.setProperty("foo", val);
System.setProperty("org.bundles.framework.storage", "target/bundles/" + System.currentTimeMillis());
System.setProperty("karaf.name", "root");
List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
bundles.add(getBundleDescriptor("target/jasypt.jar", bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "jasypt").set("Bundle-Version", "0.0.0")));
bundles.add(getBundleDescriptor("target/test.jar", bundle().add("OSGI-INF/blueprint/test.xml", getClass().getResource("test.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "test").set("Bundle-Version", "0.0.0")));
Map config = new HashMap();
config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
bundleContext = reg.getBundleContext();
}
use of org.apache.felix.connect.launch.BundleDescriptor in project jackrabbit-oak by apache.
the class OakOSGiRepositoryFactory method startBundles.
private void startBundles(PojoServiceRegistry registry, String bundleFilter, Map config) {
try {
if (bundleFilter == null) {
bundleFilter = REPOSITORY_BUNDLE_FILTER_DEFAULT;
}
List<BundleDescriptor> descriptors = new ClasspathScanner().scanForBundles(bundleFilter);
descriptors = Lists.newArrayList(descriptors);
if (PropertiesUtil.toBoolean(config.get(REPOSITORY_ENV_SPRING_BOOT), false)) {
descriptors = SpringBootSupport.processDescriptors(descriptors);
}
descriptors = processDescriptors(descriptors);
registry.startBundles(descriptors);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.felix.connect.launch.BundleDescriptor in project felix by apache.
the class PojoSR method startBundles.
public void startBundles(Collection<BundleDescriptor> scan) throws Exception {
for (BundleDescriptor desc : scan) {
Revision revision = desc.getRevision();
if (revision == null) {
revision = buildRevision(desc);
}
Map<String, String> bundleHeaders = desc.getHeaders();
Version osgiVersion;
try {
osgiVersion = Version.parseVersion(bundleHeaders.get(Constants.BUNDLE_VERSION));
} catch (Exception ex) {
ex.printStackTrace();
osgiVersion = Version.emptyVersion;
}
String sym = bundleHeaders.get(Constants.BUNDLE_SYMBOLICNAME);
if (sym != null) {
int idx = sym.indexOf(';');
if (idx > 0) {
sym = sym.substring(0, idx);
}
sym = sym.trim();
}
Bundle bundle = new PojoSRBundle(m_registry, m_dispatcher, m_bundles, desc.getUrl(), m_bundles.size(), sym, osgiVersion, revision, desc.getClassLoader(), bundleHeaders, desc.getServices(), bundleConfig);
m_bundles.put(bundle.getBundleId(), bundle);
}
for (Bundle bundle : m_bundles.values()) {
try {
bundle.start();
} catch (Throwable e) {
System.out.println("Unable to start bundle: " + bundle);
e.printStackTrace();
}
}
}
Aggregations