You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2017/10/05 18:50:27 UTC

svn commit: r1811226 - in /tomcat/trunk/java/org/apache/tomcat/util/scan: LocalStrings.properties StandardJarScanner.java

Author: markt
Date: Thu Oct  5 18:50:26 2017
New Revision: 1811226

URL: http://svn.apache.org/viewvc?rev=1811226&view=rev
Log:
Start to improved Java 9 JAR scanning
Make StandardJarScanner easier to extend

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

Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/LocalStrings.properties?rev=1811226&r1=1811225&r2=1811226&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/LocalStrings.properties Thu Oct  5 18:50:26 2017
@@ -17,6 +17,7 @@ jarScan.classloaderFail=Failed to scan [
 jarScan.classloaderStart=Scanning for JARs in classloader hierarchy
 jarScan.classloaderJarScan=Scanning JAR [{0}] from classpath
 jarScan.classloaderJarNoScan=Not scanning JAR [{0}] from classpath
+jarScan.classPath.badEntry=The class path entry [{0}] could not be converted to a URL
 jarScan.jarUrlStart=Scanning JAR at URL [{0}]
 jarScan.webinfclassesFail=Failed to scan /WEB-INF/classes
 jarScan.webinflibFail=Failed to scan JAR [{0}] from /WEB-INF/lib

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=1811226&r1=1811225&r2=1811226&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java Thu Oct  5 18:50:26 2017
@@ -262,6 +262,15 @@ public class StandardJarScanner implemen
                 classPathUrlsToProcess.addAll(
                         Arrays.asList(((URLClassLoader) classLoader).getURLs()));
 
+                if (JreCompat.isJre9Available()) {
+                    // The application and platform class loaders are not
+                    // instances of URLClassLoader. Use the class path in this
+                    // case.
+                    addClassPath(classPathUrlsToProcess);
+
+                    // TODO Java 9 module path
+                }
+
                 while (!classPathUrlsToProcess.isEmpty()) {
                     URL url = classPathUrlsToProcess.pop();
 
@@ -270,10 +279,6 @@ public class StandardJarScanner implemen
                         continue;
                     }
 
-                    // TODO: Java 9 support. Details are TBD. It will depend
-                    //       on the extent to which Java 8 supports the
-                    //       Java 9 file formats since this code MUST run on
-                    //       Java 8.
                     ClassPathEntry cpe = new ClassPathEntry(url);
 
                     // JARs are scanned unless the filter says not to.
@@ -304,13 +309,25 @@ public class StandardJarScanner implemen
             }
             classLoader = classLoader.getParent();
         }
+    }
 
-        if (JreCompat.isJre9Available()) {
-            // The application and platform class loaders are not instances of
-            // URLClassLoader
 
+    protected void addClassPath(Deque<URL> classPathUrlsToProcess) {
+        String classPath = System.getProperty("java.class.path");
+
+        if (classPath == null || classPath.length() == 0) {
+            return;
         }
 
+        String[] classPathEntries = classPath.split(File.pathSeparator);
+        for (String classPathEntry : classPathEntries) {
+            File f = new File(classPath);
+            try {
+                classPathUrlsToProcess.add(f.toURI().toURL());
+            } catch (MalformedURLException e) {
+                log.warn(sm.getString("jarScan.classPath.badEntry", classPathEntry), e);
+            }
+        }
     }
 
 
@@ -337,7 +354,7 @@ public class StandardJarScanner implemen
      * Scan a URL for JARs with the optional extensions to look at all files
      * and all directories.
      */
-    private void process(JarScanType scanType, JarScannerCallback callback,
+    protected void process(JarScanType scanType, JarScannerCallback callback,
             URL url, String webappPath, boolean isWebapp, Deque<URL> classPathUrlsToProcess)
             throws IOException {
 



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