Search in sources :

Example 16 with BundleException

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);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleException(org.osgi.framework.BundleException)

Example 17 with BundleException

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;
    }
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) Region(org.eclipse.equinox.region.Region) BundleException(org.osgi.framework.BundleException) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder)

Example 18 with BundleException

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);
}
Also used : BatchInstallResult(org.apache.aries.jmx.codec.BatchInstallResult) Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BundleException(org.osgi.framework.BundleException) Test(org.junit.Test)

Example 19 with BundleException

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
    }
}
Also used : Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with BundleException

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
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Test(org.junit.Test)

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