You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by bo...@apache.org on 2014/10/28 03:43:06 UTC

svn commit: r1634763 - in /felix/trunk/framework/src: main/java/org/apache/felix/framework/ExtensionManager.java test/java/org/apache/felix/framework/ExtensionManagerTest.java

Author: bob
Date: Tue Oct 28 02:43:06 2014
New Revision: 1634763

URL: http://svn.apache.org/r1634763
Log:
FELIX-4503 - Append osgi.native namespace and capabilities to the bundle capabilities.  And test.

Added:
    felix/trunk/framework/src/test/java/org/apache/felix/framework/ExtensionManagerTest.java
Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java?rev=1634763&r1=1634762&r2=1634763&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java Tue Oct 28 02:43:06 2014
@@ -52,6 +52,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
+import org.osgi.framework.namespace.NativeNamespace;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRequirement;
 import org.osgi.framework.wiring.BundleRevision;
@@ -229,6 +230,7 @@ class ExtensionManager extends URLStream
             ManifestParser mp = new ManifestParser(
                 m_logger, m_configMap, m_systemBundleRevision, m_headerMap);
             List<BundleCapability> caps = aliasSymbolicName(mp.getCapabilities());
+            caps.add(buildNativeCapabilites());
             appendCapabilities(caps);
         }
         catch (Exception ex)
@@ -241,6 +243,36 @@ class ExtensionManager extends URLStream
         }
     }
 
+	protected BundleCapability buildNativeCapabilites() {
+		String osArchitecture = (String)m_configMap.get(FelixConstants.FRAMEWORK_PROCESSOR);
+		String osName = (String)m_configMap.get(FelixConstants.FRAMEWORK_OS_NAME);
+		String osVersion = (String)m_configMap.get(FelixConstants.FRAMEWORK_OS_VERSION);
+		String userLang = (String)m_configMap.get(FelixConstants.FRAMEWORK_LANGUAGE);
+		Map<String, Object> attributes = new HashMap<String, Object>();
+		
+		if( osArchitecture != null ) 
+		{
+			attributes.put(NativeNamespace.CAPABILITY_PROCESSOR_ATTRIBUTE, osArchitecture);
+		}
+		
+		if( osName != null)
+		{
+			attributes.put(NativeNamespace.CAPABILITY_OSNAME_ATTRIBUTE, osName);
+		}
+		
+		if( osVersion != null)
+		{
+			attributes.put(NativeNamespace.CAPABILITY_OSVERSION_ATTRIBUTE, new Version(osVersion));
+		}
+		
+		if( userLang != null) 
+		{
+			attributes.put(NativeNamespace.CAPABILITY_LANGUAGE_ATTRIBUTE, userLang);
+		}
+		
+		return new BundleCapabilityImpl(getRevision(), NativeNamespace.NATIVE_NAMESPACE, Collections.<String, String> emptyMap(), attributes);
+	}
+	
     private static List<BundleCapability> aliasSymbolicName(List<BundleCapability> caps)
     {
         if (caps == null)

Added: felix/trunk/framework/src/test/java/org/apache/felix/framework/ExtensionManagerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/test/java/org/apache/felix/framework/ExtensionManagerTest.java?rev=1634763&view=auto
==============================================================================
--- felix/trunk/framework/src/test/java/org/apache/felix/framework/ExtensionManagerTest.java (added)
+++ felix/trunk/framework/src/test/java/org/apache/felix/framework/ExtensionManagerTest.java Tue Oct 28 02:43:06 2014
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.framework.util.FelixConstants;
+import org.junit.Test;
+import org.osgi.framework.Version;
+import org.osgi.framework.namespace.NativeNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+
+/**
+ * 
+ * Test Classes for the ExtentionManager
+ *
+ */
+public class ExtensionManagerTest {
+
+	/**
+	 * 
+	 * 
+	 * Ensure Native Bundle Capabilities are properly formed based on
+	 * Framework properties.
+	 * 
+	 */
+	@Test
+	public void testBuildNativeCapabilities() {
+		Logger logger = new Logger();
+		Map<String, String> configMap = new HashMap<String, String>();
+		configMap.put(FelixConstants.FELIX_VERSION_PROPERTY, "1.0");
+		configMap.put(FelixConstants.FRAMEWORK_LANGUAGE, "en");
+		configMap.put(FelixConstants.FRAMEWORK_PROCESSOR, "x86_64");
+		configMap.put(FelixConstants.FRAMEWORK_OS_NAME, "windows8");
+		configMap.put(FelixConstants.FRAMEWORK_OS_VERSION, "6.3");
+		ExtensionManager extensionManager = new ExtensionManager(logger,
+				configMap, null);
+		BundleCapability nativeBundleCapability = extensionManager
+				.buildNativeCapabilites();
+		assertEquals(
+				"Native Language should be same as framework Language",
+				"en",
+				nativeBundleCapability.getAttributes().get(
+						NativeNamespace.CAPABILITY_LANGUAGE_ATTRIBUTE));
+		assertEquals(
+				"Native Processor should be same as framework Processor",
+				"x86_64",
+				nativeBundleCapability.getAttributes().get(
+						NativeNamespace.CAPABILITY_PROCESSOR_ATTRIBUTE));
+		assertEquals(
+				"Native OS Name should be the same as the framework os name",
+				"windows8",
+				nativeBundleCapability.getAttributes().get(
+						NativeNamespace.CAPABILITY_OSNAME_ATTRIBUTE));
+		assertEquals(
+				"Native OS Version should be the same as the framework OS Version",
+				new Version("6.3"),
+				nativeBundleCapability.getAttributes().get(
+						NativeNamespace.CAPABILITY_OSVERSION_ATTRIBUTE));
+	}
+
+}