Move exec env checking to resolver state. (FELIX-2035)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@929722 13f79535-47bb-0310-9956-ffa450edef68
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 4682d3b..982ce59 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -333,11 +333,10 @@
m_bundleStreamHandler = new URLHandlersBundleStreamHandler(this);
// Create a resolver and its state.
- m_resolverState = new FelixResolverState(m_logger);
+ m_resolverState = new FelixResolverState(
+ m_logger, (String) m_configMap.get(Constants.FRAMEWORK_EXECUTIONENVIRONMENT));
m_felixResolver = new FelixResolver(
- new ResolverImpl(m_logger,
- (String) m_configMap.get(Constants.FRAMEWORK_EXECUTIONENVIRONMENT)),
- m_resolverState);
+ new ResolverImpl(m_logger), m_resolverState);
// Create the extension manager, which we will use as the module
// definition for creating the system bundle module.
diff --git a/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java b/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
index 8fcf9b0..f3b9bcb 100644
--- a/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
+++ b/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
@@ -20,10 +20,12 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.StringTokenizer;
import java.util.TreeSet;
import org.apache.felix.framework.capabilityset.Capability;
import org.apache.felix.framework.capabilityset.CapabilitySet;
@@ -54,12 +56,18 @@
private final Map<String, List<Module>> m_fragmentMap = new HashMap();
// Maps singleton symbolic names to list of modules sorted by version.
private final Map<String, List<Module>> m_singletons = new HashMap();
+ // Execution environment.
+ private final String m_fwkExecEnvStr;
+ private final Set m_fwkExecEnvSet;
- public FelixResolverState(Logger logger)
+ public FelixResolverState(Logger logger, String fwkExecEnvStr)
{
m_logger = logger;
m_modules = new ArrayList<Module>();
+ m_fwkExecEnvStr = (fwkExecEnvStr != null) ? fwkExecEnvStr.trim() : null;
+ m_fwkExecEnvSet = parseExecutionEnvironments(fwkExecEnvStr);
+
List indices = new ArrayList();
indices.add(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
m_modCapSet = new CapabilitySet(indices);
@@ -756,11 +764,75 @@
return result;
}
+ /**
+ * Checks to see if the passed in module's required execution environment
+ * is provided by the framework.
+ * @param fwkExecEvnStr The original property value of the framework's
+ * supported execution environments.
+ * @param fwkExecEnvSet Parsed set of framework's supported execution environments.
+ * @param module The module whose required execution environment is to be to verified.
+ * @throws ResolveException if the module's required execution environment does
+ * not match the framework's supported execution environment.
+ **/
+ public void checkExecutionEnvironment(Module module) throws ResolveException
+ {
+ String bundleExecEnvStr = (String)
+ module.getHeaders().get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
+ if (bundleExecEnvStr != null)
+ {
+ bundleExecEnvStr = bundleExecEnvStr.trim();
+
+ // If the bundle has specified an execution environment and the
+ // framework has an execution environment specified, then we must
+ // check for a match.
+ if (!bundleExecEnvStr.equals("")
+ && (m_fwkExecEnvStr != null)
+ && (m_fwkExecEnvStr.length() > 0))
+ {
+ StringTokenizer tokens = new StringTokenizer(bundleExecEnvStr, ",");
+ boolean found = false;
+ while (tokens.hasMoreTokens() && !found)
+ {
+ if (m_fwkExecEnvSet.contains(tokens.nextToken().trim()))
+ {
+ found = true;
+ }
+ }
+ if (!found)
+ {
+ throw new ResolveException(
+ "Execution environment not supported: "
+ + bundleExecEnvStr, module, null);
+ }
+ }
+ }
+ }
+
//
// Utility methods.
//
/**
+ * Updates the framework wide execution environment string and a cached Set of
+ * execution environment tokens from the comma delimited list specified by the
+ * system variable 'org.osgi.framework.executionenvironment'.
+ * @param frameworkEnvironment Comma delimited string of provided execution environments
+ **/
+ private static Set parseExecutionEnvironments(String fwkExecEnvStr)
+ {
+ Set newSet = new HashSet();
+ if (fwkExecEnvStr != null)
+ {
+ StringTokenizer tokens = new StringTokenizer(fwkExecEnvStr, ",");
+ while (tokens.hasMoreTokens())
+ {
+ newSet.add(tokens.nextToken().trim());
+ }
+ }
+ return newSet;
+ }
+
+ /**
* Returns true if the specified module is a singleton
* (i.e., directive singleton:=true in Bundle-SymbolicName).
*
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java b/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
index c8bd513..9fd679c 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
@@ -32,5 +32,6 @@
public static interface ResolverState
{
Set<Capability> getCandidates(Module module, Requirement req, boolean obeyMandatory);
+ void checkExecutionEnvironment(Module module) throws ResolveException;
}
}
\ No newline at end of file
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 9a9f459..723547f 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
@@ -47,23 +47,16 @@
{
private final Logger m_logger;
- // Execution environment.
-// TODO: FELIX3 - Move EE checking to ResolverState interface.
- private final String m_fwkExecEnvStr;
- private final Set m_fwkExecEnvSet;
-
private static final Map<String, Long> m_invokeCounts = new HashMap<String, Long>();
private static boolean m_isInvokeCount = false;
// Reusable empty array.
private static final List<Wire> m_emptyWires = new ArrayList<Wire>(0);
- public ResolverImpl(Logger logger, String fwkExecEnvStr)
+ public ResolverImpl(Logger logger)
{
//System.out.println("+++ PROTO3 RESOLVER");
m_logger = logger;
- m_fwkExecEnvStr = (fwkExecEnvStr != null) ? fwkExecEnvStr.trim() : null;
- m_fwkExecEnvSet = parseExecutionEnvironments(fwkExecEnvStr);
String v = System.getProperty("invoke.count");
m_isInvokeCount = (v == null) ? false : Boolean.valueOf(v);
@@ -94,8 +87,7 @@
Map<Requirement, Set<Capability>> candidateMap =
new HashMap<Requirement, Set<Capability>>();
- populateCandidates(state, module, m_fwkExecEnvStr, m_fwkExecEnvSet,
- candidateMap, new HashMap<Module, Object>());
+ populateCandidates(state, module, candidateMap, new HashMap<Module, Object>());
m_candidatePermutations.add(candidateMap);
ResolveException rethrow = null;
@@ -166,8 +158,7 @@
Map<Module, Packages> modulePkgMap = new HashMap();
//System.out.println("+++ DYNAMICALLY RESOLVING " + module + " - " + pkgName);
- populateDynamicCandidates(state, module,
- m_fwkExecEnvStr, m_fwkExecEnvSet, candidateMap);
+ populateDynamicCandidates(state, module, candidateMap);
m_candidatePermutations.add(candidateMap);
ResolveException rethrow = null;
@@ -366,8 +357,9 @@
// TODO: FELIX3 - Modify to not be recursive.
private static void populateCandidates(
- ResolverState state, Module module, String fwkExecEnvStr, Set fwkExecEnvSet,
- Map<Requirement, Set<Capability>> candidateMap, Map<Module, Object> resultCache)
+ ResolverState state, Module module,
+ Map<Requirement, Set<Capability>> candidateMap,
+ Map<Module, Object> resultCache)
{
if (m_isInvokeCount)
{
@@ -435,7 +427,7 @@
if ((remainingReqs == null) && (localCandidateMap == null))
{
// Verify that any required execution environment is satisfied.
- verifyExecutionEnvironment(fwkExecEnvStr, fwkExecEnvSet, module);
+ state.checkExecutionEnvironment(module);
// Verify that any native libraries match the current platform.
verifyNativeLibraries(module);
@@ -472,7 +464,7 @@
try
{
populateCandidates(state, candCap.getModule(),
- fwkExecEnvStr, fwkExecEnvSet, candidateMap, resultCache);
+ candidateMap, resultCache);
}
catch (ResolveException ex)
{
@@ -524,7 +516,6 @@
private static void populateDynamicCandidates(
ResolverState state, Module module,
- String fwkExecEnvStr, Set fwkExecEnvSet,
Map<Requirement, Set<Capability>> candidateMap)
{
if (m_isInvokeCount)
@@ -549,8 +540,7 @@
try
{
populateCandidates(state, candCap.getModule(),
- fwkExecEnvStr, fwkExecEnvSet, candidateMap,
- new HashMap<Module, Object>());
+ candidateMap, new HashMap<Module, Object>());
}
catch (ResolveException ex)
{
@@ -1497,72 +1487,6 @@
}
}
- /**
- * Checks to see if the passed in module's required execution environment
- * is provided by the framework.
- * @param fwkExecEvnStr The original property value of the framework's
- * supported execution environments.
- * @param fwkExecEnvSet Parsed set of framework's supported execution environments.
- * @param module The module whose required execution environment is to be to verified.
- * @throws ResolveException if the module's required execution environment does
- * not match the framework's supported execution environment.
- **/
- private static void verifyExecutionEnvironment(
- String fwkExecEnvStr, Set fwkExecEnvSet, Module module)
- throws ResolveException
- {
- String bundleExecEnvStr = (String)
- module.getHeaders().get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
- if (bundleExecEnvStr != null)
- {
- bundleExecEnvStr = bundleExecEnvStr.trim();
-
- // If the bundle has specified an execution environment and the
- // framework has an execution environment specified, then we must
- // check for a match.
- if (!bundleExecEnvStr.equals("")
- && (fwkExecEnvStr != null)
- && (fwkExecEnvStr.length() > 0))
- {
- StringTokenizer tokens = new StringTokenizer(bundleExecEnvStr, ",");
- boolean found = false;
- while (tokens.hasMoreTokens() && !found)
- {
- if (fwkExecEnvSet.contains(tokens.nextToken().trim()))
- {
- found = true;
- }
- }
- if (!found)
- {
- throw new ResolveException(
- "Execution environment not supported: "
- + bundleExecEnvStr, module, null);
- }
- }
- }
- }
-
- /**
- * Updates the framework wide execution environment string and a cached Set of
- * execution environment tokens from the comma delimited list specified by the
- * system variable 'org.osgi.framework.executionenvironment'.
- * @param frameworkEnvironment Comma delimited string of provided execution environments
- **/
- private static Set parseExecutionEnvironments(String fwkExecEnvStr)
- {
- Set newSet = new HashSet();
- if (fwkExecEnvStr != null)
- {
- StringTokenizer tokens = new StringTokenizer(fwkExecEnvStr, ",");
- while (tokens.hasMoreTokens())
- {
- newSet.add(tokens.nextToken().trim());
- }
- }
- return newSet;
- }
-
private static class Packages
{
public final Map<String, Blame> m_exportedPkgs