Author: markt Date: Tue Nov 5 00:04:26 2013 New Revision: 1538831 URL: http://svn.apache.org/r1538831 Log: Remove unused fields and methods as a result of refactoring JAR handling in the web application class loader
Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderWeaving.java Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=1538831&r1=1538830&r2=1538831&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Tue Nov 5 00:04:26 2013 @@ -58,7 +58,6 @@ import java.util.concurrent.ThreadPoolEx import java.util.jar.Attributes; import java.util.jar.Attributes.Name; import java.util.jar.JarEntry; -import java.util.jar.JarFile; import java.util.jar.Manifest; import org.apache.catalina.Globals; @@ -292,26 +291,6 @@ public class WebappClassLoader extends U /** - * The list of JARs, in the order they should be searched - * for locally loaded classes or resources. - */ - protected File[] jarRealFiles = new File[0]; - - - /** - * The path which will be monitored for added Jar files. - */ - protected String jarPath = null; - - - /** - * The list of JARs, in the order they should be searched - * for locally loaded classes or resources. - */ - protected String[] jarNames = new String[0]; - - - /** * The list of JARs last modified dates, in the order they should be * searched for locally loaded classes or resources. */ @@ -541,22 +520,6 @@ public class WebappClassLoader extends U } - /** - * Return the JAR path. - */ - public String getJarPath() { - return this.jarPath; - } - - - /** - * Change the Jar path. - */ - public void setJarPath(String jarPath) { - this.jarPath = jarPath; - } - - /** * Utility method for use in subclasses. * Must be called before Lifecycle methods to have any effect. @@ -737,7 +700,6 @@ public class WebappClassLoader extends U loader.resources = this.resources; loader.delegate = this.delegate; - loader.jarPath = this.jarPath; loader.started = this.started; loader.needConvert = this.needConvert; loader.clearReferencesStatic = this.clearReferencesStatic; @@ -746,9 +708,6 @@ public class WebappClassLoader extends U loader.clearReferencesLogFactoryRelease = this.clearReferencesLogFactoryRelease; loader.clearReferencesHttpClientKeepAliveThread = this.clearReferencesHttpClientKeepAliveThread; - loader.jarRealFiles = this.jarRealFiles.clone(); - loader.jarNames = this.jarNames.clone(); - loader.lastModifiedDates = this.lastModifiedDates.clone(); loader.paths = this.paths.clone(); loader.permissionList.addAll(this.permissionList); @@ -758,64 +717,6 @@ public class WebappClassLoader extends U } - synchronized void addJar(String jar, JarFile jarFile, File file) - throws IOException { - - if (jar == null) - return; - if (jarFile == null) - return; - if (file == null) - return; - - if (log.isDebugEnabled()) - log.debug("addJar(" + jar + ")"); - - int i; - - if ((jarPath != null) && (jar.startsWith(jarPath))) { - - String jarName = jar.substring(jarPath.length()); - while (jarName.startsWith("/")) - jarName = jarName.substring(1); - - String[] result = new String[jarNames.length + 1]; - for (i = 0; i < jarNames.length; i++) { - result[i] = jarNames[i]; - } - result[jarNames.length] = jarName; - jarNames = result; - - } - - // Register the JAR for tracking - - long lastModified = resources.getResource(jar).getLastModified(); - - String[] result = new String[paths.length + 1]; - for (i = 0; i < paths.length; i++) { - result[i] = paths[i]; - } - result[paths.length] = jar; - paths = result; - - long[] result3 = new long[lastModifiedDates.length + 1]; - for (i = 0; i < lastModifiedDates.length; i++) { - result3[i] = lastModifiedDates[i]; - } - result3[lastModifiedDates.length] = lastModified; - lastModifiedDates = result3; - - // Add the file to the list - File[] result4 = new File[jarRealFiles.length + 1]; - for (i = 0; i < jarRealFiles.length; i++) { - result4[i] = jarRealFiles[i]; - } - result4[jarRealFiles.length] = file; - jarRealFiles = result4; - } - - /** * Have one or more classes or resources been modified so that a reload * is appropriate? @@ -1561,9 +1462,6 @@ public class WebappClassLoader extends U resourceEntries.clear(); jarModificationTimes.clear(); resources = null; - jarRealFiles = null; - jarPath = null; - jarNames = null; lastModifiedDates = null; paths = null; parent = null; Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java?rev=1538831&r1=1538830&r2=1538831&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Tue Nov 5 00:04:26 2013 @@ -20,10 +20,8 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; -import java.io.FileOutputStream; import java.io.FilePermission; import java.io.IOException; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -31,7 +29,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.net.URLDecoder; -import java.util.jar.JarFile; import javax.management.ObjectName; import javax.servlet.ServletContext; @@ -42,8 +39,6 @@ import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; import org.apache.catalina.Loader; -import org.apache.catalina.WebResource; -import org.apache.catalina.WebResourceRoot; import org.apache.catalina.util.LifecycleMBeanBase; import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.modeler.Registry; @@ -52,7 +47,8 @@ import org.apache.tomcat.util.res.String /** * Classloader implementation which is specialized for handling web * applications in the most efficient way, while being Catalina aware (all - * accesses to resources are made through {@link WebResourceRoot}). + * accesses to resources are made through + * {@link org.apache.catalina.WebResourceRoot}). * This class loader supports detection of modified * Java classes, which can be used to implement auto-reload support. * <p> @@ -399,7 +395,6 @@ public class WebappLoader extends Lifecy classLoader.setDelegate(this.delegate); // Configure our repositories - setRepositories(); setClassPath(); setPermissions(); @@ -611,105 +606,6 @@ public class WebappLoader extends Lifecy /** - * Configure the repositories for our class loader, based on the - * associated Context. - * @throws IOException - */ - private void setRepositories() throws IOException { - - if (context == null) - return; - ServletContext servletContext = context.getServletContext(); - if (servletContext == null) - return; - - // Loading the work directory - File workDir = - (File) servletContext.getAttribute(ServletContext.TEMPDIR); - if (workDir == null) { - log.info("No work dir for " + servletContext); - } - - if( log.isDebugEnabled() && workDir != null) - log.debug(sm.getString("webappLoader.deploy", workDir.getAbsolutePath())); - - WebResourceRoot resources = context.getResources(); - - // Setting up the JAR repository (/WEB-INF/lib), if it exists - // TODO Simplify this in a similar manner to WEB-INF/classes - - String libPath = "/WEB-INF/lib"; - - classLoader.setJarPath(libPath); - - WebResource libDir = resources.getResource(libPath); - - if (libDir.isDirectory()) { - - boolean copyJars = false; - String absoluteLibPath = libDir.getCanonicalPath(); - - File destDir = null; - - if (absoluteLibPath != null) { - destDir = new File(absoluteLibPath); - } else { - copyJars = true; - destDir = new File(workDir, libPath); - if (!destDir.mkdirs() && !destDir.isDirectory()) { - throw new IOException( - sm.getString("webappLoader.mkdirFailure")); - } - } - - WebResource[] jars = resources.listResources(libPath); - for (WebResource jar : jars) { - - String jarName = jar.getName(); - - if (!jarName.endsWith(".jar")) - continue; - - String filename = libPath + "/" + jarName; - - // Copy JAR in the work directory, always (the JAR file - // would get locked otherwise, which would make it - // impossible to update it or remove it at runtime) - File destFile = new File(destDir, jarName); - - if (log.isDebugEnabled()) { - log.debug(sm.getString("webappLoader.jarDeploy", filename, - destFile.getAbsolutePath())); - } - - // Bug 45403 - Check that the resource is readable - if (!jar.canRead()) { - IOException ioe = new IOException(sm.getString( - "webappLoader.readFailure", filename)); - throw ioe; - } - - if (copyJars) { - if (!copy(jar.getInputStream(),destFile)) { - throw new IOException( - sm.getString("webappLoader.copyFailure")); - } - } - - try { - JarFile jarFile = new JarFile(destFile); - classLoader.addJar(filename, jarFile, destFile); - } catch (Exception ex) { - // Catch the exception if there is an empty jar file - // Should ignore and continue loading other jar files - // in the dir - } - } - } - } - - - /** * Set the appropriate context attribute for our class path. This * is required only because Jasper depends on it. */ @@ -747,11 +643,10 @@ public class WebappLoader extends Lifecy } } - this.classpath=classpath.toString(); + this.classpath = classpath.toString(); // Store the assembled class path as a servlet context attribute - servletContext.setAttribute(Globals.CLASS_PATH_ATTR, - classpath.toString()); + servletContext.setAttribute(Globals.CLASS_PATH_ATTR, this.classpath); } @@ -824,34 +719,6 @@ public class WebappLoader extends Lifecy } - /** - * Copy a file to the specified temp directory. This is required only - * because Jasper depends on it. - */ - private boolean copy(InputStream is, File file) { - - try (FileOutputStream os = new FileOutputStream(file)){ - byte[] buf = new byte[4096]; - while (true) { - int len = is.read(buf); - if (len < 0) - break; - os.write(buf, 0, len); - } - } catch (IOException e) { - return false; - } finally { - try { - is.close(); - } catch (IOException e) { - // Ignore - } - } - - return true; - } - - private static final org.apache.juli.logging.Log log= org.apache.juli.logging.LogFactory.getLog( WebappLoader.class ); Modified: tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderWeaving.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderWeaving.java?rev=1538831&r1=1538830&r2=1538831&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderWeaving.java (original) +++ tomcat/trunk/test/org/apache/catalina/loader/TestWebappClassLoaderWeaving.java Tue Nov 5 00:04:26 2013 @@ -278,8 +278,6 @@ public class TestWebappClassLoaderWeavin assertEquals("getDelegate did not match.", Boolean.valueOf(this.loader.getDelegate()), Boolean.valueOf(copiedLoader.getDelegate())); - assertEquals("getJarPath did not match.", this.loader.getJarPath(), - copiedLoader.getJarPath()); assertEquals("getURLs did not match.", this.loader.getURLs().length, copiedLoader.getURLs().length); assertSame("getParent did not match.", this.loader.getParent(), copiedLoader.getParent()); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org