public String translateToMessage(BundleException e) { switch (e.getType()) { case BundleException.ACTIVATOR_ERROR: Throwable t = e.getCause(); StackTraceElement[] stackTrace = t.getStackTrace(); if (stackTrace == null || stackTrace.length == 0) return "activator error " + t.getMessage(); StackTraceElement top = stackTrace[0]; return "activator error " + t.getMessage() + " from: " + top.getClassName() + ":" + top.getMethodName() + "#" + top.getLineNumber(); case BundleException.DUPLICATE_BUNDLE_ERROR: case BundleException.RESOLVE_ERROR: case BundleException.INVALID_OPERATION: case BundleException.MANIFEST_ERROR: case BundleException.NATIVECODE_ERROR: case BundleException.STATECHANGE_ERROR: case BundleException.UNSUPPORTED_OPERATION: case BundleException.UNSPECIFIED: default: return e.getMessage(); } }
private void assertInstallFail(String name, Region region) { try { Bundle b = bundleInstaller.installBundle(name, region); b.uninstall(); fail("Expected a bundle exception on duplicate bundle install: " + region); } catch (BundleException e) { // expected assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType()); } }
@Override public boolean install( Configuration oteConfiguration, OTEStatusCallback<ConfigurationStatus> statusCallback) { boolean pass = true; for (ConfigurationItem bundleDescription : oteConfiguration.getItems()) { String bundleName = bundleDescription.getSymbolicName(); try { boolean exists = false; for (Bundle bundle : runningBundles) { if (bundle.getSymbolicName().equals(bundleName)) { exists = true; break; } } if (!exists) { Bundle bundle = Platform.getBundle(bundleDescription.getSymbolicName()); if (bundle == null) { Bundle installedBundle; File bundleData = acquireSystemLibraryStream(bundleDescription); installedBundle = context.installBundle("reference:" + bundleData.toURI().toURL().toExternalForm()); bundleNameToMd5Map.put(bundleName, bundleDescription.getMd5Digest()); installedBundles.add(installedBundle); } } statusCallback.log("installed " + bundleName); } catch (BundleException ex) { if (ex.getType() == BundleException.DUPLICATE_BUNDLE_ERROR) { statusCallback.log(String.format("Duplicate bundle [%s].", bundleName)); } else { statusCallback.error(String.format("Unable to load [%s].", bundleName), ex); pass = false; } } catch (Throwable th) { statusCallback.error(String.format("Unable to load [%s].", bundleName), th); pass = false; } finally { statusCallback.incrememtUnitsWorked(1); } } return pass; }
public int translateToError(BundleException e) { switch (e.getType()) { case BundleException.ACTIVATOR_ERROR: return LauncherConstants.ACTIVATOR_ERROR; case BundleException.DUPLICATE_BUNDLE_ERROR: return LauncherConstants.DUPLICATE_BUNDLE; case BundleException.RESOLVE_ERROR: return LauncherConstants.RESOLVE_ERROR; case BundleException.INVALID_OPERATION: case BundleException.MANIFEST_ERROR: case BundleException.NATIVECODE_ERROR: case BundleException.STATECHANGE_ERROR: case BundleException.UNSUPPORTED_OPERATION: case BundleException.UNSPECIFIED: default: return LauncherConstants.ERROR; } }
public void testBundleCollisionDisconnectedRegions() throws BundleException, InvalidSyntaxException { // get the system region Region systemRegion = digraph.getRegion(0); Collection<Bundle> bundles = new HashSet<Bundle>(); // create 4 disconnected test regions and install each bundle into each region int numRegions = 4; String regionName = "IsolatedRegion_"; for (int i = 0; i < numRegions; i++) { Region region = digraph.createRegion(regionName + i); // Import the system bundle from the systemRegion digraph.connect(region, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, "(id=0)").build(), systemRegion); // must import Boolean services into systemRegion to test digraph.connect(systemRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_SERVICE_NAMESPACE, "(objectClass=java.lang.Boolean)").build(), region); for (String location : ALL) { Bundle b = bundleInstaller.installBundle(location, region); bundles.add(b); } } assertEquals("Wrong number of bundles installed", numRegions * ALL.size(), bundles.size()); assertTrue("Could not resolve bundles.", bundleInstaller.resolveBundles(bundles.toArray(new Bundle[bundles.size()]))); // test install of duplicates for (int i = 0; i < numRegions; i++) { Region region = digraph.getRegion(regionName + i); for (String name : ALL) { String location = bundleInstaller.getBundleLocation(name); try { Bundle b = region.installBundle(getName() + "_expectToFail", new URL(location).openStream()); b.uninstall(); fail("Expected a bundle exception on duplicate bundle installation: " + name); } catch (BundleException e) { // expected assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType()); } catch (IOException e) { fail("Failed to open bunldle location: " + e.getMessage()); } } } // test update to a duplicate for (int i = 0; i < numRegions; i++) { Region region = digraph.getRegion(regionName + i); Bundle regionPP1 = region.getBundle(PP1, new Version(1, 0, 0)); String locationSP1 = bundleInstaller.getBundleLocation(SP1); try { regionPP1.update(new URL(locationSP1).openStream()); fail("Expected a bundle exception on duplicate bundle update: " + region); } catch (BundleException e) { // expected assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType()); } catch (IOException e) { fail("Failed to open bunldle location: " + e.getMessage()); } // now uninstall SP1 and try to update PP1 to SP1 again Bundle regionSP1 = region.getBundle(SP1, new Version(1, 0, 0)); regionSP1.uninstall(); try { regionPP1.update(new URL(locationSP1).openStream()); } catch (IOException e) { fail("Failed to open bunldle location: " + e.getMessage()); } } }