Author: markt Date: Thu Sep 12 19:48:57 2013 New Revision: 1522704 URL: http://svn.apache.org/r1522704 Log: More resources refactoring. Remove the need to extract the classes into the work dir.
Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.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=1522704&r1=1522703&r2=1522704&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Thu Sep 12 19:48:57 2013 @@ -253,8 +253,9 @@ public class WebappClassLoader /** - * Associated directory context giving access to the resources in this - * webapp. + * Associated web resources for this webapp. + * TODO Review the use of resources in this class to see if further + * simplifications can be made. */ protected WebResourceRoot resources = null; @@ -299,9 +300,10 @@ public class WebappClassLoader /** - * The local repository for locally loaded classes or resources. + * The path to the repository for locally loaded classes or resources. This + * would normally be /WEB-INF/classes/. */ - protected String repository = null; + protected String repositoryPath = null; /** @@ -310,12 +312,11 @@ public class WebappClassLoader protected URL[] repositoryURLs = null; - /** - * Repository translated as path in the work directory (for Jasper - * originally), but which is used to generate a fake URL should getURLs be - * called. - */ - protected File file = null; + /** + * The {@link WebResource} for the repository for locally loaded classes or + * resources. This would normally point to /WEB-INF/classes/. + */ + protected WebResource repository = null; /** @@ -740,25 +741,22 @@ public class WebappClassLoader /** * Set the place this ClassLoader can look for classes to be loaded. * - * @param repository Name of a source of classes to be loaded, such as a + * @param path Path of a source of classes to be loaded, such as a * directory pathname, a JAR file pathname, or a ZIP file pathname * * @exception IllegalArgumentException if the specified repository is * invalid or does not exist */ - synchronized void setRepository(String repository, File file) { - - // Note : There should be only one (of course), but I think we should - // keep this a bit generic + synchronized void setRepository(String path, WebResource repository) { - if (repository == null) + if (path == null) return; if (log.isDebugEnabled()) - log.debug("addRepository(" + repository + ")"); + log.debug("addRepository(" + path + ")"); + this.repositoryPath = path; this.repository = repository; - this.file = file; } @@ -920,8 +918,8 @@ public class WebappClassLoader sb.append(" delegate: "); sb.append(delegate); sb.append("\r\n"); - sb.append(" repository: "); - sb.append(repository); + sb.append(" repositoryPath: "); + sb.append(repositoryPath); sb.append("\r\n"); if (this.parent != null) { sb.append("----------> Parent Classloader:\r\n"); @@ -1084,9 +1082,9 @@ public class WebappClassLoader int jarFilesLength = jarFiles.length; - if (repository != null) { + if (repositoryPath != null) { // Looking at the repository - WebResource[] webResources = resources.getResources(repository + name); + WebResource[] webResources = resources.getResources(repositoryPath + name); for (WebResource webResource : webResources) { if (webResource.exists()) { result.add(webResource.getURL()); @@ -1512,7 +1510,7 @@ public class WebappClassLoader } int resultLength; - if (file == null) { + if (repository == null) { resultLength = jarRealFiles.length; } else { resultLength = jarRealFiles.length + 1; @@ -1522,8 +1520,8 @@ public class WebappClassLoader try { URL[] urls = new URL[resultLength]; - if (file != null) { - urls[off ++] = getURI(file); + if (repository != null) { + urls[off ++] = repository.getURL(); } for (File jarRealFile : jarRealFiles) { urls[off++] = getURI(jarRealFile); @@ -1641,8 +1639,6 @@ public class WebappClassLoader started = false; - file = null; - int length = jarFiles.length; for (int i = 0; i < length; i++) { try { @@ -1658,9 +1654,9 @@ public class WebappClassLoader notFoundResources.clear(); resourceEntries.clear(); resources = null; - repository = null; + repositoryPath = null; repositoryURLs = null; - file = null; + repository = null; jarFiles = null; jarRealFiles = null; jarPath = null; @@ -2647,22 +2643,6 @@ public class WebappClassLoader } - /** - * Find specified resource in local repositories. - * - * @return the loaded resource, or null if the resource isn't found - */ - protected ResourceEntry findResourceInternal(File file, String path){ - ResourceEntry entry = new ResourceEntry(); - try { - entry.source = getURI(new File(file, path)); - entry.codeBase = entry.source; - } catch (MalformedURLException e) { - return null; - } - return entry; - } - /** * Find specified resource in local repositories. @@ -2693,25 +2673,16 @@ public class WebappClassLoader boolean fileNeedConvert = false; - if (repository != null) { - String fullPath = repository + path; + if (repositoryPath != null) { + String fullPath = repositoryPath + path; resource = resources.getResource(fullPath); if (resource.exists()) { contentLength = (int) resource.getContentLength(); - String canonicalPath = resource.getCanonicalPath(); - if (canonicalPath != null) { - // we create the ResourceEntry based on the information returned - // by the DirContext rather than just using the path to the - // repository. This allows to have smart DirContext implementations - // that "virtualize" the docbase (e.g. Eclipse WTP) - entry = findResourceInternal(new File(canonicalPath), ""); - } else { - // probably a resource not in the filesystem (e.g. in a - // packaged war) - entry = findResourceInternal(file, path); - } + entry = new ResourceEntry(); + entry.source = resource.getURL(); + entry.codeBase = entry.source; entry.lastModified = resource.getLastModified(); binaryStream = resource.getInputStream(); 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=1522704&r1=1522703&r2=1522704&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Thu Sep 12 19:48:57 2013 @@ -691,35 +691,17 @@ public class WebappLoader extends Lifecy if (classes.isDirectory()) { - File classRepository = null; - - String absoluteClassesPath = classes.getCanonicalPath(); - - if (absoluteClassesPath != null) { - classRepository = new File(absoluteClassesPath); - } else { - classRepository = new File(workDir, classesPath); - if (!classRepository.mkdirs() && - !classRepository.isDirectory()) { - throw new IOException( - sm.getString("webappLoader.mkdirFailure")); - } - if (!copyDir(classes, classRepository)) { - throw new IOException( - sm.getString("webappLoader.copyFailure")); - } - } - if(log.isDebugEnabled()) log.debug(sm.getString("webappLoader.classDeploy", classesPath, - classRepository.getAbsolutePath())); + classes.getURL().toExternalForm())); // Adding the repository to the class loader - classLoader.setRepository(classesPath + "/", classRepository); + classLoader.setRepository(classesPath + "/", classes); loaderRepositories.add(classesPath + "/" ); } // 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"; @@ -909,30 +891,6 @@ public class WebappLoader extends Lifecy return null; } - /** - * Copy directory. - */ - private boolean copyDir(WebResource src, File destDir) { - - WebResource[] resources = - src.getWebResourceRoot().listResources(src.getWebappPath()); - for (WebResource resource : resources) { - File currentFile = new File(destDir, resource.getName()); - if (resource.isFile()) { - InputStream is = resource.getInputStream(); - if (!copy(is, currentFile)) - return false; - } else if (resource.isDirectory()) { - if (!currentFile.isDirectory() && !currentFile.mkdir()) - return false; - if (!copyDir(resource, currentFile)) - return false; - } - } - - return true; - } - /** * Copy a file to the specified temp directory. This is required only --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org