[FELIX-4914] Add failing test case
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1685090 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/resolver/pom.xml b/resolver/pom.xml
index c93eff3..0448b6a 100644
--- a/resolver/pom.xml
+++ b/resolver/pom.xml
@@ -106,6 +106,7 @@
<exclude>src/**/packageinfo</exclude>
<exclude>src/main/appended-resources/**</exclude>
<exclude>src/test/resources/resolution.json</exclude>
+ <exclude>src/test/resources/felix-4914.json</exclude>
</excludes>
</configuration>
</plugin>
diff --git a/resolver/src/test/java/org/apache/felix/resolver/test/FELIX_4914_Test.java b/resolver/src/test/java/org/apache/felix/resolver/test/FELIX_4914_Test.java
new file mode 100644
index 0000000..043cb9a
--- /dev/null
+++ b/resolver/src/test/java/org/apache/felix/resolver/test/FELIX_4914_Test.java
@@ -0,0 +1,140 @@
+/*
+ * 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.resolver.test;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+import org.apache.felix.resolver.Logger;
+import org.apache.felix.resolver.ResolverImpl;
+import org.apache.felix.resolver.Util;
+import org.apache.felix.resolver.test.util.CapabilitySet;
+import org.apache.felix.resolver.test.util.JsonReader;
+import org.apache.felix.resolver.test.util.ResolveContextImpl;
+import org.apache.felix.resolver.test.util.SimpleFilter;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+import org.osgi.resource.Wire;
+import org.osgi.resource.Wiring;
+import org.osgi.service.resolver.Resolver;
+
+public class FELIX_4914_Test extends TestCase {
+
+ @Test
+ @Ignore
+ public void testResolution() throws Exception {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/felix-4914.json")));
+ Map<String, Object> resolution = (Map<String, Object>) JsonReader.read(reader);
+ List<Resource> repository = readRepository(resolution.get("repository"));
+
+ Map<String, CapabilitySet> capSets = new HashMap<String, CapabilitySet>();
+ for (Resource resource : repository) {
+ for (Capability cap : resource.getCapabilities(null)) {
+ String ns = cap.getNamespace();
+ CapabilitySet set = capSets.get(ns);
+ if (set == null) {
+ set = new CapabilitySet(Collections.singletonList(ns));
+ capSets.put(ns, set);
+ }
+ set.addCapability(cap);
+ }
+ }
+
+ Resource root = null;
+ for (Resource resource : repository) {
+ if ("root".equals(Util.getSymbolicName(resource))) {
+ root = resource;
+ break;
+ }
+ }
+ List<Resource> mandatory = new ArrayList<Resource>();
+ mandatory.add(root);
+
+
+ Map<Requirement, List<Capability>> candidates = new HashMap<Requirement, List<Capability>>();
+ for (Resource resource : repository) {
+ for (Requirement requirement : resource.getRequirements(null)) {
+ CapabilitySet set = capSets.get(requirement.getNamespace());
+ if (set != null) {
+ String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
+ SimpleFilter sf = (filter != null)
+ ? SimpleFilter.parse(filter)
+ : SimpleFilter.convert(requirement.getAttributes());
+ candidates.put(requirement, new ArrayList<Capability>(set.match(sf, true)));
+ } else {
+ candidates.put(requirement, Collections.<Capability>emptyList());
+ }
+ }
+ }
+
+ ResolveContextImpl rci = new ResolveContextImpl(Collections.<Resource, Wiring>emptyMap(), candidates, mandatory, Collections.EMPTY_LIST);
+ Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
+ Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
+
+
+ }
+
+ private static List<Resource> readRepository(Object repository) throws BundleException {
+ List<Resource> resources = new ArrayList<Resource>();
+ Collection<Map<String, List<String>>> metadatas;
+ if (repository instanceof Map) {
+ metadatas = ((Map<String, Map<String, List<String>>>) repository).values();
+ } else {
+ metadatas = (Collection<Map<String, List<String>>>) repository;
+ }
+ for (Map<String, List<String>> metadata : metadatas) {
+ resources.add(BigResolutionTest.parseResource(metadata));
+ /*
+ ResourceImpl res = new ResourceImpl() {
+ @Override
+ public String toString() {
+ Capability cap = getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).get(0);
+ return cap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE) + "/"
+ + cap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
+ }
+ };
+ for (String cap : metadata.get("capabilities")) {
+ for (Capability c : ResourceBuilder.parseCapability(res, cap)) {
+ res.addCapability(c);
+ }
+ }
+ if (metadata.containsKey("requirements")) {
+ for (String req : metadata.get("requirements")) {
+ for (Requirement r : ResourceBuilder.parseRequirement(res, req)) {
+ res.addRequirement(r);
+ }
+ }
+ }
+ resources.add(res);
+ */
+ }
+ return resources;
+ }
+
+}
diff --git a/resolver/src/test/resources/felix-4914.json b/resolver/src/test/resources/felix-4914.json
new file mode 100644
index 0000000..5794925
--- /dev/null
+++ b/resolver/src/test/resources/felix-4914.json
@@ -0,0 +1,59 @@
+{
+ "repository": [
+ {
+ "capabilities": [
+ "osgi.identity; osgi.identity=root; type=karaf.subsystem; version:Version=0.0.0"
+ ],
+ "requirements": [
+ "osgi.identity; osgi.identity=org.apache.activemq.activemq-blueprint; type=osgi.fragment",
+ "osgi.identity; osgi.identity=org.apache.aries.blueprint.core.compatibility; type=osgi.fragment",
+ "osgi.identity; osgi.identity=org.apache.aries.blueprint.core; type=osgi.bundle"
+ ]
+ },
+ {
+ "capabilities": [
+ "osgi.identity; osgi.identity=org.apache.activemq.activemq-blueprint; type=osgi.fragment; version:Version=5.11.1"
+ ],
+ "requirements": [
+ "osgi.wiring.host; osgi.wiring.host=org.apache.activemq.activemq-osgi; filter:=\"(osgi.wiring.host=org.apache.activemq.activemq-osgi)\"",
+ "osgi.wiring.package; filter:=\"(osgi.wiring.package=org.apache.aries.blueprint)\"",
+ "osgi.wiring.package; filter:=\"(osgi.wiring.package=org.apache.xbean.blueprint.context.impl)\""
+ ]
+ },
+ {
+ "capabilities": [
+ "osgi.identity; osgi.identity=org.apache.activemq.activemq-osgi; type=osgi.bundle; version:Version=5.11.1",
+ "osgi.wiring.host; osgi.wiring.host=org.apache.activemq.activemq-osgi"
+ ],
+ "requirements": [
+ "osgi.wiring.package; filter:=\"(osgi.wiring.package=org.osgi.service.blueprint)\""
+ ]
+ },
+ {
+ "capabilities": [
+ "osgi.identity; osgi.identity=org.apache.xbean.blueprint; type=osgi.bundle; version:Version=3.18.0",
+ "osgi.wiring.package; osgi.wiring.package=org.apache.xbean.blueprint.context.impl; uses:=\"org.apache.aries.blueprint\""
+ ],
+ "requirements": [
+ "osgi.wiring.package; filter:=\"(osgi.wiring.package=org.apache.aries.blueprint)\""
+ ]
+ },
+ {
+ "capabilities": [
+ "osgi.identity; osgi.identity=org.apache.aries.blueprint.core.compatibility; type=osgi.fragment; version:Version=1.0.0"
+ ],
+ "requirements": [
+ "osgi.wiring.host; osgi.wiring.host=org.apache.aries.blueprint.core; filter:=\"(osgi.wiring.host=org.apache.aries.blueprint.core)\""
+ ]
+ },
+ {
+ "capabilities": [
+ "osgi.identity; osgi.identity=org.apache.aries.blueprint.core; type=osgi.bundle; version:Version=1.4.3",
+ "osgi.wiring.host; osgi.wiring.host=org.apache.aries.blueprint.core",
+ "osgi.wiring.package; osgi.wiring.package=org.apache.aries.blueprint; uses:=\"org.apache.aries.blueprint.services,org.osgi.service.blueprint.reflect\"",
+ "osgi.wiring.package; osgi.wiring.package=org.osgi.service.blueprint"
+ ]
+ }
+ ],
+ "exception": "org.osgi.service.resolver.ResolutionException: Uses constraint violation. Unable to resolve resource org.apache.activemq.activemq-blueprint [org.apache.activemq.activemq-blueprint/5.11.1] because it is exposed to package 'org.apache.aries.blueprint' from resources org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.3] and org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.3] via two dependency chains.\n\nChain 1:\n org.apache.activemq.activemq-blueprint [org.apache.activemq.activemq-blueprint/5.11.1]\n import: (&(osgi.wiring.package=org.apache.aries.blueprint)(version>=1.0.0)(!(version>=2.0.0)))\n |\n export: osgi.wiring.package: org.apache.aries.blueprint\n org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.3]\n\nChain 2:\n org.apache.activemq.activemq-blueprint [org.apache.activemq.activemq-blueprint/5.11.1]\n import: (&(osgi.wiring.package=org.apache.xbean.blueprint.context.impl)(version>=3.13.0)(!(version>=4.0.0)))\n |\n export: osgi.wiring.package=org.apache.xbean.blueprint.context.impl; uses:=org.apache.aries.blueprint\n org.apache.xbean.blueprint [org.apache.xbean.blueprint/3.18.0]\n import: (&(osgi.wiring.package=org.apache.aries.blueprint)(version>=1.0.0)(!(version>=2.0.0)))\n |\n export: osgi.wiring.package: org.apache.aries.blueprint\n org.apache.aries.blueprint.core [org.apache.aries.blueprint.core/1.4.3]"
+}
\ No newline at end of file