Java Code Examples for org.osgi.framework.Bundle#uninstall()

The following examples show how to use org.osgi.framework.Bundle#uninstall() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BindingInfoTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertThatBindingInfoWithoutAuthorIsReadProperly() throws Exception {
    int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();

    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME2);
    assertThat(bundle, is(notNullValue()));

    Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos();
    assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
    BindingInfo bindingInfo = bindingInfos.iterator().next();
    assertThat(bindingInfo.getUID(), is("hue"));
    assertThat(bindingInfo.getConfigDescriptionURI(), is(URI.create("binding:hue")));
    assertThat(bindingInfo.getDescription(),
            is("The hue Binding integrates the Philips hue system. It allows to control hue lights."));
    assertThat(bindingInfo.getName(), is("hue Binding"));
    assertThat(bindingInfo.getAuthor(), is((String) null));

    // uninstall test bundle
    bundle.uninstall();
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
}
 
Example 2
Source File: SystemChannelsInChannelGroupsTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void systemChannelsInChannelGroupsShouldLoadAndUnload() throws Exception {
    int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
    int initialNumberOfChannelTypes = channelTypeRegistry.getChannelTypes().size();
    int initialNumberOfChannelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes().size();

    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_IN_CHANNEL_GROUPS_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));

    Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 1));
    assertThat(channelTypeRegistry.getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));
    assertThat(channelGroupTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes + 1));

    // uninstall test bundle
    bundle.uninstall();
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));

    assertThat(thingTypeProvider.getThingTypes(null).size(), is(initialNumberOfThingTypes));
    assertThat(channelTypeRegistry.getChannelTypes().size(), is(initialNumberOfChannelTypes));
    assertThat(channelGroupTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes));

}
 
Example 3
Source File: SystemWideChannelTypesTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void systemChannelsShouldBeAddedWithoutThingTypes() throws Exception {
    int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
    int initialNumberOfChannelTypes = getChannelTypes().size();

    // install test bundle
    Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext,
            SYSTEM_CHANNELS_WITHOUT_THING_TYPES_BUNDLE_NAME);
    assertThat(sysBundle, is(notNullValue()));

    Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes));

    assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));

    // uninstall test bundle
    sysBundle.uninstall();
    assertThat(sysBundle.getState(), is(Bundle.UNINSTALLED));

    assertThat(getChannelTypes().size(), is(initialNumberOfChannelTypes));
}
 
Example 4
Source File: FelixFrameworkIntegrationTest.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Test
public void requireThatBundlesCanBeRefreshed() throws Exception {
    FelixFramework felix = TestDriver.newOsgiFramework();
    felix.start();
    Bundle bundleL = startBundle(felix, "cert-l1.jar");
    Bundle bundleM = startBundle(felix, "cert-ml.jar");
    assertEquals(1, callClass(bundleM, "com.yahoo.jdisc.bundle.m.CertificateM"));

    // Switch from l1 to l2 (identical bundles, except for bsn)
    bundleL.uninstall();
    startBundle(felix, "cert-l2.jar");

    felix.refreshPackages();
    assertEquals(2, callClass(bundleM, "com.yahoo.jdisc.bundle.m.CertificateM"));
    felix.stop();
}
 
Example 5
Source File: WisdomBlackBoxTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
public static void removeTestBundle() throws BundleException {
    BundleContext context = ChameleonInstanceHolder.get().context();
    // Check whether the test bundle is already installed
    Bundle probe = null;
    for (Bundle bundle : context.getBundles()) {
        if (bundle.getSymbolicName().equalsIgnoreCase(ProbeBundleMaker.BUNDLE_NAME)) {
            probe = bundle;
        }
    }

    if (probe != null) {
        probe.uninstall();
        LOGGER.info("Probe / Test bundle uninstall ({})", probe.getBundleId());
        ChameleonInstanceHolder.get().waitForStability();
    }
}
 
Example 6
Source File: BindingInfoTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertThatBindingInfoIsReadProperly() throws Exception {
    int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();

    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));

    Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos();
    assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
    BindingInfo bindingInfo = bindingInfos.iterator().next();
    assertThat(bindingInfo.getUID(), is("hue"));
    assertThat(bindingInfo.getConfigDescriptionURI(), is(URI.create("binding:hue")));
    assertThat(bindingInfo.getDescription(),
            is("The hue Binding integrates the Philips hue system. It allows to control hue lights."));
    assertThat(bindingInfo.getName(), is("hue Binding"));
    assertThat(bindingInfo.getAuthor(), is("Deutsche Telekom AG"));

    // uninstall test bundle
    bundle.uninstall();
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
}
 
