[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
diff --git a/bundlerepository.osgi-ct/pom.xml b/bundlerepository.osgi-ct/pom.xml
index 9ce9613..320ab2f 100644
--- a/bundlerepository.osgi-ct/pom.xml
+++ b/bundlerepository.osgi-ct/pom.xml
@@ -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>
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalResourceImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalResourceImpl.java
index 1272b41..e3d4c27 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalResourceImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalResourceImpl.java
@@ -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 @@
}
}
-/* 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 };
+ for (Map.Entry<String, String> entry : cap.getDirectives().entrySet())
+ {
+ bcap.addDirective(entry.getKey(), entry.getValue());
+ }
+ addCapability(bcap);
}
- else
- {
- Map[] newCaps = new Map[capMaps.length + 1];
- newCaps[0] = map;
- System.arraycopy(capMaps, 0, newCaps, 1, capMaps.length);
- capMaps = newCaps;
- }
- bundleMap.put("capability", capMaps);
-*/
}
}
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java
index 7bc728a..7f95a08 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java
@@ -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 @@
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);
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java
index a70fe17..631f061 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java
@@ -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 @@
{
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);
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryAdminTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryAdminTest.java
index 70e38b7..df6f099 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryAdminTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryAdminTest.java
@@ -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 @@
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 @@
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 @@
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));
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryImplTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryImplTest.java
index 5e4b459..d46d8cb 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryImplTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryImplTest.java
@@ -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 @@
{
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 @@
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 @@
return true;
}
}).anyTimes();
- EasyMock.replay(new Object[] { bundleContext, systemBundle });
+ EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });
RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
index 7bd8f6b..3ec9288 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
@@ -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 @@
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 @@
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 @@
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));
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/StaxParserTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/StaxParserTest.java
index e2e5725..54a3a91 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/StaxParserTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/StaxParserTest.java
@@ -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 @@
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 @@
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 @@
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));
diff --git a/main/pom.xml b/main/pom.xml
index 6156ae5..3ed3599 100644
--- a/main/pom.xml
+++ b/main/pom.xml
@@ -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>