Search in sources :

Example 11 with BundleException

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;
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) ManifestItem(org.talend.designer.camel.dependencies.core.model.ManifestItem) ArrayList(java.util.ArrayList) BundleException(org.osgi.framework.BundleException)

Example 12 with BundleException

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());
}
Also used : ServiceListener(org.osgi.framework.ServiceListener) Bundle(org.osgi.framework.Bundle) ServiceEvent(org.osgi.framework.ServiceEvent) Subsystem(org.osgi.service.subsystem.Subsystem) AtomicReference(java.util.concurrent.atomic.AtomicReference) BundleException(org.osgi.framework.BundleException) FileInputStream(java.io.FileInputStream) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 13 with BundleException

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);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) BundleException(org.osgi.framework.BundleException) Test(org.junit.Test)

Example 14 with 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;
}
Also used : JarInputStream(java.util.jar.JarInputStream) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) Manifest(java.util.jar.Manifest)

Example 15 with BundleException

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);
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Manifest(java.util.jar.Manifest) URI(java.net.URI) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

BundleException (org.osgi.framework.BundleException)99 Bundle (org.osgi.framework.Bundle)54 IOException (java.io.IOException)31 Test (org.junit.Test)19 File (java.io.File)15 ArrayList (java.util.ArrayList)13 InputStream (java.io.InputStream)10 FileInputStream (java.io.FileInputStream)9 BundleContext (org.osgi.framework.BundleContext)9 HashMap (java.util.HashMap)8 Map (java.util.Map)7 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)7 Hashtable (java.util.Hashtable)5 Manifest (java.util.jar.Manifest)5 ServiceReference (org.osgi.framework.ServiceReference)5 Version (org.osgi.framework.Version)5 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)5 LowDiskException (android.taobao.atlas.runtime.LowDiskException)4 TimeoutException (java.util.concurrent.TimeoutException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4