svn commit: r1811838 - in /tomcat/trunk/java/org/apache/tomcat/util: compat/Jre9Compat.java compat/JreCompat.java compat/LocalStrings.properties scan/StandardJarScanner.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1811838 - in /tomcat/trunk/java/org/apache/tomcat/util: compat/Jre9Compat.java compat/JreCompat.java compat/LocalStrings.properties scan/StandardJarScanner.java

markt
Author: markt
Date: Wed Oct 11 15:33:21 2017
New Revision: 1811838

URL: http://svn.apache.org/viewvc?rev=1811838&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=61597

Scan the module path as part of the standard Jar scanning when running
on Java 9.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java
    tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java
    tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties
    tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java?rev=1811838&r1=1811837&r2=1811838&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java Wed Oct 11 15:33:21 2017
@@ -19,29 +19,74 @@ package org.apache.tomcat.util.compat;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
 import java.net.URLConnection;
+import java.util.Deque;
+import java.util.Set;
 
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLParameters;
 
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
+
 class Jre9Compat extends JreCompat {
 
+    private static final Log log = LogFactory.getLog(Jre9Compat.class);
+    private static final StringManager sm = StringManager.getManager(Jre9Compat.class);
+
     private static final Class<?> inaccessibleObjectExceptionClazz;
     private static final Method setApplicationProtocolsMethod;
     private static final Method getApplicationProtocolMethod;
     private static final Method setDefaultUseCachesMethod;
+    private static final Method bootMethod;
+    private static final Method configurationMethod;
+    private static final Method modulesMethod;
+    private static final Method referenceMethod;
+    private static final Method locationMethod;
+    private static final Method isPresentMethod;
+    private static final Method getMethod;
 
     static {
+        Class<?> moduleLayerClazz = null;
+        Class<?> configurationClazz = null;
+        Class<?> resolvedModuleClazz = null;
+        Class<?> moduleReferenceClazz = null;
+        Class<?> optionalClazz = null;
+
         Class<?> c1 = null;
         Method m2 = null;
         Method m3 = null;
         Method m4 = null;
+        Method m5 = null;
+        Method m6 = null;
+        Method m7 = null;
+        Method m8 = null;
+        Method m9 = null;
+        Method m10 = null;
+        Method m11 = null;
 
         try {
+            moduleLayerClazz = Class.forName("java.lang.ModuleLayer");
+            configurationClazz = Class.forName("java.lang.module.Configuration");
+            resolvedModuleClazz = Class.forName("java.lang.module.ResolvedModule");
+            moduleReferenceClazz = Class.forName("java.lang.module.ModuleReference");
+            optionalClazz = Class.forName("java.util.Optional");
+
             c1 = Class.forName("java.lang.reflect.InaccessibleObjectException");
             m2 = SSLParameters.class.getMethod("setApplicationProtocols", String[].class);
             m3 = SSLEngine.class.getMethod("getApplicationProtocol");
             m4 = URLConnection.class.getMethod("setDefaultUseCaches", String.class, boolean.class);
+            m5 = moduleLayerClazz.getMethod("boot");
+            m6 = moduleLayerClazz.getMethod("configuration");
+            m7 = configurationClazz.getMethod("modules");
+            m8 = resolvedModuleClazz.getMethod("reference");
+            m9 = moduleReferenceClazz.getMethod("location");
+            m10 = optionalClazz.getMethod("isPresent");
+            m11 = optionalClazz.getMethod("get");
         } catch (SecurityException | NoSuchMethodException e) {
             // Should never happen
         } catch (ClassNotFoundException e) {
@@ -51,6 +96,13 @@ class Jre9Compat extends JreCompat {
         setApplicationProtocolsMethod = m2;
         getApplicationProtocolMethod = m3;
         setDefaultUseCachesMethod = m4;
+        bootMethod = m5;
+        configurationMethod = m6;
+        modulesMethod = m7;
+        referenceMethod = m8;
+        locationMethod = m9;
+        isPresentMethod = m10;
+        getMethod = m11;
     }
 
 
@@ -97,4 +149,30 @@ class Jre9Compat extends JreCompat {
             throw new UnsupportedOperationException(e);
         }
     }
+
+
+    @Override
+    public void addBootModulePath(Deque<URL> classPathUrlsToProcess) {
+        try {
+            Object bootLayer = bootMethod.invoke(null);
+            Object bootConfiguration = configurationMethod.invoke(bootLayer);
+            Set<?> resolvedModules = (Set<?>) modulesMethod.invoke(bootConfiguration);
+            for (Object resolvedModule : resolvedModules) {
+                Object moduleReference = referenceMethod.invoke(resolvedModule);
+                Object optionalURI = locationMethod.invoke(moduleReference);
+                Boolean isPresent = (Boolean) isPresentMethod.invoke(optionalURI);
+                if (isPresent.booleanValue()) {
+                    URI uri = (URI) getMethod.invoke(optionalURI);
+                    try {
+                        URL url = uri.toURL();
+                        classPathUrlsToProcess.add(url);
+                    } catch (MalformedURLException e) {
+                        log.warn(sm.getString("jre9Compat.invalidModuleUri", uri), e);
+                    }
+                }
+            }
+        } catch (ReflectiveOperationException e) {
+            throw new UnsupportedOperationException(e);
+        }
+    }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java?rev=1811838&r1=1811837&r2=1811838&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/compat/JreCompat.java Wed Oct 11 15:33:21 2017
@@ -19,6 +19,7 @@ package org.apache.tomcat.util.compat;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.Deque;
 
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLParameters;
@@ -115,4 +116,17 @@ public class JreCompat {
         URLConnection uConn = url.openConnection();
         uConn.setDefaultUseCaches(false);
     }
+
+
+    /**
+     * Obtains the URls for all the JARs on the module path when the JVM starts
+     * and adds them to the provided Deque.
+     *
+     * @param classPathUrlsToProcess    The Deque to which the modules should be
+     *                                  added
+     */
+    public void addBootModulePath(Deque<URL> classPathUrlsToProcess) {
+        // NO-OP for Java 8. There is no module path.
+    }
+
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties?rev=1811838&r1=1811837&r2=1811838&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties Wed Oct 11 15:33:21 2017
@@ -14,4 +14,6 @@
 # limitations under the License.
 
 jreCompat.noApplicationProtocols=Java Runtime does not support SSLParameters.setApplicationProtocols(). You must use Java 9 to use this feature.
-jreCompat.noApplicationProtocol=Java Runtime does not support SSLEngine.getApplicationProtocol(). You must use Java 9 to use this feature.
\ No newline at end of file
+jreCompat.noApplicationProtocol=Java Runtime does not support SSLEngine.getApplicationProtocol(). You must use Java 9 to use this feature.
+
+jre9Compat.invalidModuleUri=The module URI provided [{0}] could not be converted to a URL for the JarScanner to process

Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java?rev=1811838&r1=1811837&r2=1811838&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java Wed Oct 11 15:33:21 2017
@@ -273,9 +273,9 @@ public class StandardJarScanner implemen
             // instances of URLClassLoader. Use the class path in this
             // case.
             addClassPath(classPathUrlsToProcess);
+            // Also add any modules
+            JreCompat.getInstance().addBootModulePath(classPathUrlsToProcess);
             processURLs(scanType, callback, processedURLs, false, classPathUrlsToProcess);
-
-            // TODO Java 9 module path
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]