Search in sources :

Example 6 with TinyBundle

use of org.ops4j.pax.tinybundles.core.TinyBundle in project sling by apache.

the class ClientSideTeleporter method buildTestBundle.

private InputStream buildTestBundle(Class<?> c, Collection<Class<?>> embeddedClasses, String bundleSymbolicName) throws IOException {
    final TinyBundle b = TinyBundles.bundle().set(Constants.BUNDLE_SYMBOLICNAME, bundleSymbolicName).set("Sling-Test-Regexp", c.getName() + ".*").set("Sling-Test-WaitForService-Timeout", Integer.toString(waitForServiceTimout)).add(c);
    for (Map.Entry<String, String> header : additionalBundleHeaders.entrySet()) {
        log.info("Add bundle header '{}' with value '{}'", header.getKey(), header.getValue());
        b.set(header.getKey(), header.getValue());
    }
    // enrich embedded classes by automatically detected dependencies
    for (Class<?> clz : dependencyAnalyzer.getDependencies(log)) {
        log.debug("Embed dependent class '{}' because it is referenced and in the allowed package prefixes", clz);
        b.add(clz);
    }
    // Embed specified classes
    for (Class<?> clz : embeddedClasses) {
        log.info("Embed class '{}'", clz);
        b.add(clz);
    }
    // Embed specified resources
    if (!embeddedResourcePaths.isEmpty()) {
        for (String path : embeddedResourcePaths) {
            final ClassResourceVisitor.Processor p = new ClassResourceVisitor.Processor() {

                @Override
                public void process(String resourcePath, InputStream resourceStream) throws IOException {
                    b.add(resourcePath, resourceStream);
                    log.info("Embed resource '{}'", resourcePath);
                }
            };
            new ClassResourceVisitor(getClass(), path).visit(p);
        }
    }
    return b.build(TinyBundles.withBnd());
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with TinyBundle

use of org.ops4j.pax.tinybundles.core.TinyBundle in project camel by apache.

the class CamelCxfBeanInjectTest method installBlueprintXML.

@Before
public void installBlueprintXML() throws Exception {
    // install the camel blueprint xml file we use in this test
    URL url = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/cxf/CamelCxfBeanInjectTest.xml", CamelCxfBeanInjectTest.class.getClassLoader());
    Bundle bundle = installBlueprintAsBundle("CamelCxfBeanInjectTest", url, false, b -> {
        ((TinyBundle) b).add(BeanInjectRouteBuilder.class, InnerClassStrategy.NONE).add(SimpleService.class, InnerClassStrategy.NONE).add(SimpleBean.class, InnerClassStrategy.NONE).set(Constants.DYNAMICIMPORT_PACKAGE, "*");
    });
    Properties props = new Properties();
    props.put("router.address", ENDPOINT_ADDRESS);
    props.put("router.port", Integer.toString(PORT));
    overridePropertiesWithConfigAdmin("my-placeholders", props);
    bundle.start();
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) Bundle(org.osgi.framework.Bundle) Properties(java.util.Properties) URL(java.net.URL) Before(org.junit.Before)

Example 8 with TinyBundle

use of org.ops4j.pax.tinybundles.core.TinyBundle in project camel by apache.

the class AbstractFeatureTest method installSpringAsBundle.

protected Bundle installSpringAsBundle(String name, URL url, boolean start, Consumer<Object> consumer) throws BundleException {
    // TODO Type Consumer<TinyBundle> cannot be used for this method signature to avoid bundle dependency to pax tinybundles
    TinyBundle bundle = TinyBundles.bundle();
    bundle.add("META-INF/spring/spring-" + name.toLowerCase(Locale.ENGLISH) + ".xml", url);
    bundle.set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", name).set("Bundle-Version", "1.0.0");
    consumer.accept(bundle);
    Bundle answer = bundleContext.installBundle(name, bundle.build());
    if (start) {
        answer.start();
    }
    return answer;
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) Bundle(org.osgi.framework.Bundle) TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle)

Aggregations

TinyBundle (org.ops4j.pax.tinybundles.core.TinyBundle)8 Bundle (org.osgi.framework.Bundle)3 InputStream (java.io.InputStream)2 URL (java.net.URL)2 CoreOptions.mavenBundle (org.ops4j.pax.exam.CoreOptions.mavenBundle)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ZipInputStream (java.util.zip.ZipInputStream)1 CamelContext (org.apache.camel.CamelContext)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1 MyConverter (org.apache.camel.itest.typeconverter.MyConverter)1 AbstractFeatureTest (org.apache.camel.test.karaf.AbstractFeatureTest)1 WebConsoleTestActivator (org.apache.sling.commons.log.webconsole.remote.WebConsoleTestActivator)1 AfterClass (org.junit.AfterClass)1 Before (org.junit.Before)1