felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject svn commit: r1812580 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: Felix.java util/Util.java
Date Wed, 18 Oct 2017 20:50:22 GMT
Author: pauls
Date: Wed Oct 18 20:50:22 2017
New Revision: 1812580

URL: http://svn.apache.org/viewvc?rev=1812580&view=rev
Log:
FELIX-5718: Autodetect java9 modules available.

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.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=1812580&r1=1812579&r2=1812580&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 Oct 18 20:50:22
2017
@@ -27,6 +27,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLStreamHandler;
@@ -4642,6 +4643,8 @@ public class Felix extends BundleImpl im
         // if not explicitly configured.
         loadPrefixFromDefaultIfNotDefined(m_configMutableMap, defaultProperties, FelixConstants.NATIVE_OS_NAME_ALIAS_PREFIX);
         loadPrefixFromDefaultIfNotDefined(m_configMutableMap, defaultProperties, FelixConstants.NATIVE_PROC_NAME_ALIAS_PREFIX);
+        loadPrefixFromDefaultIfNotDefined(m_configMutableMap, defaultProperties, "felix.detect.jpms.");
+        loadPrefixFromDefaultIfNotDefined(m_configMutableMap, defaultProperties, "felix.jpms.");
     }
 
     private void loadFromDefaultIfNotDefined(Properties defaultProperties, String propertyName)

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java?rev=1812580&r1=1812579&r2=1812580&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java Wed Oct
18 20:50:22 2017
@@ -86,7 +86,42 @@ public class Util
                     Logger.LOG_ERROR, "Unable to load any configuration properties.", ex);
             }
         }
-        return defaultProperties;
+        return initializeJPMS(defaultProperties);
+    }
+
+    private static Properties initializeJPMS(Properties properties)
+    {
+        try
+        {
+            Class<?> c_ModuleLayer = Felix.class.getClassLoader().loadClass("java.lang.ModuleLayer");
+            Class<?> c_Module = Felix.class.getClassLoader().loadClass("java.lang.Module");
+            Method m_getLayer = c_Module.getMethod("getLayer");
+            Method m_getModule = Class.class.getMethod("getModule");
+            Method m_canRead = c_Module.getMethod("canRead", c_Module);
+            Method m_getName = c_Module.getMethod("getName");
+
+            Object self = m_getModule.invoke(Felix.class);
+            Object moduleLayer = m_getLayer.invoke(self);
+
+            if (moduleLayer == null)
+            {
+                moduleLayer = c_ModuleLayer.getMethod("boot").invoke(null);
+            }
+
+            for (Object module : ((Iterable) c_ModuleLayer.getMethod("modules").invoke(moduleLayer)))
+            {
+                if ((Boolean) m_canRead.invoke(self, module))
+                {
+                    Object name = m_getName.invoke(module);
+                    properties.put("felix.detect.jpms." + name, name);
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            // Not much we can do - probably not on java9
+        }
+        return properties;
     }
 
     public static String getDefaultProperty(Logger logger, String name)



Mime
View raw message