use of org.osgi.framework.BundleException in project aries by apache.
the class RegionContextBundleHelper method uninstallRegionContextBundle.
public static void uninstallRegionContextBundle(BasicSubsystem subsystem) {
String symbolicName = SYMBOLICNAME_PREFIX + subsystem.getSubsystemId();
Bundle bundle = subsystem.getRegion().getBundle(symbolicName, VERSION);
if (bundle == null)
return;
BundleRevision revision = bundle.adapt(BundleRevision.class);
try {
bundle.uninstall();
} catch (BundleException e) {
// TODO Should we really eat this? At least log it?
}
ResourceUninstaller.newInstance(revision, subsystem).uninstall();
subsystem.setRegionContextBundle(null);
}
use of org.osgi.framework.BundleException in project aries by apache.
the class RegionUpdater method addRequirements.
public void addRequirements(Collection<? extends Requirement> requirements) throws BundleException, InvalidSyntaxException {
for (int i = 0; i < MAX_ATTEMPTS_DEFAULT; i++) {
RegionDigraph copy = copyDigraph();
Region tail = copyTail(copy);
Region head = copyHead(copy);
Set<Long> bundleIds = copyBundleIds(tail);
Map<String, RegionFilterBuilder> heads = copyHeadRegions(tail, copy);
Map<String, RegionFilterBuilder> tails = copyTailRegions(tail, copy);
copy.removeRegion(tail);
tail = copy.createRegion(tail.getName());
addBundleIds(bundleIds, tail);
RegionFilterBuilder builder = heads.get(head.getName());
if (builder == null) {
// See ARIES-1429.
throw new IllegalStateException(new StringBuilder(tail.getName()).append(" not connected to ").append(head.getName()).toString());
}
if (requirements == null) {
heads.put(head.getName(), null);
} else {
addRequirements(requirements, builder);
}
addHeadRegions(heads, tail, copy);
addTailRegions(tails, tail, copy);
// Replace the current digraph.
try {
digraph.replace(copy);
} catch (BundleException e) {
// Something modified digraph since the copy was made.
if (i < MAX_ATTEMPTS_DEFAULT)
// There are more attempts to make.
continue;
// Number of attempts has been exhausted.
throw e;
}
// Success! No need to continue looping.
break;
}
}
use of org.osgi.framework.BundleException in project aries by apache.
the class FrameworkTest method testInstallBundles.
@Test
public void testInstallBundles() throws Exception {
String[] locations = new String[] { "file:test.jar" };
Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(context.installBundle("file:test.jar")).thenReturn(bundle);
Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(2));
CompositeData data = mbean.installBundles(locations);
BatchInstallResult batch = BatchInstallResult.from(data);
Assert.assertNotNull(batch);
Assert.assertEquals(2, batch.getCompleted()[0]);
Assert.assertTrue(batch.isSuccess());
Assert.assertNull(batch.getError());
Assert.assertNull(batch.getRemainingLocationItems());
Mockito.reset(context);
Mockito.when(context.installBundle("file:test.jar")).thenThrow(new BundleException("location doesn't exist"));
CompositeData data2 = mbean.installBundles(locations);
BatchInstallResult batch2 = BatchInstallResult.from(data2);
Assert.assertNotNull(batch2);
Assert.assertNotNull(batch2.getCompleted());
Assert.assertEquals(0, batch2.getCompleted().length);
Assert.assertFalse(batch2.isSuccess());
Assert.assertNotNull(batch2.getError());
Assert.assertEquals("file:test.jar", batch2.getBundleInError());
Assert.assertNotNull(batch2.getRemainingLocationItems());
Assert.assertEquals(0, batch2.getRemainingLocationItems().length);
}
use of org.osgi.framework.BundleException in project aries by apache.
the class FrameworkTest method testInstallBundleFromURL.
@Test
public void testInstallBundleFromURL() throws Exception {
Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(context.installBundle(Mockito.anyString(), Mockito.any(InputStream.class))).thenReturn(bundle);
Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(2));
Framework spiedMBean = Mockito.spy(mbean);
InputStream stream = Mockito.mock(InputStream.class);
Mockito.doReturn(stream).when(spiedMBean).createStream("test.jar");
long bundleId = spiedMBean.installBundleFromURL("file:test.jar", "test.jar");
Assert.assertEquals(2, bundleId);
Mockito.reset(context);
Mockito.doReturn(stream).when(spiedMBean).createStream(Mockito.anyString());
Mockito.when(context.installBundle(Mockito.anyString(), Mockito.any(InputStream.class))).thenThrow(new BundleException("location doesn't exist"));
try {
spiedMBean.installBundleFromURL("file:test2.jar", "test.jar");
Assert.fail("Shouldn't go to this stage, location doesn't exist");
} catch (IOException e) {
// ok
}
}
use of org.osgi.framework.BundleException in project aries by apache.
the class FrameworkTest method testInstallBundle.
@Test
public void testInstallBundle() throws Exception {
Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(context.installBundle("file:test.jar")).thenReturn(bundle);
Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(2));
long bundleId = mbean.installBundle("file:test.jar");
Assert.assertEquals(2, bundleId);
Mockito.reset(context);
Mockito.when(context.installBundle("file:test2.jar")).thenThrow(new BundleException("location doesn't exist"));
try {
mbean.installBundle("file:test2.jar");
Assert.fail("Shouldn't go to this stage, location doesn't exist");
} catch (IOException e) {
// ok
}
}
Aggregations