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