diff --git a/.gitignore b/.gitignore
index 90c4d7ec224..6f843501666 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
/*/*/bin/
+bin_test
/bundles/archived/*/bin/
.DS_Store
@@ -8,4 +9,4 @@ target/
.polyglot.*
.META-INF_*
pom.tycho
-.tycho-consumer-pom.xml
+.tycho-consumer-pom.xml
\ No newline at end of file
diff --git a/bundles/org.eclipse.osgi/.classpath b/bundles/org.eclipse.osgi/.classpath
index d1e9a6c35df..9dd86311065 100644
--- a/bundles/org.eclipse.osgi/.classpath
+++ b/bundles/org.eclipse.osgi/.classpath
@@ -14,5 +14,12 @@
+
+
+
+
+
+
+
diff --git a/bundles/org.eclipse.osgi/build.properties b/bundles/org.eclipse.osgi/build.properties
index 463474d3aa8..8fc583284f1 100644
--- a/bundles/org.eclipse.osgi/build.properties
+++ b/bundles/org.eclipse.osgi/build.properties
@@ -37,3 +37,4 @@ output.. = bin/
javacWarnings..=-raw,unchecked,hiding,unused,warningToken
jars.extra.classpath = osgi/j9stubs.jar
jre.compilation.profile = JavaSE-1.8
+additional.bundles = org.mockito.mockito-core
diff --git a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/Candidates.java b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/Candidates.java
index bfb1b4681c8..33cdffadaab 100644
--- a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/Candidates.java
+++ b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/Candidates.java
@@ -18,17 +18,37 @@
*/
package org.apache.felix.resolver;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
-
import org.apache.felix.resolver.ResolverImpl.PermutationType;
import org.apache.felix.resolver.ResolverImpl.ResolveSession;
import org.apache.felix.resolver.reason.ReasonException;
-import org.apache.felix.resolver.util.*;
+import org.apache.felix.resolver.util.CandidateSelector;
+import org.apache.felix.resolver.util.CopyOnWriteSet;
+import org.apache.felix.resolver.util.OpenHashMap;
+import org.apache.felix.resolver.util.OpenHashMapList;
+import org.apache.felix.resolver.util.OpenHashMapSet;
import org.osgi.framework.Version;
-import org.osgi.framework.namespace.*;
-import org.osgi.resource.*;
+import org.osgi.framework.namespace.HostNamespace;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+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.HostedCapability;
import org.osgi.service.resolver.ResolutionException;
import org.osgi.service.resolver.ResolveContext;
@@ -842,12 +862,7 @@ public ResolutionError prepare()
CandidateSelector cands = m_candidateMap.get(origReq);
if (cands != null)
{
- if (cands instanceof ShadowList)
- {
- m_candidateMap.put(r, ShadowList.deepCopy((ShadowList) cands));
- } else {
m_candidateMap.put(r, cands.copy());
- }
for (Capability cand : cands.getRemainingCandidates())
{
Set dependents = m_dependentMap.get(cand);
@@ -907,36 +922,26 @@ public ResolutionError prepare()
// matter if they come from the host or fragment,
// since we are completing replacing the declaring
// host and fragments with the wrapped host.
- CandidateSelector cands = m_candidateMap.get(r);
- ShadowList shadow;
- if (!(cands instanceof ShadowList))
- {
- shadow = ShadowList.createShadowList(cands);
- m_candidateMap.put(r, shadow);
- cands = shadow;
- }
- else
- {
- shadow = (ShadowList) cands;
- }
// If the original capability is from a fragment, then
// ask the ResolveContext to insert it and update the
// shadow copy of the list accordingly.
if (!origCap.getResource().equals(hostResource.getDeclaredResource()))
{
- shadow.insertHostedCapability(
+ CandidateSelector cands = m_candidateMap.get(r);
+ m_candidateMap.put(r, cands.insertHostedCapability(
m_session.getContext(),
(HostedCapability) c,
new SimpleHostedCapability(
hostResource.getDeclaredResource(),
- origCap));
+ origCap)));
}
// If the original capability is from the host, then
// we just need to replace it in the shadow list.
else
{
- shadow.replace(origCap, c);
+ CandidateSelector cands = m_candidateMap.get(r);
+ m_candidateMap.put(r, cands.replace(origCap, c));
}
}
}
@@ -965,6 +970,16 @@ public ResolutionError prepare()
return null;
}
+// protected ShadowList getShadowList(Requirement r) {
+// CandidateSelector cands = m_candidateMap.get(r);
+// if (cands instanceof ShadowList) {
+// return (ShadowList) cands;
+// }
+// ShadowList shadow = ShadowList.createShadowList(cands);
+// m_candidateMap.put(r, shadow);
+// return shadow;
+// }
+
// Maps a host capability to a map containing its potential fragments;
// the fragment map maps a fragment symbolic name to a map that maps
// a version to a list of fragments requirements matching that symbolic
diff --git a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/CandidateSelector.java b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/CandidateSelector.java
index de8a5f502d2..e07c81bbea1 100644
--- a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/CandidateSelector.java
+++ b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/CandidateSelector.java
@@ -22,13 +22,14 @@
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
-
import org.osgi.resource.Capability;
+import org.osgi.service.resolver.HostedCapability;
+import org.osgi.service.resolver.ResolveContext;
public class CandidateSelector {
protected final AtomicBoolean isUnmodifiable;
protected final List unmodifiable;
- private int currentIndex = 0;
+ protected int currentIndex = 0;
public CandidateSelector(List candidates, AtomicBoolean isUnmodifiable) {
this.isUnmodifiable = isUnmodifiable;
@@ -54,9 +55,16 @@ public Capability getCurrentCandidate() {
}
public List getRemainingCandidates() {
- return Collections.unmodifiableList(unmodifiable.subList(currentIndex, unmodifiable.size()));
+ return Collections.unmodifiableList(getRemainingView());
}
+ private List getRemainingView() {
+ if (currentIndex == 0) {
+ return unmodifiable;
+ }
+ return unmodifiable.subList(currentIndex, unmodifiable.size());
+ }
+
public boolean isEmpty() {
return unmodifiable.size() <= currentIndex;
}
@@ -69,6 +77,17 @@ public Capability removeCurrentCandidate() {
return current;
}
+ public CandidateSelector replace(Capability origCap, Capability c) {
+ List view = getRemainingView();
+ int idx = view.indexOf(origCap);
+ if (idx < 0) {
+ return this;
+ }
+ List list = new ArrayList(view);
+ list.set(idx, c);
+ return new CandidateSelector(list, isUnmodifiable);
+ }
+
public String toString() {
return getRemainingCandidates().toString();
}
@@ -82,6 +101,33 @@ public int remove(Capability cap) {
return index;
}
+// public void insertHostedCapability(ResolveContext context, HostedCapability wrappedCapability, HostedCapability toInsertCapability) {
+// checkModifiable();
+// if (currentIndex != 0) {
+// throw new IllegalStateException("modifiable but index != 0??");
+// }
+// int removeIdx = m_original.indexOf(toInsertCapability.getDeclaredCapability());
+// if (removeIdx != -1)
+// {
+// m_original.remove(removeIdx);
+// unmodifiable.remove(removeIdx);
+// }
+// int insertIdx = context.insertHostedCapability(m_original, toInsertCapability);
+// unmodifiable.add(insertIdx, wrappedCapability);
+// }
+
+ public CandidateSelector insertHostedCapability(ResolveContext context, HostedCapability wrappedCapability,
+ HostedCapability toInsertCapability) {
+ List list = new ArrayList(getRemainingView());
+ int removeIdx = list.indexOf(toInsertCapability.getDeclaredCapability());
+ if (removeIdx != -1) {
+ list.remove(removeIdx);
+ }
+ int insertIdx = context.insertHostedCapability(list, toInsertCapability);
+ list.add(insertIdx, wrappedCapability);
+ return new CandidateSelector(list, isUnmodifiable);
+ }
+
protected void checkModifiable() {
if (isUnmodifiable.get()) {
throw new IllegalStateException("Trying to mutate after candidates have been prepared.");
diff --git a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/ShadowList.java b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/ShadowList.java
deleted file mode 100644
index a91ba30ee93..00000000000
--- a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/ShadowList.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.util;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.osgi.resource.Capability;
-import org.osgi.service.resolver.HostedCapability;
-import org.osgi.service.resolver.ResolveContext;
-
-public class ShadowList extends CandidateSelector
-{
- public static ShadowList createShadowList(CandidateSelector original) {
- if (original instanceof ShadowList)
- {
- throw new IllegalArgumentException("Cannot create a ShadowList using another ShadowList.");
- }
- return new ShadowList(original.unmodifiable, original.unmodifiable, original.isUnmodifiable);
- }
-
- public static ShadowList deepCopy(ShadowList original) {
- return new ShadowList(original.unmodifiable, original.m_original, original.isUnmodifiable);
- }
-
- private final List m_original;
-
- private ShadowList(CandidateSelector shadow, List original)
- {
- super(shadow);
- m_original = original;
- }
-
- private ShadowList(List unmodifiable, List original, AtomicBoolean isUnmodifiable) {
- super(unmodifiable, isUnmodifiable);
- m_original = new ArrayList(original);
- }
-
- public ShadowList copy() {
- return new ShadowList(this, m_original);
- }
-
- public void insertHostedCapability(ResolveContext context, HostedCapability wrappedCapability, HostedCapability toInsertCapability) {
- checkModifiable();
- int removeIdx = m_original.indexOf(toInsertCapability.getDeclaredCapability());
- if (removeIdx != -1)
- {
- m_original.remove(removeIdx);
- unmodifiable.remove(removeIdx);
- }
- int insertIdx = context.insertHostedCapability(m_original, toInsertCapability);
- unmodifiable.add(insertIdx, wrappedCapability);
- }
-
- public void replace(Capability origCap, Capability c) {
- checkModifiable();
- int idx = unmodifiable.indexOf(origCap);
- unmodifiable.set(idx, c);
- }
-}
\ No newline at end of file
diff --git a/bundles/org.eclipse.osgi/felix/src_test/felix-4914.json b/bundles/org.eclipse.osgi/felix/src_test/felix-4914.json
new file mode 100644
index 00000000000..579492517fa
--- /dev/null
+++ b/bundles/org.eclipse.osgi/felix/src_test/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
diff --git a/bundles/org.eclipse.osgi/felix/src_test/org/apache/felix/resolver/test/BigResolutionTest.java b/bundles/org.eclipse.osgi/felix/src_test/org/apache/felix/resolver/test/BigResolutionTest.java
new file mode 100644
index 00000000000..7e1174877aa
--- /dev/null
+++ b/bundles/org.eclipse.osgi/felix/src_test/org/apache/felix/resolver/test/BigResolutionTest.java
@@ -0,0 +1,447 @@
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.felix.resolver.Logger;
+import org.apache.felix.resolver.ResolverImpl;
+import org.apache.felix.resolver.test.util.CandidateComparator;
+import org.apache.felix.resolver.test.util.CapabilitySet;
+import org.apache.felix.resolver.test.util.ClauseParser;
+import org.apache.felix.resolver.test.util.GenericCapability;
+import org.apache.felix.resolver.test.util.GenericRequirement;
+import org.apache.felix.resolver.test.util.IterativeResolver;
+import org.apache.felix.resolver.test.util.JsonReader;
+import org.apache.felix.resolver.test.util.ResourceImpl;
+import org.apache.felix.resolver.test.util.SimpleFilter;
+import org.apache.felix.utils.version.VersionRange;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Version;
+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.HostedCapability;
+import org.osgi.service.resolver.ResolveContext;
+
+import static org.junit.Assert.assertEquals;
+
+public class BigResolutionTest {
+
+ @Test
+ @Ignore
+ public void testResolutionSpeed() throws Exception {
+ ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_INFO));
+
+ ResolveContext rc = buildResolutionContext();
+
+ System.out.println("Warming up...");
+ Map> wires = resolver.resolve(rc);
+ resolver.resolve(rc);
+
+ System.out.println("Running...");
+ RunningStat stats = new RunningStat();
+ for (int i = 1; i <= 100; i++) {
+ System.gc();
+ Thread.sleep(100);
+ System.gc();
+ Thread.sleep(100);
+ long t0 = System.nanoTime();
+ Map> newWires = resolver.resolve(rc);
+ long t1 = System.nanoTime();
+ double dt = (t1 - t0) * 1E-6;
+ System.out.println("Resolver took " + String.format("%7.2f", dt) + " ms");
+ stats.put(dt);
+ assertEquals(wires, newWires);
+
+ if (i % 10 == 0) {
+ System.out.println();
+ System.out.println("Summary");
+ System.out.println(" Min: " + String.format("%7.2f", stats.getMin()) + " ms");
+ System.out.println(" Max: " + String.format("%7.2f", stats.getMax()) + " ms");
+ System.out.println(" Avg: " + String.format("%7.2f", stats.getAverage()) + " ms");
+ System.out.println(" StdDev: " + String.format("%7" +
+ ".2f", stats.getStdDev() / stats.getAverage() * 100.0) + " %");
+ System.out.println();
+ stats = new RunningStat();
+ }
+ }
+
+ }
+
+ @Test
+ @Ignore
+ public void testIterativeResolution() throws Exception {
+ ResolveContext rc = buildResolutionContext();
+
+ ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_INFO));
+
+ long t0 = System.currentTimeMillis();
+ Map> wiring1 = resolver.resolve(rc);
+ long t1 = System.currentTimeMillis();
+ System.out.println("Resolver took " + (t1 - t0) + " ms");
+
+ long t2 = System.currentTimeMillis();
+ Map> wiring2 = new IterativeResolver(resolver).resolve(rc);
+ long t3 = System.currentTimeMillis();
+ System.out.println("Iterative resolver took " + (t3 - t2) + " ms");
+
+ checkResolutions(wiring1, wiring2);
+ }
+
+ private ResolveContext buildResolutionContext() throws IOException, BundleException {
+ Object resolution;
+
+ InputStream is = getClass().getClassLoader().getResourceAsStream("resolution.json");
+ try {
+ resolution = JsonReader.read(is);
+ } finally {
+ is.close();
+ }
+
+ List resources = new ArrayList();
+ ResourceImpl system = new ResourceImpl("system-bundle");
+ parseCapability(system, "osgi.ee; osgi.ee=JavaSE; version=1.5");
+ parseCapability(system, "osgi.ee; osgi.ee=JavaSE; version=1.6");
+ parseCapability(system, "osgi.ee; osgi.ee=JavaSE; version=1.7");
+ resources.add(system);
+ for (Object r : (Collection) ((Map) resolution).get("resources")) {
+ resources.add(parseResource(r));
+ }
+ final List mandatory = new ArrayList();
+ for (Object r : (Collection) ((Map) resolution).get("mandatory")) {
+ mandatory.add(parseResource(r));
+ }
+
+ final Map capSets = new HashMap();
+ CapabilitySet svcSet = new CapabilitySet(Collections.singletonList("objectClass"));
+ capSets.put("osgi.service", svcSet);
+ for (Resource resource : resources) {
+ 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);
+ }
+ }
+
+ return new ResolveContext() {
+ @Override
+ public Collection getMandatoryResources() {
+ return mandatory;
+ }
+
+ @Override
+ public List findProviders(Requirement requirement) {
+ SimpleFilter sf;
+ if (requirement.getDirectives().containsKey("filter")) {
+ sf = SimpleFilter.parse(requirement.getDirectives().get("filter"));
+ } else {
+ sf = SimpleFilter.convert(requirement.getAttributes());
+ }
+ CapabilitySet set = capSets.get(requirement.getNamespace());
+ List caps = new ArrayList(set.match(sf, true));
+ Collections.sort(caps, new CandidateComparator());
+ return caps;
+ }
+
+ @Override
+ public int insertHostedCapability(List capabilities, HostedCapability hostedCapability) {
+ capabilities.add(hostedCapability);
+ return capabilities.size() - 1;
+ }
+
+ @Override
+ public boolean isEffective(Requirement requirement) {
+ return true;
+ }
+
+ @Override
+ public Map getWirings() {
+ return Collections.emptyMap();
+ }
+ };
+ }
+
+ private void checkResolutions(Map> wireMap1, Map> wireMap2) {
+ Set resources;
+ resources = new HashSet(wireMap1.keySet());
+ resources.removeAll(wireMap2.keySet());
+ for (Resource res : resources) {
+ System.out.println("Resource resolved in r1 and not in r2: " + res);
+ }
+ resources = new HashSet(wireMap2.keySet());
+ resources.removeAll(wireMap1.keySet());
+ for (Resource res : resources) {
+ System.out.println("Resource resolved in r2 and not in r1: " + res);
+ }
+ resources = new HashSet(wireMap2.keySet());
+ resources.retainAll(wireMap1.keySet());
+ for (Resource resource : resources) {
+ Set wires1 = new HashSet(wireMap1.get(resource));
+ Set wires2 = new HashSet(wireMap2.get(resource));
+ wires1.removeAll(wireMap2.get(resource));
+ wires2.removeAll(wireMap1.get(resource));
+ if (!wires1.isEmpty() || !wires2.isEmpty()) {
+ System.out.println("Different wiring for resource: " + resource);
+ }
+ for (Wire wire : wires1) {
+ System.out.println("\tR1: " + wire);
+ }
+ for (Wire wire : wires2) {
+ System.out.println("\tR2: " + wire);
+ }
+ }
+ if (!wireMap1.equals(wireMap2)) {
+ throw new RuntimeException("Different wiring");
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Resource parseResource(Object resource) throws BundleException {
+ ResourceImpl res = new ResourceImpl();
+ Collection caps = (Collection) ((Map) resource).get("capabilities");
+ if (caps != null) {
+ for (String s : caps) {
+ parseCapability(res, s);
+ }
+ }
+ Collection reqs = (Collection) ((Map) resource).get("requirements");
+ if (reqs != null) {
+ for (String s : reqs) {
+ parseRequirement(res, s);
+ }
+ }
+ return res;
+ }
+
+ private static void parseRequirement(ResourceImpl res, String s) throws BundleException {
+ List clauses = ClauseParser.parseStandardHeader(s);
+ normalizeRequirementClauses(clauses);
+ for (ClauseParser.ParsedHeaderClause clause : clauses) {
+ for (String path : clause.paths) {
+ GenericRequirement requirement = new GenericRequirement(res, path);
+ for (Map.Entry dir : clause.dirs.entrySet()) {
+ requirement.addDirective(dir.getKey(), dir.getValue());
+ }
+ for (Map.Entry attr : clause.attrs.entrySet()) {
+ requirement.addAttribute(attr.getKey(), attr.getValue());
+ }
+ res.addRequirement(requirement);
+ }
+ }
+ }
+
+ private static void parseCapability(ResourceImpl res, String s) throws BundleException {
+ List clauses = ClauseParser.parseStandardHeader(s);
+ normalizeCapabilityClauses(clauses);
+ for (ClauseParser.ParsedHeaderClause clause : clauses) {
+ for (String path : clause.paths) {
+ GenericCapability capability = new GenericCapability(res, path);
+ for (Map.Entry dir : clause.dirs.entrySet()) {
+ capability.addDirective(dir.getKey(), dir.getValue());
+ }
+ for (Map.Entry attr : clause.attrs.entrySet()) {
+ capability.addAttribute(attr.getKey(), attr.getValue());
+ }
+ res.addCapability(capability);
+ }
+ }
+ }
+
+ private static void normalizeRequirementClauses(
+ List clauses)
+ throws BundleException {
+
+ // Convert attributes into specified types.
+ for (ClauseParser.ParsedHeaderClause clause : clauses)
+ {
+ for (Map.Entry entry : clause.attrs.entrySet())
+ {
+ String key = entry.getKey();
+ Object val = entry.getValue();
+ String type = clause.types.get(key);
+ if ("Version".equals(type) || "version".equals(key))
+ {
+ clause.attrs.put(
+ key,
+ VersionRange.parseVersionRange(val.toString().trim()));
+ }
+ }
+ }
+ }
+
+ private static void normalizeCapabilityClauses(
+ List clauses)
+ throws BundleException
+ {
+ // Convert attributes into specified types.
+ for (ClauseParser.ParsedHeaderClause clause : clauses)
+ {
+ for (Map.Entry entry : clause.types.entrySet())
+ {
+ String type = entry.getValue();
+ if (!type.equals("String"))
+ {
+ if (type.equals("Double"))
+ {
+ clause.attrs.put(
+ entry.getKey(),
+ new Double(clause.attrs.get(entry.getKey()).toString().trim()));
+ }
+ else if (type.equals("Version"))
+ {
+ clause.attrs.put(
+ entry.getKey(),
+ new Version(clause.attrs.get(entry.getKey()).toString().trim()));
+ }
+ else if (type.equals("Long"))
+ {
+ clause.attrs.put(
+ entry.getKey(),
+ new Long(clause.attrs.get(entry.getKey()).toString().trim()));
+ }
+ else if (type.startsWith("List"))
+ {
+ int startIdx = type.indexOf('<');
+ int endIdx = type.indexOf('>');
+ if (((startIdx > 0) && (endIdx <= startIdx))
+ || ((startIdx < 0) && (endIdx > 0)))
+ {
+ throw new BundleException(
+ "Invalid Provide-Capability attribute list type for '"
+ + entry.getKey()
+ + "' : "
+ + type);
+ }
+
+ String listType = "String";
+ if (endIdx > startIdx)
+ {
+ listType = type.substring(startIdx + 1, endIdx).trim();
+ }
+
+ List tokens = ClauseParser.parseDelimitedString(
+ clause.attrs.get(entry.getKey()).toString(), ",", false);
+ List