Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2013-09-07 11:47:31 +0000
committerThomas Watson2013-09-07 11:47:56 +0000
commite639431d3aa3ccabcb40ea34a6e02e7c009a699c (patch)
tree9ec4fb7c33a359307417261b59a3077700461ed2 /bundles/org.eclipse.osgi
parent75092469f948217c94704f6cb298d81b75d9f9d6 (diff)
downloadrt.equinox.framework-e639431d3aa3ccabcb40ea34a6e02e7c009a699c.tar.gz
rt.equinox.framework-e639431d3aa3ccabcb40ea34a6e02e7c009a699c.tar.xz
rt.equinox.framework-e639431d3aa3ccabcb40ea34a6e02e7c009a699c.zip
Add better diagnostics for uses constraint violations.I20130910-2000I20130910-0800I20130909-2000I20130908-2000
Diffstat (limited to 'bundles/org.eclipse.osgi')
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/Logger.java20
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/ResolverImpl.java16
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainerAdaptor.java13
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java4
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java39
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java5
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/report/resolution/ResolutionReport.java14
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/ExternalMessages.properties1
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/Msg.java1
9 files changed, 73 insertions, 40 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/Logger.java b/bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/Logger.java
index 9eaa21212..b652051f7 100644
--- a/bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/Logger.java
+++ b/bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/Logger.java
@@ -18,6 +18,10 @@
*/
package org.apache.felix.resolver;
+import org.osgi.resource.Resource;
+
+import org.osgi.service.resolver.ResolutionException;
+
/**
* <p>
* This class mimics the standard OSGi <tt>LogService</tt> interface. An
@@ -46,10 +50,6 @@ public class Logger
private int m_logLevel = 1;
- private final static int LOGGER_OBJECT_IDX = 0;
- private final static int LOGGER_METHOD_IDX = 1;
- private Object[] m_logger = null;
-
public Logger(int i)
{
m_logLevel = i;
@@ -77,6 +77,10 @@ public class Logger
protected void doLog(int level, String msg, Throwable throwable)
{
+ if (level > m_logLevel)
+ {
+ return;
+ }
String s = "";
s = s + msg;
if (throwable != null)
@@ -110,13 +114,13 @@ public class Logger
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.
- Object[] logger = m_logger;
-
if (m_logLevel >= level)
{
doLog(level, msg, throwable);
}
}
+
+ public void logUsesConstraintViolation(Resource resource, ResolutionException error) {
+ // do nothing by default
+ }
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/ResolverImpl.java b/bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/ResolverImpl.java
index 82d1d4d22..f45cc858c 100644
--- a/bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/ResolverImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/apache/felix/resolver/ResolverImpl.java
@@ -214,7 +214,7 @@ public class ResolverImpl implements Resolver
}
}
- Collection<Resource> faultyResources = null;
+ Map<Resource, ResolutionException> faultyResources = null;
do
{
rethrow = null;
@@ -230,7 +230,7 @@ public class ResolverImpl implements Resolver
? usesPermutations.remove(0)
: importPermutations.remove(0);
//allCandidates.dump();
- Collection<Resource> currentFaultyResources = null;
+ Map<Resource, ResolutionException> currentFaultyResources = null;
// Reuse a resultCache map for checking package consistency
// for all resources.
Map<Resource, Object> resultCache =
@@ -266,9 +266,9 @@ public class ResolverImpl implements Resolver
{
rethrow = ex;
if (currentFaultyResources == null) {
- currentFaultyResources = new ArrayList();
+ currentFaultyResources = new HashMap<Resource, ResolutionException>();
}
- currentFaultyResources.add(resource);
+ currentFaultyResources.put(resource, ex);
}
}
if (currentFaultyResources != null) {
@@ -290,7 +290,13 @@ public class ResolverImpl implements Resolver
if (rethrow != null)
{
if (faultyResources != null) {
- retry = (optionalResources.removeAll(faultyResources) || ondemandFragments.removeAll(faultyResources));
+ Set<Resource> resourceKeys = faultyResources.keySet();
+ retry = (optionalResources.removeAll(resourceKeys) || ondemandFragments.removeAll(resourceKeys));
+ // remove mandatory resources and log optional resource exceptions
+ resourceKeys.removeAll(mandatoryResources);
+ for (Map.Entry<Resource, ResolutionException> usesError : faultyResources.entrySet()) {
+ m_logger.logUsesConstraintViolation(usesError.getKey(), usesError.getValue());
+ }
}
if (!retry) {
throw rethrow;
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainerAdaptor.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainerAdaptor.java
index c0f3b837f..c7a16dc8a 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainerAdaptor.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainerAdaptor.java
@@ -12,13 +12,10 @@ package org.eclipse.osgi.container;
import java.io.DataInputStream;
import java.util.EnumSet;
-import org.apache.felix.resolver.Logger;
-import org.apache.felix.resolver.ResolverImpl;
import org.eclipse.osgi.container.Module.Settings;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
-import org.osgi.service.resolver.Resolver;
/**
* Adapts the behavior of a container.
@@ -78,16 +75,6 @@ public abstract class ModuleContainerAdaptor {
}
/**
- * Returns the resolver the container will use. This implementation will
- * return the default implementation of the resolver. Override this method
- * to provide an alternative resolver implementation for the container.
- * @return the resolver the container will use.
- */
- public Resolver getResolver() {
- return new ResolverImpl(new Logger(4));
- }
-
- /**
* Returns the collision hook the container will use.
* @return the collision hook the container will use.
*/
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java
index a3e2a9f31..7ea21e5bb 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java
@@ -132,6 +132,10 @@ public class ModuleResolutionReport implements ResolutionReport {
case FILTERED_BY_RESOLVER_HOOK :
result.append(Msg.ModuleResolutionReport_FilteredByHook).append('\n');
break;
+ case USES_CONSTRAINT_VIOLATION :
+ result.append(prepend).append(Msg.ModuleResolutionReport_UsesConstraintError).append('\n');
+ result.append(" ").append(entry.getData()); //$NON-NLS-1$
+ break;
default :
result.append(Msg.ModuleResolutionReport_Unknown).append("type=").append(entry.getType()).append(" data=").append(entry.getData()).append('\n'); //$NON-NLS-1$ //$NON-NLS-2$
break;
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java
index f25b838ce..1a657a483 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java
@@ -12,6 +12,7 @@ package org.eclipse.osgi.container;
import java.security.Permission;
import java.util.*;
+import org.apache.felix.resolver.Logger;
import org.apache.felix.resolver.ResolverImpl;
import org.eclipse.osgi.container.ModuleRequirement.DynamicModuleRequirement;
import org.eclipse.osgi.internal.container.InternalUtils;
@@ -42,7 +43,6 @@ final class ModuleResolver {
}
};
final ModuleContainerAdaptor adaptor;
- final Resolver resolver;
/**
* Constructs the module resolver with the specified resolver hook factory
@@ -51,7 +51,6 @@ final class ModuleResolver {
*/
ModuleResolver(ModuleContainerAdaptor adaptor) {
this.adaptor = adaptor;
- this.resolver = adaptor.getResolver();
}
/**
@@ -404,6 +403,26 @@ final class ModuleResolver {
}
class ResolveProcess extends ResolveContext implements Comparator<Capability> {
+ class ResolveLogger extends Logger {
+ private Map<Resource, ResolutionException> errors = null;
+
+ public ResolveLogger() {
+ super(0);
+ }
+
+ @Override
+ public void logUsesConstraintViolation(Resource resource, ResolutionException error) {
+ if (errors == null) {
+ errors = new HashMap<Resource, ResolutionException>();
+ }
+ errors.put(resource, error);
+ }
+
+ Map<Resource, ResolutionException> getUsesConstraintViolations() {
+ return errors == null ? Collections.<Resource, ResolutionException> emptyMap() : errors;
+ }
+ }
+
private final ModuleResolutionReport.Builder reportBuilder = new ModuleResolutionReport.Builder();
/*
* Contains the revisions that were requested to be resolved and is not
@@ -610,6 +629,7 @@ final class ModuleResolver {
Map<Resource, List<Wire>> result = null;
ResolutionException re = null;
ModuleResolutionReport report;
+ ResolveLogger logger = new ResolveLogger();
try {
filterResolvable();
selectSingletons();
@@ -629,13 +649,14 @@ final class ModuleResolver {
wirings.put(updatedWiring.getKey(), updatedWiring.getValue());
}
}
- result = resolver.resolve(this);
+ result = new ResolverImpl(logger).resolve(this);
result.putAll(dynamicAttachWirings);
}
} catch (ResolutionException e) {
re = e;
} finally {
computeUnresolvedProviderResolutionReportEntries(result);
+ computeUsesConstraintViolations(logger.getUsesConstraintViolations());
report = reportBuilder.build(result, re);
if (hook instanceof ResolutionReport.Listener)
((ResolutionReport.Listener) hook).handleResolutionReport(report);
@@ -647,6 +668,12 @@ final class ModuleResolver {
}
}
+ private void computeUsesConstraintViolations(Map<Resource, ResolutionException> usesConstraintViolations) {
+ for (Map.Entry<Resource, ResolutionException> usesConstraintViolation : usesConstraintViolations.entrySet()) {
+ reportBuilder.addEntry(usesConstraintViolation.getKey(), Type.USES_CONSTRAINT_VIOLATION, usesConstraintViolation.getValue());
+ }
+ }
+
/*
* Given the results of a resolution, compute which, if any, of the
* enabled, resolving resources are still unresolved. For those that are
@@ -796,14 +823,10 @@ final class ModuleResolver {
}
private Map<Resource, List<Wire>> resolveDynamic() throws ResolutionException {
- if (!(resolver instanceof ResolverImpl)) {
- throw new ResolutionException("Dynamic import resolution not supported by the resolver: " + resolver.getClass()); //$NON-NLS-1$
- }
List<Capability> dynamicMatches = filterProviders(dynamicReq.getOriginal(), moduleDatabase.findCapabilities(dynamicReq));
Collection<Resource> ondemandFragments = InternalUtils.asCollectionResource(moduleDatabase.getFragmentRevisions());
- return ((ResolverImpl) resolver).resolve(this, dynamicReq.getRevision(), dynamicReq.getOriginal(), dynamicMatches, ondemandFragments);
-
+ return new ResolverImpl(new Logger(0)).resolve(this, dynamicReq.getRevision(), dynamicReq.getOriginal(), dynamicMatches, ondemandFragments);
}
private void filterResolvable() {
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java
index 6fa984613..1d65a6ec2 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java
@@ -11,6 +11,9 @@
package org.eclipse.osgi.internal.framework;
+import org.apache.felix.resolver.Logger;
+
+import org.apache.felix.resolver.ResolverImpl;
import java.util.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParserFactory;
@@ -73,7 +76,7 @@ public class SystemBundleActivator implements BundleActivator {
register(bc, PermissionAdmin.class, sa, null);
register(bc, ConditionalPermissionAdmin.class, sa, null);
- register(bc, Resolver.class, bundle.getEquinoxContainer().getStorage().getAdaptor().getResolver(), null);
+ register(bc, Resolver.class, new ResolverImpl(new Logger(0)), null);
register(bc, DebugOptions.class, dbgOptions, null);
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/report/resolution/ResolutionReport.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/report/resolution/ResolutionReport.java
index 43d9cf027..1e74fa8dc 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/report/resolution/ResolutionReport.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/report/resolution/ResolutionReport.java
@@ -109,8 +109,6 @@ public interface ResolutionReport {
* Resource</code>, which represents the singleton with which the
* resource collided.
*/
- // TODO Should the data present all of the colliding singletons
- // rather than multiple entries each containing a single collision?
SINGLETON_SELECTION,
/**
* Indicates a resource failed to resolve because one or more
@@ -118,7 +116,13 @@ public interface ResolutionReport {
* were not resolved. The structure of the data is <code>
* Map&lt;Requirement, Set&lt;Capability&gt;&gt;</code>.
*/
- UNRESOLVED_PROVIDER
+ UNRESOLVED_PROVIDER,
+ /**
+ * Indicates a resource failed to resolve because of a uses
+ * constraint violation. The structure of the data is
+ * <code>ResolutionException</code>.
+ */
+ USES_CONSTRAINT_VIOLATION
}
// TODO Can this make use of generics? Or should this be Map<String, Object>
@@ -163,8 +167,8 @@ public interface ResolutionReport {
* or {@code null} if there is no resolution exception. For some resolve
* operations a resolution exception may not be thrown even if the
* resolve process could not resolve some resources. For example, if
- * the resources are optional resources to resolve.
- * @return thee resolution exception or {@code null} if there is
+ * the resources are not optional resources to resolve.
+ * @return the resolution exception or {@code null} if there is
* no resolution exception.
*/
ResolutionException getResoltuionException();
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/ExternalMessages.properties b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/ExternalMessages.properties
index 58a5aecee..b9d8b593f 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/ExternalMessages.properties
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/ExternalMessages.properties
@@ -130,6 +130,7 @@ ModuleResolutionReport_FilteredByHook=Bundle was filtered by a resolver hook.
ModuleResolutionReport_NoReport=No resolution report for the bundle.
ModuleResolutionReport_Unknown=Unknown error:
ModuleResolutionReport_UnresolvedReq=Unresolved requirement:
+ModuleResolutionReport_UsesConstraintError=Bundle was not resolved because of a uses contraint violation.
ModuleResolver_RecursiveError=Detected a recursive resolve operation.
ModuleResolver_SingletonDisabledError=Could not resolve mandatory modules because another singleton was selected or the module was disabled:
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/Msg.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/Msg.java
index 7de0d8dc9..01018a7f6 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/Msg.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/messages/Msg.java
@@ -138,6 +138,7 @@ public class Msg extends NLS {
public static String ModuleResolutionReport_NoReport;
public static String ModuleResolutionReport_Unknown;
public static String ModuleResolutionReport_UnresolvedReq;
+ public static String ModuleResolutionReport_UsesConstraintError;
public static String ModuleResolver_RecursiveError;
public static String ModuleResolver_SingletonDisabledError;

Back to the top