Return-Path: Delivered-To: apmail-felix-commits-archive@www.apache.org Received: (qmail 70417 invoked from network); 21 Jul 2009 22:38:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Jul 2009 22:38:36 -0000 Received: (qmail 83206 invoked by uid 500); 21 Jul 2009 22:39:42 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 83155 invoked by uid 500); 21 Jul 2009 22:39:41 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 83146 invoked by uid 99); 21 Jul 2009 22:39:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jul 2009 22:39:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jul 2009 22:39:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B45D52388905; Tue, 21 Jul 2009 22:39:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r796571 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: Felix.java searchpolicy/Resolver.java Date: Tue, 21 Jul 2009 22:39:16 -0000 To: commits@felix.apache.org From: rickhall@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090721223916.B45D52388905@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rickhall Date: Tue Jul 21 22:39:16 2009 New Revision: 796571 URL: http://svn.apache.org/viewvc?rev=796571&view=rev Log: Perform required execution environment check at resolve time. (FELIX-1397) Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/Resolver.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=796571&r1=796570&r2=796571&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 Tue Jul 21 22:39:16 2009 @@ -113,10 +113,6 @@ // Reusable bundle URL stream handler. private final URLStreamHandler m_bundleStreamHandler; - // Execution environment. - private String m_executionEnvironment = ""; - private Set m_executionEnvironmentCache = new HashSet(); - // Boot package delegation. private final String[] m_bootPkgs; private final boolean[] m_bootPkgWildcards; @@ -295,7 +291,10 @@ // Create a resolver and its state. m_resolverState = new FelixResolverState(m_logger); - m_felixResolver = new FelixResolver(new Resolver(m_logger), m_resolverState); + m_felixResolver = new FelixResolver( + new Resolver(m_logger, + (String) m_configMap.get(Constants.FRAMEWORK_EXECUTIONENVIRONMENT)), + m_resolverState); // Create the extension manager, which we will use as the module // definition for creating the system bundle module. @@ -2410,8 +2409,6 @@ releaseGlobalLock(); } - verifyExecutionEnvironment(bundle); - if (!bundle.isExtension()) { Object sm = System.getSecurityManager(); @@ -2533,98 +2530,6 @@ } /** - * Checks the passed in bundle and checks to see if there is a required execution environment. - * If there is, it gets the execution environment string and verifies that the framework provides it. - * @param bundle The bundle to verify - * @throws BundleException if the bundle's required execution environment does - * not match the current execution environment. - **/ - private void verifyExecutionEnvironment(BundleImpl bundle) - throws ResolveException - { - String bundleEnvironment = (String) - bundle.getCurrentModule().getHeaders().get( - Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); - if (bundleEnvironment != null) - { - bundleEnvironment = bundleEnvironment.trim(); - if (!bundleEnvironment.equals("")) - { - if (!isMatchingExecutionEnvironment(bundleEnvironment)) - { - throw new ResolveException( - "Execution Environment not supported: " + bundleEnvironment, null, null); - } - } - } - } - - /** - * Check the required bundle execution environment against the framework provided - * exectution environment. - * @param bundleEnvironment The required execution environment string - * (from Bundle-RequiredExecutionEnvironment manifest header - * @return True if the required bundle execution environment is provided by the framework - * False if none of the provided framework execution environments match - **/ - private boolean isMatchingExecutionEnvironment(String bundleEnvironment) - { - String frameworkEnvironment = getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT); - if (frameworkEnvironment == null) - { - // If no framework execution environment is set, then all are valid - return true; - } - - frameworkEnvironment = frameworkEnvironment.trim(); - if ("".equals(frameworkEnvironment)) - { - // If no framework execution environment is set, then all are valid - return true; - } - - // The execution environment has changed, so update the cache and EE set - if (!m_executionEnvironment.equals(frameworkEnvironment)) - { - updateFrameworkExecutionEnvironment(frameworkEnvironment); - } - - StringTokenizer tokens = new StringTokenizer(bundleEnvironment, ","); - while (tokens.hasMoreTokens()) - { - if (m_executionEnvironmentCache.contains(tokens.nextToken().trim())) - { - return true; - } - } - - return false; - } - - /** - * 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 void updateFrameworkExecutionEnvironment(String frameworkEnvironment) - { - StringTokenizer tokens = new StringTokenizer(frameworkEnvironment, ","); - - Set newSet = new HashSet(tokens.countTokens()); - while (tokens.hasMoreTokens()) - { - newSet.add(tokens.nextToken().trim()); - } - - synchronized (m_executionEnvironmentCache) - { - m_executionEnvironment = frameworkEnvironment; - m_executionEnvironmentCache = newSet; - } - } - - /** * Retrieves a bundle from its location. * * @param location The location of the bundle to retrieve. @@ -3990,8 +3895,6 @@ } } - verifyExecutionEnvironment(bundle); - // Before trying to resolve, tell the resolver state to // merge all fragments into host, which may result in the // rootModule changing if the real root is a module. Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/Resolver.java URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/Resolver.java?rev=796571&r1=796570&r2=796571&view=diff ============================================================================== --- felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/Resolver.java (original) +++ felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/Resolver.java Tue Jul 21 22:39:16 2009 @@ -22,9 +22,12 @@ import java.util.Collections; import java.util.Comparator; 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 org.apache.felix.framework.Logger; import org.apache.felix.framework.util.Util; import org.apache.felix.framework.util.manifestparser.Capability; @@ -36,20 +39,27 @@ import org.apache.felix.moduleloader.IModule; import org.apache.felix.moduleloader.IRequirement; import org.apache.felix.moduleloader.IWire; +import org.osgi.framework.BundleException; import org.osgi.framework.Constants; public class Resolver { private final Logger m_logger; + // Execution environment. + private final String m_fwkExecEnvStr; + private final Set m_fwkExecEnvSet; + // Reusable empty array. private static final IWire[] m_emptyWires = new IWire[0]; private static final IModule[] m_emptyModules = new IModule[0]; private static final PackageSource[] m_emptySources = new PackageSource[0]; - public Resolver(Logger logger) + public Resolver(Logger logger, String fwkExecEnvStr) { m_logger = logger; + m_fwkExecEnvStr = fwkExecEnvStr.trim(); + m_fwkExecEnvSet = parseExecutionEnvironments(fwkExecEnvStr); } // Returns a map of resolved bundles where the key is the module @@ -336,7 +346,7 @@ return populateWireMap(state, candidatesMap, provider, new HashMap()); } - private static void populateCandidatesMap( + private void populateCandidatesMap( ResolverState state, Map candidatesMap, IModule targetModule) throws ResolveException { @@ -346,39 +356,15 @@ return; } - // First, try to resolve any native code, since the module is - // not resolvable if its native code cannot be loaded. - R4Library[] libs = targetModule.getNativeLibraries(); - if (libs != null) - { - String msg = null; - // Verify that all native libraries exist in advance; this will - // throw an exception if the native library does not exist. - for (int libIdx = 0; (msg == null) && (libIdx < libs.length); libIdx++) - { - String entryName = libs[libIdx].getEntryName(); - if (entryName != null) - { - if (!targetModule.getContent().hasEntry(entryName)) - { - msg = "Native library does not exist: " + entryName; - } - } - } - // If we have a zero-length native library array, then - // this means no native library class could be selected - // so we should fail to resolve. - if (libs.length == 0) - { - msg = "No matching native libraries found."; - } - if (msg != null) - { - throw new ResolveException(msg, targetModule, null); - } - } + // Verify that any required execution environment is satisfied. + verifyExecutionEnvironment(m_fwkExecEnvStr, m_fwkExecEnvSet, targetModule); - // List to hold the resolving candidate sets for the target + // Verify that any native libraries match the current platform. + verifyNativeLibraries(targetModule); + + // Finally, resolve any dependencies the module may have. + + // Create list to hold the resolving candidate sets for the target // module's requirements. List candSetList = new ArrayList(); @@ -1558,6 +1544,106 @@ // Utility methods. // + private static void verifyNativeLibraries(IModule module) + throws ResolveException + { + // Next, try to resolve any native code, since the module is + // not resolvable if its native code cannot be loaded. + R4Library[] libs = module.getNativeLibraries(); + if (libs != null) + { + String msg = null; + // Verify that all native libraries exist in advance; this will + // throw an exception if the native library does not exist. + for (int libIdx = 0; (msg == null) && (libIdx < libs.length); libIdx++) + { + String entryName = libs[libIdx].getEntryName(); + if (entryName != null) + { + if (!module.getContent().hasEntry(entryName)) + { + msg = "Native library does not exist: " + entryName; + } + } + } + // If we have a zero-length native library array, then + // this means no native library class could be selected + // so we should fail to resolve. + if (libs.length == 0) + { + msg = "No matching native libraries found."; + } + if (msg != null) + { + throw new ResolveException(msg, module, null); + } + } + } + + /** + * 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, IModule 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 frameworkEnvironment) + { + StringTokenizer tokens = new StringTokenizer(frameworkEnvironment, ","); + + Set newSet = new HashSet(tokens.countTokens()); + while (tokens.hasMoreTokens()) + { + newSet.add(tokens.nextToken().trim()); + } + return newSet; + } + private static IModule[] shrinkModuleArray(IModule[] modules) { if (modules == null)