You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2020/01/28 21:59:25 UTC
svn commit: r1873273 - in
/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework:
ExtensionManager.java util/Util.java
Author: pauls
Date: Tue Jan 28 21:59:25 2020
New Revision: 1873273
URL: http://svn.apache.org/viewvc?rev=1873273&view=rev
Log:
Move module info calcuation to make it work better with native image
Modified:
felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/ExtensionManager.java
felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/util/Util.java
Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/ExtensionManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/ExtensionManager.java?rev=1873273&r1=1873272&r2=1873273&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/ExtensionManager.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/ExtensionManager.java Tue Jan 28 21:59:25 2020
@@ -260,7 +260,6 @@ class ExtensionManager implements Conten
if (exports != null && (sysprops == null || "true".equalsIgnoreCase(felix._getProperty(FelixConstants.USE_PROPERTY_SUBSTITUTION_IN_SYSTEMPACKAGES))))
{
- java.nio.file.FileSystem fs = java.nio.file.FileSystems.getFileSystem(URI.create("jrt:/"));
final ClassParser classParser = new ClassParser();
final Set<String> imports = new HashSet<String>();
for (Set<String> moduleImport : exports.values())
@@ -282,6 +281,7 @@ class ExtensionManager implements Conten
final SortedMap<String, SortedSet<String>> referred = new TreeMap<String, SortedSet<String>>();
if ("true".equalsIgnoreCase(felix._getProperty(FelixConstants.CALCULATE_SYSTEMPACKAGES_USES)))
{
+ java.nio.file.FileSystem fs = java.nio.file.FileSystems.getFileSystem(URI.create("jrt:/"));
try
{
Properties cachedProps = new Properties();
Modified: felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/util/Util.java?rev=1873273&r1=1873272&r2=1873273&view=diff
==============================================================================
--- felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ felix/sandbox/pauls/connect/src/main/java/org/apache/felix/framework/util/Util.java Tue Jan 28 21:59:25 2020
@@ -47,12 +47,15 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Random;
import java.util.Set;
+import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
@@ -67,6 +70,8 @@ public class Util
private static final IOException DEFAULT_EX;
+ private static final Map<String, Set<String>> MODULES_MAP;
+
static
{
Properties defaults = null;
@@ -79,6 +84,8 @@ public class Util
}
DEFAULTS = defaults;
DEFAULT_EX = defaultEX;
+
+ MODULES_MAP = calculateModulesMap();
}
public static Properties loadDefaultProperties(Logger logger) {
@@ -164,9 +171,9 @@ public class Util
}
}
- public static Map<String, Set<String>> initializeJPMS(Properties properties)
+ private static Map<String, Set<String>> calculateModulesMap()
{
- Map<String,Set<String>> exports = null;
+ Map<String, Set<String>> result = new LinkedHashMap<>();
try
{
Class<?> c_ModuleLayer = Felix.class.getClassLoader().loadClass("java.lang.ModuleLayer");
@@ -186,16 +193,13 @@ public class Util
moduleLayer = c_ModuleLayer.getMethod("boot").invoke(null);
}
- Set<String> modules = new TreeSet<String>();
- exports = new HashMap<String, Set<String>>();
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);
- modules.add("felix.jpms." + name);
- Set<String> pkgs = new HashSet<String>();
+ String name = (String) m_getName.invoke(module);
+
+ Set<String> pkgs = new LinkedHashSet<>();
Object descriptor = c_Module.getMethod("getDescriptor").invoke(module);
@@ -206,10 +210,35 @@ public class Util
pkgs.add((String) c_Exports.getMethod("source").invoke(export));
}
}
- if (!pkgs.isEmpty())
- {
- exports.put("felix.jpms." + c_Descriptor.getMethod("toNameAndVersion").invoke(descriptor), pkgs);
- }
+ result.put(name, pkgs);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ // Not much we can do - probably not on java9
+ }
+ return result;
+ }
+
+ public static Map<String, Set<String>> initializeJPMS(Properties properties)
+ {
+ Map<String,Set<String>> exports = null;
+ if (!MODULES_MAP.isEmpty())
+ {
+ Set<String> modules = new TreeSet<String>();
+ exports = new HashMap<String, Set<String>>();
+ for (Map.Entry<String, Set<String>> module : MODULES_MAP.entrySet())
+ {
+ Object name = module.getKey();
+ properties.put("felix.detect.jpms." + name, name);
+ modules.add("felix.jpms." + name);
+ Set<String> pkgs = module.getValue();
+
+ if (!pkgs.isEmpty())
+ {
+ exports.put("felix.jpms." + name, pkgs);
}
}
@@ -219,11 +248,6 @@ public class Util
}
properties.put("jre-jpms", modulesString);
}
- catch (Exception ex)
- {
- ex.printStackTrace();
- // Not much we can do - probably not on java9
- }
return exports;
}