Set default value for execution environment. (FELIX-2324)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@943640 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 6cf6cc9..b646b2d 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -34,7 +34,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
-import java.util.Properties;
 import java.util.Set;
 
 import org.apache.felix.framework.Felix.FelixResolver;
@@ -180,7 +179,10 @@
         // packages should be exported by the system bundle.
         String syspkgs = (String) felix.getConfig().get(FelixConstants.FRAMEWORK_SYSTEMPACKAGES);
         // If no system packages were specified, load our default value.
-        syspkgs = (syspkgs == null) ? loadDefaultSystemPackages(m_logger) : syspkgs;
+        syspkgs = (syspkgs == null)
+            ? Util.getDefaultProperty(logger, Constants.FRAMEWORK_SYSTEMPACKAGES)
+            : syspkgs;
+        syspkgs = (syspkgs == null) ? "" : syspkgs;
         // If any extra packages are specified, then append them.
         String extra = (String) felix.getConfig().get(FelixConstants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
         syspkgs = (extra == null) ? syspkgs : syspkgs + "," + extra;
@@ -597,56 +599,6 @@
     // Utility methods.
     //
 
-    /**
-     * The default name used for the default configuration properties file.
-    **/
-    public static final String DEFAULT_PROPERTIES_FILE_VALUE = "default.properties";
-
-    static String loadDefaultSystemPackages(Logger logger)
-    {
-        // If we cannot get configuration properties for any reason, then just
-        // attempt to load resource default.properties instead.
-        URL propURL = ExtensionManager.class.getClassLoader()
-            .getResource(DEFAULT_PROPERTIES_FILE_VALUE);
-        if (propURL != null)
-        {
-            InputStream is = null;
-            try
-            {
-                // Load properties from URL.
-                is = propURL.openConnection().getInputStream();
-                Properties props = new Properties();
-                props.load(is);
-                is.close();
-                // Perform variable substitution for system properties.
-                for (Enumeration e = props.propertyNames(); e.hasMoreElements(); )
-                {
-                    String name = (String) e.nextElement();
-                    props.setProperty(name,
-                        Util.substVars(props.getProperty(name), name, null, props));
-                }
-                // Return system packages property.
-                return props.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
-            }
-            catch (Exception ex)
-            {
-                // Try to close input stream if we have one.
-                try
-                {
-                    if (is != null) is.close();
-                }
-                catch (IOException ex2)
-                {
-                    // Nothing we can do.
-                }
-
-                logger.log(
-                    Logger.LOG_ERROR, "Unable to load any configuration properties.", ex);
-            }
-        }
-        return "";
-    }
-
     class ExtensionManagerModule extends ModuleImpl
     {
         private final Version m_version;
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 52c7085..6b123aa 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -3752,6 +3752,19 @@
         m_configMutableMap.put(FelixConstants.FRAMEWORK_PROCESSOR, s);
         m_configMutableMap.put(
             FelixConstants.FELIX_VERSION_PROPERTY, getFrameworkVersion());
+
+        // Set supported execution environments to default value,
+        // if not explicitly configured.
+        if (!getConfig().containsKey(Constants.FRAMEWORK_EXECUTIONENVIRONMENT))
+        {
+            s = Util.getDefaultProperty(
+                m_logger, Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
+            if (s != null)
+            {
+                m_configMutableMap.put(
+                    Constants.FRAMEWORK_EXECUTIONENVIRONMENT, s);
+            }
+        }
     }
 
     /**
diff --git a/framework/src/main/java/org/apache/felix/framework/util/Util.java b/framework/src/main/java/org/apache/felix/framework/util/Util.java
index 5c625dd..526e20c 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/Util.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/Util.java
@@ -19,13 +19,16 @@
 package org.apache.felix.framework.util;
 
 import java.io.*;
+import java.net.URL;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.capabilityset.Capability;
 import org.apache.felix.framework.capabilityset.CapabilitySet;
 import org.apache.felix.framework.resolver.Module;
@@ -41,6 +44,53 @@
     public static final List m_emptyList = Collections.unmodifiableList(new ArrayList());
 
     /**
+     * The default name used for the default configuration properties file.
+    **/
+    private static final String DEFAULT_PROPERTIES_FILE = "default.properties";
+
+    public static String getDefaultProperty(Logger logger, String prop)
+    {
+        URL propURL = Util.class.getClassLoader().getResource(DEFAULT_PROPERTIES_FILE);
+        if (propURL != null)
+        {
+            InputStream is = null;
+            try
+            {
+                // Load properties from URL.
+                is = propURL.openConnection().getInputStream();
+                Properties props = new Properties();
+                props.load(is);
+                is.close();
+                // Perform variable substitution for system properties.
+                for (Enumeration e = props.propertyNames(); e.hasMoreElements(); )
+                {
+                    String name = (String) e.nextElement();
+                    props.setProperty(name,
+                        Util.substVars(props.getProperty(name), name, null, props));
+                }
+                // Return system packages property.
+                return props.getProperty(prop);
+            }
+            catch (Exception ex)
+            {
+                // Try to close input stream if we have one.
+                try
+                {
+                    if (is != null) is.close();
+                }
+                catch (IOException ex2)
+                {
+                    // Nothing we can do.
+                }
+
+                logger.log(
+                    Logger.LOG_ERROR, "Unable to load any configuration properties.", ex);
+            }
+        }
+        return "";
+    }
+
+    /**
      * Converts a module identifier to a bundle identifier. Module IDs
      * are typically <tt>&lt;bundle-id&gt;.&lt;revision&gt;</tt>; this
      * method returns only the portion corresponding to the bundle ID.
diff --git a/framework/src/main/resources/default.properties b/framework/src/main/resources/default.properties
index 2663d7e..c19bd3c 100644
--- a/framework/src/main/resources/default.properties
+++ b/framework/src/main/resources/default.properties
@@ -18,6 +18,14 @@
 #
 # Framework config properties.
 #
+org.osgi.framework.executionenvironment= \
+ ${dollar}{ee-${dollar}{java.specification.version}}
+
+ee-1.6=JavaSE-1.6,J2SE-1.5,J2SE-1.4,J2SE-1.3
+ee-1.5=J2SE-1.5,J2SE-1.4,J2SE-1.3
+ee-1.4=J2SE-1.4,J2SE-1.3
+ee-1.3=J2SE-1.3
+
 org.osgi.framework.system.packages=org.osgi.framework; version=1.5.0, \
  org.osgi.framework.launch; version=1.0.0, \
  org.osgi.framework.hooks.service; version=1.0.0, \