Example 7
Source File: BindingInfoTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertThatBindingInfoIsRemovedAfterTheBundleWasUninstalled() throws Exception {
    int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size();

    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));

    Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos();
    assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1));
    BindingInfo bindingInfo = bindingInfos.iterator().next();

    // uninstall test bundle
    bundle.uninstall();
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));

    bindingInfos = bindingInfoRegistry.getBindingInfos();
    assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos));

    if (initialNumberOfBindingInfos > 0) {
        for (BindingInfo bindingInfo_ : bindingInfos) {
            assertThat(bindingInfo_.getUID(), is(not(bindingInfo.getUID())));
        }
    }
}
 
Example 8
Source File: ThingTypesTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void thingTypesShouldBeRemoved_whenBundleIsUninstalled() throws Exception {
    int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();

    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));

    Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 3));

    // uninstall test bundle
    bundle.uninstall();
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));

    thingTypes = thingTypeProvider.getThingTypes(null);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes));
}
 
Example 9
Source File: Activator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void reapDrivers(final long now)
{
  final Bundle[] ba = bc.getBundles();
  if (ba != null) {
    for (final Bundle b : ba) {
      try {
        if (b.getLocation().startsWith(DYNAMIC_DRIVER_TAG)) {
          final Long expire = tempDrivers.get(b);
          boolean inUse = false;

          final ServiceReference<?>[] sra = b.getServicesInUse();
          if (sra != null) {
            for (final ServiceReference<?> element : sra) {
              if (isDevice.match(element)) {
                inUse = true;
                break;
              }
            }
          }

          if (inUse) {
            updateLife(b, LONG_LIFE);
          } else if (expire == null) {
            updateLife(b, SHORT_LIFE);
                      } else if (expire.longValue() - now < 0) {
            info("uninstalling " + b.getLocation());
            b.uninstall();
          }
        }
      } catch (final Exception e) {
      }
    }
  }
}
 
Example 10
Source File: BundleUtilsTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testLoadAndUpdate() throws Exception {
	loadBundles(Arrays.asList(getBundle()));
	String bundleLocation = getBundleLocation(getBundle(), true);

	BundleContext context = JavaLanguageServerPlugin.getBundleContext();
	Bundle installedBundle = context.getBundle(bundleLocation);
	try {
		assertNotNull(installedBundle);

		assertTrue(installedBundle.getState() == Bundle.STARTING || installedBundle.getState() == Bundle.ACTIVE);
		installedBundle.loadClass("testbundle.Activator");
		assertEquals(installedBundle.getState(), Bundle.ACTIVE);

		String extResult = getBundleExtensionResult();
		assertEquals("EXT_TOSTRING", extResult);
		loadBundles(Arrays.asList(getBundle("testresources", "testbundle-0.6.0-SNAPSHOT.jar")));
		bundleLocation = getBundleLocation(getBundle("testresources", "testbundle-0.6.0-SNAPSHOT.jar"), true);

		installedBundle = context.getBundle(bundleLocation);
		assertNotNull(installedBundle);
		assertTrue(installedBundle.getState() == Bundle.STARTING || installedBundle.getState() == Bundle.ACTIVE);
		installedBundle.loadClass("testbundle.Activator");
		assertEquals(installedBundle.getState(), Bundle.ACTIVE);

		extResult = getBundleExtensionResult();
		assertEquals("EXT_TOSTRING_0.6.0", extResult);
	} finally {
		// Uninstall the bundle to clean up the testing bundle context.
		installedBundle.uninstall();
	}
}
 
Example 11
Source File: Test1.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public boolean runTest() {

    try {
      Bundle bundle = Util.installBundle(bc, "bundleEnd1_test-1.0.0.jar");
      bundle.start();
      bundle.stop();
      bundle.uninstall();
    } catch (BundleException e) {
      e.printStackTrace();
      return false;
    }
        
    return true;
  }
 
Example 12
Source File: ConfigDescriptionsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void syntheticBundleShouldLoadFromTestResource() throws Exception {

    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));

    // uninstall test bundle
    bundle.uninstall();
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
}
 
