geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r890225 - in /geronimo/external/trunk/tomcat-parent-7.0.0: catalina/src/main/java/org/apache/catalina/startup/DefaultJarScanner.java jasper/src/main/java/org/apache/jasper/JspC.java
Date Mon, 14 Dec 2009 08:42:41 GMT
Author: djencks
Date: Mon Dec 14 08:42:40 2009
New Revision: 890225

URL: http://svn.apache.org/viewvc?rev=890225&view=rev
Log:
fix the problem with maven jspc plugin, very badly

Modified:
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/DefaultJarScanner.java
    geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/JspC.java

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/DefaultJarScanner.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/DefaultJarScanner.java?rev=890225&r1=890224&r2=890225&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/DefaultJarScanner.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/DefaultJarScanner.java
Mon Dec 14 08:42:40 2009
@@ -53,7 +53,7 @@
     private static final String WEB_INF_LIB = "/WEB-INF/lib/";
 
     private static final org.apache.juli.logging.Log log=
-        org.apache.juli.logging.LogFactory.getLog( TldConfig.class );
+        org.apache.juli.logging.LogFactory.getLog( DefaultJarScanner.class );
 
     /**
      * The string resources for this package.

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/JspC.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/JspC.java?rev=890225&r1=890224&r2=890225&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/JspC.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/JspC.java
Mon Dec 14 08:42:40 2009
@@ -28,19 +28,11 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.Writer;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Stack;
-import java.util.StringTokenizer;
-import java.util.Vector;
+import java.net.*;
+import java.util.*;
 
 import javax.servlet.jsp.tagext.TagLibraryInfo;
+import javax.servlet.ServletContext;
 
 import org.apache.jasper.compiler.Compiler;
 import org.apache.jasper.compiler.JspConfig;
@@ -55,6 +47,8 @@
 import org.apache.tools.ant.AntClassLoader;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.util.FileUtils;
+import org.apache.tomcat.JarScanner;
+import org.apache.tomcat.JarScannerCallback;
 
 /**
  * Shell for the jspc compiler.  Handles all options associated with the
@@ -1248,6 +1242,7 @@
             context =new JspCServletContext
                 (new PrintWriter(System.out),
                  new URL("file:" + uriRoot.replace('\\','/') + '/'));
+            context.setAttribute(JarScanner.class.getName(), new DefaultJarScanner());
             tldLocationsCache = new TldLocationsCache(context);
         } catch (MalformedURLException me) {
             System.out.println("**" + me);
@@ -1418,3 +1413,185 @@
          }
      }
 }
+class DefaultJarScanner implements JarScanner {
+
+    private static final String JAR_EXT = ".jar";
+    private static final String WEB_INF_LIB = "/WEB-INF/lib/";
+
+    private static final org.apache.juli.logging.Log log=
+        org.apache.juli.logging.LogFactory.getLog( DefaultJarScanner.class );
+
+    /**
+     * The string resources for this package.
+     */
+//    private static final StringManager sm =
+//        StringManager.getManager(Constants.Package);
+
+
+    /**
+     * Controls the classpath scanning extension.
+     */
+    private boolean scanClassPath = true;
+    public boolean isScanClassPath() {
+        return scanClassPath;
+    }
+    public void setScanClassPath(boolean scanClassPath) {
+        this.scanClassPath = scanClassPath;
+    }
+
+    /**
+     * Controls the testing all files to see of they are JAR files extension.
+     */
+    private boolean scanAllFiles = false;
+    public boolean isScanAllFiles() {
+        return scanAllFiles;
+    }
+    public void setScanAllFiles(boolean scanAllFiles) {
+        this.scanAllFiles = scanAllFiles;
+    }
+
+    /**
+     * Controls the testing all directories to see of they are exploded JAR
+     * files extension.
+     */
+    private boolean scanAllDirectories = false;
+    public boolean isScanAllDirectories() {
+        return scanAllDirectories;
+    }
+    public void setScanAllDirectories(boolean scanAllDirectories) {
+        this.scanAllDirectories = scanAllDirectories;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void scan(ServletContext context, ClassLoader classloader,
+            JarScannerCallback callback, Set<String> jarsToSkip) {
+
+//        if (log.isTraceEnabled()) {
+//            log.trace(sm.getString("jarScan.webinflibStart"));
+//        }
+
+        // Scan WEB-INF/lib
+        Set<String> dirList = context.getResourcePaths(WEB_INF_LIB);
+        if (dirList != null) {
+            Iterator<String> it = dirList.iterator();
+            while (it.hasNext()) {
+                String path = it.next();
+                if (path.endsWith(JAR_EXT) &&
+                        !jarsToSkip.contains(
+                                path.substring(path.lastIndexOf('/')))) {
+                    // Need to scan this JAR
+                    URL url = null;
+                    try {
+                        url = context.getResource(path);
+                        process(callback, url);
+                    } catch (IOException e) {
+//                        log.warn(sm.getString("jarScan.webinflibFail", url), e);
+                    }
+                }
+            }
+        }
+
+        // Scan the classpath
+        if (scanClassPath) {
+//            if (log.isTraceEnabled()) {
+//                log.trace(sm.getString("jarScan.classloaderStart"));
+//            }
+
+            ClassLoader loader =
+                Thread.currentThread().getContextClassLoader();
+
+            while (loader != null) {
+                if (loader instanceof URLClassLoader) {
+                    URL[] urls = ((URLClassLoader) loader).getURLs();
+                    for (int i=0; i<urls.length; i++) {
+                        // Extract the jarName if there is one to be found
+                        String jarName = getJarName(urls[i]);
+
+                        // Skip JARs with known not to be interesting and JARs
+                        // in WEB-INF/lib we have already scanned
+                        if (!(jarsToSkip.contains(jarName) ||
+                                urls[i].toString().contains(
+                                        WEB_INF_LIB + jarName))) {
+                            try {
+                                process(callback, urls[i]);
+                            } catch (IOException ioe) {
+//                                log.warn(sm.getString(
+//                                        "jarScan.classloaderFail",urls[i]), ioe);
+                            }
+                        }
+                    }
+                }
+                loader = loader.getParent();
+            }
+
+        }
+    }
+
+    /*
+     * Scan a URL for JARs with the optional extensions to look at all files
+     * and all directories.
+     */
+    private void process(JarScannerCallback callback, URL url)
+            throws IOException {
+
+//        if (log.isTraceEnabled()) {
+//            log.trace(sm.getString("jarScan.jarUrlStart", url));
+//        }
+
+        URLConnection conn = url.openConnection();
+        if (conn instanceof JarURLConnection) {
+            callback.scan((JarURLConnection) conn);
+        } else {
+            String urlStr = url.toString();
+            if (urlStr.startsWith("file:") || urlStr.startsWith("jndi:")) {
+                if (urlStr.endsWith(JAR_EXT)) {
+                    URL jarURL = new URL("jar:" + urlStr + "!/");
+                    callback.scan((JarURLConnection) jarURL.openConnection());
+                } else {
+                    File f;
+                    try {
+                        f = new File(url.toURI());
+                        if (f.isFile() && scanAllFiles) {
+                            // Treat this file as a JAR
+                            URL jarURL = new URL("jar:" + urlStr + "!/");
+                            callback.scan((JarURLConnection) jarURL.openConnection());
+                        } else if (f.isDirectory() && scanAllDirectories) {
+                            File metainf = new File(f.getAbsoluteFile() +
+                                    File.separator + "META-INF");
+                            if (metainf.isDirectory()) {
+                                callback.scan(f);
+                            }
+                        }
+                    } catch (URISyntaxException e) {
+                        // Wrap the exception and re-throw
+                        IOException ioe = new IOException();
+                        ioe.initCause(e);
+                        throw ioe;
+                    }
+                }
+            }
+        }
+
+    }
+
+    /*
+     * Extract the JAR name, if present, from a URL
+     */
+    private String getJarName(URL url) {
+
+        String name = null;
+
+        String path = url.getPath();
+        int end = path.indexOf(JAR_EXT);
+        if (end != -1) {
+            int start = path.lastIndexOf('/', end);
+            name = path.substring(start + 1, end + 4);
+        }
+
+        return name;
+    }
+
+}



Mime
View raw message