Minor edits to the resolver and editing of some "to do" tasks. (FELIX-2035)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@927685 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
index 3726438..cc433b1 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -284,7 +284,7 @@
}
catch (SecurityException ex)
{
- // TODO: security - we need to throw this exception because of the 4.2.0 ct
+ // TODO: SECURITY - we need to throw this exception because of the 4.2.0 ct
throw new AccessControlException(ex.getMessage());
}
}
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 4c70fa2..4682d3b 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -532,7 +532,7 @@
security = security.trim();
if (Constants.FRAMEWORK_SECURITY_OSGI.equalsIgnoreCase(security) || (security.length() == 0))
{
- // TODO: security - we only need our own security manager to convert the exceptions
+ // TODO: SECURITY - we only need our own security manager to convert the exceptions
// because the 4.2.0 ct does expect them like this in one case.
System.setSecurityManager(m_securityManager = new SecurityManager()
{
@@ -3968,8 +3968,7 @@
// dynamic import is allowed without holding any locks, but this is
// okay since the resolver will double check later after we have
// acquired the global lock below.
- if (module.isResolved()
- && (ResolverImpl.isAllowedDynamicImport(m_resolverState, module, pkgName, new HashMap())))
+ if (module.isResolved() && isAllowedDynamicImport(module, pkgName))
{
// Acquire global lock.
boolean locked = acquireGlobalLock();
@@ -4032,6 +4031,12 @@
return m_resolverState.getCandidates(reqModule, req, obeyMandatory);
}
+ public boolean isAllowedDynamicImport(Module module, String pkgName)
+ {
+ return ResolverImpl.getDynamicImportCandidates(
+ m_resolverState, module, pkgName) != null;
+ }
+
private void markResolvedModules(Map<Module, List<Wire>> wireMap)
{
if (wireMap != null)
diff --git a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
index 12aab90..e20a1ce 100644
--- a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
@@ -2078,41 +2078,28 @@
}
*/
// Next, check to see if the package is dynamically imported by the module.
-// TODO: FELIX3 - Add Resolver.findAllowedDynamicImport().
-/*
- Requirement pkgReq = Resolver.findAllowedDynamicImport(module, pkgName);
- if (pkgReq != null)
+ if (resolver.isAllowedDynamicImport(module, pkgName))
{
// Try to see if there is an exporter available.
- List exports =
- resolver.getResolvedCandidates(pkgReq, module);
- exports = (exports.size() == 0)
- ? resolver.getUnresolvedCandidates(pkgReq, module)
- : exports;
+ List<Directive> dirs = Collections.EMPTY_LIST;
+ List<Attribute> attrs = new ArrayList(1);
+ attrs.add(new Attribute(Capability.PACKAGE_ATTR, pkgName, false));
+ Requirement req = new RequirementImpl(
+ Capability.PACKAGE_NAMESPACE, dirs, attrs);
+ Set<Capability> exporters = resolver.getCandidates(module, req, false);
- // An exporter might be available, but it may have attributes
- // that do not match the importer's required attributes, so
- // check that case by simply looking for an exporter of the
- // desired package without any attributes.
- if (exports.size() == 0)
+ Wire wire = null;
+ try
{
- try
- {
- IRequirement req = new Requirement(
- ICapability.PACKAGE_NAMESPACE, "(package=" + pkgName + ")");
- exports = resolver.getResolvedCandidates(req, module);
- exports = (exports.size() == 0)
- ? resolver.getUnresolvedCandidates(req, module)
- : exports;
- }
- catch (InvalidSyntaxException ex)
- {
- // This should never happen.
- }
+ wire = resolver.resolve(module, pkgName);
+ }
+ catch (Exception ex)
+ {
+ wire = null;
}
- String exporter = (exports.size() == 0)
- ? null : ((ICapability) exports.get(0)).getModule().getBundle().toString();
+ String exporter = (exporters.size() == 0)
+ ? null : exporters.iterator().next().getModule().getBundle().toString();
StringBuffer sb = new StringBuffer("*** Class '");
sb.append(name);
@@ -2121,27 +2108,24 @@
sb.append("' is dynamically imported by bundle ");
sb.append(importer);
sb.append(".");
- if (exports.size() > 0)
+ if ((exporters.size() > 0) && (wire == null))
{
- if (!pkgReq.isSatisfied((ICapability) exports.get(0)))
- {
- sb.append(" However, bundle ");
- sb.append(exporter);
- sb.append(" does export this package with attributes that do not match.");
- }
+ sb.append(" However, bundle ");
+ sb.append(exporter);
+ sb.append(" does export this package with attributes that do not match.");
}
sb.append(" ***");
return sb.toString();
}
-*/
+
// Next, check to see if there are any exporters for the package at all.
- Requirement pkgReq = null;
+ List<Directive> dirs = Collections.EMPTY_LIST;
List<Attribute> attrs = new ArrayList(1);
attrs.add(new Attribute(Capability.PACKAGE_ATTR, pkgName, false));
- pkgReq = new RequirementImpl(
- Capability.PACKAGE_NAMESPACE, new ArrayList<Directive>(0), attrs);
- Set<Capability> exports = resolver.getCandidates(module, pkgReq, false);
+ Requirement req = new RequirementImpl(
+ Capability.PACKAGE_NAMESPACE, dirs, attrs);
+ Set<Capability> exports = resolver.getCandidates(module, req, false);
if (exports.size() > 0)
{
boolean classpath = false;
diff --git a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
index 58be85c..1751567 100644
--- a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
+++ b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
@@ -188,7 +188,7 @@
public Permission getPermission()
{
- // TODO: This should probably return a FilePermission
+ // TODO: SECURITY - This should probably return a FilePermission
// to access the bundle JAR file, but we don't have the
// necessary information here to construct the absolute
// path of the JAR file...so it would take some
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java b/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java
index 394cc76..68cd6c9 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java
@@ -181,7 +181,7 @@
return null;
}
-// TODO: This will need to consider security.
+// TODO: SECURITY - This will need to consider security.
public synchronized String getEntryAsNativeLibrary(String entryName)
{
// Return result.
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java b/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
index 6402e78..2adef24 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
@@ -270,7 +270,7 @@
return null;
}
-// TODO: This will need to consider security.
+// TODO: SECURITY - This will need to consider security.
public String getEntryAsNativeLibrary(String entryName)
{
// Return result.
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java b/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
index b72ea49..5cc9ed2 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
@@ -62,7 +62,7 @@
c = v2.compareTo(v1);
}
}
-// TODO: PROTO3 RESOLVER - Need to change this to handle arbitrary capabilities
+// TODO: FELIX3 - Need to change this to handle arbitrary capabilities
// that may not have a natural ordering.
// Assume everything else is a package capability.
else if (c == 0)
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
index 473d91e..cd3fc6d 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
@@ -19,6 +19,7 @@
package org.apache.felix.framework.resolver;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -156,19 +157,19 @@
// The following call checks all of these conditions and returns
// a matching dynamic requirement if possible.
Map<Requirement, Set<Capability>> candidateMap =
- new HashMap<Requirement, Set<Capability>>();
- if (isAllowedDynamicImport(state, module, pkgName, candidateMap))
+ getDynamicImportCandidates(state, module, pkgName);
+ if (candidateMap != null)
{
m_candidatePermutations.clear();
- Map<Module, List<Wire>> wireMap = new HashMap<Module, List<Wire>>();
-
- Map<Module, Packages> modulePkgMap = new HashMap<Module, Packages>();
+ Map<Module, List<Wire>> wireMap = new HashMap();
+ Map<Module, Packages> modulePkgMap = new HashMap();
//System.out.println("+++ DYNAMICALLY RESOLVING " + module + " - " + pkgName);
populateDynamicCandidates(state, module,
m_fwkExecEnvStr, m_fwkExecEnvSet, candidateMap);
m_candidatePermutations.add(candidateMap);
+
ResolveException rethrow = null;
do
@@ -212,17 +213,14 @@
}
// TODO: FELIX3 - It would be nice to make this private.
- // TODO: FELIX3 - At a minimum, figure out a different way than passing in the
- // candidate map.
- public static boolean isAllowedDynamicImport(
- ResolverState state, Module module, String pkgName, Map<Requirement,
- Set<Capability>> candidateMap)
+ public static Map<Requirement, Set<Capability>> getDynamicImportCandidates(
+ ResolverState state, Module module, String pkgName)
{
// Unresolved modules cannot dynamically import, nor can the default
// package be dynamically imported.
if (!module.isResolved() || pkgName.length() == 0)
{
- return false;
+ return null;
}
// If any of the module exports this package, then we cannot
@@ -233,7 +231,7 @@
if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE)
&& caps.get(i).getAttribute(Capability.PACKAGE_ATTR).getValue().equals(pkgName))
{
- return false;
+ return null;
}
}
// If any of our wires have this package, then we cannot
@@ -243,17 +241,18 @@
{
if (wires.get(i).hasPackage(pkgName))
{
- return false;
+ return null;
}
}
// Loop through the importer's dynamic requirements to determine if
// there is a matching one for the package from which we want to
// load a class.
- List<Directive> dirs = new ArrayList(0);
+ List<Directive> dirs = Collections.EMPTY_LIST;
List<Attribute> attrs = new ArrayList(1);
attrs.add(new Attribute(Capability.PACKAGE_ATTR, pkgName, false));
- Requirement req = new RequirementImpl(Capability.PACKAGE_NAMESPACE, dirs, attrs);
+ Requirement req = new RequirementImpl(
+ Capability.PACKAGE_NAMESPACE, dirs, attrs);
Set<Capability> candidates = state.getCandidates(module, req, false);
List<Requirement> dynamics = module.getDynamicRequirements();
@@ -286,18 +285,21 @@
itCand.remove();
}
}
-
- if (candidates.size() > 0)
- {
- candidateMap.put(dynReq, candidates);
- }
}
else
{
candidates.clear();
}
- return !candidates.isEmpty();
+
+ if (candidates.size() > 0)
+ {
+ Map<Requirement, Set<Capability>> candidateMap = new HashMap();
+ candidateMap.put(dynReq, candidates);
+ return candidateMap;
+ }
+
+ return null;
}
private static void dumpCandidateMap(
@@ -708,10 +710,10 @@
}
catch (ResolveException ex)
{
-System.out.println("RE: " + ex);
-ex.printStackTrace();
+//System.out.println("RE: " + ex);
+//ex.printStackTrace();
-// TODO: FELIX3 RESOLVER - Is it ok to remove the failed candidate? By removing
+// TODO: FELIX3 - Is it ok to remove the failed candidate? By removing
// it we keep the candidateMap up to date with the selected candidate, but
// theoretically this eliminates some potential combinations. Are those
// combinations guaranteed to be failures so eliminating them is ok?
@@ -801,7 +803,7 @@
{
System.out.println("RE: " + ex);
ex.printStackTrace();
-// TODO: FELIX3 RESOLVER - Is it ok to remove the failed candidate? By removing
+// TODO: FELIX3 - Is it ok to remove the failed candidate? By removing
// it we keep the candidateMap up to date with the selected candidate, but
// theoretically this eliminates some potential combinations. Are those
// combinations guaranteed to be failures so eliminating them is ok?
@@ -835,7 +837,7 @@
{
for (int i = 0; i < caps.size(); i++)
{
-// TODO: PROTO3 RESOLVER - Assume if a module imports the same package it
+// TODO: FELIX3 - Assume if a module imports the same package it
// exports that the import will overlap the export.
if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE)
&& !hasOverlappingImport(module, caps.get(i)))
@@ -896,8 +898,6 @@
// will be visible to the current module.
Packages candPkgs = modulePkgMap.get(candCap.getModule());
-// TODO: PROTO3 RESOLVER - For now assume only exports, but eventually we also
-// have to support re-exported packages.
for (Entry<String, Blame> entry : candPkgs.m_exportedPkgs.entrySet())
{
mergeCandidatePackage(
@@ -912,7 +912,7 @@
List<Blame> blames = entry.getValue();
for (Blame blame : blames)
{
-// TODO: FELIX3 RESOLVER - Since a single module requirement can include many packages,
+// TODO: FELIX3 - Since a single module requirement can include many packages,
// it is likely we call merge too many times for the same module req. If we knew
// which candidates were being used to resolve this candidate's module dependencies,
// then we could just try to merge them directly. This info would also help in
@@ -953,7 +953,7 @@
m_invokeCounts.put(methodName, count);
}
-// TODO: PROTO3 RESOLVER - Check for merging where module imports from itself,
+// TODO: FELIX3 - Check for merging where module imports from itself,
// then it should be listed as an export for requiring bundles.
if (candBlame.m_cap.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
{
@@ -1027,7 +1027,7 @@
currentRequiredBlames = new ArrayList<Blame>();
currentPkgsCopy.m_requiredPkgs.put(pkgName, currentRequiredBlames);
}
-// TODO: PROTO3 RESOLVER - This is potentially modifying the original, we need to modify a copy.
+// TODO: FELIX3 - This is potentially modifying the original, we need to modify a copy.
currentRequiredBlames.add(candBlame);
}
else
@@ -1079,7 +1079,7 @@
}
}
-// TODO: PROTO3 RESOLVER - We end up with duplicates in uses constraints,
+// TODO: FELIX3 - We end up with duplicates in uses constraints,
// see scenario 2 for an example.
private void verifyAndMergeUses(
Module current, Packages currentPkgs,
@@ -1115,7 +1115,7 @@
{
Blame currentExportedBlame = currentPkgs.m_exportedPkgs.get(usedPkgName);
Blame currentImportedBlame = currentPkgs.m_importedPkgs.get(usedPkgName);
-// TODO: PROTO3 RESOLVER - What do we do with required packages?
+// TODO: FELIX3 - What do we do with required packages?
List<Blame> currentRequiredBlames = currentPkgs.m_requiredPkgs.get(usedPkgName);
Packages candSourcePkgs = modulePkgMap.get(candSourceCap.getModule());
@@ -1190,9 +1190,7 @@
throws ResolveException
{
// TODO: FELIX3 - I think permutation is not as efficient as it could be, since
-// the check for subsets is costly. Maybe we can just check if the candidates
-// for the blamed requirements are a subset, rather than computing the
-// entire permutation first.
+// the check for subsets is costly.
// When we detect a conflict, we need to permutate the candidate map
// we when we try again, we'll select different candidates. To achieve
diff --git a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/RequirementImpl.java b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/RequirementImpl.java
index 995dabb..e091803 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/RequirementImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/RequirementImpl.java
@@ -36,7 +36,6 @@
private final List<Directive> m_dirs;
private final List<Directive> m_dirsConst;
-// TODO: FELIX3 - Get rid of dynamic argument.
public RequirementImpl(
String namespace, List<Directive> dirs, List<Attribute> attrs)
{