Example 13
Source File: ScriptEngineBundleTrackerCustomizerIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
/**
 * The Engine should throw a {@link ProcessEngineException} when trying to
 * execute the script because the bundle with the ScriptEngine has been
 * uninstalled.
 */
@Test(expected = ProcessEngineException.class)
public void scriptEngineHasUnregisteredAfterBundleUninstall() throws BundleException {
  Bundle testBundle = getBundle("org.camunda.bpm.osgi.example");
  testBundle.uninstall();
  processEngine.getRuntimeService().startProcessInstanceByKey("Process_1");
}
 
Example 14
Source File: AbstractLoadBundleTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Tests LOG4J2-1637.
 */
@Test
public void testClassNotFoundErrorLogger() throws BundleException {

    final Bundle api = getApiBundle();
    final Bundle plugins = getPluginsBundle();
    final Bundle core = getCoreBundle();

    api.start();
    plugins.start();
    // fails if LOG4J2-1637 is not fixed
    try {
        core.start();
    }
    catch (final BundleException ex) {
        boolean shouldRethrow = true;
        final Throwable t = ex.getCause();
        if (t != null) {
            final Throwable t2 = t.getCause();
            if (t2 != null) {
                final String cause = t2.toString();
                final boolean result = cause.equals("java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger") // Equinox
                              || cause.equals("java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger not found by org.apache.logging.log4j.core [2]"); // Felix
                Assert.assertFalse("org.apache.logging.log4j package is not properly imported in org.apache.logging.log4j.core bundle, check that the package is exported from api and is not split between api and core", result);
                shouldRethrow = !result;
            }
        }
        if (shouldRethrow) {
            throw ex; // rethrow if the cause of the exception is something else
        }
    }

    core.stop();
    plugins.stop();
    api.stop();
    
    core.uninstall();
    plugins.uninstall();
    api.uninstall();
}
 
Example 15
Source File: ConfigDescriptionsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatConfigDescriptionsOfFragmentHostAreLoadedProperly() throws Exception {
    int initialNumberOfConfigDescriptions = configDescriptionRegistry.getConfigDescriptions().size();

    // install test bundle
    Bundle fragment = SyntheticBundleInstaller.installFragment(bundleContext, FRAGMENT_TEST_FRAGMENT_NAME);
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, FRAGMENT_TEST_HOST_NAME);
    assertThat(bundle, is(notNullValue()));

    Collection<ConfigDescription> configDescriptions = configDescriptionRegistry.getConfigDescriptions();
    assertThat(configDescriptions.size(), is(initialNumberOfConfigDescriptions + 1));

    ConfigDescription description = findDescription(configDescriptions, new URI("config:fragmentConfig"));
    assertThat(description, is(notNullValue()));

    List<ConfigDescriptionParameter> parameters = description.getParameters();
    assertThat(parameters.size(), is(1));

    ConfigDescriptionParameter usernameParameter = findParameter(description, "testParam");
    assertThat(usernameParameter, is(notNullValue()));
    assertThat(usernameParameter.getType(), is(Type.TEXT));
    assertThat(usernameParameter.getLabel(), is("Test"));
    assertThat(usernameParameter.isRequired(), is(false));
    assertThat(usernameParameter.isMultiple(), is(false));
    assertThat(usernameParameter.isReadOnly(), is(false));
    assertThat(usernameParameter.getDescription(), is("Test Parameter."));

    fragment.uninstall();
    assertThat(fragment.getState(), is(Bundle.UNINSTALLED));
    bundle.uninstall();
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
}
 
Example 16
Source File: AbstractLoadBundleTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
private void uninstall(final Bundle api, final Bundle plugins, final Bundle core, final Bundle dummy) throws BundleException {
    dummy.uninstall();
    core.uninstall();
    plugins.uninstall();
    api.uninstall();
}
 
Example 17
Source File: ComponentTestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Test setup: ComponentA references ComponentB,
 *             ComponentB references ComponentC,TestService2
 *             ComponentC references TestService
 *             ComponentD provides TestService and reference ComponentA
 * before: no components are started.
 * action: TestService and TestService2 is registered
 * after: all components are activated
 *
 * then:
 *
 * before: all components are activated
 * action: modify TestService2 to block ComponentB
 * after: only ComponentC is active
 *
 * then:
 *
 * before: all components are activated
 * action: unregister TestService and TestService2
 * after: all components are deactivated
 *
 * (the components call bump when they are (de-)actived)
 */

