FELIX-1007: OBR search doesn't take 'categories' into account
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@915039 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
index 4f52b9d..cc89181 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/ResourceImpl.java
@@ -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);
}
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryAdminTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryAdminTest.java
new file mode 100644
index 0000000..1680886
--- /dev/null
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/RepositoryAdminTest.java
@@ -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;
+ }
+
+}
diff --git a/org.osgi.service.obr/src/main/java/org/osgi/service/obr/Resource.java b/org.osgi.service.obr/src/main/java/org/osgi/service/obr/Resource.java
index e6b050b..7064b75 100644
--- a/org.osgi.service.obr/src/main/java/org/osgi/service/obr/Resource.java
+++ b/org.osgi.service.obr/src/main/java/org/osgi/service/obr/Resource.java
@@ -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