Author: davidb Date: Fri Apr 1 14:15:05 2016 New Revision: 1737394 URL: http://svn.apache.org/viewvc?rev=1737394&view=rev Log: FELIX-5229 BundleNamespace on Req/Cap is not translated correctly
Patch applied on behalf of PK Søreide with many thanks. This closes #61 Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java felix/trunk/bundlerepository/src/test/resources/spec_repository.gz felix/trunk/bundlerepository/src/test/resources/spec_repository.xml Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java?rev=1737394&r1=1737393&r2=1737394&view=diff ============================================================================== --- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java (original) +++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SpecXMLPullParser.java Fri Apr 1 14:15:05 2016 @@ -28,6 +28,7 @@ import org.apache.felix.bundlerepository import org.apache.felix.bundlerepository.Requirement; import org.apache.felix.bundlerepository.Resource; import org.osgi.framework.Version; +import org.osgi.framework.namespace.BundleNamespace; import org.osgi.framework.namespace.IdentityNamespace; import org.osgi.resource.Namespace; import org.osgi.service.repository.ContentNamespace; @@ -152,6 +153,16 @@ public class SpecXMLPullParser for (Map.Entry<String, Object> entry : attributes.entrySet()) { + if (BundleNamespace.BUNDLE_NAMESPACE.equals(namespace) && BundleNamespace.BUNDLE_NAMESPACE.equals(entry.getKey())) + { + capability.addProperty(new FelixPropertyAdapter(Resource.SYMBOLIC_NAME, entry.getValue())); + continue; + } + if (BundleNamespace.BUNDLE_NAMESPACE.equals(namespace) && BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE.equals(entry.getKey())) + { + capability.addProperty(new FelixPropertyAdapter(Resource.VERSION, entry.getValue())); + continue; + } capability.addProperty(new FelixPropertyAdapter(NamespaceTranslator.getFelixNamespace(entry.getKey()), entry.getValue())); } for (Map.Entry<String, String> entry : directives.entrySet()) @@ -338,8 +349,14 @@ public class SpecXMLPullParser String filter = directives.remove(Namespace.REQUIREMENT_FILTER_DIRECTIVE); for (String ns : NamespaceTranslator.getTranslatedOSGiNamespaces()) { - filter = filter.replaceAll("[(][ ]*" + ns + "[ ]*=", - "(" + NamespaceTranslator.getFelixNamespace(ns) + "="); + if (BundleNamespace.BUNDLE_NAMESPACE.equals(namespace) && BundleNamespace.BUNDLE_NAMESPACE.equals(ns)) + { + filter = filter.replaceAll("[(][ ]*" + ns + "[ ]*=", + "(" + Resource.SYMBOLIC_NAME + "="); + } + else + filter = filter.replaceAll("[(][ ]*" + ns + "[ ]*=", + "(" + NamespaceTranslator.getFelixNamespace(ns) + "="); } requirement.setFilter(filter); requirement.setMultiple(Namespace.CARDINALITY_MULTIPLE.equals( Modified: felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java?rev=1737394&r1=1737393&r2=1737394&view=diff ============================================================================== --- felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java (original) +++ felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java Fri Apr 1 14:15:05 2016 @@ -117,6 +117,23 @@ public class ResolverImplTest extends Te assertTrue("Resolver could not resolve", resolver.resolve()); } + public void testSpecBundleNamespace() throws Exception + { + URL url = getClass().getResource("/spec_repository.xml"); + RepositoryAdminImpl repoAdmin = createRepositoryAdmin(); + RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url); + + Resolver resolver = repoAdmin.resolver(); + + Resource[] discoverResources = repoAdmin.discoverResources("(symbolicname=org.apache.felix.bundlerepository.test_file_6*)"); + assertNotNull(discoverResources); + assertEquals(1, discoverResources.length); + + resolver.add(discoverResources[0]); + assertTrue(resolver.resolve()); + + } + public void testMatchingReq() throws Exception { RepositoryAdminImpl repoAdmin = createRepositoryAdmin(); Modified: felix/trunk/bundlerepository/src/test/resources/spec_repository.gz URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/resources/spec_repository.gz?rev=1737394&r1=1737393&r2=1737394&view=diff ============================================================================== Binary files - no diff available. 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=1737394&r1=1737393&r2=1737394&view=diff ============================================================================== --- felix/trunk/bundlerepository/src/test/resources/spec_repository.xml (original) +++ felix/trunk/bundlerepository/src/test/resources/spec_repository.xml Fri Apr 1 14:15:05 2016 @@ -65,6 +65,45 @@ <directive name="effective" value="active"/> </requirement> </resource> + <resource> + <capability namespace='osgi.identity'> + <attribute name='osgi.identity' value='org.apache.felix.bundlerepository.test_file_6'/> + <attribute name='type' value='osgi.bundle'/> + <attribute name='version' type='Version' value='2.2.3.something'/> + <attribute name='license' value='http://www.opensource.org/licenses/mytestlicense2' /> + </capability> + <capability namespace='osgi.content'> + <attribute name='osgi.content' value='a1c64578808c38a63cd6563e9936f025638aeaf9de70f36765367db81c0afc38'/> + <attribute name='url' value='repo_files/test_file_6.jar'/> + <attribute name='size' type='Long' value='3'/> + <attribute name='mime' value='application/vnd.osgi.bundle'/> + </capability> + <capability namespace='osgi.wiring.bundle'> + <attribute name='osgi.wiring.bundle' value='org.apache.felix.bundlerepository.test_file_6'/> + <attribute name='bundle-version' type='Version' value='2.2.3.something'/> + </capability> + <requirement namespace="osgi.wiring.bundle"> + <directive name="filter" value="(&(osgi.wiring.bundle=org.apache.felix.bundlerepository.test_file_7)(version>=3.3.0)(!(version>=4.0.0)))"/> + </requirement> + </resource> + <resource> + <capability namespace='osgi.identity'> + <attribute name='osgi.identity' value='org.apache.felix.bundlerepository.test_file_7'/> + <attribute name='type' value='osgi.bundle'/> + <attribute name='version' type='Version' value='3.3.4.something'/> + <attribute name='license' value='http://www.opensource.org/licenses/mytestlicense2' /> + </capability> + <capability namespace='osgi.content'> + <attribute name='osgi.content' value='a1c64578808c38a63cd6563e9936f025638aeaf9de70f36765367db81c0afc38'/> + <attribute name='url' value='repo_files/test_file_7.jar'/> + <attribute name='size' type='Long' value='3'/> + <attribute name='mime' value='application/vnd.osgi.bundle'/> + </capability> + <capability namespace='osgi.wiring.bundle'> + <attribute name='osgi.wiring.bundle' value='org.apache.felix.bundlerepository.test_file_7'/> + <attribute name='bundle-version' type='Version' value='3.3.4.something'/> + </capability> + </resource> <resource> <capability namespace='osgi.identity'> <attribute name='osgi.identity' value='org.apache.sshd.core'/>