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