Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java?rev=1811846&r1=1811845&r2=1811846&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre9Compat.java Wed 
Oct 11 16:07:32 2017
@@ -19,29 +19,81 @@ 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 org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
 
 class Jre9Compat extends Jre8Compat {
 
+    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 setDefaultUseCaches;
+    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 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");
             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 e) {
             // Should never happen
-        } catch (ClassNotFoundException e) {
-            // Must be Java 8
         } catch (NoSuchMethodException e) {
             // Should never happen
+        } catch (ClassNotFoundException e) {
+            // Must be Java 8
         }
         inaccessibleObjectExceptionClazz = c1;
-        setDefaultUseCaches = m4;
+        setDefaultUseCachesMethod = m4;
+        bootMethod = m5;
+        configurationMethod = m6;
+        modulesMethod = m7;
+        referenceMethod = m8;
+        locationMethod = m9;
+        isPresentMethod = m10;
+        getMethod = m11;
     }
 
 
@@ -63,13 +115,43 @@ class Jre9Compat extends Jre8Compat {
     @Override
     public void disableCachingForJarUrlConnections() throws IOException {
         try {
-            setDefaultUseCaches.invoke(null, "JAR", Boolean.FALSE);
+            setDefaultUseCachesMethod.invoke(null, "JAR", Boolean.FALSE);
         } catch (IllegalAccessException e) {
             throw new UnsupportedOperationException(e);
         } catch (IllegalArgumentException e) {
             throw new UnsupportedOperationException(e);
         } catch (InvocationTargetException e) {
             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 (IllegalArgumentException e) {
+            throw new UnsupportedOperationException(e);
+        } catch (IllegalAccessException e) {
+            throw new UnsupportedOperationException(e);
+        } catch (InvocationTargetException e) {
+            throw new UnsupportedOperationException(e);
         }
     }
 }

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java?rev=1811846&r1=1811845&r2=1811846&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java Wed 
Oct 11 16:07:32 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 java.util.Locale;
 
 import javax.net.ssl.SSLEngine;
@@ -179,4 +180,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/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties?rev=1811846&r1=1811845&r2=1811846&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties 
Wed Oct 11 16:07:32 2017
@@ -13,4 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-jreCompat.noServerCipherSuiteOrder=Java Runtime does not support 
"useServerCipherSuitesOrder". You must use Java 8 or later to use this feature.
\ No newline at end of file
+jreCompat.noServerCipherSuiteOrder=Java Runtime does not support 
"useServerCipherSuitesOrder". You must use Java 8 or later 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/tc7.0.x/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java?rev=1811846&r1=1811845&r2=1811846&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java 
Wed Oct 11 16:07:32 2017
@@ -26,7 +26,9 @@ import java.net.URLClassLoader;
 import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Deque;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
 import java.util.StringTokenizer;
@@ -250,6 +252,11 @@ public class StandardJarScanner implemen
             // instances of URLClassLoader. Use the class path in this
             // case.
             List<URL> urls = getClassPath();
+            // Also add any modules
+            Deque<URL> modulePathUrls = new LinkedList<URL>();
+            JreCompat.getInstance().addBootModulePath(modulePathUrls);
+            urls.addAll(modulePathUrls);
+            // Process URLs
             for (URL url : urls) {
                 if (!processedURLs.contains(url)) {
                     try {
@@ -260,8 +267,6 @@ public class StandardJarScanner implemen
                     }
                 }
             }
-
-            // TODO Java 9 module path
         }
 
     }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1811846&r1=1811845&r2=1811846&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Oct 11 16:07:32 2017
@@ -71,6 +71,11 @@
         <bug>61581</bug>: Fix possible <code>SecurityException</code> when 
using
         the APR/native connector with a <code>SecurityManager</code>. (markt)
       </fix>
+      <fix>
+        <bug>61597</bug>: Extend the <code>StandardJarScanner</code> to scan
+        JARs on the module path when running on Java 9 and class path scanning
+        is enabled. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Web applications">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to