Skip to content
Permalink
Browse files
[FELIX-4640] Missing framework capabilities.
This commit fixes the issue. 
New unit test included.
Note that OBR still passes the OSGi R5 repository CT.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1627285 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bosschaert committed Sep 24, 2014
1 parent 5de1554 commit e17386212134ae41fae4af18f9ea6a6f6a76504e
Showing 9 changed files with 90 additions and 57 deletions.
@@ -32,7 +32,7 @@
how to prime the repository with the provided repository xml file.
</description>
<artifactId>org.apache.felix.bundlerepository.osgi-ct</artifactId>
<version>1.7.0-SNAPSHOT</version>
<version>2.0.3-SNAPSHOT</version>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/bundlerepository.osgi-ct</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/trunk/bundlerepository.osgi-ct</developerConnection>
@@ -20,6 +20,7 @@

import java.util.Dictionary;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

@@ -29,6 +30,7 @@
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.wiring.BundleRevision;

public class LocalResourceImpl extends ResourceImpl
{
@@ -87,49 +89,21 @@ public void close() { }
}
}

/* TODO: OBR - Fix system capabilities.
// Create a case-insensitive map.
Map map = new TreeMap(new Comparator() {
public int compare(Object o1, Object o2)
// Add all the OSGi capabilities from the system bundle as repo capabilities
BundleRevision br = m_bundle.adapt(BundleRevision.class);
for (org.osgi.resource.Capability cap : br.getCapabilities(null))
{
CapabilityImpl bcap = new CapabilityImpl(cap.getNamespace());
for (Map.Entry<String, Object> entry : cap.getAttributes().entrySet())
{
return o1.toString().compareToIgnoreCase(o2.toString());
bcap.addProperty(new FelixPropertyAdapter(entry));
}
});
map.put(
Constants.FRAMEWORK_VERSION,
m_context.getProperty(Constants.FRAMEWORK_VERSION));
map.put(
Constants.FRAMEWORK_VENDOR,
m_context.getProperty(Constants.FRAMEWORK_VENDOR));
map.put(
Constants.FRAMEWORK_LANGUAGE,
m_context.getProperty(Constants.FRAMEWORK_LANGUAGE));
map.put(
Constants.FRAMEWORK_OS_NAME,
m_context.getProperty(Constants.FRAMEWORK_OS_NAME));
map.put(
Constants.FRAMEWORK_OS_VERSION,
m_context.getProperty(Constants.FRAMEWORK_OS_VERSION));
map.put(
Constants.FRAMEWORK_PROCESSOR,
m_context.getProperty(Constants.FRAMEWORK_PROCESSOR));
// map.put(
// FelixConstants.FELIX_VERSION_PROPERTY,
// m_context.getProperty(FelixConstants.FELIX_VERSION_PROPERTY));
Map[] capMaps = (Map[]) bundleMap.get("capability");
if (capMaps == null)
{
capMaps = new Map[] { map };
}
else
{
Map[] newCaps = new Map[capMaps.length + 1];
newCaps[0] = map;
System.arraycopy(capMaps, 0, newCaps, 1, capMaps.length);
capMaps = newCaps;
for (Map.Entry<String, String> entry : cap.getDirectives().entrySet())
{
bcap.addDirective(entry.getKey(), entry.getValue());
}
addCapability(bcap);
}
bundleMap.put("capability", capMaps);
*/
}
}

@@ -29,6 +29,8 @@

import junit.framework.TestCase;

import org.apache.felix.bundlerepository.Reason;
import org.apache.felix.bundlerepository.Resolver;
import org.apache.felix.utils.log.Logger;
import org.mockito.Mockito;
import org.osgi.framework.Bundle;
@@ -37,6 +39,7 @@
import org.osgi.framework.namespace.BundleNamespace;
import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.framework.namespace.PackageNamespace;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import org.osgi.resource.Resource;
@@ -198,11 +201,40 @@ public void testRepositoryContent() throws Exception {
assertTrue(Arrays.equals(expectedBytes, actualBytes));
}

