felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1564341 - in /felix/trunk/bundlerepository/src: main/java/org/apache/felix/bundlerepository/impl/ test/java/org/apache/felix/bundlerepository/impl/ test/resources/
Date Tue, 04 Feb 2014 15:21:00 GMT
Author: davidb
Date: Tue Feb  4 15:20:59 2014
New Revision: 1564341

URL: http://svn.apache.org/r1564341
Log:
[FELIX-4368] Support custom attributes on the osgi.identity capability.

Modified:
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixResourceAdapter.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java
    felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java
    felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java
    felix/trunk/bundlerepository/src/test/resources/spec_repository.xml

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixResourceAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixResourceAdapter.java?rev=1564341&r1=1564340&r2=1564341&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixResourceAdapter.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FelixResourceAdapter.java
Tue Feb  4 15:20:59 2014
@@ -42,8 +42,7 @@ public class FelixResourceAdapter implem
         {
             // TODO cater for null request
             Object type = resource.getProperties().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
-            OSGiCapabilityImpl c = OSGiRepositoryImpl.newOSGiIdentityCapability(resource.getSymbolicName(),
-                type != null ? type.toString() : IdentityNamespace.TYPE_BUNDLE, resource.getVersion());
+            OSGiCapabilityImpl c = OSGiRepositoryImpl.newOSGiIdentityCapability(resource);
             c.setResource(this);
             return Collections.<Capability>singletonList(c);
         }

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java?rev=1564341&r1=1564340&r2=1564341&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImpl.java
Tue Feb  4 15:20:59 2014
@@ -37,7 +37,6 @@ import org.apache.felix.bundlerepository
 import org.apache.felix.bundlerepository.impl.LazyHashMap.LazyValue;
 import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.Version;
 import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Namespace;
@@ -108,9 +107,7 @@ class OSGiRepositoryImpl implements Repo
     private void addResourceForIdentity(final org.apache.felix.bundlerepository.Resource
res, Filter filter, List<Capability> caps)
         throws Exception
     {
-        Object type = res.getProperties().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
-        OSGiCapabilityImpl idCap = newOSGiIdentityCapability(res.getSymbolicName(),
-            type != null ? type.toString() : IdentityNamespace.TYPE_BUNDLE, res.getVersion());
+        OSGiCapabilityImpl idCap = newOSGiIdentityCapability(res);
         if (filter != null)
         {
             if (!filter.matches(idCap.getAttributes()))
@@ -131,12 +128,15 @@ class OSGiRepositoryImpl implements Repo
         caps.add(idCap);
     }
 
-    static OSGiCapabilityImpl newOSGiIdentityCapability(String symbolicName, String type,
Version version)
-    {
-        Map<String, Object> idAttrs = new HashMap<String, Object>();
-        idAttrs.put(IdentityNamespace.IDENTITY_NAMESPACE, symbolicName);
-        idAttrs.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, type);
-        idAttrs.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
+    static OSGiCapabilityImpl newOSGiIdentityCapability(org.apache.felix.bundlerepository.Resource
res) {
+        @SuppressWarnings("unchecked")
+        Map<String, Object> idAttrs = new HashMap<String, Object>(res.getProperties());
+
+        // Set a number of specific properties that need to be translated
+        idAttrs.put(IdentityNamespace.IDENTITY_NAMESPACE, res.getSymbolicName());
+
+        if (idAttrs.get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE) == null)
+            idAttrs.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE);
 
         return new OSGiCapabilityImpl(IdentityNamespace.IDENTITY_NAMESPACE, idAttrs, Collections.<String,
String> emptyMap());
     }

