This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 178bded965 Code clean-up - formatting. No functional change. 178bded965 is described below commit 178bded9655a31ec067c785a9c04a96d325e0dc7 Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri May 23 11:24:21 2025 +0100 Code clean-up - formatting. No functional change. --- .../tomcat/util/scan/AbstractInputStreamJar.java | 13 +-- java/org/apache/tomcat/util/scan/Constants.java | 6 +- java/org/apache/tomcat/util/scan/JarFactory.java | 6 +- .../org/apache/tomcat/util/scan/JarFileUrlJar.java | 13 ++- .../tomcat/util/scan/JarFileUrlNestedJar.java | 5 +- .../tomcat/util/scan/NonClosingJarInputStream.java | 10 +- .../tomcat/util/scan/ReferenceCountedJar.java | 4 +- .../tomcat/util/scan/StandardJarScanFilter.java | 39 +++---- .../tomcat/util/scan/StandardJarScanner.java | 114 ++++++++++----------- java/org/apache/tomcat/util/scan/UrlJar.java | 3 +- 10 files changed, 90 insertions(+), 123 deletions(-) diff --git a/java/org/apache/tomcat/util/scan/AbstractInputStreamJar.java b/java/org/apache/tomcat/util/scan/AbstractInputStreamJar.java index 73fd50b457..985ba7899e 100644 --- a/java/org/apache/tomcat/util/scan/AbstractInputStreamJar.java +++ b/java/org/apache/tomcat/util/scan/AbstractInputStreamJar.java @@ -29,8 +29,7 @@ import org.apache.tomcat.Jar; import org.apache.tomcat.util.compat.JreCompat; /** - * Base implementation of Jar for implementations that use a JarInputStream to - * access the JAR file. + * Base implementation of Jar for implementations that use a JarInputStream to access the JAR file. */ public abstract class AbstractInputStreamJar implements Jar { @@ -67,10 +66,8 @@ public abstract class AbstractInputStreamJar implements Jar { if (multiRelease.booleanValue()) { // Skip base entries where there is a multi-release entry // Skip multi-release entries that are not being used - while (entry != null && - (mrMap.containsKey(entry.getName()) || - entry.getName().startsWith("META-INF/versions/") && - !mrMap.containsValue(entry.getName()))) { + while (entry != null && (mrMap.containsKey(entry.getName()) || + entry.getName().startsWith("META-INF/versions/") && !mrMap.containsValue(entry.getName()))) { entry = jarInputStream.getNextJarEntry(); } } else { @@ -273,8 +270,8 @@ public abstract class AbstractInputStreamJar implements Jar { mrMap = new HashMap<>(); for (Entry<String,Integer> mrVersion : mrVersions.entrySet()) { - mrMap.put(mrVersion.getKey() , "META-INF/versions/" + mrVersion.getValue().toString() + - "/" + mrVersion.getKey()); + mrMap.put(mrVersion.getKey(), + "META-INF/versions/" + mrVersion.getValue().toString() + "/" + mrVersion.getKey()); } // Reset stream back to the beginning of the JAR diff --git a/java/org/apache/tomcat/util/scan/Constants.java b/java/org/apache/tomcat/util/scan/Constants.java index 1edd13eda0..229967eff3 100644 --- a/java/org/apache/tomcat/util/scan/Constants.java +++ b/java/org/apache/tomcat/util/scan/Constants.java @@ -24,10 +24,8 @@ public final class Constants { public static final String Package = "org.apache.tomcat.util.scan"; /* System properties */ - public static final String SKIP_JARS_PROPERTY = - "tomcat.util.scan.StandardJarScanFilter.jarsToSkip"; - public static final String SCAN_JARS_PROPERTY = - "tomcat.util.scan.StandardJarScanFilter.jarsToScan"; + public static final String SKIP_JARS_PROPERTY = "tomcat.util.scan.StandardJarScanFilter.jarsToSkip"; + public static final String SCAN_JARS_PROPERTY = "tomcat.util.scan.StandardJarScanFilter.jarsToScan"; /* Commons strings */ public static final String JAR_EXT = ".jar"; diff --git a/java/org/apache/tomcat/util/scan/JarFactory.java b/java/org/apache/tomcat/util/scan/JarFactory.java index 51c0011ed1..fa0aef1a37 100644 --- a/java/org/apache/tomcat/util/scan/JarFactory.java +++ b/java/org/apache/tomcat/util/scan/JarFactory.java @@ -53,8 +53,7 @@ public class JarFactory { } - public static URL getJarEntryURL(URL baseUrl, String entryName) - throws MalformedURLException { + public static URL getJarEntryURL(URL baseUrl, String entryName) throws MalformedURLException { String baseExternal = baseUrl.toExternalForm(); @@ -62,8 +61,7 @@ public class JarFactory { // Assume this is pointing to a JAR file within a WAR. Java doesn't // support jar:jar:file:... so switch to Tomcat's war:file:... baseExternal = baseExternal.replaceFirst("^jar:", "war:"); - baseExternal = baseExternal.replaceFirst("!/", - Matcher.quoteReplacement(UriUtil.getWarSeparator())); + baseExternal = baseExternal.replaceFirst("!/", Matcher.quoteReplacement(UriUtil.getWarSeparator())); } return new URL("jar:" + baseExternal + "!/" + entryName); diff --git a/java/org/apache/tomcat/util/scan/JarFileUrlJar.java b/java/org/apache/tomcat/util/scan/JarFileUrlJar.java index a7f5f69e08..43557c5ebb 100644 --- a/java/org/apache/tomcat/util/scan/JarFileUrlJar.java +++ b/java/org/apache/tomcat/util/scan/JarFileUrlJar.java @@ -34,9 +34,8 @@ import org.apache.tomcat.Jar; import org.apache.tomcat.util.compat.JreCompat; /** - * Implementation of {@link Jar} that is optimised for file based JAR URLs that - * refer directly to a JAR file (e.g. URLs of the form jar:file: ... .jar!/ or - * file:... .jar). + * Implementation of {@link Jar} that is optimised for file based JAR URLs that refer directly to a JAR file (e.g. URLs + * of the form jar:file: ... .jar!/ or file:... .jar). */ public class JarFileUrlJar implements Jar { @@ -106,7 +105,7 @@ public class JarFileUrlJar implements Jar { @Override public String getURL(String entry) { - return "jar:" + getJarFileURL().toExternalForm() + "!/" + entry; + return "jar:" + getJarFileURL().toExternalForm() + "!/" + entry; } @Override @@ -133,11 +132,11 @@ public class JarFileUrlJar implements Jar { if (multiRelease) { // Need to ensure that: // - the one, correct entry is returned where multiple versions - // are available + // are available // - that the order of entries in the JAR doesn't prevent the - // correct entries being returned + // correct entries being returned // - the case where an entry appears in the versions location - // but not in the base location is handled correctly + // but not in the base location is handled correctly // Enumerate the entries until one is reached that represents an // entry that has not been seen before. diff --git a/java/org/apache/tomcat/util/scan/JarFileUrlNestedJar.java b/java/org/apache/tomcat/util/scan/JarFileUrlNestedJar.java index 47dd738b9d..7707630974 100644 --- a/java/org/apache/tomcat/util/scan/JarFileUrlNestedJar.java +++ b/java/org/apache/tomcat/util/scan/JarFileUrlNestedJar.java @@ -23,9 +23,8 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; /** - * Implementation of {@link org.apache.tomcat.Jar} that is optimised for file - * based JAR URLs that refer to a JAR file nested inside a WAR - * (e.g. URLs of the form jar:file: ... .war!/ ... .jar). + * Implementation of {@link org.apache.tomcat.Jar} that is optimised for file based JAR URLs that refer to a JAR file + * nested inside a WAR (e.g. URLs of the form jar:file: ... .war!/ ... .jar). */ public class JarFileUrlNestedJar extends AbstractInputStreamJar { diff --git a/java/org/apache/tomcat/util/scan/NonClosingJarInputStream.java b/java/org/apache/tomcat/util/scan/NonClosingJarInputStream.java index 1488624067..7a49647775 100644 --- a/java/org/apache/tomcat/util/scan/NonClosingJarInputStream.java +++ b/java/org/apache/tomcat/util/scan/NonClosingJarInputStream.java @@ -21,15 +21,13 @@ import java.io.InputStream; import java.util.jar.JarInputStream; /** - * When using a {@link JarInputStream} with an XML parser, the stream will be - * closed by the parser. This causes problems if multiple entries from the JAR - * need to be parsed. This implementation makes {{@link #close()} a NO-OP and - * adds {@link #reallyClose()} that will close the stream. + * When using a {@link JarInputStream} with an XML parser, the stream will be closed by the parser. This causes problems + * if multiple entries from the JAR need to be parsed. This implementation makes {{@link #close()} a NO-OP and adds + * {@link #reallyClose()} that will close the stream. */ public class NonClosingJarInputStream extends JarInputStream { - public NonClosingJarInputStream(InputStream in, boolean verify) - throws IOException { + public NonClosingJarInputStream(InputStream in, boolean verify) throws IOException { super(in, verify); } diff --git a/java/org/apache/tomcat/util/scan/ReferenceCountedJar.java b/java/org/apache/tomcat/util/scan/ReferenceCountedJar.java index 1d53573d35..b79a3aa2f2 100644 --- a/java/org/apache/tomcat/util/scan/ReferenceCountedJar.java +++ b/java/org/apache/tomcat/util/scan/ReferenceCountedJar.java @@ -24,8 +24,8 @@ import java.util.jar.Manifest; import org.apache.tomcat.Jar; /** - * This class provides a wrapper around {@link Jar} that uses reference counting - * to close and re-create the wrapped {@link Jar} instance as required. + * This class provides a wrapper around {@link Jar} that uses reference counting to close and re-create the wrapped + * {@link Jar} instance as required. */ public class ReferenceCountedJar implements Jar { diff --git a/java/org/apache/tomcat/util/scan/StandardJarScanFilter.java b/java/org/apache/tomcat/util/scan/StandardJarScanFilter.java index e80d4d5b49..038bbba591 100644 --- a/java/org/apache/tomcat/util/scan/StandardJarScanFilter.java +++ b/java/org/apache/tomcat/util/scan/StandardJarScanFilter.java @@ -29,8 +29,7 @@ import org.apache.tomcat.util.file.Matcher; public class StandardJarScanFilter implements JarScanFilter { - private final ReadWriteLock configurationLock = - new ReentrantReadWriteLock(); + private final ReadWriteLock configurationLock = new ReentrantReadWriteLock(); private static final String defaultSkip; private static final String defaultScan; @@ -60,32 +59,22 @@ public class StandardJarScanFilter implements JarScanFilter { private boolean defaultPluggabilityScan = true; /** - * This is the standard implementation of {@link JarScanFilter}. By default, - * the following filtering rules are used: + * This is the standard implementation of {@link JarScanFilter}. By default, the following filtering rules are used: * <ul> - * <li>JARs that match neither the skip nor the scan list will be included - * in scan results.</li> - * <li>JARs that match the skip list but not the scan list will be excluded - * from scan results.</li> - * <li>JARs that match the scan list will be included from scan results. - * </li> + * <li>JARs that match neither the skip nor the scan list will be included in scan results.</li> + * <li>JARs that match the skip list but not the scan list will be excluded from scan results.</li> + * <li>JARs that match the scan list will be included from scan results.</li> * </ul> - * The default skip list and default scan list are obtained from the system - * properties {@link Constants#SKIP_JARS_PROPERTY} and - * {@link Constants#SCAN_JARS_PROPERTY} respectively. These default values - * may be over-ridden for the {@link JarScanType#TLD} and - * {@link JarScanType#PLUGGABILITY} scans. The filtering rules may also be - * modified for these scan types using {@link #setDefaultTldScan(boolean)} - * and {@link #setDefaultPluggabilityScan(boolean)}. If set to - * <code>false</code>, the following filtering rules are used for associated - * type: + * The default skip list and default scan list are obtained from the system properties + * {@link Constants#SKIP_JARS_PROPERTY} and {@link Constants#SCAN_JARS_PROPERTY} respectively. These default values + * may be over-ridden for the {@link JarScanType#TLD} and {@link JarScanType#PLUGGABILITY} scans. The filtering + * rules may also be modified for these scan types using {@link #setDefaultTldScan(boolean)} and + * {@link #setDefaultPluggabilityScan(boolean)}. If set to <code>false</code>, the following filtering rules are + * used for associated type: * <ul> - * <li>JARs that match neither the skip nor the scan list will be excluded - * from scan results.</li> - * <li>JARs that match the scan list but not the skip list will be included - * in scan results.</li> - * <li>JARs that match the skip list will be excluded from scan results. - * </li> + * <li>JARs that match neither the skip nor the scan list will be excluded from scan results.</li> + * <li>JARs that match the scan list but not the skip list will be included in scan results.</li> + * <li>JARs that match the skip list will be excluded from scan results.</li> * </ul> */ public StandardJarScanFilter() { diff --git a/java/org/apache/tomcat/util/scan/StandardJarScanner.java b/java/org/apache/tomcat/util/scan/StandardJarScanner.java index 9ba2b53d1b..a48ad28b7e 100644 --- a/java/org/apache/tomcat/util/scan/StandardJarScanner.java +++ b/java/org/apache/tomcat/util/scan/StandardJarScanner.java @@ -46,16 +46,13 @@ import org.apache.tomcat.util.compat.JreCompat; import org.apache.tomcat.util.res.StringManager; /** - * The default {@link JarScanner} implementation scans the WEB-INF/lib directory - * followed by the provided classloader and then works up the classloader - * hierarchy. This implementation is sufficient to meet the requirements of the - * Servlet 3.0 specification as well as to provide a number of Tomcat specific - * extensions. The extensions are: + * The default {@link JarScanner} implementation scans the WEB-INF/lib directory followed by the provided classloader + * and then works up the classloader hierarchy. This implementation is sufficient to meet the requirements of the + * Servlet 3.0 specification as well as to provide a number of Tomcat specific extensions. The extensions are: * <ul> - * <li>Scanning the classloader hierarchy (enabled by default)</li> - * <li>Testing all files to see if they are JARs (disabled by default)</li> - * <li>Testing all directories to see if they are exploded JARs - * (disabled by default)</li> + * <li>Scanning the classloader hierarchy (enabled by default)</li> + * <li>Testing all files to see if they are JARs (disabled by default)</li> + * <li>Testing all directories to see if they are exploded JARs (disabled by default)</li> * </ul> * All of the extensions may be controlled via configuration. */ @@ -86,9 +83,11 @@ public class StandardJarScanner implements JarScanner { * Controls the classpath scanning extension. */ private boolean scanClassPath = true; + public boolean isScanClassPath() { return scanClassPath; } + public void setScanClassPath(boolean scanClassPath) { this.scanClassPath = scanClassPath; } @@ -97,9 +96,11 @@ public class StandardJarScanner implements JarScanner { * Controls the JAR file Manifest scanning extension. */ private boolean scanManifest = true; + public boolean isScanManifest() { return scanManifest; } + public void setScanManifest(boolean scanManifest) { this.scanManifest = scanManifest; } @@ -108,33 +109,38 @@ public class StandardJarScanner implements JarScanner { * Controls the testing all files to see of they are JAR files extension. */ private boolean scanAllFiles = false; + public boolean isScanAllFiles() { return scanAllFiles; } + public void setScanAllFiles(boolean scanAllFiles) { this.scanAllFiles = scanAllFiles; } /** - * Controls the testing all directories to see of they are exploded JAR - * files extension. + * Controls the testing all directories to see of they are exploded JAR files extension. */ private boolean scanAllDirectories = true; + public boolean isScanAllDirectories() { return scanAllDirectories; } + public void setScanAllDirectories(boolean scanAllDirectories) { this.scanAllDirectories = scanAllDirectories; } /** - * Controls the testing of the bootstrap classpath which consists of the - * runtime classes provided by the JVM and any installed system extensions. + * Controls the testing of the bootstrap classpath which consists of the runtime classes provided by the JVM and any + * installed system extensions. */ private boolean scanBootstrapClassPath = false; + public boolean isScanBootstrapClassPath() { return scanBootstrapClassPath; } + public void setScanBootstrapClassPath(boolean scanBootstrapClassPath) { this.scanBootstrapClassPath = scanBootstrapClassPath; } @@ -143,29 +149,28 @@ public class StandardJarScanner implements JarScanner { * Controls the filtering of the results from the scan for JARs */ private JarScanFilter jarScanFilter = new StandardJarScanFilter(); + @Override public JarScanFilter getJarScanFilter() { return jarScanFilter; } + @Override public void setJarScanFilter(JarScanFilter jarScanFilter) { this.jarScanFilter = jarScanFilter; } /** - * Scan the provided ServletContext and class loader for JAR files. Each JAR - * file found will be passed to the callback handler to be processed. + * Scan the provided ServletContext and class loader for JAR files. Each JAR file found will be passed to the + * callback handler to be processed. * - * @param scanType The type of JAR scan to perform. This is passed to - * the filter which uses it to determine how to - * filter the results - * @param context The ServletContext - used to locate and access - * WEB-INF/lib - * @param callback The handler to process any JARs found + * @param scanType The type of JAR scan to perform. This is passed to the filter which uses it to determine how to + * filter the results + * @param context The ServletContext - used to locate and access WEB-INF/lib + * @param callback The handler to process any JARs found */ @Override - public void scan(JarScanType scanType, ServletContext context, - JarScannerCallback callback) { + public void scan(JarScanType scanType, ServletContext context, JarScannerCallback callback) { if (log.isTraceEnabled()) { log.trace(sm.getString("jarScan.webinflibStart")); @@ -182,8 +187,7 @@ public class StandardJarScanner implements JarScanner { if (dirList != null) { for (String path : dirList) { if (path.endsWith(Constants.JAR_EXT) && - getJarScanFilter().check(scanType, - path.substring(path.lastIndexOf('/')+1))) { + getJarScanFilter().check(scanType, path.substring(path.lastIndexOf('/') + 1))) { // Need to scan this JAR if (log.isDebugEnabled()) { log.debug(sm.getString("jarScan.webinflibJarScan", path)); @@ -239,8 +243,8 @@ public class StandardJarScanner implements JarScanner { } - protected void doScanClassPath(JarScanType scanType, ServletContext context, - JarScannerCallback callback, Set<URL> processedURLs) { + protected void doScanClassPath(JarScanType scanType, ServletContext context, JarScannerCallback callback, + Set<URL> processedURLs) { if (log.isTraceEnabled()) { log.trace(sm.getString("jarScan.classloaderStart")); } @@ -268,8 +272,7 @@ public class StandardJarScanner implements JarScanner { isWebapp = isWebappClassLoader(classLoader); } - classPathUrlsToProcess.addAll( - Arrays.asList(((URLClassLoader) classLoader).getURLs())); + classPathUrlsToProcess.addAll(Arrays.asList(((URLClassLoader) classLoader).getURLs())); processURLs(scanType, callback, processedURLs, isWebapp, classPathUrlsToProcess); } @@ -288,8 +291,8 @@ public class StandardJarScanner implements JarScanner { } - protected void processURLs(JarScanType scanType, JarScannerCallback callback, - Set<URL> processedURLs, boolean isWebapp, Deque<URL> classPathUrlsToProcess) { + protected void processURLs(JarScanType scanType, JarScannerCallback callback, Set<URL> processedURLs, + boolean isWebapp, Deque<URL> classPathUrlsToProcess) { if (jarScanFilter.isSkipAll()) { return; @@ -309,11 +312,8 @@ public class StandardJarScanner implements JarScanner { // Directories are scanned for pluggability scans or // if scanAllDirectories is enabled unless the // filter says not to. - if ((cpe.isJar() || - scanType == JarScanType.PLUGGABILITY || - isScanAllDirectories()) && - getJarScanFilter().check(scanType, - cpe.getName())) { + if ((cpe.isJar() || scanType == JarScanType.PLUGGABILITY || isScanAllDirectories()) && + getJarScanFilter().check(scanType, cpe.getName())) { if (log.isDebugEnabled()) { log.debug(sm.getString("jarScan.classloaderJarScan", url)); } @@ -353,18 +353,14 @@ public class StandardJarScanner implements JarScanner { /* - * Since class loader hierarchies can get complicated, this method attempts - * to apply the following rule: A class loader is a web application class - * loader unless it loaded this class (StandardJarScanner) or is a parent - * of the class loader that loaded this class. + * Since class loader hierarchies can get complicated, this method attempts to apply the following rule: A class + * loader is a web application class loader unless it loaded this class (StandardJarScanner) or is a parent of the + * class loader that loaded this class. * - * This should mean: - * the webapp class loader is an application class loader - * the shared class loader is an application class loader - * the server class loader is not an application class loader - * the common class loader is not an application class loader - * the system class loader is not an application class loader - * the bootstrap class loader is not an application class loader + * This should mean: the webapp class loader is an application class loader the shared class loader is an + * application class loader the server class loader is not an application class loader the common class loader is + * not an application class loader the system class loader is not an application class loader the bootstrap class + * loader is not an application class loader */ private static boolean isWebappClassLoader(ClassLoader classLoader) { return !CLASSLOADER_HIERARCHY.contains(classLoader); @@ -372,12 +368,10 @@ public class StandardJarScanner implements JarScanner { /* - * Scan a URL for JARs with the optional extensions to look at all files - * and all directories. + * Scan a URL for JARs with the optional extensions to look at all files and all directories. */ - protected void process(JarScanType scanType, JarScannerCallback callback, - URL url, String webappPath, boolean isWebapp, Deque<URL> classPathUrlsToProcess) - throws IOException { + protected void process(JarScanType scanType, JarScannerCallback callback, URL url, String webappPath, + boolean isWebapp, Deque<URL> classPathUrlsToProcess) throws IOException { if (log.isTraceEnabled()) { log.trace(sm.getString("jarScan.jarUrlStart", url)); @@ -422,8 +416,7 @@ public class StandardJarScanner implements JarScanner { } - private void processManifest(Jar jar, boolean isWebapp, - Deque<URL> classPathUrlsToProcess) throws IOException { + private void processManifest(Jar jar, boolean isWebapp, Deque<URL> classPathUrlsToProcess) throws IOException { // Not processed for web application JARs nor if the caller did not // provide a Deque of URLs to append to. @@ -449,14 +442,11 @@ public class StandardJarScanner implements JarScanner { try { URI jarURI = jarURL.toURI(); /* - * Note: Resolving the relative URLs from the manifest has the - * potential to introduce security concerns. However, since - * only JARs provided by the container and NOT those provided - * by web applications are processed, there should be no - * issues. - * If this feature is ever extended to include JARs provided - * by web applications, checks should be added to ensure that - * any relative URL does not step outside the web application. + * Note: Resolving the relative URLs from the manifest has the potential to introduce security + * concerns. However, since only JARs provided by the container and NOT those provided by web + * applications are processed, there should be no issues. If this feature is ever extended to + * include JARs provided by web applications, checks should be added to ensure that any relative URL + * does not step outside the web application. */ URI classPathEntryURI = jarURI.resolve(classPathEntry); classPathEntryURL = classPathEntryURI.toURL(); diff --git a/java/org/apache/tomcat/util/scan/UrlJar.java b/java/org/apache/tomcat/util/scan/UrlJar.java index 67648004fc..4e61bb4964 100644 --- a/java/org/apache/tomcat/util/scan/UrlJar.java +++ b/java/org/apache/tomcat/util/scan/UrlJar.java @@ -22,8 +22,7 @@ import java.net.URL; import java.net.URLConnection; /** - * Implementation of {@link org.apache.tomcat.Jar} that is optimised for - * non-file based JAR URLs. + * Implementation of {@link org.apache.tomcat.Jar} that is optimised for non-file based JAR URLs. */ public class UrlJar extends AbstractInputStreamJar { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org