You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2010/03/31 23:30:42 UTC

svn commit: r929722 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: Felix.java FelixResolverState.java resolver/Resolver.java resolver/ResolverImpl.java

Author: rickhall
Date: Wed Mar 31 21:30:42 2010
New Revision: 929722

URL: http://svn.apache.org/viewvc?rev=929722&view=rev
Log:
Move exec env checking to resolver state. (FELIX-2035)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=929722&r1=929721&r2=929722&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Wed Mar 31 21:30:42 2010
@@ -333,11 +333,10 @@ public class Felix extends BundleImpl im
         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.

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java?rev=929722&r1=929721&r2=929722&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java Wed Mar 31 21:30:42 2010
@@ -20,10 +20,12 @@ package org.apache.felix.framework;
 
 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 @@ public class FelixResolverState implemen
     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 @@ public class FelixResolverState implemen
         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).
      *

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java?rev=929722&r1=929721&r2=929722&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java Wed Mar 31 21:30:42 2010
@@ -32,5 +32,6 @@ public interface Resolver
     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

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java?rev=929722&r1=929721&r2=929722&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java Wed Mar 31 21:30:42 2010
@@ -47,23 +47,16 @@ public class ResolverImpl implements Res
 {
     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 @@ public class ResolverImpl implements Res
             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 @@ public class ResolverImpl implements Res
             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 @@ public class ResolverImpl implements Res
 
 // 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 @@ public class ResolverImpl implements Res
         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 @@ public class ResolverImpl implements Res
                     try
                     {
                         populateCandidates(state, candCap.getModule(),
-                            fwkExecEnvStr, fwkExecEnvSet, candidateMap, resultCache);
+                            candidateMap, resultCache);
                     }
                     catch (ResolveException ex)
                     {
@@ -524,7 +516,6 @@ System.out.println("RE: Candidate not re
 
     private static void populateDynamicCandidates(
         ResolverState state, Module module,
-        String fwkExecEnvStr, Set fwkExecEnvSet,
         Map<Requirement, Set<Capability>> candidateMap)
     {
         if (m_isInvokeCount)
@@ -549,8 +540,7 @@ System.out.println("RE: Candidate not re
                 try
                 {
                     populateCandidates(state, candCap.getModule(),
-                        fwkExecEnvStr, fwkExecEnvSet, candidateMap,
-                        new HashMap<Module, Object>());
+                        candidateMap, new HashMap<Module, Object>());
                 }
                 catch (ResolveException ex)
                 {
@@ -1497,72 +1487,6 @@ ex.printStackTrace();
         }
     }
 
-    /**
-     * 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