Search in sources :

Example 46 with BundleException

use of org.osgi.framework.BundleException in project bnd by bndtools.

the class AgentServer method uninstall.

@Override
public String uninstall(long... ids) {
    StringBuilder sb = new StringBuilder();
    for (long id : ids) {
        Bundle bundle = context.getBundle(id);
        try {
            bundle.uninstall();
            installed.remove(bundle.getBundleId());
        } catch (BundleException e) {
            sb.append(e.getMessage()).append("\n");
        }
    }
    return sb.length() == 0 ? null : sb.toString();
}
Also used : Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException)

Example 47 with BundleException

use of org.osgi.framework.BundleException in project bndtools by bndtools.

the class Activator method start.

/*
     * (non-Javadoc)
     * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext )
     */
@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    instance = this;
    this.context = context;
    Hashtable<String, Object> p = new Hashtable<String, Object>();
    // p.put(Action.ACTION_MENU, new String[] {"a:b", "a:c", "a:d",
    // "a:d:e"});
    context.registerService(Action.class.getName(), new ReflectAction(""), p);
    // We want the repoindex bundle to start so it registers its service.
    // (sigh... Eclipse)
    Bundle repoindex = BundleUtils.findBundle(context, "org.osgi.impl.bundle.repoindex.lib", new VersionRange("0"));
    if (repoindex != null) {
        try {
            repoindex.start();
        } catch (BundleException e) {
            getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to start repository indexer plugin.", e));
        }
    } else {
        getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Repository indexer plugin is not available.", null));
    }
    Hashtable<String, Object> dataUrlHandlerProps = new Hashtable<>();
    dataUrlHandlerProps.put(URLConstants.URL_HANDLER_PROTOCOL, DataURLStreamHandler.PROTOCOL);
    dataUrlHandlerReg = context.registerService(URLStreamHandlerService.class, new DataURLStreamHandler(), dataUrlHandlerProps);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Action(aQute.bnd.service.action.Action) ReflectAction(aQute.bnd.build.ReflectAction) URLStreamHandlerService(org.osgi.service.url.URLStreamHandlerService) Hashtable(java.util.Hashtable) Bundle(org.osgi.framework.Bundle) ReflectAction(aQute.bnd.build.ReflectAction) VersionRange(aQute.bnd.version.VersionRange) BundleException(org.osgi.framework.BundleException)

Example 48 with BundleException

use of org.osgi.framework.BundleException in project bnd by bndtools.

the class Launcher method message.

private void message(String prefix, String string, Object[] objects) {
    Throwable e = null;
    StringBuilder sb = new StringBuilder();
    int n = 0;
    sb.append(prefix);
    for (int i = 0; i < string.length(); i++) {
        char c = string.charAt(i);
        if (c == '%') {
            c = string.charAt(++i);
            switch(c) {
                case 's':
                    if (n < objects.length) {
                        Object o = objects[n++];
                        if (o instanceof Throwable) {
                            Throwable t = e = (Throwable) o;
                            if (t instanceof BundleException) {
                                sb.append(translateToMessage((BundleException) t));
                            } else {
                                while (t instanceof InvocationTargetException) {
                                    Throwable cause = t.getCause();
                                    if (cause == null) {
                                        break;
                                    }
                                    t = cause;
                                }
                                sb.append(t.getMessage());
                            }
                        } else {
                            sb.append(o);
                        }
                    } else
                        sb.append("<no more arguments>");
                    break;
                default:
                    sb.append(c);
            }
        } else {
            sb.append(c);
        }
    }
    String message = sb.toString();
    out.println(message);
    if (e != null)
        e.printStackTrace(out);
    out.flush();
    DatagramSocket socket = commsSocket.get();
    if (socket != null) {
        int severity;
        if (message.startsWith("! ")) {
            // NotificationType.ERROR.ordinal();
            severity = 0;
        } else if (message.startsWith("# ") && parms.trace) {
            // NotificationType.INFO.ordinal();
            severity = 2;
        } else {
            return;
        }
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(outputStream);
        try {
            dos.writeInt(severity);
            dos.writeUTF(message.substring(2));
            byte[] byteArray = outputStream.toByteArray();
            socket.send(new DatagramPacket(byteArray, byteArray.length));
        } catch (IOException ioe) {
            out.println("! Unable to send notification to " + socket.getRemoteSocketAddress());
            if (parms.trace)
                ioe.printStackTrace(out);
            out.flush();
        }
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) BundleException(org.osgi.framework.BundleException)

Example 49 with BundleException

use of org.osgi.framework.BundleException in project ddf by codice.

the class ProfileInstallCommandTest method testExtraProfileInvalidStopBundle.

@Test(expected = BundleException.class)
public void testExtraProfileInvalidStopBundle() throws Exception {
    profileInstallCommand.profileName = "invalidStopBundles";
    Bundle badBundle = mock(Bundle.class);
    doThrow(new BundleException("")).when(badBundle).stop();
    when(bundleService.getBundle("badBundle")).thenReturn(badBundle);
    profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
    verify(bundleService, times(2)).getBundle(anyString());
}
Also used : Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) Test(org.junit.Test)

Example 50 with BundleException

use of org.osgi.framework.BundleException in project camel by apache.

the class CamelBlueprintHelper method disposeBundleContext.

public static void disposeBundleContext(BundleContext bundleContext) throws BundleException {
    try {
        if (bundleContext != null) {
            List<Bundle> bundles = new ArrayList<Bundle>();
            bundles.addAll(Arrays.asList(bundleContext.getBundles()));
            Collections.reverse(bundles);
            for (Bundle bundle : bundles) {
                LOG.debug("Stopping bundle {}", bundle);
                bundle.stop();
            }
        }
    } catch (Exception e) {
        IllegalStateException ise = ObjectHelper.getException(IllegalStateException.class, e);
        if (ise != null) {
            // we dont care about illegal state exception as that may happen from OSGi
            LOG.debug("Error during disposing BundleContext. This exception will be ignored.", e);
        } else {
            LOG.warn("Error during disposing BundleContext. This exception will be ignored.", e);
        }
    } finally {
        String tempDir = System.clearProperty("org.osgi.framework.storage");
        if (tempDir != null) {
            LOG.info("Deleting work directory {}", tempDir);
            deleteDirectory(tempDir);
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) TinyBundle(org.ops4j.pax.swissbox.tinybundles.core.TinyBundle) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

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