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;
}
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();
}
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;
}
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");
}
}
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;
}
}
Aggregations