Search in sources :

Example 11 with TinyBundle

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

the class AbstractPerformanceTest method createBundle.

protected InputStream createBundle(String symbolicName, String packageNamePrefix, String importOrExport) {
    TinyBundle tinyBundle = TinyBundles.bundle();
    tinyBundle.set(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
    StringBuilder builder = new StringBuilder(packageNamePrefix + 0);
    for (int i = 1; i < PACKAGE_COUNT; i++) {
        builder.append(',');
        builder.append(packageNamePrefix + i);
    }
    tinyBundle.set(importOrExport, builder.toString());
    InputStream is = tinyBundle.build();
    return is;
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) InputStream(java.io.InputStream)

Example 12 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 13 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)

Example 14 with TinyBundle

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

the class TestNativeMethod method buildBundleWithNativeLibraries.

public static Option buildBundleWithNativeLibraries() {
    File out = new File("target/tested/test-bundle-with-native.jar");
    if (out.exists()) {
        try {
            return bundle(out.toURI().toURL().toExternalForm());
        } catch (MalformedURLException e) {
        // Ignore it.
        }
    }
    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<String> exports = new ArrayList<String>();
    for (File file : files) {
        if (file.isDirectory()) {
            // By convention we export of .services and .service package
            if (file.getAbsolutePath().contains("/services") || file.getAbsolutePath().contains("/service")) {
                String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
                String packageName = path.replace('/', '.');
                exports.add(packageName);
            }
        } else {
            // We need to compute the path
            String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
            try {
                tested.add(path, file.toURI().toURL());
            } catch (MalformedURLException e) {
            // Ignore it.
            }
            System.out.println(file.getName() + " added to " + path);
        }
    }
    // Depending on the the order, the probe bundle may already have detected requirements on components.
    String clause = "" + "org.apache.felix.ipojo.runtime.core.components, " + "org.apache.felix.ipojo.runtime.core.services, " + "org.apache.felix.ipojo.runtime.core.services.A123";
    for (String export : exports) {
        if (export.length() > 0) {
            export += ", ";
        }
        clause += export;
    }
    System.out.println("Exported packages : " + clause);
    InputStream inputStream = tested.set(Constants.BUNDLE_SYMBOLICNAME, BaseTest.TEST_BUNDLE_SYMBOLIC_NAME + "-with-native").set(Constants.IMPORT_PACKAGE, "*").set(Constants.EXPORT_PACKAGE, clause).set(Constants.BUNDLE_NATIVECODE, NATIVE_CLAUSE).build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
    try {
        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) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile)

Example 15 with TinyBundle

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

the class Common method iPOJOHelloConsumer.

/**
 * iPOJO Hello Service Provider.
 */
public Option iPOJOHelloConsumer() {
    File out = new File("target/bundles/hello-consumer-ipojo.jar");
    if (out.exists()) {
        try {
            return bundle(out.toURI().toURL().toExternalForm());
        } catch (MalformedURLException e) {
        // Ignore it.
        }
    }
    TinyBundle bundle = TinyBundles.bundle();
    bundle.add(HelloServiceConsumer.class);
    InputStream inputStream = bundle.set(Constants.BUNDLE_SYMBOLICNAME, "iPOJO-Hello-Consumer").build(IPOJOStrategy.withiPOJO());
    try {
        FileUtils.copyInputStreamToFile(inputStream, out);
        return bundle(out.toURI().toURL().toExternalForm());
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) MalformedURLException(java.net.MalformedURLException)

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