Modified: felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java?rev=1564341&r1=1564340&r2=1564341&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java
(original)
+++ felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java
Tue Feb  4 15:20:59 2014
@@ -44,34 +44,6 @@ import org.osgi.service.repository.Repos
 
 public class OSGiRepositoryImplTest extends TestCase
 {
-    public void testRepositoryContent() throws Exception {
-        RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
-        URL url = getClass().getResource("/another_repository.xml");
-        repoAdmin.addRepository(url);
-
-        Repository repo = new OSGiRepositoryImpl(repoAdmin);
-        Requirement req = new OSGiRequirementImpl("osgi.wiring.package",
-                "(&(osgi.wiring.package=org.apache.commons.logging)(version>=1.0.1)(!(version>=2)))");
-
-        Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
-        assertEquals(1, result.size());
-        Collection<Capability> caps = result.values().iterator().next();
-        assertEquals(1, caps.size());
-        Capability cap = caps.iterator().next();
-        assertEquals("osgi.wiring.package", cap.getNamespace());
-        assertEquals("org.apache.commons.logging", cap.getAttributes().get("osgi.wiring.package"));
-        assertEquals(Version.parseVersion("1.0.4"), cap.getAttributes().get("version"));
-
-        Resource resource = cap.getResource();
-        RepositoryContent rc = (RepositoryContent) resource; // Repository Resources must
implement this interface
-        byte[] actualBytes = Streams.suck(rc.getContent());
-
-        URL actualURL = getClass().getResource("/repo_files/test_file_1.jar");
-        byte[] expectedBytes = Streams.suck(actualURL.openStream());
-
-        assertTrue(Arrays.equals(expectedBytes, actualBytes));
-    }
-
     public void testIdentityAndContentCapabilities() throws Exception
     {
         RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
@@ -178,6 +150,34 @@ public class OSGiRepositoryImplTest exte
         assertEquals(expected, identities);
     }
 
+    public void testRepositoryContent() throws Exception {
+        RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
+        URL url = getClass().getResource("/another_repository.xml");
+        repoAdmin.addRepository(url);
+
+        Repository repo = new OSGiRepositoryImpl(repoAdmin);
+        Requirement req = new OSGiRequirementImpl("osgi.wiring.package",
+                "(&(osgi.wiring.package=org.apache.commons.logging)(version>=1.0.1)(!(version>=2)))");
+
+        Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
+        assertEquals(1, result.size());
+        Collection<Capability> caps = result.values().iterator().next();
+        assertEquals(1, caps.size());
+        Capability cap = caps.iterator().next();
+        assertEquals("osgi.wiring.package", cap.getNamespace());
+        assertEquals("org.apache.commons.logging", cap.getAttributes().get("osgi.wiring.package"));
+        assertEquals(Version.parseVersion("1.0.4"), cap.getAttributes().get("version"));
+
+        Resource resource = cap.getResource();
+        RepositoryContent rc = (RepositoryContent) resource; // Repository Resources must
implement this interface
+        byte[] actualBytes = Streams.suck(rc.getContent());
+
+        URL actualURL = getClass().getResource("/repo_files/test_file_1.jar");
+        byte[] expectedBytes = Streams.suck(actualURL.openStream());
+
+        assertTrue(Arrays.equals(expectedBytes, actualBytes));
+    }
+
     private RepositoryAdminImpl createRepositoryAdmin() throws Exception
     {
         Bundle sysBundle = Mockito.mock(Bundle.class);

Modified: felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java?rev=1564341&r1=1564340&r2=1564341&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java
(original)
+++ felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java
Tue Feb  4 15:20:59 2014
@@ -63,6 +63,25 @@ public class OSGiRepositoryXMLTest exten
         assertEquals("osgi.subsystem.feature", cap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE));
     }
 
+    public void testOtherIdentityAttribute() throws Exception
+    {
+        RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
+        URL url = getClass().getResource("/spec_repository.xml");
+        repoAdmin.addRepository(url);
+
+        Repository repo = new OSGiRepositoryImpl(repoAdmin);
+        Requirement req = new OSGiRequirementImpl("osgi.identity",
+                "(license=http://www.opensource.org/licenses/mytestlicense)");
+
+        Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
+        assertEquals(1, result.size());
+        Collection<Capability> caps = result.values().iterator().next();
+        assertEquals(1, caps.size());
+        Capability cap = caps.iterator().next();
+        assertEquals("org.apache.felix.bundlerepository.test_file_3", cap.getAttributes().
+                get(IdentityNamespace.IDENTITY_NAMESPACE));
+    }
+
     public void testContentCapability() throws Exception
     {
         RepositoryAdminImpl repoAdmin = createRepositoryAdmin();

Modified: felix/trunk/bundlerepository/src/test/resources/spec_repository.xml
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/resources/spec_repository.xml?rev=1564341&r1=1564340&r2=1564341&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/test/resources/spec_repository.xml (original)
+++ felix/trunk/bundlerepository/src/test/resources/spec_repository.xml Tue Feb  4 15:20:59
2014
@@ -23,6 +23,7 @@
       <attribute name='osgi.identity' value='org.apache.felix.bundlerepository.test_file_3'/>
       <attribute name='type' value='osgi.bundle'/>
       <attribute name='version' type='Version' value='1.2.3.something'/>
+      <attribute name='license' value='http://www.opensource.org/licenses/mytestlicense'
/>
     </capability>
     <capability namespace='osgi.content'>
       <attribute name='osgi.content' value='a1c64578808c38a63cd6563e9936f025638aeaf9de70f36765367db81c0afc38'/>



Mime
View raw message