felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r915039 - in /felix/trunk: bundlerepository/src/main/java/org/apache/felix/bundlerepository/ bundlerepository/src/test/java/org/apache/felix/bundlerepository/ org.osgi.service.obr/src/main/java/org/osgi/service/obr/
Date Mon, 22 Feb 2010 19:51:28 GMT
Author: gnodet
Date: Mon Feb 22 19:51:28 2010
New Revision: 915039

URL: http://svn.apache.org/viewvc?rev=915039&view=rev
Log:
FELIX-1007: OBR search doesn't take 'categories' into account

Added:
    felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryAdminTest.java
Modified:
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
    felix/trunk/org.osgi.service.obr/src/main/java/org/osgi/service/obr/Resource.java

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java?rev=915039&r1=915038&r2=915039&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
Mon Feb 22 19:51:28 2010
@@ -31,7 +31,6 @@
 
     private Repository m_repo = null;
     private Map m_map = null;
-    private List m_catList = new ArrayList();
     private List m_capList = new ArrayList();
     private List m_reqList = new ArrayList();
 
@@ -59,7 +58,6 @@
         if (resource != null)
         {
             m_map.putAll(resource.getProperties());
-            m_catList.addAll(resource.m_catList);
             m_capList.addAll(resource.m_capList);
             m_reqList.addAll(resource.m_reqList);
         }
@@ -151,12 +149,23 @@
 
     public String[] getCategories()
     {
-        return (String[]) m_catList.toArray(new String[m_catList.size()]);
+        List catList = (List) m_map.get(CATEGORY);
+        if (catList == null)
+        {
+            return new String[0];
+        }
+        return (String[]) catList.toArray(new String[catList.size()]);
     }
 
     protected void addCategory(CategoryImpl cat)
     {
-        m_catList.add(cat.getId());
+        List catList = (List) m_map.get(CATEGORY);
+        if (catList == null)
+        {
+            catList = new ArrayList();
+            m_map.put(CATEGORY, catList);
+        }
+        catList.add(cat.getId());
     }
 
     public Repository getRepository()
@@ -208,6 +217,17 @@
             {
                 value = Long.valueOf(value.toString());
             }
+            else if (key.equals(CATEGORY))
+            {
+                if (value instanceof Collection)
+                {
+                    value = new ArrayList((Collection) value);
+                }
+                else
+                {
+                    value = Arrays.asList(value.toString().split(","));
+                }
+            }
     
             return m_map.put(key, value);
         }

Added: felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryAdminTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryAdminTest.java?rev=915039&view=auto
==============================================================================
--- felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryAdminTest.java
(added)
+++ felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryAdminTest.java
Mon Feb 22 19:51:28 2010
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.bundlerepository;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+import org.osgi.framework.Filter;
+import org.osgi.service.obr.Repository;
+import org.osgi.service.obr.Resource;
+
+public class RepositoryAdminTest extends TestCase
+{
+
+    public void testResourceFilterOnCapabilities() throws Exception
+    {
+        URL url = getClass().getResource("/repo_for_resolvertest.xml");
+
+        RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
+        RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
+
+        Resource[] resources = repoAdmin.discoverResources("(category:<*dummy)");
+        assertNotNull(resources);
+        assertEquals(1, resources.length);
+
+        resources = repoAdmin.discoverResources("(category:*>dummy)");
+        assertNotNull(resources);
+        assertEquals(1, resources.length);
+    }
+
+
+    private RepositoryAdminImpl createRepositoryAdmin()
+    {
+        final MockBundleContext bundleContext = new MockBundleContext() {
+            public Filter createFilter(String arg0) {
+                return new FilterImpl(arg0);
+            }
+        };
+        RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));
+
+        // force initialization && remove all initial repositories
+        Repository[] repos = repoAdmin.listRepositories();
+        for (int i = 0; repos != null && i < repos.length; i++)
+        {
+            repoAdmin.removeRepository(repos[i].getURL());
+        }
+
+        return repoAdmin;
+    }
+
+}

Modified: felix/trunk/org.osgi.service.obr/src/main/java/org/osgi/service/obr/Resource.java
URL: http://svn.apache.org/viewvc/felix/trunk/org.osgi.service.obr/src/main/java/org/osgi/service/obr/Resource.java?rev=915039&r1=915038&r2=915039&view=diff
==============================================================================
--- felix/trunk/org.osgi.service.obr/src/main/java/org/osgi/service/obr/Resource.java (original)
+++ felix/trunk/org.osgi.service.obr/src/main/java/org/osgi/service/obr/Resource.java Mon
Feb 22 19:51:28 2010
@@ -58,9 +58,11 @@
 
     final String SIZE = "size";
 
+    final String CATEGORY = "category";
+
     final static String[] KEYS = { DESCRIPTION, SIZE, ID, LICENSE_URL,
             DOCUMENTATION_URL, COPYRIGHT, SOURCE_URL, PRESENTATION_NAME,
-            SYMBOLIC_NAME, VERSION, URL };
+            SYMBOLIC_NAME, VERSION, URL, CATEGORY };
 
     // get readable name
 



Mime
View raw message