FELIX-4503 - Append osgi.native namespace and capabilities to the bundle capabilities. And test.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1634763 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 7b197fe..2fab5fa 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -52,6 +52,7 @@
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 @@
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 @@
}
}
+ 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)
diff --git a/framework/src/test/java/org/apache/felix/framework/ExtensionManagerTest.java b/framework/src/test/java/org/apache/felix/framework/ExtensionManagerTest.java
new file mode 100644
index 0000000..3201625
--- /dev/null
+++ b/framework/src/test/java/org/apache/felix/framework/ExtensionManagerTest.java
@@ -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));
+ }
+
+}