public void testSystemBundleCapabilities() throws Exception {
RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
Resolver resolver = repoAdmin.resolver();
RequirementImpl req = new RequirementImpl("some.system.cap");
req.setFilter("(sys.cap=something)");
resolver.add(req);
ResourceImpl res = new ResourceImpl();
res.addRequire(req);

resolver.add(res);
assertTrue(resolver.resolve());

// This should add the system bundle repo to the resolved set.
org.apache.felix.bundlerepository.Resource sysBundleRes = repoAdmin.getSystemRepository().getResources()[0];
Reason[] reason = resolver.getReason(sysBundleRes);
assertTrue(reason.length >= 1);
assertEquals(req, reason[0].getRequirement());
}

private RepositoryAdminImpl createRepositoryAdmin() throws Exception
{
Bundle sysBundle = Mockito.mock(Bundle.class);
Mockito.when(sysBundle.getHeaders()).thenReturn(new Hashtable<String, String>());

BundleRevision br = Mockito.mock(BundleRevision.class);
Mockito.when(sysBundle.adapt(BundleRevision.class)).thenReturn(br);
Capability cap1 = new OSGiCapabilityImpl("some.system.cap",
Collections.<String, Object>singletonMap("sys.cap", "something"),
Collections.singletonMap("x", "y"));
Capability cap2 = new OSGiCapabilityImpl("some.system.cap",
Collections.<String, Object>singletonMap("sys.cap", "somethingelse"),
Collections.<String, String>emptyMap());
Mockito.when(br.getCapabilities(null)).thenReturn(Arrays.asList(cap1, cap2));

BundleContext bc = Mockito.mock(BundleContext.class);
Mockito.when(bc.getBundle(0)).thenReturn(sysBundle);
Mockito.when(sysBundle.getBundleContext()).thenReturn(bc);
@@ -35,6 +35,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;
import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import org.osgi.resource.Resource;
@@ -135,6 +136,8 @@ private RepositoryAdminImpl createRepositoryAdmin() throws Exception
{
Bundle sysBundle = Mockito.mock(Bundle.class);
Mockito.when(sysBundle.getHeaders()).thenReturn(new Hashtable<String, String>());
BundleRevision br = Mockito.mock(BundleRevision.class);
Mockito.when(sysBundle.adapt(BundleRevision.class)).thenReturn(br);

BundleContext bc = Mockito.mock(BundleContext.class);
Mockito.when(bc.getBundle(0)).thenReturn(sysBundle);
@@ -19,9 +19,11 @@
package org.apache.felix.bundlerepository.impl;

import java.net.URL;
import java.util.Collections;
import java.util.Hashtable;

import junit.framework.TestCase;

import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.utils.filter.FilterImpl;
import org.apache.felix.utils.log.Logger;
@@ -33,6 +35,8 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Capability;

public class RepositoryAdminTest extends TestCase
{
@@ -54,8 +58,9 @@ public void testResourceFilterOnCapabilities() throws Exception

private RepositoryAdminImpl createRepositoryAdmin() throws Exception
{
BundleContext bundleContext = (BundleContext) EasyMock.createMock(BundleContext.class);
Bundle systemBundle = (Bundle) EasyMock.createMock(Bundle.class);
BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
Bundle systemBundle = EasyMock.createMock(Bundle.class);
BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);

Activator.setContext(bundleContext);
EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
@@ -64,6 +69,8 @@ private RepositoryAdminImpl createRepositoryAdmin() throws Exception
EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
@@ -73,7 +80,7 @@ public Object answer() throws Throwable {
return FilterImpl.newInstance((String) c.getValue());
}
}).anyTimes();
EasyMock.replay(new Object[] { bundleContext, systemBundle });
EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });

RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));

@@ -19,6 +19,7 @@
package org.apache.felix.bundlerepository.impl;

import java.net.URL;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Map;
@@ -35,6 +36,8 @@
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Capability;

