Search in sources :

Example 1 with MapToDictionary

use of org.apache.felix.utils.collections.MapToDictionary in project felix by apache.

the class RepositoryAdminImpl method discoverResources.

public synchronized Resource[] discoverResources(String filterExpr) throws InvalidSyntaxException {
    initialize();
    Filter filter = filterExpr != null ? m_helper.filter(filterExpr) : null;
    Resource[] resources;
    MapToDictionary dict = new MapToDictionary(null);
    Repository[] repos = listRepositories();
    List matchList = new ArrayList();
    for (int repoIdx = 0; (repos != null) && (repoIdx < repos.length); repoIdx++) {
        resources = repos[repoIdx].getResources();
        for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
            dict.setSourceMap(resources[resIdx].getProperties());
            if (filter == null || filter.match(dict)) {
                matchList.add(resources[resIdx]);
            }
        }
    }
    // Convert matching resources to an array an sort them by name.
    resources = (Resource[]) matchList.toArray(new Resource[matchList.size()]);
    Arrays.sort(resources, m_nameComparator);
    return resources;
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) Filter(org.osgi.framework.Filter) Resource(org.apache.felix.bundlerepository.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MapToDictionary(org.apache.felix.utils.collections.MapToDictionary)

Example 2 with MapToDictionary

use of org.apache.felix.utils.collections.MapToDictionary in project feature-flags-for-osgi by amitjoy.

the class FeatureManagerProviderTest method testConfigurationEventUpdated.

@Test
public void testConfigurationEventUpdated() throws Exception {
    final FeatureManagerProvider manager = new FeatureManagerProvider();
    manager.setConfigurationAdmin(configurationAdmin);
    manager.setMetaTypeService(metaTypeService);
    manager.activate(bundleContext1);
    final MetaTypeExtender extender = manager.getExtender();
    final String[] pids = new String[] { "a" };
    final BundleEvent bundleEvent = new BundleEvent(BundleEvent.STARTED, bundle);
    when(metaTypeService.getMetaTypeInformation(bundle)).thenReturn(metaTypeInfo);
    when(metaTypeInfo.getPids()).thenReturn(pids);
    when(metaTypeInfo.getObjectClassDefinition("a", null)).thenReturn(ocd);
    when(ocd.getAttributeDefinitions(ALL)).thenReturn(new AttributeDefinition[] { ad });
    mockADWithoutDefaultValue();
    when(bundleContext1.getBundle(0)).thenReturn(systemBundle);
    when(bundle.getState()).thenReturn(ACTIVE);
    when(bundle.getBundleContext()).thenReturn(bundleContext1);
    extender.addingBundle(bundle, bundleEvent);
    Thread.sleep(1000);
    FeatureDTO feature = manager.getFeatures().collect(Collectors.toList()).get(0);
    assertEquals(FEATURE_ID, feature.id);
    assertEquals(FEATURE_DESC, feature.description);
    assertFalse(feature.isEnabled);
    feature = manager.getFeatures(FEATURE_ID).findFirst().get();
    assertEquals(FEATURE_ID, feature.id);
    assertEquals(FEATURE_DESC, feature.description);
    assertFalse(feature.isEnabled);
    feature = manager.getFeatures(FEATURE_ID).findAny().get();
    assertEquals(FEATURE_DESC, feature.description);
    assertFalse(feature.isEnabled);
    final Map<String, Object> properties = ImmutableMap.<String, Object>builder().put("osgi.feature.myfeature", true).build();
    when(configurationAdmin.getConfiguration("a", "?")).thenReturn(configuration);
    when(configuration.getProperties()).thenReturn(new MapToDictionary(properties));
    final ConfigurationEvent configEvent = new ConfigurationEvent(reference, 1, null, "a");
    manager.configurationEvent(configEvent);
    final FeatureDTO updatedFeature = manager.getFeatures(FEATURE_ID).findAny().get();
    assertTrue(updatedFeature.isEnabled);
}
Also used : ConfigurationEvent(org.osgi.service.cm.ConfigurationEvent) BundleEvent(org.osgi.framework.BundleEvent) MapToDictionary(org.apache.felix.utils.collections.MapToDictionary) FeatureDTO(com.amitinside.featureflags.dto.FeatureDTO) Test(org.junit.Test)

Aggregations

MapToDictionary (org.apache.felix.utils.collections.MapToDictionary)2 FeatureDTO (com.amitinside.featureflags.dto.FeatureDTO)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Repository (org.apache.felix.bundlerepository.Repository)1 Resource (org.apache.felix.bundlerepository.Resource)1 Test (org.junit.Test)1 BundleEvent (org.osgi.framework.BundleEvent)1 Filter (org.osgi.framework.Filter)1 ConfigurationEvent (org.osgi.service.cm.ConfigurationEvent)1