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 2023/01/24 12:25:19 UTC
[tomcat] branch 8.5.x updated: Code cleanup (format). No functional change.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new e9403a45ba Code cleanup (format). No functional change.
e9403a45ba is described below
commit e9403a45ba465baf8e07b198edc4733d8a3369a0
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jan 24 12:25:04 2023 +0000
Code cleanup (format). No functional change.
---
.../webresources/AbstractArchiveResource.java | 22 ++--
.../webresources/AbstractArchiveResourceSet.java | 69 ++++------
.../webresources/AbstractFileResourceSet.java | 21 ++--
.../catalina/webresources/AbstractResource.java | 3 +-
.../catalina/webresources/AbstractResourceSet.java | 8 +-
.../AbstractSingleArchiveResource.java | 4 +-
.../AbstractSingleArchiveResourceSet.java | 14 +--
java/org/apache/catalina/webresources/Cache.java | 41 +++---
.../catalina/webresources/CachedResource.java | 63 ++++------
.../webresources/ClasspathURLStreamHandler.java | 3 +-
.../catalina/webresources/DirResourceSet.java | 45 +++----
.../catalina/webresources/EmptyResourceSet.java | 10 +-
.../catalina/webresources/ExtractingRoot.java | 15 +--
.../apache/catalina/webresources/FileResource.java | 32 ++---
.../catalina/webresources/FileResourceSet.java | 38 +++---
.../apache/catalina/webresources/JarResource.java | 7 +-
.../catalina/webresources/JarResourceRoot.java | 7 +-
.../catalina/webresources/JarResourceSet.java | 33 ++---
.../catalina/webresources/JarWarResource.java | 16 +--
.../catalina/webresources/JarWarResourceSet.java | 69 ++++------
.../apache/catalina/webresources/StandardRoot.java | 140 ++++++++-------------
.../webresources/TomcatJarInputStream.java | 5 +-
.../TomcatURLStreamHandlerFactory.java | 44 +++----
.../catalina/webresources/VirtualResource.java | 3 +-
.../apache/catalina/webresources/WarResource.java | 10 +-
.../catalina/webresources/WarResourceSet.java | 25 ++--
26 files changed, 290 insertions(+), 457 deletions(-)
diff --git a/java/org/apache/catalina/webresources/AbstractArchiveResource.java b/java/org/apache/catalina/webresources/AbstractArchiveResource.java
index 8e4daffddc..982d676f12 100644
--- a/java/org/apache/catalina/webresources/AbstractArchiveResource.java
+++ b/java/org/apache/catalina/webresources/AbstractArchiveResource.java
@@ -40,8 +40,8 @@ public abstract class AbstractArchiveResource extends AbstractResource {
private boolean readCerts = false;
private Certificate[] certificates;
- protected AbstractArchiveResource(AbstractArchiveResourceSet archiveResourceSet,
- String webAppPath, String baseUrl, JarEntry jarEntry, String codeBaseUrl) {
+ protected AbstractArchiveResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath, String baseUrl,
+ JarEntry jarEntry, String codeBaseUrl) {
super(archiveResourceSet.getRoot(), webAppPath);
this.archiveResourceSet = archiveResourceSet;
this.baseUrl = baseUrl;
@@ -53,8 +53,7 @@ public abstract class AbstractArchiveResource extends AbstractResource {
resourceName = resourceName.substring(0, resourceName.length() - 1);
}
String internalPath = archiveResourceSet.getInternalPath();
- if (internalPath.length() > 0 && resourceName.equals(
- internalPath.subSequence(1, internalPath.length()))) {
+ if (internalPath.length() > 0 && resourceName.equals(internalPath.subSequence(1, internalPath.length()))) {
name = "";
} else {
int index = resourceName.lastIndexOf('/');
@@ -171,9 +170,8 @@ public abstract class AbstractArchiveResource extends AbstractResource {
if (len > Integer.MAX_VALUE) {
// Can't create an array that big
- throw new ArrayIndexOutOfBoundsException(sm.getString(
- "abstractResource.getContentTooLarge", getWebappPath(),
- Long.valueOf(len)));
+ throw new ArrayIndexOutOfBoundsException(
+ sm.getString("abstractResource.getContentTooLarge", getWebappPath(), Long.valueOf(len)));
}
if (len < 0) {
@@ -202,8 +200,7 @@ public abstract class AbstractArchiveResource extends AbstractResource {
readCerts = true;
} catch (IOException ioe) {
if (getLog().isDebugEnabled()) {
- getLog().debug(sm.getString("abstractResource.getContentFail",
- getWebappPath()), ioe);
+ getLog().debug(sm.getString("abstractResource.getContentFail", getWebappPath()), ioe);
}
// Don't return corrupted content
return null;
@@ -238,10 +235,9 @@ public abstract class AbstractArchiveResource extends AbstractResource {
protected abstract JarInputStreamWrapper getJarInputStreamWrapper();
/**
- * This wrapper assumes that the InputStream was created from a JarFile
- * obtained from a call to getArchiveResourceSet().openJarFile(). If this is
- * not the case then the usage counting in AbstractArchiveResourceSet will
- * break and the JarFile may be unexpectedly closed.
+ * This wrapper assumes that the InputStream was created from a JarFile obtained from a call to
+ * getArchiveResourceSet().openJarFile(). If this is not the case then the usage counting in
+ * AbstractArchiveResourceSet will break and the JarFile may be unexpectedly closed.
*/
protected class JarInputStreamWrapper extends InputStream {
diff --git a/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java b/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
index 1b80cc8dc1..1416a729ea 100644
--- a/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
+++ b/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
@@ -39,7 +39,7 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
private String baseUrlString;
private JarFile archive = null;
- protected HashMap<String,JarEntry> archiveEntries = null;
+ protected HashMap<String, JarEntry> archiveEntries = null;
protected final Object archiveLock = new Object();
private long archiveUseCount = 0;
@@ -70,18 +70,15 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
ArrayList<String> result = new ArrayList<>();
if (path.startsWith(webAppMount)) {
- String pathInJar =
- getInternalPath() + path.substring(webAppMount.length());
+ String pathInJar = getInternalPath() + path.substring(webAppMount.length());
// Always strip off the leading '/' to get the JAR path
if (pathInJar.length() > 0 && pathInJar.charAt(0) == '/') {
pathInJar = pathInJar.substring(1);
}
for (String name : getArchiveEntries(false).keySet()) {
- if (name.length() > pathInJar.length() &&
- name.startsWith(pathInJar)) {
+ if (name.length() > pathInJar.length() && name.startsWith(pathInJar)) {
if (name.charAt(name.length() - 1) == '/') {
- name = name.substring(
- pathInJar.length(), name.length() - 1);
+ name = name.substring(pathInJar.length(), name.length() - 1);
} else {
name = name.substring(pathInJar.length());
}
@@ -103,10 +100,9 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
if (webAppMount.startsWith(path)) {
int i = webAppMount.indexOf('/', path.length());
if (i == -1) {
- return new String[] {webAppMount.substring(path.length())};
+ return new String[] { webAppMount.substring(path.length()) };
} else {
- return new String[] {
- webAppMount.substring(path.length(), i)};
+ return new String[] { webAppMount.substring(path.length(), i) };
}
}
}
@@ -120,8 +116,7 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
ResourceSet<String> result = new ResourceSet<>();
if (path.startsWith(webAppMount)) {
- String pathInJar =
- getInternalPath() + path.substring(webAppMount.length());
+ String pathInJar = getInternalPath() + path.substring(webAppMount.length());
// Always strip off the leading '/' to get the JAR path and make
// sure it ends in '/'
if (pathInJar.length() > 0) {
@@ -161,25 +156,21 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
/**
- * Obtain the map of entries in the archive. May return null in which case
- * {@link #getArchiveEntry(String)} should be used.
+ * Obtain the map of entries in the archive. May return null in which case {@link #getArchiveEntry(String)} should
+ * be used.
*
- * @param single Is this request being make to support a single lookup? If
- * false, a map will always be returned. If true,
- * implementations may use this as a hint in determining the
- * optimum way to respond.
+ * @param single Is this request being make to support a single lookup? If false, a map will always be returned. If
+ * true, implementations may use this as a hint in determining the optimum way to respond.
*
- * @return The archives entries mapped to their names or null if
- * {@link #getArchiveEntry(String)} should be used.
+ * @return The archives entries mapped to their names or null if {@link #getArchiveEntry(String)} should be used.
*/
- protected abstract HashMap<String,JarEntry> getArchiveEntries(boolean single);
+ protected abstract HashMap<String, JarEntry> getArchiveEntries(boolean single);
/**
- * Obtain a single entry from the archive. For performance reasons,
- * {@link #getArchiveEntries(boolean)} should always be called first and the
- * archive entry looked up in the map if one is returned. Only if that call
- * returns null should this method be used.
+ * Obtain a single entry from the archive. For performance reasons, {@link #getArchiveEntries(boolean)} should
+ * always be called first and the archive entry looked up in the map if one is returned. Only if that call returns
+ * null should this method be used.
*
* @param pathInArchive The path in the archive of the entry required
*
@@ -199,8 +190,7 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
checkPath(path);
if (is == null) {
- throw new NullPointerException(
- sm.getString("dirResourceSet.writeNpe"));
+ throw new NullPointerException(sm.getString("dirResourceSet.writeNpe"));
}
return false;
@@ -217,22 +207,18 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
*
* The path parameter passed into this method always starts with '/'.
*
- * The path parameter passed into this method may or may not end with a
- * '/'. JarFile.getEntry() will return a matching directory entry
- * whether or not the name ends in a '/'. However, if the entry is
- * requested without the '/' subsequent calls to JarEntry.isDirectory()
- * will return false.
+ * The path parameter passed into this method may or may not end with a '/'. JarFile.getEntry() will return a
+ * matching directory entry whether or not the name ends in a '/'. However, if the entry is requested without
+ * the '/' subsequent calls to JarEntry.isDirectory() will return false.
*
- * Paths in JARs never start with '/'. Leading '/' need to be removed
- * before any JarFile.getEntry() call.
+ * Paths in JARs never start with '/'. Leading '/' need to be removed before any JarFile.getEntry() call.
*/
// If the JAR has been mounted below the web application root, return
// an empty resource for requests outside of the mount point.
if (path.startsWith(webAppMount)) {
- String pathInJar = getInternalPath() + path.substring(
- webAppMount.length());
+ String pathInJar = getInternalPath() + path.substring(webAppMount.length());
// Always strip off the leading '/' to get the JAR path
if (pathInJar.length() > 0 && pathInJar.charAt(0) == '/') {
pathInJar = pathInJar.substring(1);
@@ -243,15 +229,14 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
if (!path.endsWith("/")) {
path = path + "/";
}
- return new JarResourceRoot(root, new File(getBase()),
- baseUrlString, path);
+ return new JarResourceRoot(root, new File(getBase()), baseUrlString, path);
} else {
JarEntry jarEntry = null;
if (isMultiRelease()) {
// Calls JarFile.getJarEntry() which is multi-release aware
jarEntry = getArchiveEntry(pathInJar);
} else {
- Map<String,JarEntry> jarEntries = getArchiveEntries(true);
+ Map<String, JarEntry> jarEntries = getArchiveEntries(true);
if (!(pathInJar.charAt(pathInJar.length() - 1) == '/')) {
if (jarEntries == null) {
jarEntry = getArchiveEntry(pathInJar + '/');
@@ -283,8 +268,7 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
protected abstract boolean isMultiRelease();
- protected abstract WebResource createArchiveResource(JarEntry jarEntry,
- String webAppPath, Manifest manifest);
+ protected abstract WebResource createArchiveResource(JarEntry jarEntry, String webAppPath, Manifest manifest);
@Override
public final boolean isReadOnly() {
@@ -298,8 +282,7 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet {
return;
}
- throw new IllegalArgumentException(
- sm.getString("abstractArchiveResourceSet.setReadOnlyFalse"));
+ throw new IllegalArgumentException(sm.getString("abstractArchiveResourceSet.setReadOnlyFalse"));
}
protected JarFile openJarFile() throws IOException {
diff --git a/java/org/apache/catalina/webresources/AbstractFileResourceSet.java b/java/org/apache/catalina/webresources/AbstractFileResourceSet.java
index 153fae819b..e910e65118 100644
--- a/java/org/apache/catalina/webresources/AbstractFileResourceSet.java
+++ b/java/org/apache/catalina/webresources/AbstractFileResourceSet.java
@@ -146,10 +146,9 @@ public abstract class AbstractFileResourceSet extends AbstractResourceSet {
protected void logIgnoredSymlink(String contextPath, String absPath, String canPath) {
- String msg = sm.getString("abstractFileResourceSet.canonicalfileCheckFailed",
- contextPath, absPath, canPath);
+ String msg = sm.getString("abstractFileResourceSet.canonicalfileCheckFailed", contextPath, absPath, canPath);
// Log issues with configuration files at a higher level
- if(absPath.startsWith("/META-INF/") || absPath.startsWith("/WEB-INF/")) {
+ if (absPath.startsWith("/META-INF/") || absPath.startsWith("/WEB-INF/")) {
log.error(msg);
} else {
log.warn(msg);
@@ -170,8 +169,8 @@ public abstract class AbstractFileResourceSet extends AbstractResourceSet {
// there are known problems for file names with these characters
// when using File#getCanonicalPath().
// Note: There are additional characters that are disallowed in
- // Windows file names but these are not known to cause
- // problems when using File#getCanonicalPath().
+ // Windows file names but these are not known to cause
+ // problems when using File#getCanonicalPath().
return true;
}
}
@@ -179,7 +178,7 @@ public abstract class AbstractFileResourceSet extends AbstractResourceSet {
// level APIs are used to create the files that bypass various checks.
// File names that end in ' ' are known to cause problems when using
// File#getCanonicalPath().
- if (name.charAt(len -1) == ' ') {
+ if (name.charAt(len - 1) == ' ') {
return true;
}
return false;
@@ -187,11 +186,9 @@ public abstract class AbstractFileResourceSet extends AbstractResourceSet {
/**
- * Return a context-relative path, beginning with a "/", that represents
- * the canonical version of the specified path after ".." and "." elements
- * are resolved out. If the specified path attempts to go outside the
- * boundaries of the current context (i.e. too many ".." path elements
- * are present), return <code>null</code> instead.
+ * Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path
+ * after ".." and "." elements are resolved out. If the specified path attempts to go outside the boundaries of the
+ * current context (i.e. too many ".." path elements are present), return <code>null</code> instead.
*
* @param path Path to be normalized
*/
@@ -219,7 +216,7 @@ public abstract class AbstractFileResourceSet extends AbstractResourceSet {
}
- //-------------------------------------------------------- Lifecycle methods
+ // -------------------------------------------------------- Lifecycle methods
@Override
protected void initInternal() throws LifecycleException {
diff --git a/java/org/apache/catalina/webresources/AbstractResource.java b/java/org/apache/catalina/webresources/AbstractResource.java
index ad6e8b2447..384c327321 100644
--- a/java/org/apache/catalina/webresources/AbstractResource.java
+++ b/java/org/apache/catalina/webresources/AbstractResource.java
@@ -67,8 +67,7 @@ public abstract class AbstractResource implements WebResource {
long contentLength = getContentLength();
long lastModified = getLastModified();
if ((contentLength >= 0) || (lastModified >= 0)) {
- weakETag = "W/\"" + contentLength + "-" +
- lastModified + "\"";
+ weakETag = "W/\"" + contentLength + "-" + lastModified + "\"";
}
}
}
diff --git a/java/org/apache/catalina/webresources/AbstractResourceSet.java b/java/org/apache/catalina/webresources/AbstractResourceSet.java
index 83c7b4710e..f139339848 100644
--- a/java/org/apache/catalina/webresources/AbstractResourceSet.java
+++ b/java/org/apache/catalina/webresources/AbstractResourceSet.java
@@ -25,8 +25,7 @@ import org.apache.catalina.WebResourceSet;
import org.apache.catalina.util.LifecycleBase;
import org.apache.tomcat.util.res.StringManager;
-public abstract class AbstractResourceSet extends LifecycleBase
- implements WebResourceSet {
+public abstract class AbstractResourceSet extends LifecycleBase implements WebResourceSet {
private WebResourceRoot root;
private String base;
@@ -42,8 +41,7 @@ public abstract class AbstractResourceSet extends LifecycleBase
protected final void checkPath(String path) {
if (path == null || path.length() == 0 || path.charAt(0) != '/') {
- throw new IllegalArgumentException(
- sm.getString("abstractResourceSet.checkPath", path));
+ throw new IllegalArgumentException(sm.getString("abstractResourceSet.checkPath", path));
}
}
@@ -122,7 +120,7 @@ public abstract class AbstractResourceSet extends LifecycleBase
}
- //-------------------------------------------------------- Lifecycle methods
+ // -------------------------------------------------------- Lifecycle methods
@Override
protected final void startInternal() throws LifecycleException {
setState(LifecycleState.STARTING);
diff --git a/java/org/apache/catalina/webresources/AbstractSingleArchiveResource.java b/java/org/apache/catalina/webresources/AbstractSingleArchiveResource.java
index ee9b686ee1..cd22d284be 100644
--- a/java/org/apache/catalina/webresources/AbstractSingleArchiveResource.java
+++ b/java/org/apache/catalina/webresources/AbstractSingleArchiveResource.java
@@ -40,8 +40,8 @@ public abstract class AbstractSingleArchiveResource extends AbstractArchiveResou
return new JarInputStreamWrapper(jarEntry, is);
} catch (IOException e) {
if (getLog().isDebugEnabled()) {
- getLog().debug(sm.getString("jarResource.getInputStreamFail",
- getResource().getName(), getBaseUrl()), e);
+ getLog().debug(sm.getString("jarResource.getInputStreamFail", getResource().getName(), getBaseUrl()),
+ e);
}
if (jarFile != null) {
getArchiveResourceSet().closeJarFile();
diff --git a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
index e6f40348cb..75b887f2b6 100644
--- a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
+++ b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
@@ -30,8 +30,7 @@ import org.apache.tomcat.util.buf.UriUtil;
import org.apache.tomcat.util.compat.JreCompat;
/**
- * Base class for a {@link org.apache.catalina.WebResourceSet} based on a
- * single, rather than nested, archive.
+ * Base class for a {@link org.apache.catalina.WebResourceSet} based on a single, rather than nested, archive.
*/
public abstract class AbstractSingleArchiveResourceSet extends AbstractArchiveResourceSet {
@@ -44,8 +43,8 @@ public abstract class AbstractSingleArchiveResourceSet extends AbstractArchiveRe
}
- public AbstractSingleArchiveResourceSet(WebResourceRoot root, String webAppMount, String base,
- String internalPath) throws IllegalArgumentException {
+ public AbstractSingleArchiveResourceSet(WebResourceRoot root, String webAppMount, String base, String internalPath)
+ throws IllegalArgumentException {
setRoot(root);
setWebAppMount(webAppMount);
setBase(base);
@@ -62,7 +61,7 @@ public abstract class AbstractSingleArchiveResourceSet extends AbstractArchiveRe
@Override
- protected HashMap<String,JarEntry> getArchiveEntries(boolean single) {
+ protected HashMap<String, JarEntry> getArchiveEntries(boolean single) {
synchronized (archiveLock) {
if (archiveEntries == null && !single) {
JarFile jarFile = null;
@@ -114,8 +113,7 @@ public abstract class AbstractSingleArchiveResourceSet extends AbstractArchiveRe
JarFile jarFile = null;
try {
jarFile = openJarFile();
- multiRelease = Boolean.valueOf(
- JreCompat.getInstance().jarFileIsMultiRelease(jarFile));
+ multiRelease = Boolean.valueOf(JreCompat.getInstance().jarFileIsMultiRelease(jarFile));
} catch (IOException ioe) {
// Should never happen
throw new IllegalStateException(ioe);
@@ -132,7 +130,7 @@ public abstract class AbstractSingleArchiveResourceSet extends AbstractArchiveRe
}
- //-------------------------------------------------------- Lifecycle methods
+ // -------------------------------------------------------- Lifecycle methods
@Override
protected void initInternal() throws LifecycleException {
diff --git a/java/org/apache/catalina/webresources/Cache.java b/java/org/apache/catalina/webresources/Cache.java
index b2ce23cc70..bfa1b2199e 100644
--- a/java/org/apache/catalina/webresources/Cache.java
+++ b/java/org/apache/catalina/webresources/Cache.java
@@ -44,13 +44,12 @@ public class Cache {
private long ttl = 5000;
private long maxSize = 10 * 1024 * 1024;
- private int objectMaxSize = (int) maxSize/OBJECT_MAX_SIZE_FACTOR;
+ private int objectMaxSize = (int) maxSize / OBJECT_MAX_SIZE_FACTOR;
private AtomicLong lookupCount = new AtomicLong(0);
private AtomicLong hitCount = new AtomicLong(0);
- private final ConcurrentMap<String,CachedResource> resourceCache =
- new ConcurrentHashMap<>();
+ private final ConcurrentMap<String, CachedResource> resourceCache = new ConcurrentHashMap<>();
public Cache(StandardRoot root) {
this.root = root;
@@ -74,8 +73,8 @@ public class Cache {
if (cacheEntry == null) {
// Local copy to ensure consistency
int objectMaxSizeBytes = getObjectMaxSizeBytes();
- CachedResource newCacheEntry = new CachedResource(this, root, path, getTtl(),
- objectMaxSizeBytes, useClassLoaderResources);
+ CachedResource newCacheEntry = new CachedResource(this, root, path, getTtl(), objectMaxSizeBytes,
+ useClassLoaderResources);
// Concurrent callers will end up with the same CachedResource
// instance
@@ -118,12 +117,12 @@ public class Cache {
// that isn't added to the cache.
// There are assumptions here. They are:
// - refactoring the Cache to use a combined key of
- // path+useClassLoaderResources adds unnecessary
- // complexity
+ // path+useClassLoaderResources adds unnecessary
+ // complexity
// - the race condition is rare (over the lifetime of an
- // application)
+ // application)
// - it would be rare for an application to need to cache a
- // resource for both values of useClassLoaderResources
+ // resource for both values of useClassLoaderResources
cacheEntry = newCacheEntry;
}
// Make sure it is validated
@@ -152,8 +151,8 @@ public class Cache {
if (cacheEntry == null) {
// Local copy to ensure consistency
int objectMaxSizeBytes = getObjectMaxSizeBytes();
- CachedResource newCacheEntry = new CachedResource(this, root, path, getTtl(),
- objectMaxSizeBytes, useClassLoaderResources);
+ CachedResource newCacheEntry = new CachedResource(this, root, path, getTtl(), objectMaxSizeBytes,
+ useClassLoaderResources);
// Concurrent callers will end up with the same CachedResource
// instance
@@ -198,30 +197,24 @@ public class Cache {
// Create an ordered set of all cached resources with the least recently
// used first. This is a background process so we can afford to take the
// time to order the elements first
- TreeSet<CachedResource> orderedResources =
- new TreeSet<>(new EvictionOrder());
+ TreeSet<CachedResource> orderedResources = new TreeSet<>(new EvictionOrder());
orderedResources.addAll(resourceCache.values());
Iterator<CachedResource> iter = orderedResources.iterator();
- long targetSize =
- maxSize * (100 - TARGET_FREE_PERCENT_BACKGROUND) / 100;
+ long targetSize = maxSize * (100 - TARGET_FREE_PERCENT_BACKGROUND) / 100;
long newSize = evict(targetSize, iter);
if (newSize > targetSize) {
- log.info(sm.getString("cache.backgroundEvictFail",
- Long.valueOf(TARGET_FREE_PERCENT_BACKGROUND),
- root.getContext().getName(),
- Long.valueOf(newSize / 1024)));
+ log.info(sm.getString("cache.backgroundEvictFail", Long.valueOf(TARGET_FREE_PERCENT_BACKGROUND),
+ root.getContext().getName(), Long.valueOf(newSize / 1024)));
}
}
private boolean noCache(String path) {
// Don't cache classes. The class loader handles this.
// Don't cache JARs. The ResourceSet handles this.
- if ((path.endsWith(".class") &&
- (path.startsWith("/WEB-INF/classes/") || path.startsWith("/WEB-INF/lib/")))
- ||
+ if ((path.endsWith(".class") && (path.startsWith("/WEB-INF/classes/") || path.startsWith("/WEB-INF/lib/"))) ||
(path.startsWith("/WEB-INF/lib/") && path.endsWith(".jar"))) {
return true;
}
@@ -311,8 +304,8 @@ public class Cache {
return;
}
if (objectMaxSize > limit) {
- log.warn(sm.getString("cache.objectMaxSizeTooBig",
- Integer.valueOf(objectMaxSize / 1024), Integer.valueOf((int)limit / 1024)));
+ log.warn(sm.getString("cache.objectMaxSizeTooBig", Integer.valueOf(objectMaxSize / 1024),
+ Integer.valueOf((int) limit / 1024)));
objectMaxSize = (int) limit;
}
}
diff --git a/java/org/apache/catalina/webresources/CachedResource.java b/java/org/apache/catalina/webresources/CachedResource.java
index 516effdeff..649d2054c0 100644
--- a/java/org/apache/catalina/webresources/CachedResource.java
+++ b/java/org/apache/catalina/webresources/CachedResource.java
@@ -43,9 +43,8 @@ import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.res.StringManager;
/**
- * This class is designed to wrap a 'raw' WebResource and providing caching for
- * expensive operations. Inexpensive operations may be passed through to the
- * underlying resource.
+ * This class is designed to wrap a 'raw' WebResource and providing caching for expensive operations. Inexpensive
+ * operations may be passed through to the underlying resource.
*/
public class CachedResource implements WebResource {
@@ -77,8 +76,8 @@ public class CachedResource implements WebResource {
private volatile Long cachedContentLength = null;
- public CachedResource(Cache cache, StandardRoot root, String path, long ttl,
- int objectMaxSizeBytes, boolean usesClassLoaderResources) {
+ public CachedResource(Cache cache, StandardRoot root, String path, long ttl, int objectMaxSizeBytes,
+ boolean usesClassLoaderResources) {
this.cache = cache;
this.root = root;
this.webAppPath = path;
@@ -104,8 +103,7 @@ public class CachedResource implements WebResource {
if (webResource == null) {
synchronized (this) {
if (webResource == null) {
- webResource = root.getResourceInternal(
- webAppPath, useClassLoaderResources);
+ webResource = root.getResourceInternal(webAppPath, useClassLoaderResources);
getLastModified();
getContentLength();
nextCheck = ttl + now;
@@ -127,8 +125,7 @@ public class CachedResource implements WebResource {
// Assume resources inside WARs will not change
if (!root.isPackedWarFile()) {
- WebResource webResourceInternal = root.getResourceInternal(
- webAppPath, useClassLoaderResources);
+ WebResource webResourceInternal = root.getResourceInternal(webAppPath, useClassLoaderResources);
if (!webResource.exists() && webResourceInternal.exists()) {
return false;
}
@@ -157,8 +154,7 @@ public class CachedResource implements WebResource {
if (webResources == null) {
synchronized (this) {
if (webResources == null) {
- webResources = root.getResourcesInternal(
- webAppPath, useClassLoaderResources);
+ webResources = root.getResourcesInternal(webAppPath, useClassLoaderResources);
nextCheck = ttl + now;
return true;
}
@@ -318,40 +314,30 @@ public class CachedResource implements WebResource {
@Override
public URL getURL() {
/*
- * We don't want applications using this URL to access the resource
- * directly as that could lead to inconsistent results when the resource
- * is updated on the file system but the cache entry has not yet
- * expired. We saw this, for example, in JSP compilation.
- * - last modified time was obtained via
- * ServletContext.getResource("path").openConnection().getLastModified()
- * - JSP content was obtained via
- * ServletContext.getResourceAsStream("path")
- * The result was that the JSP modification was detected but the JSP
- * content was read from the cache so the non-updated JSP page was
- * used to generate the .java and .class file
+ * We don't want applications using this URL to access the resource directly as that could lead to inconsistent
+ * results when the resource is updated on the file system but the cache entry has not yet expired. We saw this,
+ * for example, in JSP compilation. - last modified time was obtained via
+ * ServletContext.getResource("path").openConnection().getLastModified() - JSP content was obtained via
+ * ServletContext.getResourceAsStream("path") The result was that the JSP modification was detected but the JSP
+ * content was read from the cache so the non-updated JSP page was used to generate the .java and .class file
*
- * One option to resolve this issue is to use a custom URL scheme for
- * resource URLs. This would allow us, via registration of a
- * URLStreamHandlerFactory, to control how the resources are accessed
- * and ensure that all access go via the cache We took this approach for
- * war: URLs so we can use jar:war:file: URLs to reference resources in
- * unpacked WAR files. However, because URL.setURLStreamHandlerFactory()
- * may only be caused once, this can cause problems when using other
- * libraries that also want to use a custom URL scheme.
+ * One option to resolve this issue is to use a custom URL scheme for resource URLs. This would allow us, via
+ * registration of a URLStreamHandlerFactory, to control how the resources are accessed and ensure that all
+ * access go via the cache We took this approach for war: URLs so we can use jar:war:file: URLs to reference
+ * resources in unpacked WAR files. However, because URL.setURLStreamHandlerFactory() may only be caused once,
+ * this can cause problems when using other libraries that also want to use a custom URL scheme.
*
- * The approach below allows us to insert a custom URLStreamHandler
- * without registering a custom protocol. The only limitation (compared
- * to registering a custom protocol) is that if the application
- * constructs the same URL from a String, they will access the resource
- * directly and not via the cache.
+ * The approach below allows us to insert a custom URLStreamHandler without registering a custom protocol. The
+ * only limitation (compared to registering a custom protocol) is that if the application constructs the same
+ * URL from a String, they will access the resource directly and not via the cache.
*/
URL resourceURL = webResource.getURL();
if (resourceURL == null) {
return null;
}
try {
- CachedResourceURLStreamHandler handler =
- new CachedResourceURLStreamHandler(resourceURL, root, webAppPath, usesClassLoaderResources);
+ CachedResourceURLStreamHandler handler = new CachedResourceURLStreamHandler(resourceURL, root, webAppPath,
+ usesClassLoaderResources);
URL result = new URL(null, resourceURL.toExternalForm(), handler);
handler.setAssociatedURL(result);
return result;
@@ -411,8 +397,7 @@ public class CachedResource implements WebResource {
/*
- * Mimics the behaviour of FileURLConnection.getInputStream for a directory.
- * Deliberately uses default locale.
+ * Mimics the behaviour of FileURLConnection.getInputStream for a directory. Deliberately uses default locale.
*/
private static InputStream buildInputStream(String[] files) {
Arrays.sort(files, Collator.getInstance(Locale.getDefault()));
diff --git a/java/org/apache/catalina/webresources/ClasspathURLStreamHandler.java b/java/org/apache/catalina/webresources/ClasspathURLStreamHandler.java
index 9a9100c554..daab855b3e 100644
--- a/java/org/apache/catalina/webresources/ClasspathURLStreamHandler.java
+++ b/java/org/apache/catalina/webresources/ClasspathURLStreamHandler.java
@@ -26,8 +26,7 @@ import org.apache.tomcat.util.res.StringManager;
public class ClasspathURLStreamHandler extends URLStreamHandler {
- private static final StringManager sm =
- StringManager.getManager(ClasspathURLStreamHandler.class);
+ private static final StringManager sm = StringManager.getManager(ClasspathURLStreamHandler.class);
@Override
diff --git a/java/org/apache/catalina/webresources/DirResourceSet.java b/java/org/apache/catalina/webresources/DirResourceSet.java
index eed886a364..3bd0245f0a 100644
--- a/java/org/apache/catalina/webresources/DirResourceSet.java
+++ b/java/org/apache/catalina/webresources/DirResourceSet.java
@@ -48,25 +48,19 @@ public class DirResourceSet extends AbstractFileResourceSet {
}
/**
- * Creates a new {@link org.apache.catalina.WebResourceSet} based on a
- * directory.
+ * Creates a new {@link org.apache.catalina.WebResourceSet} based on a directory.
*
- * @param root The {@link WebResourceRoot} this new
- * {@link org.apache.catalina.WebResourceSet} will
- * be added to.
- * @param webAppMount The path within the web application at which this
- * {@link org.apache.catalina.WebResourceSet} will
- * be mounted. For example, to add a directory of
- * JARs to a web application, the directory would
- * be mounted at "/WEB-INF/lib/"
- * @param base The absolute path to the directory on the file
- * system from which the resources will be served.
- * @param internalPath The path within this new {@link
- * org.apache.catalina.WebResourceSet} where
- * resources will be served from.
+ * @param root The {@link WebResourceRoot} this new {@link org.apache.catalina.WebResourceSet} will be added
+ * to.
+ * @param webAppMount The path within the web application at which this {@link org.apache.catalina.WebResourceSet}
+ * will be mounted. For example, to add a directory of JARs to a web application, the
+ * directory would be mounted at "/WEB-INF/lib/"
+ * @param base The absolute path to the directory on the file system from which the resources will be
+ * served.
+ * @param internalPath The path within this new {@link org.apache.catalina.WebResourceSet} where resources will be
+ * served from.
*/
- public DirResourceSet(WebResourceRoot root, String webAppMount, String base,
- String internalPath) {
+ public DirResourceSet(WebResourceRoot root, String webAppMount, String base, String internalPath) {
super(internalPath);
setRoot(root);
setWebAppMount(webAppMount);
@@ -77,8 +71,7 @@ public class DirResourceSet extends AbstractFileResourceSet {
f = new File(f, "/WEB-INF/classes/META-INF/resources");
if (f.isDirectory()) {
- root.createWebResourceSet(ResourceSetType.RESOURCE_JAR, "/",
- f.getAbsolutePath(), null, "/");
+ root.createWebResourceSet(ResourceSetType.RESOURCE_JAR, "/", f.getAbsolutePath(), null, "/");
}
}
@@ -136,10 +129,9 @@ public class DirResourceSet extends AbstractFileResourceSet {
if (webAppMount.startsWith(path)) {
int i = webAppMount.indexOf('/', path.length());
if (i == -1) {
- return new String[] {webAppMount.substring(path.length())};
+ return new String[] { webAppMount.substring(path.length()) };
} else {
- return new String[] {
- webAppMount.substring(path.length(), i)};
+ return new String[] { webAppMount.substring(path.length(), i) };
}
}
return EMPTY_STRING_ARRAY;
@@ -239,8 +231,7 @@ public class DirResourceSet extends AbstractFileResourceSet {
checkPath(path);
if (is == null) {
- throw new NullPointerException(
- sm.getString("dirResourceSet.writeNpe"));
+ throw new NullPointerException(sm.getString("dirResourceSet.writeNpe"));
}
if (isReadOnly()) {
@@ -284,12 +275,12 @@ public class DirResourceSet extends AbstractFileResourceSet {
@Override
protected void checkType(File file) {
if (file.isDirectory() == false) {
- throw new IllegalArgumentException(sm.getString("dirResourceSet.notDirectory",
- getBase(), File.separator, getInternalPath()));
+ throw new IllegalArgumentException(
+ sm.getString("dirResourceSet.notDirectory", getBase(), File.separator, getInternalPath()));
}
}
- //-------------------------------------------------------- Lifecycle methods
+ // -------------------------------------------------------- Lifecycle methods
@Override
protected void initInternal() throws LifecycleException {
super.initInternal();
diff --git a/java/org/apache/catalina/webresources/EmptyResourceSet.java b/java/org/apache/catalina/webresources/EmptyResourceSet.java
index 69f05e2ec5..c408feb1b7 100644
--- a/java/org/apache/catalina/webresources/EmptyResourceSet.java
+++ b/java/org/apache/catalina/webresources/EmptyResourceSet.java
@@ -29,10 +29,9 @@ import org.apache.catalina.WebResourceSet;
import org.apache.catalina.util.LifecycleBase;
/**
- * A {@link WebResourceSet} implementation that is not backed by a file system
- * and behaves as if it has no resources available. This is primarily used in
- * embedded mode when the web application is configured entirely
- * programmatically and does not use any static resources from the file system.
+ * A {@link WebResourceSet} implementation that is not backed by a file system and behaves as if it has no resources
+ * available. This is primarily used in embedded mode when the web application is configured entirely programmatically
+ * and does not use any static resources from the file system.
*/
public class EmptyResourceSet extends LifecycleBase implements WebResourceSet {
@@ -134,8 +133,7 @@ public class EmptyResourceSet extends LifecycleBase implements WebResourceSet {
/**
* {@inheritDoc}
* <p>
- * Calls to this method will be ignored as this implementation always read
- * only.
+ * Calls to this method will be ignored as this implementation always read only.
*/
@Override
public void setReadOnly(boolean readOnly) {
diff --git a/java/org/apache/catalina/webresources/ExtractingRoot.java b/java/org/apache/catalina/webresources/ExtractingRoot.java
index 32448ad45b..8d28381aa5 100644
--- a/java/org/apache/catalina/webresources/ExtractingRoot.java
+++ b/java/org/apache/catalina/webresources/ExtractingRoot.java
@@ -31,8 +31,8 @@ import org.apache.catalina.util.IOTools;
import org.apache.tomcat.util.res.StringManager;
/**
- * If the main resources are packaged as a WAR file then any JARs will be
- * extracted to the work directory and used from there.
+ * If the main resources are packaged as a WAR file then any JARs will be extracted to the work directory and used from
+ * there.
*/
public class ExtractingRoot extends StandardRoot {
@@ -53,8 +53,7 @@ public class ExtractingRoot extends StandardRoot {
File expansionTarget = getExpansionTarget();
if (!expansionTarget.isDirectory()) {
if (!expansionTarget.mkdirs()) {
- throw new LifecycleException(
- sm.getString("extractingRoot.targetFailed", expansionTarget));
+ throw new LifecycleException(sm.getString("extractingRoot.targetFailed", expansionTarget));
}
}
@@ -66,15 +65,13 @@ public class ExtractingRoot extends StandardRoot {
File dest = new File(expansionTarget, possibleJar.getName());
dest = dest.getCanonicalFile();
try (InputStream sourceStream = possibleJar.getInputStream();
- OutputStream destStream= new FileOutputStream(dest)) {
+ OutputStream destStream = new FileOutputStream(dest)) {
IOTools.flow(sourceStream, destStream);
}
- createWebResourceSet(ResourceSetType.CLASSES_JAR,
- "/WEB-INF/classes", dest.toURI().toURL(), "/");
+ createWebResourceSet(ResourceSetType.CLASSES_JAR, "/WEB-INF/classes", dest.toURI().toURL(), "/");
} catch (IOException ioe) {
- throw new LifecycleException(
- sm.getString("extractingRoot.jarFailed", possibleJar.getName()), ioe);
+ throw new LifecycleException(sm.getString("extractingRoot.jarFailed", possibleJar.getName()), ioe);
}
}
}
diff --git a/java/org/apache/catalina/webresources/FileResource.java b/java/org/apache/catalina/webresources/FileResource.java
index babe1905a7..e1ca5f8b37 100644
--- a/java/org/apache/catalina/webresources/FileResource.java
+++ b/java/org/apache/catalina/webresources/FileResource.java
@@ -35,8 +35,7 @@ import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
/**
- * Represents a single resource (file or directory) that is located on a file
- * system.
+ * Represents a single resource (file or directory) that is located on a file system.
*/
public class FileResource extends AbstractResource {
@@ -63,9 +62,8 @@ public class FileResource extends AbstractResource {
private final Manifest manifest;
private final boolean needConvert;
- public FileResource(WebResourceRoot root, String webAppPath,
- File resource, boolean readOnly, Manifest manifest) {
- super(root,webAppPath);
+ public FileResource(WebResourceRoot root, String webAppPath, File resource, boolean readOnly, Manifest manifest) {
+ super(root, webAppPath);
this.resource = resource;
if (webAppPath.charAt(webAppPath.length() - 1) == '/') {
@@ -76,9 +74,7 @@ public class FileResource extends AbstractResource {
// This is the root directory of a mounted ResourceSet
// Need to return the mounted name, not the real name
int endOfName = webAppPath.length() - 1;
- name = webAppPath.substring(
- webAppPath.lastIndexOf('/', endOfName - 1) + 1,
- endOfName);
+ name = webAppPath.substring(webAppPath.lastIndexOf('/', endOfName - 1) + 1, endOfName);
}
} else {
// Must be a file
@@ -156,8 +152,7 @@ public class FileResource extends AbstractResource {
return resource.getCanonicalPath();
} catch (IOException ioe) {
if (log.isDebugEnabled()) {
- log.debug(sm.getString("fileResource.getCanonicalPathFail",
- resource.getPath()), ioe);
+ log.debug(sm.getString("fileResource.getCanonicalPathFail", resource.getPath()), ioe);
}
return null;
}
@@ -193,9 +188,8 @@ public class FileResource extends AbstractResource {
if (len > Integer.MAX_VALUE) {
// Can't create an array that big
- throw new ArrayIndexOutOfBoundsException(sm.getString(
- "abstractResource.getContentTooLarge", getWebappPath(),
- Long.valueOf(len)));
+ throw new ArrayIndexOutOfBoundsException(
+ sm.getString("abstractResource.getContentTooLarge", getWebappPath(), Long.valueOf(len)));
}
if (len < 0) {
@@ -217,8 +211,7 @@ public class FileResource extends AbstractResource {
}
} catch (IOException ioe) {
if (getLog().isDebugEnabled()) {
- getLog().debug(sm.getString("abstractResource.getContentFail",
- getWebappPath()), ioe);
+ getLog().debug(sm.getString("abstractResource.getContentFail", getWebappPath()), ioe);
}
return null;
}
@@ -242,13 +235,11 @@ public class FileResource extends AbstractResource {
@Override
public long getCreation() {
try {
- BasicFileAttributes attrs = Files.readAttributes(resource.toPath(),
- BasicFileAttributes.class);
+ BasicFileAttributes attrs = Files.readAttributes(resource.toPath(), BasicFileAttributes.class);
return attrs.creationTime().toMillis();
} catch (IOException e) {
if (log.isDebugEnabled()) {
- log.debug(sm.getString("fileResource.getCreationFail",
- resource.getPath()), e);
+ log.debug(sm.getString("fileResource.getCreationFail", resource.getPath()), e);
}
return 0;
}
@@ -261,8 +252,7 @@ public class FileResource extends AbstractResource {
return resource.toURI().toURL();
} catch (MalformedURLException e) {
if (log.isDebugEnabled()) {
- log.debug(sm.getString("fileResource.getUrlFail",
- resource.getPath()), e);
+ log.debug(sm.getString("fileResource.getUrlFail", resource.getPath()), e);
}
return null;
}
diff --git a/java/org/apache/catalina/webresources/FileResourceSet.java b/java/org/apache/catalina/webresources/FileResourceSet.java
index bdc415fdf1..035e2f7a4e 100644
--- a/java/org/apache/catalina/webresources/FileResourceSet.java
+++ b/java/org/apache/catalina/webresources/FileResourceSet.java
@@ -26,8 +26,7 @@ import org.apache.catalina.WebResourceRoot;
import org.apache.catalina.util.ResourceSet;
/**
- * Represents a {@link org.apache.catalina.WebResourceSet} based on a single
- * file.
+ * Represents a {@link org.apache.catalina.WebResourceSet} based on a single file.
*/
public class FileResourceSet extends AbstractFileResourceSet {
@@ -39,25 +38,18 @@ public class FileResourceSet extends AbstractFileResourceSet {
}
/**
- * Creates a new {@link org.apache.catalina.WebResourceSet} based on a
- * file.
+ * Creates a new {@link org.apache.catalina.WebResourceSet} based on a file.
*
- * @param root The {@link WebResourceRoot} this new
- * {@link org.apache.catalina.WebResourceSet} will
- * be added to.
- * @param webAppMount The path within the web application at which this
- * {@link org.apache.catalina.WebResourceSet} will
- * be mounted. For example, to add a directory of
- * JARs to a web application, the directory would
- * be mounted at "WEB-INF/lib/"
- * @param base The absolute path to the file on the file system
- * from which the resource will be served.
- * @param internalPath The path within this new {@link
- * org.apache.catalina.WebResourceSet} where
- * resources will be served from.
+ * @param root The {@link WebResourceRoot} this new {@link org.apache.catalina.WebResourceSet} will be added
+ * to.
+ * @param webAppMount The path within the web application at which this {@link org.apache.catalina.WebResourceSet}
+ * will be mounted. For example, to add a directory of JARs to a web application, the
+ * directory would be mounted at "WEB-INF/lib/"
+ * @param base The absolute path to the file on the file system from which the resource will be served.
+ * @param internalPath The path within this new {@link org.apache.catalina.WebResourceSet} where resources will be
+ * served from.
*/
- public FileResourceSet(WebResourceRoot root, String webAppMount,
- String base, String internalPath) {
+ public FileResourceSet(WebResourceRoot root, String webAppMount, String base, String internalPath) {
super(internalPath);
setRoot(root);
setWebAppMount(webAppMount);
@@ -113,12 +105,12 @@ public class FileResourceSet extends AbstractFileResourceSet {
if (webAppMount.startsWith(path)) {
webAppMount = webAppMount.substring(path.length());
if (webAppMount.equals(getFileBase().getName())) {
- return new String[] {getFileBase().getName()};
+ return new String[] { getFileBase().getName() };
} else {
// Virtual directory
int i = webAppMount.indexOf('/');
if (i > 0) {
- return new String[] {webAppMount.substring(0, i)};
+ return new String[] { webAppMount.substring(0, i) };
}
}
}
@@ -169,8 +161,8 @@ public class FileResourceSet extends AbstractFileResourceSet {
@Override
protected void checkType(File file) {
if (file.isFile() == false) {
- throw new IllegalArgumentException(sm.getString("fileResourceSet.notFile",
- getBase(), File.separator, getInternalPath()));
+ throw new IllegalArgumentException(
+ sm.getString("fileResourceSet.notFile", getBase(), File.separator, getInternalPath()));
}
}
}
diff --git a/java/org/apache/catalina/webresources/JarResource.java b/java/org/apache/catalina/webresources/JarResource.java
index 23eb6d8d52..56199304ec 100644
--- a/java/org/apache/catalina/webresources/JarResource.java
+++ b/java/org/apache/catalina/webresources/JarResource.java
@@ -22,16 +22,15 @@ import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
/**
- * Represents a single resource (file or directory) that is located within a
- * JAR.
+ * Represents a single resource (file or directory) that is located within a JAR.
*/
public class JarResource extends AbstractSingleArchiveResource {
private static final Log log = LogFactory.getLog(JarResource.class);
- public JarResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath,
- String baseUrl, JarEntry jarEntry) {
+ public JarResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath, String baseUrl,
+ JarEntry jarEntry) {
super(archiveResourceSet, webAppPath, "jar:" + baseUrl + "!/", jarEntry, baseUrl);
}
diff --git a/java/org/apache/catalina/webresources/JarResourceRoot.java b/java/org/apache/catalina/webresources/JarResourceRoot.java
index fc11a47b05..27686edf76 100644
--- a/java/org/apache/catalina/webresources/JarResourceRoot.java
+++ b/java/org/apache/catalina/webresources/JarResourceRoot.java
@@ -37,13 +37,11 @@ public class JarResourceRoot extends AbstractResource {
private final String baseUrl;
private final String name;
- public JarResourceRoot(WebResourceRoot root, File base, String baseUrl,
- String webAppPath) {
+ public JarResourceRoot(WebResourceRoot root, File base, String baseUrl, String webAppPath) {
super(root, webAppPath);
// Validate the webAppPath before going any further
if (!webAppPath.endsWith("/")) {
- throw new IllegalArgumentException(sm.getString(
- "jarResourceRoot.invalidWebAppPath", webAppPath));
+ throw new IllegalArgumentException(sm.getString("jarResourceRoot.invalidWebAppPath", webAppPath));
}
this.base = base;
this.baseUrl = "jar:" + baseUrl;
@@ -146,6 +144,7 @@ public class JarResourceRoot extends AbstractResource {
return null;
}
}
+
@Override
protected Log getLog() {
return log;
diff --git a/java/org/apache/catalina/webresources/JarResourceSet.java b/java/org/apache/catalina/webresources/JarResourceSet.java
index c39ac745e6..c6e8a095c0 100644
--- a/java/org/apache/catalina/webresources/JarResourceSet.java
+++ b/java/org/apache/catalina/webresources/JarResourceSet.java
@@ -35,34 +35,27 @@ public class JarResourceSet extends AbstractSingleArchiveResourceSet {
/**
- * Creates a new {@link org.apache.catalina.WebResourceSet} based on a JAR
- * file.
+ * Creates a new {@link org.apache.catalina.WebResourceSet} based on a JAR file.
*
- * @param root The {@link WebResourceRoot} this new
- * {@link org.apache.catalina.WebResourceSet} will
- * be added to.
- * @param webAppMount The path within the web application at which this
- * {@link org.apache.catalina.WebResourceSet} will
- * be mounted.
- * @param base The absolute path to the JAR file on the file system
- * from which the resources will be served.
- * @param internalPath The path within this new {@link
- * org.apache.catalina.WebResourceSet} where
- * resources will be served from. E.g. for a
- * resource JAR, this would be "META-INF/resources"
+ * @param root The {@link WebResourceRoot} this new {@link org.apache.catalina.WebResourceSet} will be added
+ * to.
+ * @param webAppMount The path within the web application at which this {@link org.apache.catalina.WebResourceSet}
+ * will be mounted.
+ * @param base The absolute path to the JAR file on the file system from which the resources will be served.
+ * @param internalPath The path within this new {@link org.apache.catalina.WebResourceSet} where resources will be
+ * served from. E.g. for a resource JAR, this would be "META-INF/resources"
*
- * @throws IllegalArgumentException if the webAppMount or internalPath is
- * not valid (valid paths must start with '/')
+ * @throws IllegalArgumentException if the webAppMount or internalPath is not valid (valid paths must start with
+ * '/')
*/
- public JarResourceSet(WebResourceRoot root, String webAppMount, String base,
- String internalPath) throws IllegalArgumentException {
+ public JarResourceSet(WebResourceRoot root, String webAppMount, String base, String internalPath)
+ throws IllegalArgumentException {
super(root, webAppMount, base, internalPath);
}
@Override
- protected WebResource createArchiveResource(JarEntry jarEntry,
- String webAppPath, Manifest manifest) {
+ protected WebResource createArchiveResource(JarEntry jarEntry, String webAppPath, Manifest manifest) {
return new JarResource(this, webAppPath, getBaseUrlString(), jarEntry);
}
}
diff --git a/java/org/apache/catalina/webresources/JarWarResource.java b/java/org/apache/catalina/webresources/JarWarResource.java
index cce12338a8..dcefd22213 100644
--- a/java/org/apache/catalina/webresources/JarWarResource.java
+++ b/java/org/apache/catalina/webresources/JarWarResource.java
@@ -27,8 +27,7 @@ import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.buf.UriUtil;
/**
- * Represents a single resource (file or directory) that is located within a
- * JAR that in turn is located in a WAR file.
+ * Represents a single resource (file or directory) that is located within a JAR that in turn is located in a WAR file.
*/
public class JarWarResource extends AbstractArchiveResource {
@@ -36,11 +35,10 @@ public class JarWarResource extends AbstractArchiveResource {
private final String archivePath;
- public JarWarResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath,
- String baseUrl, JarEntry jarEntry, String archivePath) {
+ public JarWarResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath, String baseUrl,
+ JarEntry jarEntry, String archivePath) {
- super(archiveResourceSet, webAppPath,
- "jar:war:" + baseUrl + UriUtil.getWarSeparator() + archivePath + "!/",
+ super(archiveResourceSet, webAppPath, "jar:war:" + baseUrl + UriUtil.getWarSeparator() + archivePath + "!/",
jarEntry, "war:" + baseUrl + UriUtil.getWarSeparator() + archivePath);
this.archivePath = archivePath;
}
@@ -57,8 +55,7 @@ public class JarWarResource extends AbstractArchiveResource {
jarIs = new JarInputStream(isInWar);
entry = jarIs.getNextJarEntry();
- while (entry != null &&
- !entry.getName().equals(getResource().getName())) {
+ while (entry != null && !entry.getName().equals(getResource().getName())) {
entry = jarIs.getNextJarEntry();
}
@@ -69,8 +66,7 @@ public class JarWarResource extends AbstractArchiveResource {
return new JarInputStreamWrapper(entry, jarIs);
} catch (IOException e) {
if (log.isDebugEnabled()) {
- log.debug(sm.getString("jarResource.getInputStreamFail",
- getResource().getName(), getBaseUrl()), e);
+ log.debug(sm.getString("jarResource.getInputStreamFail", getResource().getName(), getBaseUrl()), e);
}
// Ensure jarIs is closed if there is an exception
entry = null;
diff --git a/java/org/apache/catalina/webresources/JarWarResourceSet.java b/java/org/apache/catalina/webresources/JarWarResourceSet.java
index adfb2653a8..de4cba1d41 100644
--- a/java/org/apache/catalina/webresources/JarWarResourceSet.java
+++ b/java/org/apache/catalina/webresources/JarWarResourceSet.java
@@ -36,39 +36,30 @@ import org.apache.tomcat.util.buf.UriUtil;
import org.apache.tomcat.util.compat.JreCompat;
/**
- * Represents a {@link org.apache.catalina.WebResourceSet} based on a JAR file
- * that is nested inside a packed WAR file. This is only intended for internal
- * use within Tomcat and therefore cannot be created via configuration.
+ * Represents a {@link org.apache.catalina.WebResourceSet} based on a JAR file that is nested inside a packed WAR file.
+ * This is only intended for internal use within Tomcat and therefore cannot be created via configuration.
*/
public class JarWarResourceSet extends AbstractArchiveResourceSet {
private final String archivePath;
/**
- * Creates a new {@link org.apache.catalina.WebResourceSet} based on a JAR
- * file that is nested inside a WAR.
+ * Creates a new {@link org.apache.catalina.WebResourceSet} based on a JAR file that is nested inside a WAR.
*
- * @param root The {@link WebResourceRoot} this new
- * {@link org.apache.catalina.WebResourceSet} will
- * be added to.
- * @param webAppMount The path within the web application at which this
- * {@link org.apache.catalina.WebResourceSet} will
- * be mounted.
- * @param base The absolute path to the WAR file on the file system
- * in which the JAR is located.
- * @param archivePath The path within the WAR file where the JAR file is
- * located.
- * @param internalPath The path within this new {@link
- * org.apache.catalina.WebResourceSet} where
- * resources will be served from. E.g. for a
- * resource JAR, this would be "META-INF/resources"
+ * @param root The {@link WebResourceRoot} this new {@link org.apache.catalina.WebResourceSet} will be added
+ * to.
+ * @param webAppMount The path within the web application at which this {@link org.apache.catalina.WebResourceSet}
+ * will be mounted.
+ * @param base The absolute path to the WAR file on the file system in which the JAR is located.
+ * @param archivePath The path within the WAR file where the JAR file is located.
+ * @param internalPath The path within this new {@link org.apache.catalina.WebResourceSet} where resources will be
+ * served from. E.g. for a resource JAR, this would be "META-INF/resources"
*
- * @throws IllegalArgumentException if the webAppMount or internalPath is
- * not valid (valid paths must start with '/')
+ * @throws IllegalArgumentException if the webAppMount or internalPath is not valid (valid paths must start with
+ * '/')
*/
- public JarWarResourceSet(WebResourceRoot root, String webAppMount,
- String base, String archivePath, String internalPath)
- throws IllegalArgumentException {
+ public JarWarResourceSet(WebResourceRoot root, String webAppMount, String base, String archivePath,
+ String internalPath) throws IllegalArgumentException {
setRoot(root);
setWebAppMount(webAppMount);
setBase(base);
@@ -85,8 +76,7 @@ public class JarWarResourceSet extends AbstractArchiveResourceSet {
}
@Override
- protected WebResource createArchiveResource(JarEntry jarEntry,
- String webAppPath, Manifest manifest) {
+ protected WebResource createArchiveResource(JarEntry jarEntry, String webAppPath, Manifest manifest) {
return new JarWarResource(this, webAppPath, getBaseUrlString(), jarEntry, archivePath);
}
@@ -94,11 +84,10 @@ public class JarWarResourceSet extends AbstractArchiveResourceSet {
/**
* {@inheritDoc}
* <p>
- * JarWar can't optimise for a single resource so the Map is always
- * returned.
+ * JarWar can't optimise for a single resource so the Map is always returned.
*/
@Override
- protected HashMap<String,JarEntry> getArchiveEntries(boolean single) {
+ protected HashMap<String, JarEntry> getArchiveEntries(boolean single) {
synchronized (archiveLock) {
if (archiveEntries == null) {
JarFile warFile = null;
@@ -168,10 +157,10 @@ public class JarWarResourceSet extends AbstractArchiveResourceSet {
int targetVersion = JreCompat.getInstance().jarFileRuntimeMajorVersion();
- Map<String,VersionedJarEntry> versionedEntries = new HashMap<>();
- Iterator<Entry<String,JarEntry>> iter = archiveEntries.entrySet().iterator();
+ Map<String, VersionedJarEntry> versionedEntries = new HashMap<>();
+ Iterator<Entry<String, JarEntry>> iter = archiveEntries.entrySet().iterator();
while (iter.hasNext()) {
- Entry<String,JarEntry> entry = iter.next();
+ Entry<String, JarEntry> entry = iter.next();
String name = entry.getKey();
if (name.startsWith("META-INF/versions/")) {
// Remove the multi-release version
@@ -190,16 +179,14 @@ public class JarWarResourceSet extends AbstractArchiveResourceSet {
if (versionedJarEntry == null) {
// No versioned entry found for this name. Create
// one.
- versionedEntries.put(baseName,
- new VersionedJarEntry(version, entry.getValue()));
+ versionedEntries.put(baseName, new VersionedJarEntry(version, entry.getValue()));
} else {
// Ignore any entry for which we have already found
// a later version
if (version > versionedJarEntry.getVersion()) {
// Replace the entry targeted at an earlier
// version
- versionedEntries.put(baseName,
- new VersionedJarEntry(version, entry.getValue()));
+ versionedEntries.put(baseName, new VersionedJarEntry(version, entry.getValue()));
}
}
}
@@ -207,9 +194,8 @@ public class JarWarResourceSet extends AbstractArchiveResourceSet {
}
}
- for (Entry<String,VersionedJarEntry> versionedJarEntry : versionedEntries.entrySet()) {
- archiveEntries.put(versionedJarEntry.getKey(),
- versionedJarEntry.getValue().getJarEntry());
+ for (Entry<String, VersionedJarEntry> versionedJarEntry : versionedEntries.entrySet()) {
+ archiveEntries.put(versionedJarEntry.getKey(), versionedJarEntry.getValue().getJarEntry());
}
}
@@ -217,8 +203,7 @@ public class JarWarResourceSet extends AbstractArchiveResourceSet {
/**
* {@inheritDoc}
* <p>
- * Should never be called since {@link #getArchiveEntries(boolean)} always
- * returns a Map.
+ * Should never be called since {@link #getArchiveEntries(boolean)} always returns a Map.
*/
@Override
protected JarEntry getArchiveEntry(String pathInArchive) {
@@ -234,7 +219,7 @@ public class JarWarResourceSet extends AbstractArchiveResourceSet {
}
- //-------------------------------------------------------- Lifecycle methods
+ // -------------------------------------------------------- Lifecycle methods
@Override
protected void initInternal() throws LifecycleException {
diff --git a/java/org/apache/catalina/webresources/StandardRoot.java b/java/org/apache/catalina/webresources/StandardRoot.java
index a3b0d07812..e48d1502f6 100644
--- a/java/org/apache/catalina/webresources/StandardRoot.java
+++ b/java/org/apache/catalina/webresources/StandardRoot.java
@@ -51,14 +51,13 @@ import org.apache.tomcat.util.res.StringManager;
/**
* <p>
- * Provides the resources implementation for a web application. The
- * {@link org.apache.catalina.Lifecycle} of this class should be aligned with
- * that of the associated {@link Context}.
- * </p><p>
- * This implementation assumes that the base attribute supplied to {@link
- * StandardRoot#createWebResourceSet(
- * org.apache.catalina.WebResourceRoot.ResourceSetType, String, String, String,
- * String)} represents the absolute path to a file.
+ * Provides the resources implementation for a web application. The {@link org.apache.catalina.Lifecycle} of this class
+ * should be aligned with that of the associated {@link Context}.
+ * </p>
+ * <p>
+ * This implementation assumes that the base attribute supplied to
+ * {@link StandardRoot#createWebResourceSet( org.apache.catalina.WebResourceRoot.ResourceSetType, String, String, String, String)}
+ * represents the absolute path to a file.
* </p>
*/
public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot {
@@ -79,13 +78,12 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
private ObjectName cacheJmxName = null;
private boolean trackLockedFiles = false;
- private final Set<TrackedWebResource> trackedResources =
- Collections.newSetFromMap(new ConcurrentHashMap<TrackedWebResource,Boolean>());
+ private final Set<TrackedWebResource> trackedResources = Collections
+ .newSetFromMap(new ConcurrentHashMap<TrackedWebResource, Boolean>());
// Constructs to make iteration over all WebResourceSets simpler
private final List<WebResourceSet> mainResources = new ArrayList<>();
- private final List<List<WebResourceSet>> allResources =
- new ArrayList<>();
+ private final List<List<WebResourceSet>> allResources = new ArrayList<>();
{
allResources.add(preResources);
allResources.add(mainResources);
@@ -96,10 +94,8 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
/**
- * Creates a new standard implementation of {@link WebResourceRoot}. A no
- * argument constructor is required for this to work with the digester.
- * {@link #setContext(Context)} must be called before this component is
- * initialized.
+ * Creates a new standard implementation of {@link WebResourceRoot}. A no argument constructor is required for this
+ * to work with the digester. {@link #setContext(Context)} must be called before this component is initialized.
*/
public StandardRoot() {
// NO-OP
@@ -205,8 +201,7 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
return getResource(path, true, false);
}
- protected WebResource getResource(String path, boolean validate,
- boolean useClassLoaderResources) {
+ protected WebResource getResource(String path, boolean validate, boolean useClassLoaderResources) {
if (validate) {
path = validate(path);
}
@@ -232,22 +227,20 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
/**
- * Ensures that this object is in a valid state to serve resources, checks
- * that the path is a String that starts with '/' and checks that the path
- * can be normalized without stepping outside of the root.
+ * Ensures that this object is in a valid state to serve resources, checks that the path is a String that starts
+ * with '/' and checks that the path can be normalized without stepping outside of the root.
*
* @param path The path to validate
- * @return the normalized path
+ *
+ * @return the normalized path
*/
private String validate(String path) {
if (!getState().isAvailable()) {
- throw new IllegalStateException(
- sm.getString("standardRoot.checkStateNotStarted"));
+ throw new IllegalStateException(sm.getString("standardRoot.checkStateNotStarted"));
}
if (path == null || path.length() == 0 || !path.startsWith("/")) {
- throw new IllegalArgumentException(
- sm.getString("standardRoot.invalidPath", path));
+ throw new IllegalArgumentException(sm.getString("standardRoot.invalidPath", path));
}
String result;
@@ -261,21 +254,19 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
result = RequestUtil.normalize(path, false);
}
if (result == null || result.length() == 0 || !result.startsWith("/")) {
- throw new IllegalArgumentException(
- sm.getString("standardRoot.invalidPathNormal", path, result));
+ throw new IllegalArgumentException(sm.getString("standardRoot.invalidPathNormal", path, result));
}
return result;
}
- protected final WebResource getResourceInternal(String path,
- boolean useClassLoaderResources) {
+ protected final WebResource getResourceInternal(String path, boolean useClassLoaderResources) {
WebResource result = null;
WebResource virtual = null;
WebResource mainEmpty = null;
for (List<WebResourceSet> list : allResources) {
for (WebResourceSet webResourceSet : list) {
- if (!useClassLoaderResources && !webResourceSet.getClassLoaderOnly() ||
+ if (!useClassLoaderResources && !webResourceSet.getClassLoaderOnly() ||
useClassLoaderResources && !webResourceSet.getStaticOnly()) {
result = webResourceSet.getResource(path);
if (result.exists()) {
@@ -306,8 +297,7 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
return getResources(path, false);
}
- private WebResource[] getResources(String path,
- boolean useClassLoaderResources) {
+ private WebResource[] getResources(String path, boolean useClassLoaderResources) {
path = validate(path);
if (isCachingAllowed()) {
@@ -317,8 +307,7 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
}
}
- protected WebResource[] getResourcesInternal(String path,
- boolean useClassLoaderResources) {
+ protected WebResource[] getResourcesInternal(String path, boolean useClassLoaderResources) {
List<WebResource> result = new ArrayList<>();
for (List<WebResourceSet> list : allResources) {
for (WebResourceSet webResourceSet : list) {
@@ -361,19 +350,18 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
}
// TODO: Should the createWebResourceSet() methods be removed to some
- // utility class for file system based resource sets?
+ // utility class for file system based resource sets?
@Override
- public void createWebResourceSet(ResourceSetType type, String webAppMount,
- URL url, String internalPath) {
+ public void createWebResourceSet(ResourceSetType type, String webAppMount, URL url, String internalPath) {
BaseLocation baseLocation = new BaseLocation(url);
- createWebResourceSet(type, webAppMount, baseLocation.getBasePath(),
- baseLocation.getArchivePath(), internalPath);
+ createWebResourceSet(type, webAppMount, baseLocation.getBasePath(), baseLocation.getArchivePath(),
+ internalPath);
}
@Override
- public void createWebResourceSet(ResourceSetType type, String webAppMount,
- String base, String archivePath, String internalPath) {
+ public void createWebResourceSet(ResourceSetType type, String webAppMount, String base, String archivePath,
+ String internalPath) {
List<WebResourceSet> resourceList;
WebResourceSet resourceSet;
@@ -391,8 +379,7 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
resourceList = postResources;
break;
default:
- throw new IllegalArgumentException(
- sm.getString("standardRoot.createUnknownType", type));
+ throw new IllegalArgumentException(sm.getString("standardRoot.createUnknownType", type));
}
// This implementation assumes that the base for all resources will be a
@@ -402,21 +389,16 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
if (file.isFile()) {
if (archivePath != null) {
// Must be a JAR nested inside a WAR if archivePath is non-null
- resourceSet = new JarWarResourceSet(this, webAppMount, base,
- archivePath, internalPath);
+ resourceSet = new JarWarResourceSet(this, webAppMount, base, archivePath, internalPath);
} else if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
- resourceSet = new JarResourceSet(this, webAppMount, base,
- internalPath);
+ resourceSet = new JarResourceSet(this, webAppMount, base, internalPath);
} else {
- resourceSet = new FileResourceSet(this, webAppMount, base,
- internalPath);
+ resourceSet = new FileResourceSet(this, webAppMount, base, internalPath);
}
} else if (file.isDirectory()) {
- resourceSet =
- new DirResourceSet(this, webAppMount, base, internalPath);
+ resourceSet = new DirResourceSet(this, webAppMount, base, internalPath);
} else {
- throw new IllegalArgumentException(
- sm.getString("standardRoot.createInvalidFile", file));
+ throw new IllegalArgumentException(sm.getString("standardRoot.createInvalidFile", file));
}
if (type.equals(ResourceSetType.CLASSES_JAR)) {
@@ -564,32 +546,27 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
}
/**
- * Class loader resources are handled by treating JARs in WEB-INF/lib as
- * resource JARs (without the internal META-INF/resources/ prefix) mounted
- * at WEB-INF/classes (rather than the web app root). This enables reuse
- * of the resource handling plumbing.
- *
- * These resources are marked as class loader only so they are only used in
- * the methods that are explicitly defined to return class loader resources.
- * This prevents calls to getResource("/WEB-INF/classes") returning from one
- * or more of the JAR files.
+ * Class loader resources are handled by treating JARs in WEB-INF/lib as resource JARs (without the internal
+ * META-INF/resources/ prefix) mounted at WEB-INF/classes (rather than the web app root). This enables reuse of the
+ * resource handling plumbing. These resources are marked as class loader only so they are only used in the methods
+ * that are explicitly defined to return class loader resources. This prevents calls to
+ * getResource("/WEB-INF/classes") returning from one or more of the JAR files.
*
- * @throws LifecycleException If an error occurs that should stop the web
- * application from starting
+ * @throws LifecycleException If an error occurs that should stop the web application from starting
*/
protected void processWebInfLib() throws LifecycleException {
WebResource[] possibleJars = listResources("/WEB-INF/lib", false);
for (WebResource possibleJar : possibleJars) {
if (possibleJar.isFile() && possibleJar.getName().endsWith(".jar")) {
- createWebResourceSet(ResourceSetType.CLASSES_JAR,
- "/WEB-INF/classes", possibleJar.getURL(), "/");
+ createWebResourceSet(ResourceSetType.CLASSES_JAR, "/WEB-INF/classes", possibleJar.getURL(), "/");
}
}
}
/**
* For unit testing.
+ *
* @param main The main resources
*/
protected final void setMainResources(WebResourceSet main) {
@@ -606,7 +583,6 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
}
-
@Override
public void gc() {
for (List<WebResourceSet> list : allResources) {
@@ -645,11 +621,9 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
}
-
/*
- * Returns true if and only if all the resources for this web application
- * are provided via a packed WAR file. It is used to optimise cache
- * validation in this case on the basis that the WAR file will not change.
+ * Returns true if and only if all the resources for this web application are provided via a packed WAR file. It is
+ * used to optimise cache validation in this case on the basis that the WAR file will not change.
*/
protected boolean isPackedWarFile() {
return main instanceof WarResourceSet && preResources.isEmpty() && postResources.isEmpty();
@@ -677,8 +651,7 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
super.initInternal();
if (context == null) {
- throw new IllegalStateException(
- sm.getString("standardRoot.noContext"));
+ throw new IllegalStateException(sm.getString("standardRoot.noContext"));
}
cacheJmxName = register(cache, getObjectNameKeyProperties() + ",name=Cache");
@@ -737,16 +710,14 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
} else {
File f = new File(docBase);
if (!f.isAbsolute()) {
- f = new File(((Host)context.getParent()).getAppBaseFile(), f.getPath());
+ f = new File(((Host) context.getParent()).getAppBaseFile(), f.getPath());
}
if (f.isDirectory()) {
mainResourceSet = new DirResourceSet(this, "/", f.getAbsolutePath(), "/");
- } else if(f.isFile() && docBase.endsWith(".war")) {
+ } else if (f.isFile() && docBase.endsWith(".war")) {
mainResourceSet = new WarResourceSet(this, "/", f.getAbsolutePath());
} else {
- throw new IllegalArgumentException(
- sm.getString("standardRoot.startInvalidMain",
- f.getAbsolutePath()));
+ throw new IllegalArgumentException(sm.getString("standardRoot.startInvalidMain", f.getAbsolutePath()));
}
}
@@ -777,9 +748,7 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
classResources.clear();
for (TrackedWebResource trackedResource : trackedResources) {
- log.error(sm.getString("standardRoot.lockedFile",
- context.getName(),
- trackedResource.getName()),
+ log.error(sm.getString("standardRoot.lockedFile", context.getName(), trackedResource.getName()),
trackedResource.getCreatedBy());
try {
trackedResource.close();
@@ -830,12 +799,12 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
throw new IllegalArgumentException(e);
}
int startOfArchivePath = endOfFileUrl + 2;
- if (jarUrl.length() > startOfArchivePath) {
+ if (jarUrl.length() > startOfArchivePath) {
archivePath = jarUrl.substring(startOfArchivePath);
} else {
archivePath = null;
}
- } else if ("file".equals(url.getProtocol())){
+ } else if ("file".equals(url.getProtocol())) {
try {
f = new File(url.toURI());
} catch (URISyntaxException e) {
@@ -843,8 +812,7 @@ public class StandardRoot extends LifecycleMBeanBase implements WebResourceRoot
}
archivePath = null;
} else {
- throw new IllegalArgumentException(sm.getString(
- "standardRoot.unsupportedProtocol", url.getProtocol()));
+ throw new IllegalArgumentException(sm.getString("standardRoot.unsupportedProtocol", url.getProtocol()));
}
basePath = f.getAbsolutePath();
diff --git a/java/org/apache/catalina/webresources/TomcatJarInputStream.java b/java/org/apache/catalina/webresources/TomcatJarInputStream.java
index a00dda56f1..a05add04fa 100644
--- a/java/org/apache/catalina/webresources/TomcatJarInputStream.java
+++ b/java/org/apache/catalina/webresources/TomcatJarInputStream.java
@@ -23,9 +23,8 @@ import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry;
/**
- * The purpose of this sub-class is to obtain references to the JarEntry objects
- * for META-INF/ and META-INF/MANIFEST.MF that are otherwise swallowed by the
- * JarInputStream implementation.
+ * The purpose of this sub-class is to obtain references to the JarEntry objects for META-INF/ and META-INF/MANIFEST.MF
+ * that are otherwise swallowed by the JarInputStream implementation.
*/
public class TomcatJarInputStream extends JarInputStream {
diff --git a/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java b/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java
index d58f9d3fef..02a0842eea 100644
--- a/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java
+++ b/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java
@@ -33,9 +33,8 @@ public class TomcatURLStreamHandlerFactory implements URLStreamHandlerFactory {
private static volatile TomcatURLStreamHandlerFactory instance = null;
/**
- * Obtain a reference to the singleton instance. It is recommended that
- * callers check the value of {@link #isRegistered()} before using the
- * returned instance.
+ * Obtain a reference to the singleton instance. It is recommended that callers check the value of
+ * {@link #isRegistered()} before using the returned instance.
*
* @return A reference to the singleton instance
*/
@@ -61,17 +60,14 @@ public class TomcatURLStreamHandlerFactory implements URLStreamHandlerFactory {
private final boolean registered;
// List of factories for application defined stream handler factories.
- private final List<URLStreamHandlerFactory> userFactories =
- new CopyOnWriteArrayList<>();
+ private final List<URLStreamHandlerFactory> userFactories = new CopyOnWriteArrayList<>();
/**
- * Register this factory with the JVM. May be called more than once. The
- * implementation ensures that registration only occurs once.
+ * Register this factory with the JVM. May be called more than once. The implementation ensures that registration
+ * only occurs once.
*
- * @return <code>true</code> if the factory is already registered with the
- * JVM or was successfully registered as a result of this call.
- * <code>false</code> if the factory was disabled prior to this
- * call.
+ * @return <code>true</code> if the factory is already registered with the JVM or was successfully registered as a
+ * result of this call. <code>false</code> if the factory was disabled prior to this call.
*/
public static boolean register() {
return getInstanceInternal(true).isRegistered();
@@ -79,13 +75,10 @@ public class TomcatURLStreamHandlerFactory implements URLStreamHandlerFactory {
/**
- * Prevent this this factory from registering with the JVM. May be called
- * more than once.
+ * Prevent this this factory from registering with the JVM. May be called more than once.
*
- * @return <code>true</code> if the factory is already disabled or was
- * successfully disabled as a result of this call.
- * <code>false</code> if the factory was already registered prior
- * to this call.
+ * @return <code>true</code> if the factory is already disabled or was successfully disabled as a result of this
+ * call. <code>false</code> if the factory was already registered prior to this call.
*/
public static boolean disable() {
return !getInstanceInternal(false).isRegistered();
@@ -93,9 +86,8 @@ public class TomcatURLStreamHandlerFactory implements URLStreamHandlerFactory {
/**
- * Release references to any user provided factories that have been loaded
- * using the provided class loader. Called during web application stop to
- * prevent memory leaks.
+ * Release references to any user provided factories that have been loaded using the provided class loader. Called
+ * during web application stop to prevent memory leaks.
*
* @param classLoader The class loader to release
*/
@@ -137,13 +129,10 @@ public class TomcatURLStreamHandlerFactory implements URLStreamHandlerFactory {
/**
- * Since the JVM only allows a single call to
- * {@link URL#setURLStreamHandlerFactory(URLStreamHandlerFactory)} and
- * Tomcat needs to register a handler, provide a mechanism to allow
- * applications to register their own handlers.
+ * Since the JVM only allows a single call to {@link URL#setURLStreamHandlerFactory(URLStreamHandlerFactory)} and
+ * Tomcat needs to register a handler, provide a mechanism to allow applications to register their own handlers.
*
- * @param factory The user provided factory to add to the factories Tomcat
- * has already registered
+ * @param factory The user provided factory to add to the factories Tomcat has already registered
*/
public void addUserFactory(URLStreamHandlerFactory factory) {
userFactories.add(factory);
@@ -163,8 +152,7 @@ public class TomcatURLStreamHandlerFactory implements URLStreamHandlerFactory {
// Application handlers
for (URLStreamHandlerFactory factory : userFactories) {
- URLStreamHandler handler =
- factory.createURLStreamHandler(protocol);
+ URLStreamHandler handler = factory.createURLStreamHandler(protocol);
if (handler != null) {
return handler;
}
diff --git a/java/org/apache/catalina/webresources/VirtualResource.java b/java/org/apache/catalina/webresources/VirtualResource.java
index 3f30b5fc26..24a33e1e81 100644
--- a/java/org/apache/catalina/webresources/VirtualResource.java
+++ b/java/org/apache/catalina/webresources/VirtualResource.java
@@ -22,8 +22,7 @@ public class VirtualResource extends EmptyResource {
private final String name;
- public VirtualResource(WebResourceRoot root, String webAppPath,
- String name) {
+ public VirtualResource(WebResourceRoot root, String webAppPath, String name) {
super(root, webAppPath);
this.name = name;
}
diff --git a/java/org/apache/catalina/webresources/WarResource.java b/java/org/apache/catalina/webresources/WarResource.java
index c6425311a3..4672a3923f 100644
--- a/java/org/apache/catalina/webresources/WarResource.java
+++ b/java/org/apache/catalina/webresources/WarResource.java
@@ -23,18 +23,16 @@ import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.buf.UriUtil;
/**
- * Represents a single resource (file or directory) that is located within a
- * WAR.
+ * Represents a single resource (file or directory) that is located within a WAR.
*/
public class WarResource extends AbstractSingleArchiveResource {
private static final Log log = LogFactory.getLog(WarResource.class);
- public WarResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath,
- String baseUrl, JarEntry jarEntry) {
- super(archiveResourceSet, webAppPath, "war:" + baseUrl + UriUtil.getWarSeparator(),
- jarEntry, baseUrl);
+ public WarResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath, String baseUrl,
+ JarEntry jarEntry) {
+ super(archiveResourceSet, webAppPath, "war:" + baseUrl + UriUtil.getWarSeparator(), jarEntry, baseUrl);
}
diff --git a/java/org/apache/catalina/webresources/WarResourceSet.java b/java/org/apache/catalina/webresources/WarResourceSet.java
index f6fdd29fd3..c3d76d49dc 100644
--- a/java/org/apache/catalina/webresources/WarResourceSet.java
+++ b/java/org/apache/catalina/webresources/WarResourceSet.java
@@ -35,30 +35,23 @@ public class WarResourceSet extends AbstractSingleArchiveResourceSet {
/**
- * Creates a new {@link org.apache.catalina.WebResourceSet} based on a WAR
- * file.
+ * Creates a new {@link org.apache.catalina.WebResourceSet} based on a WAR file.
*
- * @param root The {@link WebResourceRoot} this new
- * {@link org.apache.catalina.WebResourceSet} will
- * be added to.
- * @param webAppMount The path within the web application at which this
- * {@link org.apache.catalina.WebResourceSet} will
- * be mounted.
- * @param base The absolute path to the WAR file on the file system
- * from which the resources will be served.
+ * @param root The {@link WebResourceRoot} this new {@link org.apache.catalina.WebResourceSet} will be added
+ * to.
+ * @param webAppMount The path within the web application at which this {@link org.apache.catalina.WebResourceSet}
+ * will be mounted.
+ * @param base The absolute path to the WAR file on the file system from which the resources will be served.
*
- * @throws IllegalArgumentException if the webAppMount is not valid (valid
- * paths must start with '/')
+ * @throws IllegalArgumentException if the webAppMount is not valid (valid paths must start with '/')
*/
- public WarResourceSet(WebResourceRoot root, String webAppMount, String base)
- throws IllegalArgumentException {
+ public WarResourceSet(WebResourceRoot root, String webAppMount, String base) throws IllegalArgumentException {
super(root, webAppMount, base, "/");
}
@Override
- protected WebResource createArchiveResource(JarEntry jarEntry,
- String webAppPath, Manifest manifest) {
+ protected WebResource createArchiveResource(JarEntry jarEntry, String webAppPath, Manifest manifest) {
return new WarResource(this, webAppPath, getBaseUrlString(), jarEntry);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org