public class RepositoryImplTest extends TestCase
{
@@ -96,6 +99,7 @@ private RepositoryAdminImpl createRepositoryAdmin() throws Exception
{
BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
Bundle systemBundle = EasyMock.createMock(Bundle.class);
BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);

Activator.setContext(bundleContext);
EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
@@ -104,6 +108,8 @@ private RepositoryAdminImpl createRepositoryAdmin() throws Exception
EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
@@ -121,7 +127,7 @@ public boolean matches(Map<String, ?> map) {
return true;
}
}).anyTimes();
EasyMock.replay(new Object[] { bundleContext, systemBundle });
EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });

RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));

@@ -19,11 +19,14 @@
package org.apache.felix.bundlerepository.impl;

import java.net.URL;
import java.util.Collections;
import java.util.Hashtable;

import junit.framework.TestCase;

import org.apache.felix.bundlerepository.Repository;
import org.apache.felix.bundlerepository.Requirement;
import org.apache.felix.bundlerepository.Resolver;
import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.utils.filter.FilterImpl;
import org.apache.felix.utils.log.Logger;
@@ -35,8 +38,8 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceListener;
import org.apache.felix.bundlerepository.Repository;
import org.apache.felix.bundlerepository.Resolver;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Capability;

public class ResolverImplTest extends TestCase
{
@@ -138,8 +141,9 @@ public static void main(String[] args) throws Exception

private RepositoryAdminImpl createRepositoryAdmin() throws Exception
{
BundleContext bundleContext = (BundleContext) EasyMock.createMock(BundleContext.class);
Bundle systemBundle = (Bundle) EasyMock.createMock(Bundle.class);
BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
Bundle systemBundle = EasyMock.createMock(Bundle.class);
BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);

Activator.setContext(bundleContext);
EasyMock.expect(bundleContext.getProperty(RepositoryAdminImpl.REPOSITORY_URL_PROP))
@@ -150,6 +154,8 @@ private RepositoryAdminImpl createRepositoryAdmin() throws Exception
EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
@@ -159,7 +165,7 @@ public Object answer() throws Throwable {
return FilterImpl.newInstance((String) c.getValue());
}
}).anyTimes();
EasyMock.replay(new Object[] { bundleContext, systemBundle });
EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });

RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));

@@ -19,13 +19,14 @@
package org.apache.felix.bundlerepository.impl;

import java.net.URL;
import java.util.Collections;
import java.util.Hashtable;

import junit.framework.TestCase;
import org.apache.felix.bundlerepository.impl.PullParser;

import org.apache.felix.bundlerepository.Repository;
import org.apache.felix.bundlerepository.Resolver;
import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.bundlerepository.impl.StaxParser;
import org.apache.felix.utils.filter.FilterImpl;
import org.apache.felix.utils.log.Logger;
import org.easymock.Capture;
@@ -36,7 +37,8 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceListener;
import org.apache.felix.bundlerepository.Repository;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Capability;

public class StaxParserTest extends TestCase
{
@@ -138,8 +140,9 @@ public static void main(String[] args) throws Exception

private RepositoryAdminImpl createRepositoryAdmin(Class repositoryParser) throws Exception
{
BundleContext bundleContext = (BundleContext) EasyMock.createMock(BundleContext.class);
Bundle systemBundle = (Bundle) EasyMock.createMock(Bundle.class);
BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
Bundle systemBundle = EasyMock.createMock(Bundle.class);
BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);

Activator.setContext(bundleContext);
EasyMock.expect(bundleContext.getProperty(RepositoryAdminImpl.REPOSITORY_URL_PROP))
@@ -152,6 +155,8 @@ private RepositoryAdminImpl createRepositoryAdmin(Class repositoryParser) throws
EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
@@ -161,7 +166,7 @@ public Object answer() throws Throwable {
return FilterImpl.newInstance((String) c.getValue());
}
}).anyTimes();
EasyMock.replay(new Object[] { bundleContext, systemBundle });
EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });

RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));

@@ -47,7 +47,7 @@
<gogo.runtime.version>0.12.1</gogo.runtime.version>
<gogo.shell.version>0.10.0</gogo.shell.version>
<gogo.command.version>0.14.0</gogo.command.version>
<obr.version>2.0.2</obr.version>
<obr.version>2.0.3-SNAPSHOT</obr.version>
</properties>
<profiles>
<profile>

0 comments on commit e173862

Please sign in to comment.