use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project camel by apache.
the class CamelBlueprintHelper method createBundleContext.
public static BundleContext createBundleContext(String name, String descriptors, boolean includeTestBundle, String bundleFilter, String testBundleVersion, String testBundleDirectives, ClassLoader loader, String[]... configAdminPidFiles) throws Exception {
TinyBundle bundle = null;
TinyBundle configAdminInitBundle = null;
if (includeTestBundle) {
// add ourselves as a bundle
bundle = createTestBundle(testBundleDirectives == null ? name : name + ';' + testBundleDirectives, testBundleVersion, descriptors);
}
if (configAdminPidFiles != null) {
configAdminInitBundle = createConfigAdminInitBundle(configAdminPidFiles);
}
return createBundleContext(name, bundleFilter, bundle, configAdminInitBundle, loader);
}
use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project camel by apache.
the class MainTest method testMainWithoutIncludingTestBundle.
@Test
public void testMainWithoutIncludingTestBundle() throws Exception {
TinyBundle bundle = TinyBundles.newBundle();
bundle.add("OSGI-INF/blueprint/camel.xml", getClass().getResourceAsStream("main-loadfile.xml"));
bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", SYMBOLIC_NAME).set("Bundle-Version", "1.0.0");
File tb = File.createTempFile(SYMBOLIC_NAME + "-", ".jar", new File("target"));
FileOutputStream out = new FileOutputStream(tb);
IOUtils.copy(bundle.build(), out);
out.close();
// simulate `camel:run` which is run after packaging the artifact, so a "bundle" (location with
// META-INF/MANIFEST.MF) is detected in target/classes
URLClassLoader loader = new URLClassLoader(new URL[] { tb.toURI().toURL() }, getClass().getClassLoader());
Main main = new Main();
main.setLoader(loader);
// bundle name will be used as filter for blueprint container filter
main.setBundleName(SYMBOLIC_NAME);
// don't include test bundle (which is what `mvn camel:run` actually does)
main.setIncludeSelfAsBundle(false);
// don't setup the blueprint file here - it'll be picked up from a bundle on classpath
//main.setDescriptors("none!");
// set the configAdmin persistent id
main.setConfigAdminPid("stuff");
// set the configAdmin persistent file name
main.setConfigAdminFileName("src/test/resources/etc/stuff.cfg");
main.doStart();
ProducerTemplate template = main.getCamelTemplate();
assertNotNull("We should get the template here", template);
String result = template.requestBody("direct:start", "hello", String.class);
assertEquals("Get a wrong response", "Bye hello", result);
main.stop();
}
use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project aries by apache.
the class Helper method createTestBundle.
protected static TinyBundle createTestBundle(String name, String version, String descriptors) throws FileNotFoundException, MalformedURLException {
TinyBundle bundle = TinyBundles.newBundle();
for (URL url : getBlueprintDescriptors(descriptors)) {
LOG.info("Using Blueprint XML file: " + url.getFile());
bundle.add("OSGI-INF/blueprint/blueprint-" + url.getFile().replace("/", "-"), url);
}
bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", name).set("Bundle-Version", version);
return bundle;
}
use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project camel by apache.
the class CamelBlueprintHelper method createConfigAdminInitBundle.
protected static TinyBundle createConfigAdminInitBundle(String[]... configAdminPidFiles) throws IOException {
TinyBundle bundle = TinyBundles.newBundle();
StringWriter configAdminInit = null;
for (String[] configAdminPidFile : configAdminPidFiles) {
if (configAdminPidFile == null) {
continue;
}
if (configAdminInit == null) {
configAdminInit = new StringWriter();
} else {
configAdminInit.append(',');
}
configAdminInit.append(configAdminPidFile[1]).append("=");
configAdminInit.append(new File(configAdminPidFile[0]).toURI().toString());
}
bundle.add(TestBundleActivator.class);
bundle.add(Util.class);
bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "ConfigAdminInit").set("Bundle-Version", BUNDLE_VERSION).set("Bundle-Activator", TestBundleActivator.class.getName());
if (configAdminInit != null) {
bundle.set("X-Camel-Blueprint-ConfigAdmin-Init", configAdminInit.toString());
}
return bundle;
}
use of org.ops4j.pax.swissbox.tinybundles.core.TinyBundle in project camel by apache.
the class CamelBlueprintHelper method createTestBundle.
protected static TinyBundle createTestBundle(String name, String version, String descriptors) throws IOException {
TinyBundle bundle = TinyBundles.newBundle();
for (URL url : getBlueprintDescriptors(descriptors)) {
LOG.info("Using Blueprint XML file: " + url.getFile());
bundle.add("OSGI-INF/blueprint/blueprint-" + url.getFile().replace("/", "-"), url);
}
bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", name).set("Bundle-Version", version);
return bundle;
}
Aggregations