public void runTest() {
  Bundle c1 = null;
  ServiceRegistration<?> reg = null;
  ServiceRegistration<?> reg2 = null;
  try {
    reg = bc.registerService(TestService.class.getName(), new TestService(), new Hashtable<String,Object>());
    reg2 = bc.registerService(TestService2.class.getName(), new TestService2(), new Hashtable<String,Object>());

    counter = 0;
    c1 = Util.installBundle(bc, "componentA_test-1.0.1.jar");
    c1.start();

    Thread.sleep(SLEEP_TIME);

    ServiceReference<?> ref = bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentB");
    assertNotNull("Should get serviceRef B", ref);
    assertNotNull("Should get service B", bc.getService(ref));

    ref = bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentC");
    assertNotNull("Should get serviceRef C", ref);
    assertNotNull("Should get service C", bc.getService(ref));

    assertEquals("Should have been activate(B&C)/bind(C) bumped", 102, counter);
    Hashtable<String, Object> p = new Hashtable<String,Object>();
    p.put("block","yes");
    reg2.setProperties(p);

    Thread.sleep(SLEEP_TIME);
    assertNull("Should not get B", bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentB"));
    assertNotNull("Should still get C", bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentC"));
    assertEquals("Should have been deactivate B", 112, counter);

    reg.unregister();
    reg = null;

    Thread.sleep(SLEEP_TIME);

    assertNull("Should not get C", bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentC"));
    assertEquals("Should have been deactivate/unbind C bumped", 1122, counter);

    counter = 0;
  } catch (Exception e) {
    e.printStackTrace();
    fail("Test4: got unexpected exception " + e);
  } finally {
    if (c1 != null) {
      try {
        c1.uninstall();
      } catch (BundleException be) {
        be.printStackTrace();
        fail("Test4: got uninstall exception " + be);
      }
    }
    if (reg != null) {
      reg.unregister();
    }
    if (reg2 != null) {
      reg2.unregister();
    }
  }
}
 
Example 18
Source File: ComponentTestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Test that SCR handles factory CM pids with target filters.
 * 
 */

public void runTest() {
  Bundle b1 = null;
  ServiceTracker<ConfigurationAdmin, ConfigurationAdmin> cmt = null;
  try {
    b1 = Util.installBundle(bc, "componentC_test-1.0.0.jar");
    b1.start();
    final String b1loc = b1.getLocation();

    cmt = new ServiceTracker<ConfigurationAdmin,ConfigurationAdmin>(bc, ConfigurationAdmin.class.getName(), null);
    cmt.open();
    
    Thread.sleep(SLEEP_TIME);

    ServiceReference<?> ref = bc.getServiceReference("org.knopflerfish.service.componentC_test.ComponentU");
    assertNull("Should not get serviceRef U", ref);

    ConfigurationAdmin ca = cmt.getService();
    Configuration c = ca.createFactoryConfiguration("componentC_test.U", b1loc);

    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("vRef.target", "(vnum=v0)");
    c.update(props);
    
    Thread.sleep(SLEEP_TIME);

    ref = bc.getServiceReference("org.knopflerfish.service.componentC_test.ComponentU");
    assertNull("Should not get serviceRef U", ref);

    props.put("vRef.target", "(vnum=v1)");
    c.update(props);
    
    Thread.sleep(SLEEP_TIME);

    ServiceReference<?> [] refs = bc.getServiceReferences("org.knopflerfish.service.componentC_test.ComponentU", null);
    assertTrue("Should get one serviceRef to ComponentU", refs != null && refs.length == 1);

    Configuration c2 = ca.createFactoryConfiguration("componentC_test.U", b1loc);
    props = new Hashtable<String, Object>();
    props.put("vRef.target", "(vnum=v2)");
    c2.update(props);
    
    Thread.sleep(SLEEP_TIME);

    refs = bc.getServiceReferences("org.knopflerfish.service.componentC_test.ComponentU", null);
    assertTrue("Should get two serviceRef to ComponentU", refs != null && refs.length == 2);

    refs = bc.getServiceReferences("org.knopflerfish.service.componentC_test.ComponentU", "(vRef.target=\\(vnum=v1\\))");
    assertTrue("Should get one serviceRef to ComponentU with ref v1", refs != null && refs.length == 1);
    org.knopflerfish.service.componentC_test.ComponentU u =
        (org.knopflerfish.service.componentC_test.ComponentU)bc.getService(refs[0]);
    assertEquals("Should get v1 version", "v1", u.getV());

    refs = bc.getServiceReferences("org.knopflerfish.service.componentC_test.ComponentU", "(vRef.target=\\(vnum=v2\\))");
    assertTrue("Should get one serviceRef to ComponentU with ref v2", refs != null && refs.length == 1);
    org.knopflerfish.service.componentC_test.ComponentU u2 =
        (org.knopflerfish.service.componentC_test.ComponentU)bc.getService(refs[0]);
    assertNotSame("Services should differ", u, u2);
    assertEquals("Should get v2 version", "v2", u2.getV());
  } catch (Exception e) {
    e.printStackTrace();
    fail("Test11: got unexpected exception " + e);
  } finally {
    if (b1 != null) {
      try {
        if (cmt != null) {
          deleteConfig(cmt.getService(), b1.getLocation());
          cmt.close();
        }
        b1.uninstall();
      } catch (Exception be) {
        be.printStackTrace();
        fail("Test11: got uninstall exception " + be);
      }
    }
  }
}
 
Example 19
Source File: ComponentTestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void runTest() {
  Bundle c1 = null;
  ServiceReference<?> sr = null;
  ServiceRegistration<?> reg = null;
  ServiceRegistration<?> reg2 = null;
  try {
    counter = 0;
    gotCircularError = false;
    sr = bc.getServiceReference(LogReaderService.class.getName());
    LogReaderService lrs = (LogReaderService)bc.getService(sr);
    lrs.addLogListener(this);
    c1 = Util.installBundle(bc, "componentA_test-1.0.1.jar");
    c1.start();

    Thread.sleep(SLEEP_TIME);

    assertNull("Should be null (1)", bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentA"));
    assertNull("Should be null (2)", bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentB"));
    assertNull("Should be null (3)", bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentC"));
    assertEquals("Should not have been bumped", 0, counter);
    assertTrue("Should have got circular error message", gotCircularError);
    lrs.removeLogListener(this);

    reg2 = bc.registerService(TestService2.class.getName(), new TestService2(), new Hashtable<String, Object>());
    reg = bc.registerService(TestService.class.getName(), new TestService(), new Hashtable<String, Object>());

    Thread.sleep(SLEEP_TIME);

    ServiceReference<?> ref = bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentA");
    assertNotNull("Should get service A", bc.getService(ref));

    ref = bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentB");
    assertNotNull("Should get service B", bc.getService(ref));

    ref = bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentC");
    assertNotNull("Should get service C", bc.getService(ref));

    assertEquals("Should have been activate/bind bumped", 103, counter);
    reg.unregister();
    reg = null;

    Thread.sleep(SLEEP_TIME);
    assertNull("Should be null (1(2))", bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentA"));
    assertNull("Should be null (2(2))", bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentB"));
    assertNull("Should be null (3(2))", bc.getServiceReference("org.knopflerfish.bundle.componentA_test.ComponentC"));
    assertEquals("Should have been bind/2*unbind and deactive bumped", 2233, counter);

    counter = 0;
  } catch (Exception e) {
    e.printStackTrace();
    fail("Test2b: got unexpected exception " + e);
  } finally {
    if (c1 != null) {
      try {
        c1.uninstall();
      } catch (BundleException be) {
        be.printStackTrace();
        fail("Test2b: got uninstall exception " + be);
      }
    }
    if (sr != null) {
      bc.ungetService(sr);
    }
    if (reg != null) {
      reg.unregister();
    }
    if (reg2 != null) {
      reg2.unregister();
    }
  }
}
 
Example 20
Source File: BundleUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Uninstall the specified bundle and update the set for bundle refreshing and
 * starting.
 *
 * @param context
 *            Bundle context
 * @param bundlesToStart
 *            The set containing bundles which need to start
 * @param toRefresh
 *            The set containing bundles which need to refresh after
 *            unsintallation
 * @param bundle
 *            Bundle needs to be uninstalled
 *
 * @throws BundleException
 */
private static void uninstallBundle(BundleContext context, Set<Bundle> bundlesToStart, Set<Bundle> toRefresh, Bundle bundle) throws BundleException {
	bundle.uninstall();
	JavaLanguageServerPlugin.logInfo("Uninstalled " + bundle.getLocation());
	toRefresh.add(bundle);
	bundlesToStart.remove(bundle);
}