Search in sources :

Example 1 with TinyBundle

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

the class ITWebConsoleRemote method createWebConsoleTestBundle.

private Option createWebConsoleTestBundle() {
    TinyBundle bundle = bundle();
    for (Class c : WebConsoleTestActivator.BUNDLE_CLASS_NAMES) {
        bundle.add(c);
    }
    bundle.set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.sling.common.log.testbundle").set(Constants.BUNDLE_ACTIVATOR, WebConsoleTestActivator.class.getName());
    return provision(bundle.build(withBnd()));
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) AfterClass(org.junit.AfterClass) WebConsoleTestActivator(org.apache.sling.commons.log.webconsole.remote.WebConsoleTestActivator)

Example 2 with TinyBundle

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

the class CamelTypeConverterTest method testTypeConverterInSameBundleAsCamelRoute.

@Test
public void testTypeConverterInSameBundleAsCamelRoute() throws Exception {
    // install the camel blueprint xml file and the Camel converter we use in this test
    URL blueprintUrl = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelTypeConverterTest.xml", CamelTypeConverterTest.class.getClassLoader());
    installBlueprintAsBundle("CamelTypeConverterTest", blueprintUrl, true, bundle -> {
        ((TinyBundle) bundle).add("META-INF/services/org/apache/camel/TypeConverter", new ByteArrayInputStream("org.apache.camel.itest.typeconverter.MyConverter".getBytes())).add(MyConverter.class, InnerClassStrategy.NONE).set(Constants.DYNAMICIMPORT_PACKAGE, "*");
    });
    // lookup Camel from OSGi
    CamelContext camel = getOsgiService(bundleContext, CamelContext.class);
    final Pojo pojo = new Pojo();
    String pojoName = "Constantine";
    pojo.setName(pojoName);
    final DefaultExchange exchange = new DefaultExchange(camel);
    final String string = camel.getTypeConverter().mandatoryConvertTo(String.class, exchange, pojo);
    LOG.info("POJO -> String: {}", string);
    final Pojo copy = camel.getTypeConverter().mandatoryConvertTo(Pojo.class, exchange, string);
    LOG.info("String -> POJO: {}", copy);
    Assert.assertEquals(pojoName, copy.getName());
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) CamelContext(org.apache.camel.CamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) ByteArrayInputStream(java.io.ByteArrayInputStream) MyConverter(org.apache.camel.itest.typeconverter.MyConverter) URL(java.net.URL) Test(org.junit.Test) AbstractFeatureTest(org.apache.camel.test.karaf.AbstractFeatureTest)

Example 3 with TinyBundle

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

the class AbstractFeatureTest method installBlueprintAsBundle.

protected Bundle installBlueprintAsBundle(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("OSGI-INF/blueprint/blueprint-" + 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)

Example 4 with TinyBundle

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

the class Common method testedBundle.

public Option testedBundle() throws MalformedURLException {
    File out = new File("target/tested/bundle.jar");
    TinyBundle tested = TinyBundles.bundle();
    // We look inside target/classes to find the class and resources
    File classes = new File("target/classes");
    Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    List<File> services = new ArrayList<File>();
    for (File file : files) {
        if (file.isDirectory()) {
            // By convention we export of .services and .service package
            if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
                services.add(file);
            }
        } else {
            // We need to compute the path
            String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
            tested.add(path, file.toURI().toURL());
            System.out.println(file.getName() + " added to " + path);
        }
    }
    String export = "";
    for (File file : services) {
        if (export.length() > 0) {
            export += ", ";
        }
        String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
        String packageName = path.replace('/', '.');
        export += packageName;
    }
    System.out.println("Exported packages : " + export);
    InputStream inputStream = tested.set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle").build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
    try {
        FileUtils.copyInputStreamToFile(inputStream, out);
        return bundle(out.toURI().toURL().toExternalForm());
    } catch (MalformedURLException e) {
        throw new RuntimeException("Cannot compute the url of the manipulated bundle");
    } catch (IOException e) {
        throw new RuntimeException("Cannot write of the manipulated bundle");
    }
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 5 with TinyBundle

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

the class Common method testedBundle.

public Option testedBundle() throws MalformedURLException {
    File out = new File("target/tested/bundle.jar");
    TinyBundle tested = TinyBundles.bundle();
    // We look inside target/classes to find the class and resources
    File classes = new File("target/classes");
    Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    List<File> services = new ArrayList<File>();
    for (File file : files) {
        if (file.isDirectory()) {
            // By convention we export of .services and .service package
            if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
                services.add(file);
            }
        } else {
            // We need to compute the path
            String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
            tested.add(path, file.toURI().toURL());
            System.out.println(file.getName() + " added to " + path);
        }
    }
    String export = "";
    for (File file : services) {
        if (export.length() > 0) {
            export += ", ";
        }
        String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
        String packageName = path.replace('/', '.');
        export += packageName;
    }
    System.out.println("Exported packages : " + export);
    InputStream inputStream = tested.set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle").build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
    try {
        FileUtils.copyInputStreamToFile(inputStream, out);
        return bundle(out.toURI().toURL().toExternalForm());
    } catch (MalformedURLException e) {
        throw new RuntimeException("Cannot compute the url of the manipulated bundle");
    } catch (IOException e) {
        throw new RuntimeException("Cannot write of the manipulated bundle");
    }
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Aggregations

TinyBundle (org.ops4j.pax.tinybundles.core.TinyBundle)19 MalformedURLException (java.net.MalformedURLException)11 InputStream (java.io.InputStream)6 File (java.io.File)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Bundle (org.osgi.framework.Bundle)3 URL (java.net.URL)2 CoreOptions.mavenBundle (org.ops4j.pax.exam.CoreOptions.mavenBundle)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)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