Skip to content

Commit

Permalink
Changes to upgrade to Felix 3.0.4 resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
bosschaert committed Nov 3, 2010
1 parent a46aeb4 commit b4ead75
Show file tree
Hide file tree
Showing 15 changed files with 432 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public FelixResolverState(Logger logger, String fwkExecEnvStr)

List<String> indices = new ArrayList<String>();
indices.add(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
m_capSets.put(Capability.MODULE_NAMESPACE, new CapabilitySet(indices));
m_capSets.put(Capability.MODULE_NAMESPACE, new CapabilitySet(indices, true));

indices = new ArrayList<String>();
indices.add(Capability.PACKAGE_ATTR);
m_capSets.put(Capability.PACKAGE_NAMESPACE, new CapabilitySet(indices));
m_capSets.put(Capability.PACKAGE_NAMESPACE, new CapabilitySet(indices, true));

indices = new ArrayList<String>();
indices.add(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
m_capSets.put(Capability.HOST_NAMESPACE, new CapabilitySet(indices));
m_capSets.put(Capability.HOST_NAMESPACE, new CapabilitySet(indices, true));
}

public synchronized void addModule(Module module)
Expand Down Expand Up @@ -140,7 +140,7 @@ public synchronized void removeModule(Module module)
if (modules != null)
{
modules.remove(module);
if (modules.size() == 0)
if (modules.isEmpty())
{
m_singletons.remove(module.getSymbolicName());
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public void detachFragment(Module host, Module fragment)
{
// Ignore
}
m_logger.log(Logger.LOG_ERROR,
m_logger.log(host.getBundle(), Logger.LOG_ERROR,
"Serious error attaching fragments.", ex);
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ private void addFragment(Module fragment)
{
// Ignore
}
m_logger.log(Logger.LOG_ERROR,
m_logger.log(host.getBundle(), Logger.LOG_ERROR,
"Serious error attaching fragments.", ex);
}

Expand Down Expand Up @@ -361,7 +361,7 @@ private void removeFragment(Module fragment)
{
// Ignore
}
m_logger.log(Logger.LOG_ERROR,
m_logger.log(host.getBundle(), Logger.LOG_ERROR,
"Serious error attaching fragments.", ex);
}

Expand All @@ -382,7 +382,7 @@ private void addCapabilities(List<Capability> caps)
CapabilitySet capSet = m_capSets.get(cap.getNamespace());
if (capSet == null)
{
capSet = new CapabilitySet(null);
capSet = new CapabilitySet(null, true);
m_capSets.put(cap.getNamespace(), capSet);
}
capSet.addCapability(cap);
Expand Down Expand Up @@ -450,7 +450,8 @@ private Set<Capability> getMatchingHostCapabilities(Module fragment)
}
else if ((sm != null) && (hostCap.getModule().getSymbolicName() != null))
{
if (!hostCap.getModule().impliesDirect(
if (!hostCap.getModule()
.impliesDirect(
new BundlePermission(hostCap.getModule().getSymbolicName(),
BundlePermission.HOST)))
{
Expand Down Expand Up @@ -499,7 +500,7 @@ private void addHost(Module host)
{
// Ignore
}
m_logger.log(Logger.LOG_ERROR,
m_logger.log(host.getBundle(), Logger.LOG_ERROR,
"Serious error attaching fragments.", ex);
}
}
Expand Down Expand Up @@ -538,14 +539,15 @@ private void removeHost(Module host)
}
catch (Exception ex)
{
m_logger.log(Logger.LOG_ERROR, "Error detaching fragments.", ex);
m_logger.log(
host.getBundle(), Logger.LOG_ERROR, "Error detaching fragments.", ex);
}
// Set wires to null, which will remove the module from all
// of its dependent modules.
host.setWires(null);
}

private List<Module> getMatchingFragments(Module host)
public List<Module> getMatchingFragments(Module host)
{
// Find the host capability for the current host.
List<Capability> caps = Util.getCapabilityByNamespace(host, Capability.HOST_NAMESPACE);
Expand Down Expand Up @@ -949,4 +951,4 @@ else if (cmp == 0)

return modules.get(0);
}
}
}
40 changes: 31 additions & 9 deletions felix/src/main/java/org/apache/felix/framework/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.osgi.framework.*;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;

/**
* <p>
Expand Down Expand Up @@ -86,27 +93,40 @@ protected void setSystemBundleContext(BundleContext context)

public final void log(int level, String msg)
{
_log(null, level, msg, null);
_log(null, null, level, msg, null);
}

public final void log(int level, String msg, Throwable throwable)
{
_log(null, level, msg, throwable);
_log(null, null, level, msg, throwable);
}

public final void log(ServiceReference sr, int level, String msg)
{
_log(sr, level, msg, null);
_log(null, sr, level, msg, null);
}

public final void log(ServiceReference sr, int level, String msg, Throwable throwable)
{
_log(sr, level, msg, throwable);
_log(null, sr, level, msg, throwable);
}

public final void log(Bundle bundle, int level, String msg)
{
_log(bundle, null, level, msg, null);
}

public final void log(Bundle bundle, int level, String msg, Throwable throwable)
{
_log(bundle, null, level, msg, throwable);
}

protected void doLog(ServiceReference sr, int level, String msg, Throwable throwable)
protected void doLog(
Bundle bundle, ServiceReference sr, int level,
String msg, Throwable throwable)
{
String s = (sr == null) ? null : "SvcRef " + sr;
s = (s == null) ? null : s + " Bundle '" + bundle.getBundleId() + "'";
s = (s == null) ? msg : s + " " + msg;
s = (throwable == null) ? s : s + " (" + throwable + ")";
switch (level)
Expand Down Expand Up @@ -137,7 +157,9 @@ protected void doLog(ServiceReference sr, int level, String msg, Throwable throw
}
}

private void _log(ServiceReference sr, int level, String msg, Throwable throwable)
private void _log(
Bundle bundle, ServiceReference sr, int level,
String msg, Throwable throwable)
{
// Save our own copy just in case it changes. We could try to do
// more conservative locking here, but let's be optimistic.
Expand All @@ -153,7 +175,7 @@ private void _log(ServiceReference sr, int level, String msg, Throwable throwabl
// Otherwise, default logging action.
else
{
doLog(sr, level, msg, throwable);
doLog(bundle, sr, level, msg, throwable);
}
}
}
Expand Down Expand Up @@ -296,4 +318,4 @@ private void setLogger(Object logObj)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@

public class CapabilitySet
{
private final Map<String, Map<Object, Set<Capability>>> m_indices =
new TreeMap<String, Map<Object, Set<Capability>>>(new StringComparator(false));
private final Map<String, Map<Object, Set<Capability>>> m_indices;
private final Set<Capability> m_capList = new HashSet<Capability>();
private final static SecureAction m_secureAction = new SecureAction();

public CapabilitySet(List<String> indexProps)
public CapabilitySet(List<String> indexProps, boolean caseSensitive)
{
m_indices = (caseSensitive)
? new TreeMap<String, Map<Object, Set<Capability>>>()
: new TreeMap<String, Map<Object, Set<Capability>>>(new StringComparator(false));
for (int i = 0; (indexProps != null) && (i < indexProps.size()); i++)
{
m_indices.put(indexProps.get(i), new HashMap<Object, Set<Capability>>());
Expand Down Expand Up @@ -135,7 +137,7 @@ private void deindexCapability(
if (caps != null)
{
caps.remove(cap);
if (caps.size() == 0)
if (caps.isEmpty())
{
index.remove(capValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,16 @@ public static boolean compareSubstring(List<String> pieces, String s)
boolean result = true;
int len = pieces.size();

// Special case, if there is only one piece, then
// we must perform an equality test.
if (len == 1)
{
return s.equals(pieces.get(0));
}

// Otherwise, check whether the pieces match
// the specified string.

int index = 0;

loop: for (int i = 0; i < len; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,57 @@

public class FragmentRequirement implements Requirement
{
private final Module m_owner;
private final Requirement m_fragmentReq;
private final Module m_owner;
private final Requirement m_fragmentReq;

public FragmentRequirement(Module owner, Requirement fragmentReq)
{
m_owner = owner;
m_fragmentReq = fragmentReq;
}
public FragmentRequirement(Module owner, Requirement fragmentReq)
{
m_owner = owner;
m_fragmentReq = fragmentReq;
}

public Requirement getRequirement()
{
public Requirement getRequirement()
{
return m_fragmentReq;
}
}

public Module getFragment()
{
return m_fragmentReq.getModule();
}
public Module getFragment()
{
return m_fragmentReq.getModule();
}

public Module getModule()
{
return m_owner;
}
public Module getModule()
{
return m_owner;
}

public String getNamespace()
{
return m_fragmentReq.getNamespace();
}
public String getNamespace()
{
return m_fragmentReq.getNamespace();
}

public SimpleFilter getFilter()
{
return m_fragmentReq.getFilter();
}
public SimpleFilter getFilter()
{
return m_fragmentReq.getFilter();
}

public boolean isOptional()
{
return m_fragmentReq.isOptional();
}
public boolean isOptional()
{
return m_fragmentReq.isOptional();
}

public Directive getDirective(String name)
{
return m_fragmentReq.getDirective(name);
}
public Directive getDirective(String name)
{
return m_fragmentReq.getDirective(name);
}

public List<Directive> getDirectives()
{
return m_fragmentReq.getDirectives();
}
public List<Directive> getDirectives()
{
return m_fragmentReq.getDirectives();
}

public String toString()
{
return m_fragmentReq.toString();
}
}
public String toString()
{
return m_fragmentReq.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface Module
boolean isStale();
boolean isRemovalPending();
boolean impliesDirect(Permission permission);

// Fragment access methods.
void attachFragments(List<Module> fragments) throws Exception;
List<Module> getFragments();
Expand All @@ -85,4 +85,4 @@ boolean hasInputStream(int index, String urlPath)
throws IOException;
InputStream getInputStream(int index, String urlPath)
throws IOException;
}
}

0 comments on commit b4ead75

Please sign in to comment.