tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader WebappClassLoader.java
Date Wed, 06 Aug 2003 08:58:19 GMT
remm        2003/08/06 01:58:19

  Modified:    catalina/src/share/org/apache/catalina/loader
                        WebappClassLoader.java
  Log:
  - Fix problems with the Eclipse test case by extracting all non class resources
    from a JAR on access.
  - This of course has a performance penalty, but is the only way to have
    this use case work. It is not very valid, but I gave up trying to get people to
    change their code.
  - This is needed, because it is the only way to save valuable server resources
    (file descriptors and memory on Unix, plus JAR locking on Windows preventing
    webapp management without a Tomcat restart).
  
  Revision  Changes    Path
  1.18      +82 -15    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java
  
  Index: WebappClassLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- WebappClassLoader.java	15 Jun 2003 07:22:16 -0000	1.17
  +++ WebappClassLoader.java	6 Aug 2003 08:58:19 -0000	1.18
  @@ -1079,29 +1079,15 @@
               // Locating the repository for special handling in the case 
               // of a JAR
               ResourceEntry entry = (ResourceEntry) resourceEntries.get(name);
  -            FileOutputStream os = null;
               try {
                   String repository = entry.codeBase.toString();
                   if (repository.endsWith(".jar")) {
                       // Copy binary content to the work directory if not present
                       File resourceFile = new File(loaderDir, name);
  -                    if (entry.lastModified > resourceFile.lastModified()) {
  -                        resourceFile.getParentFile().mkdirs();
  -                        os = new FileOutputStream(resourceFile);
  -                        os.write(entry.binaryContent);
  -                    }
                       url = resourceFile.toURL();
                   }
               } catch (Exception e) {
                   // Ignore
  -                e.printStackTrace();
  -            } finally {
  -                if (os != null) {
  -                    try {
  -                        os.close();
  -                    } catch (IOException ex) {
  -                    }
  -                }
               }
               if (log.isDebugEnabled())
                   log.debug("  --> Returning '" + url.toString() + "'");
  @@ -1529,6 +1515,10 @@
           permissionList.clear();
           loaderPC.clear();
   
  +        if (loaderDir != null) {
  +            deleteDir(loaderDir);
  +        }
  +
       }
   
   
  @@ -1815,6 +1805,58 @@
                       } catch (IOException e) {
                           return null;
                       }
  +
  +                    // Extract resources contained in JAR to the workdir
  +                    if (!(path.endsWith(".class"))) {
  +                        byte[] buf = new byte[1024];
  +                        File resourceFile = new File
  +                            (loaderDir, jarEntry.getName());
  +                        if (!resourceFile.exists()) {
  +                            Enumeration entries = jarFiles[i].entries();
  +                            while (entries.hasMoreElements()) {
  +                                JarEntry jarEntry2 = 
  +                                    (JarEntry) entries.nextElement();
  +                                if (!(jarEntry2.isDirectory()) 
  +                                    && (!jarEntry2.getName().endsWith
  +                                        (".class"))) {
  +                                    resourceFile = new File
  +                                        (loaderDir, jarEntry2.getName());
  +                                    resourceFile.getParentFile().mkdirs();
  +                                    FileOutputStream os = null;
  +                                    InputStream is = null;
  +                                    try {
  +                                        is = jarFiles[i].getInputStream
  +                                            (jarEntry2);
  +                                        os = new FileOutputStream
  +                                            (resourceFile);
  +                                        while (true) {
  +                                            int n = is.read(buf);
  +                                            if (n <= 0) {
  +                                                break;
  +                                            }
  +                                            os.write(buf, 0, n);
  +                                        }
  +                                    } catch (IOException e) {
  +                                        // Ignore
  +                                    } finally {
  +                                        try {
  +                                            if (is != null) {
  +                                                is.close();
  +                                            }
  +                                        } catch (IOException e) {
  +                                        }
  +                                        try {
  +                                            if (os != null) {
  +                                                os.close();
  +                                            }
  +                                        } catch (IOException e) {
  +                                        }
  +                                    }
  +                                }
  +                            }
  +                        }
  +                    }
  +
                   }
   
               }
  @@ -2078,6 +2120,31 @@
           throws MalformedURLException {
   
           return jdkCompat.getURI(file);
  +
  +    }
  +
  +
  +    /**
  +     * Delete the specified directory, including all of its contents and
  +     * subdirectories recursively.
  +     *
  +     * @param dir File object representing the directory to be deleted
  +     */
  +    protected static void deleteDir(File dir) {
  +
  +        String files[] = dir.list();
  +        if (files == null) {
  +            files = new String[0];
  +        }
  +        for (int i = 0; i < files.length; i++) {
  +            File file = new File(dir, files[i]);
  +            if (file.isDirectory()) {
  +                deleteDir(file);
  +            } else {
  +                file.delete();
  +            }
  +        }
  +        dir.delete();
   
       }
   
  
  
  

Mime
View raw message