Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce usages of ShadowList #542

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*/*/bin/
bin_test
/bundles/archived/*/bin/
.DS_Store

Expand All @@ -8,4 +9,4 @@ target/
.polyglot.*
.META-INF_*
pom.tycho
.tycho-consumer-pom.xml
.tycho-consumer-pom.xml
7 changes: 7 additions & 0 deletions bundles/org.eclipse.osgi/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@
</classpathentry>
<classpathentry kind="src" path="supplement/src"/>
<classpathentry kind="src" path="container/src"/>
<classpathentry kind="src" output="bin_test" path="felix/src_test">
<attributes>
<attribute name="test" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions bundles/org.eclipse.osgi/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -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;
Expand Down Expand Up @@ -842,12 +862,7 @@
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<Requirement> dependents = m_dependentMap.get(cand);
Expand Down Expand Up @@ -907,36 +922,26 @@
// 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));
}
}
}
Expand Down Expand Up @@ -965,6 +970,16 @@
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -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<Capability> unmodifiable;
private int currentIndex = 0;
protected int currentIndex = 0;

public CandidateSelector(List<Capability> candidates, AtomicBoolean isUnmodifiable) {
this.isUnmodifiable = isUnmodifiable;
Expand All @@ -54,9 +55,16 @@
}

public List<Capability> getRemainingCandidates() {
return Collections.unmodifiableList(unmodifiable.subList(currentIndex, unmodifiable.size()));
return Collections.unmodifiableList(getRemainingView());
}

private List<Capability> getRemainingView() {
if (currentIndex == 0) {
return unmodifiable;
}
return unmodifiable.subList(currentIndex, unmodifiable.size());
}

public boolean isEmpty() {
return unmodifiable.size() <= currentIndex;
}
Expand All @@ -69,6 +77,17 @@
return current;
}

public CandidateSelector replace(Capability origCap, Capability c) {
List<Capability> view = getRemainingView();
int idx = view.indexOf(origCap);
if (idx < 0) {
return this;
}
List<Capability> list = new ArrayList<Capability>(view);
list.set(idx, c);
return new CandidateSelector(list, isUnmodifiable);
}

public String toString() {
return getRemainingCandidates().toString();
}
Expand All @@ -82,6 +101,33 @@
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<Capability> list = new ArrayList<Capability>(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.");
Expand Down

This file was deleted.

59 changes: 59 additions & 0 deletions bundles/org.eclipse.osgi/felix/src_test/felix-4914.json
Original file line number Diff line number Diff line change
@@ -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]"
}
Loading
Loading