use of org.osgi.framework.BundleException in project tesb-studio-se by Talend.
the class DependenciesCoreUtil method getManifestItems.
private static Collection<? extends ManifestItem> getManifestItems(Map<?, ?> map, String header) {
final Object data = map.get(header);
if (null != data) {
final Collection<ManifestItem> list = new ArrayList<ManifestItem>();
final String s = data.toString();
if (!s.isEmpty()) {
try {
for (ManifestElement me : ManifestElement.parseHeader(header, data.toString())) {
final ManifestItem item = ManifestItem.newItem(header);
item.setName(me.getValue());
item.setVersion(me.getAttribute(item.getVersionAttribute()));
item.setOptional(Constants.RESOLUTION_OPTIONAL.equals(me.getDirective(Constants.RESOLUTION_DIRECTIVE)));
item.setDescription(MessageFormat.format(Messages.DependenciesCoreUtil_userDefined, header));
list.add(item);
}
} catch (BundleException e) {
ExceptionHandler.process(e);
}
}
return list;
}
return null;
}
use of org.osgi.framework.BundleException in project aries by apache.
the class BundleEventHookTest method testIgnoreUninstalledBundleInAsyncInstalledEvent.
/*
* Because bundle events are queued for later asynchronous processing while
* the root subsystem is initializing, it is possible to see an installed
* event for a bundle that has been uninstalled (i.e. the bundle revision
* will be null). These events should be ignored.
*/
@Test
public void testIgnoreUninstalledBundleInAsyncInstalledEvent() throws Exception {
final Bundle core = getSubsystemCoreBundle();
core.stop();
final AtomicReference<Bundle> a = new AtomicReference<Bundle>();
bundleContext.addServiceListener(new ServiceListener() {
@SuppressWarnings("unchecked")
@Override
public void serviceChanged(ServiceEvent event) {
if ((event.getType() & (ServiceEvent.REGISTERED | ServiceEvent.MODIFIED)) == 0)
return;
if (a.get() != null)
// We've been here before and already done what needs doing.
return;
ServiceReference sr = (ServiceReference) event.getServiceReference();
bundleContext.getService(sr);
try {
// Queue up the installed event.
a.set(core.getBundleContext().installBundle(BUNDLE_A, new FileInputStream(BUNDLE_A)));
// Ensure the bundle will be uninstalled before the event is processed.
a.get().uninstall();
} catch (Exception e) {
e.printStackTrace();
}
}
}, "(&(objectClass=org.osgi.service.subsystem.Subsystem)(subsystem.id=0)(subsystem.state=RESOLVED))");
try {
// Before the fix, this would fail due to an NPE resulting from a
// null bundle revision.
core.start();
} catch (BundleException e) {
e.printStackTrace();
fail("Subsystems failed to handle an asynchronous bundle installed event after the bundle was uninstalled");
}
assertBundleState(a.get(), Bundle.UNINSTALLED);
Subsystem root = getRootSubsystem();
assertState(Subsystem.State.ACTIVE, root);
assertNotConstituent(root, a.get().getSymbolicName());
}
use of org.osgi.framework.BundleException in project aries by apache.
the class DynamicImportTest method verifyThatDynamicImportNeedsHandling.
/*
* Install an .esa containing a bundle with a BundleActivator, and a
* DynamicImport-Package on org.apache.aries.subsystem.itests.hello.api.
* This app should fail to start because we've not yet intervened to permit
* this dynamic package wiring requirement from being met.
*/
@Test
public void verifyThatDynamicImportNeedsHandling() throws Exception {
Subsystem subsystem = installSubsystemFromFile("dynamicImport.esa");
try {
startSubsystem(subsystem);
Bundle[] bundles = subsystem.getBundleContext().getBundles();
for (Bundle b : bundles) {
System.out.println(b.getSymbolicName() + " -> " + b.getState());
}
fail("dynamicImport.esa started when we didn't expect it to");
} catch (SubsystemException sx) {
Throwable cause = sx.getCause();
assertTrue("BundleException expected", cause instanceof BundleException);
}
}
use of org.osgi.framework.BundleException in project aries by apache.
the class BundleContextMock method installBundle.
/**
* This method implements the installBundle method from BundleContext. It
* makes use of the java.util.jar package to parse the manifest from the input
* stream.
*
* @param location the location of the bundle.
* @param is the input stream to read from.
* @return the created bundle.
* @throws BundleException
*/
public Bundle installBundle(String location, InputStream is) throws BundleException {
Bundle b;
JarInputStream jis;
try {
jis = new JarInputStream(is);
Manifest man = jis.getManifest();
b = createBundle(man, null);
} catch (IOException e) {
throw new BundleException(e.getMessage(), e);
}
return b;
}
use of org.osgi.framework.BundleException in project aries by apache.
the class BundleContextMock method installBundle.
/**
* Asks to install an OSGi bundle from the given location.
*
* @param location the location of the bundle on the file system.
* @return the installed bundle.
* @throws BundleException
*/
public Bundle installBundle(String location) throws BundleException {
try {
URI uri = new URI(location.replaceAll(" ", "%20"));
File baseDir = new File(uri);
Manifest man = null;
//check if it is a directory
if (baseDir.isDirectory()) {
man = new Manifest(new FileInputStream(new File(baseDir, "META-INF/MANIFEST.MF")));
} else //if it isn't assume it is a jar file
{
InputStream is = new FileInputStream(baseDir);
JarInputStream jis = new JarInputStream(is);
man = jis.getManifest();
jis.close();
if (man == null) {
throw new BundleException("Null manifest");
}
}
return createBundle(man, location);
} catch (IOException e) {
throw new BundleException(e.getMessage(), e);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
throw new BundleException(e.getMessage(), e);
}
}
Aggregations