From 42ba41531897178348c4cf0328c4609adfd8874d Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 2 May 2024 17:40:49 +0200 Subject: [PATCH] Addendum to #11566. (#11722) * Addendum to #11566. Restored methods that were removed in WebAppClassLoader.Context. Fixed method signatures for deprecated method -- they must take the deprecated ClassMatcher, not the newly introduced one. Signed-off-by: Simone Bordet --- .../eclipse/jetty/ee/WebAppClassLoading.java | 3 +- .../jetty/util/ClassVisibilityChecker.java | 12 ++-- .../jetty/ee10/cdi/CdiConfiguration.java | 8 +-- .../ee10/webapp/AbstractConfiguration.java | 28 ++++---- .../jetty/ee10/webapp/ClassMatcher.java | 1 - .../jetty/ee10/webapp/Configuration.java | 31 +++++++-- .../jetty/ee10/webapp/WebAppClassLoader.java | 33 +++++++-- .../jetty/ee10/webapp/WebAppContext.java | 68 +++++++------------ .../ee10/webapp/WebAppClassLoaderTest.java | 3 +- .../jetty/ee9/webapp/ClassMatcher.java | 5 -- .../jetty/ee9/webapp/Configuration.java | 2 +- .../jetty/ee9/webapp/WebAppClassLoader.java | 5 -- .../jetty/ee9/webapp/WebAppContext.java | 19 ++++-- .../ee9/webapp/WebAppClassLoaderTest.java | 4 +- 14 files changed, 119 insertions(+), 103 deletions(-) diff --git a/jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebAppClassLoading.java b/jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebAppClassLoading.java index eaf13e52a64a..dcdac85af037 100644 --- a/jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebAppClassLoading.java +++ b/jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebAppClassLoading.java @@ -169,8 +169,9 @@ public static void addHiddenClasses(String... patterns) * Add a hidden (server) Class pattern to use for all WebAppContexts of a given {@link Server}. * @param attributes The {@link Attributes} instance to add classes to * @param patterns the patterns to use + * @deprecated use {@link #addHiddenClasses(Server, String...)} instead */ - @Deprecated (forRemoval = true) + @Deprecated (since = "12.0.9", forRemoval = true) public static void addHiddenClasses(Attributes attributes, String... patterns) { if (patterns != null && patterns.length > 0) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ClassVisibilityChecker.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ClassVisibilityChecker.java index 12bfaec2322f..e9d273a7e5ed 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ClassVisibilityChecker.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ClassVisibilityChecker.java @@ -21,7 +21,7 @@ public interface ClassVisibilityChecker { /** * Is the class a Protected (System) Class. - * A System class is a class that is visible to a webapplication, + * A System class is a class that is visible to a web application, * but that cannot be overridden by the contents of WEB-INF/lib or * WEB-INF/classes * @@ -33,8 +33,8 @@ public interface ClassVisibilityChecker /** * Is the class a Hidden (Server) Class. * A Server class is a class that is part of the implementation of - * the server and is NIT visible to a webapplication. The web - * application may provide it's own implementation of the class, + * the server and is NOT visible to a web application. The web + * application may provide its own implementation of the class, * to be loaded from WEB-INF/lib or WEB-INF/classes * * @param clazz The fully qualified name of the class. @@ -44,7 +44,7 @@ public interface ClassVisibilityChecker /** * Is the class a System Class. - * A System class is a class that is visible to a webapplication, + * A System class is a class that is visible to a web application, * but that cannot be overridden by the contents of WEB-INF/lib or * WEB-INF/classes * @@ -61,8 +61,8 @@ default boolean isSystemClass(Class clazz) /** * Is the class a Server Class. * A Server class is a class that is part of the implementation of - * the server and is NIT visible to a webapplication. The web - * application may provide it's own implementation of the class, + * the server and is NOT visible to a web application. The web + * application may provide its own implementation of the class, * to be loaded from WEB-INF/lib or WEB-INF/classes * * @param clazz The fully qualified name of the class. diff --git a/jetty-ee10/jetty-ee10-cdi/src/main/java/org/eclipse/jetty/ee10/cdi/CdiConfiguration.java b/jetty-ee10/jetty-ee10-cdi/src/main/java/org/eclipse/jetty/ee10/cdi/CdiConfiguration.java index 07370998d8d1..32ed6ef47c4f 100644 --- a/jetty-ee10/jetty-ee10-cdi/src/main/java/org/eclipse/jetty/ee10/cdi/CdiConfiguration.java +++ b/jetty-ee10/jetty-ee10-cdi/src/main/java/org/eclipse/jetty/ee10/cdi/CdiConfiguration.java @@ -13,8 +13,6 @@ package org.eclipse.jetty.ee10.cdi; -import java.util.function.Predicate; - import org.eclipse.jetty.ee10.annotations.AnnotationConfiguration; import org.eclipse.jetty.ee10.plus.webapp.PlusConfiguration; import org.eclipse.jetty.ee10.webapp.AbstractConfiguration; @@ -33,11 +31,11 @@ public CdiConfiguration() { super(new Builder() .protectAndExpose("org.eclipse.jetty.ee10.cdi.CdiServletContainerInitializer") - .hide(getHiddenClasses()) + .hide(getCdiHiddenClasses()) .addDependents(AnnotationConfiguration.class, PlusConfiguration.class)); } - private static String[] getHiddenClasses() + private static String[] getCdiHiddenClasses() { //Only hide the cdi api classes if there is not also an impl on the //environment classpath - vital for embedded uses. @@ -45,4 +43,4 @@ private static String[] getHiddenClasses() return new String[]{"jakarta.enterprise.", "jakarta.decorator."}; return new String[0]; } -} \ No newline at end of file +} diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/AbstractConfiguration.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/AbstractConfiguration.java index 2db4056c8bd9..ae04963208c2 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/AbstractConfiguration.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/AbstractConfiguration.java @@ -19,13 +19,15 @@ import java.util.Collections; import java.util.List; +import org.eclipse.jetty.util.ClassMatcher; + public class AbstractConfiguration implements Configuration { private final boolean _enabledByDefault; private final List _after; private final List _before; - private final ClassMatcher _system; - private final ClassMatcher _server; + private final ClassMatcher _protected; + private final ClassMatcher _hidden; public static class Builder { @@ -88,7 +90,7 @@ public Builder addDependents(Class... classes) /** * Protect classes from modification by the web application by adding them - * to the {@link WebAppConfiguration#getSystemClasses()} + * to the {@link WebAppConfiguration#getProtectedClasses()} * * @param classes classname or package pattern */ @@ -100,7 +102,7 @@ public Builder protect(String... classes) /** * Hide classes from the web application by adding them - * to the {@link WebAppConfiguration#getServerClasses()} + * to the {@link WebAppConfiguration#getHiddenClasses()} * * @param classes classname or package pattern */ @@ -112,7 +114,7 @@ public Builder hide(String... classes) /** * Expose classes to the web application by adding them - * as exclusions to the {@link WebAppConfiguration#getServerClasses()} + * as exclusions to the {@link WebAppConfiguration#getHiddenClasses()} * * @param classes classname or package pattern */ @@ -129,9 +131,9 @@ public Builder expose(String... classes) /** * Protect classes from modification by the web application by adding them - * to the {@link WebAppConfiguration#getSystemClasses()} and + * to the {@link WebAppConfiguration#getProtectedClasses()} and * expose them to the web application by adding them - * as exclusions to the {@link WebAppConfiguration#getServerClasses()} + * as exclusions to the {@link WebAppConfiguration#getHiddenClasses()} * * @param classes classname or package pattern */ @@ -154,8 +156,8 @@ protected AbstractConfiguration(Builder builder) _enabledByDefault = builder._enabledByDefault; _after = List.copyOf(builder._after); _before = List.copyOf(builder._before); - _system = new ClassMatcher(builder._system).asImmutable(); - _server = new ClassMatcher(builder._server).asImmutable(); + _protected = new ClassMatcher(builder._system).asImmutable(); + _hidden = new ClassMatcher(builder._server).asImmutable(); } @Override @@ -171,15 +173,15 @@ public Collection getDependencies() } @Override - public ClassMatcher getSystemClasses() + public ClassMatcher getProtectedClasses() { - return _system; + return _protected; } @Override - public ClassMatcher getServerClasses() + public ClassMatcher getHiddenClasses() { - return _server; + return _hidden; } @Override diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java index 23a625dcd1c3..3eb611146b6f 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java @@ -21,7 +21,6 @@ /** * @deprecated Use org.eclipse.jetty.util.ClassMatcher */ - @Deprecated(since = "12.0.8", forRemoval = true) public class ClassMatcher extends org.eclipse.jetty.util.ClassMatcher { diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/Configuration.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/Configuration.java index ca8e4934ecdb..1f172c43fe31 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/Configuration.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/Configuration.java @@ -17,6 +17,7 @@ import java.util.Collections; import java.util.ServiceLoader; +import org.eclipse.jetty.util.ClassMatcher; import org.eclipse.jetty.util.TopologicalSort; /** @@ -43,8 +44,8 @@ * (eg {@link JndiConfiguration}, {@link JaasConfiguration}} etc.) can be added or removed without concern * for ordering. *

- *

Also since Jetty-9.4, Configurations are responsible for providing {@link #getServerClasses()} and - * {@link #getSystemClasses()} to configure the {@link WebAppClassLoader} for each context. + *

Also since Jetty-9.4, Configurations are responsible for providing {@link #getHiddenClasses()} and + * {@link #getProtectedClasses()} to configure the {@link WebAppClassLoader} for each context. *

*/ public interface Configuration @@ -93,25 +94,43 @@ default Collection getDependents() } /** - * Get the system classes associated with this Configuration. + * Get the system (protected) classes associated with this Configuration. * * @return ClassMatcher of system classes. */ - default ClassMatcher getSystemClasses() + default ClassMatcher getProtectedClasses() { return new ClassMatcher(); } /** - * Get the system classes associated with this Configuration. + * Get the server (hidden) classes associated with this Configuration. * * @return ClassMatcher of server classes. */ - default ClassMatcher getServerClasses() + default ClassMatcher getHiddenClasses() { return new ClassMatcher(); } + /** + * @deprecated use {@link #getProtectedClasses()} instead + */ + @Deprecated(since = "12.0.8", forRemoval = true) + default org.eclipse.jetty.ee10.webapp.ClassMatcher getSystemClasses() + { + return new org.eclipse.jetty.ee10.webapp.ClassMatcher(getProtectedClasses()); + } + + /** + * @deprecated use {@link #getHiddenClasses()} instead + */ + @Deprecated(since = "12.0.8", forRemoval = true) + default org.eclipse.jetty.ee10.webapp.ClassMatcher getServerClasses() + { + return new org.eclipse.jetty.ee10.webapp.ClassMatcher(getHiddenClasses()); + } + /** * Set up for configuration. *

diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppClassLoader.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppClassLoader.java index a1ad3d32d9af..a2bbd6aab13a 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppClassLoader.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppClassLoader.java @@ -20,28 +20,24 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.nio.file.Files; import java.nio.file.Path; import java.security.CodeSource; import java.security.PermissionCollection; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.Enumeration; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.StringTokenizer; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.stream.Stream; import org.eclipse.jetty.util.ClassVisibilityChecker; import org.eclipse.jetty.util.FileID; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.TypeUtil; -import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceCollators; import org.eclipse.jetty.util.resource.ResourceFactory; @@ -115,9 +111,33 @@ public interface Context extends ClassVisibilityChecker List getExtraClasspath(); - boolean isHiddenResource(String name, URL parentUrl); + /** + * @deprecated use {@link #isHiddenResource(String, URL)} + */ + @Deprecated(since = "12.0.8", forRemoval = true) + default boolean isServerResource(String name, URL parentUrl) + { + return isHiddenResource(name, parentUrl); + } - boolean isProtectedResource(String name, URL webappUrl); + /** + * @deprecated use {@link #isProtectedResource(String, URL)} + */ + @Deprecated(since = "12.0.8", forRemoval = true) + default boolean isSystemResource(String name, URL webappUrl) + { + return isProtectedResource(name, webappUrl); + } + + default boolean isHiddenResource(String name, URL parentUrl) + { + return false; + } + + default boolean isProtectedResource(String name, URL webappUrl) + { + return false; + } } /** @@ -526,7 +546,6 @@ protected Class loadAsResource(final String name, boolean checkSystemResource if (webappUrl != null && (!checkSystemResource || !_context.isProtectedResource(name, webappUrl))) { - webappClass = this.foundClass(name, webappUrl); resolveClass(webappClass); if (LOG.isDebugEnabled()) diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppContext.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppContext.java index 473eca9595b0..53081d51dc39 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppContext.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppContext.java @@ -425,7 +425,7 @@ public void preConfigure() throws Exception // Add the known server class inclusions for all known configurations for (Configuration configuration : Configurations.getKnown()) { - _hiddenClasses.include(configuration.getServerClasses().getInclusions()); + _hiddenClasses.include(configuration.getHiddenClasses().getInclusions()); } // Setup Configuration classes for this webapp! @@ -433,8 +433,8 @@ public void preConfigure() throws Exception _configurations.sort(); for (Configuration configuration : _configurations) { - _protectedClasses.add(configuration.getSystemClasses().getPatterns()); - _hiddenClasses.exclude(configuration.getServerClasses().getExclusions()); + _protectedClasses.add(configuration.getProtectedClasses().getPatterns()); + _hiddenClasses.exclude(configuration.getHiddenClasses().getExclusions()); } // Configure classloader @@ -620,9 +620,9 @@ public PermissionCollection getPermissions() } /** - * Set the hidden (aka server) classes patterns. + * Set the hidden (server) classes patterns. *

- * These classes/packages are used to implement the server and are hiddenClasses + * These classes/packages are used to implement the server and are hidden * from the context. If the context needs to load these classes, it must have its * own copy of them in WEB-INF/lib or WEB-INF/classes. * @@ -635,7 +635,7 @@ public void setHiddenClassMatcher(ClassMatcher hiddenClasses) } /** - * Set the protected (aka system) classes patterns. + * Set the protected (system) classes patterns. *

* These classes/packages are provided by the JVM and * cannot be replaced by classes of the same name from WEB-INF, @@ -680,7 +680,7 @@ public ClassMatcher getProtectedClassMatcher() } /** - * @return The ClassMatcher used to match Server (hiddenClasses) classes + * @return The ClassMatcher used to match Server (hidden) classes */ public ClassMatcher getHiddenClassMatcher() { @@ -693,7 +693,7 @@ public String[] getProtectedClasses() return _protectedClasses.getPatterns(); } - @ManagedAttribute(value = "classes and packages hiddenClasses by the context classloader", readonly = true) + @ManagedAttribute(value = "classes and packages hidden by the context classloader", readonly = true) public String[] getHiddenClasses() { return _hiddenClasses.getPatterns(); @@ -727,56 +727,54 @@ public boolean isProtectedResource(String name, URL url) * @deprecated use {@link #setHiddenClassMatcher(ClassMatcher)} */ @Deprecated(since = "12.0.8", forRemoval = true) - public void setServerClassMatcher(ClassMatcher serverClasses) + public void setServerClassMatcher(org.eclipse.jetty.ee10.webapp.ClassMatcher serverClasses) { - _hiddenClasses.clear(); - _hiddenClasses.add(serverClasses.getPatterns()); + setHiddenClassMatcher(serverClasses); } /** * @deprecated use {@link #setProtectedClassMatcher(ClassMatcher)} */ @Deprecated(since = "12.0.8", forRemoval = true) - public void setSystemClassMatcher(ClassMatcher systemClasses) + public void setSystemClassMatcher(org.eclipse.jetty.ee10.webapp.ClassMatcher systemClasses) { - _protectedClasses.clear(); - _protectedClasses.add(systemClasses.getPatterns()); + setProtectedClassMatcher(systemClasses); } /** * @deprecated use {@link #addHiddenClassMatcher(ClassMatcher)} */ @Deprecated(since = "12.0.8", forRemoval = true) - public void addServerClassMatcher(ClassMatcher serverClasses) + public void addServerClassMatcher(org.eclipse.jetty.ee10.webapp.ClassMatcher serverClasses) { - _hiddenClasses.add(serverClasses.getPatterns()); + addHiddenClassMatcher(serverClasses); } /** * @deprecated use {@link #addProtectedClassMatcher(ClassMatcher)} */ @Deprecated(since = "12.0.8", forRemoval = true) - public void addSystemClassMatcher(ClassMatcher systemClasses) + public void addSystemClassMatcher(org.eclipse.jetty.ee10.webapp.ClassMatcher systemClasses) { - _protectedClasses.add(systemClasses.getPatterns()); + addProtectedClassMatcher(systemClasses); } /** * @deprecated use {@link #getProtectedClassMatcher()} */ @Deprecated(since = "12.0.8", forRemoval = true) - public ClassMatcher getSystemClassMatcher() + public org.eclipse.jetty.ee10.webapp.ClassMatcher getSystemClassMatcher() { - return _protectedClasses; + return new org.eclipse.jetty.ee10.webapp.ClassMatcher(getProtectedClassMatcher()); } /** * @deprecated use {@link #getHiddenClassMatcher()} */ @Deprecated(since = "12.0.8", forRemoval = true) - public ClassMatcher getServerClassMatcher() + public org.eclipse.jetty.ee10.webapp.ClassMatcher getServerClassMatcher() { - return _hiddenClasses; + return new org.eclipse.jetty.ee10.webapp.ClassMatcher(getHiddenClassMatcher()); } /** @@ -785,7 +783,7 @@ public ClassMatcher getServerClassMatcher() @Deprecated(since = "12.0.8", forRemoval = true) public String[] getSystemClasses() { - return _protectedClasses.getPatterns(); + return getProtectedClasses(); } /** @@ -794,7 +792,7 @@ public String[] getSystemClasses() @Deprecated(since = "12.0.8", forRemoval = true) public String[] getServerClasses() { - return _hiddenClasses.getPatterns(); + return getHiddenClasses(); } /** @@ -803,7 +801,7 @@ public String[] getServerClasses() @Deprecated(since = "12.0.8", forRemoval = true) public boolean isServerClass(Class clazz) { - return _hiddenClasses.match(clazz); + return isHiddenClass(clazz); } /** @@ -812,25 +810,7 @@ public boolean isServerClass(Class clazz) @Deprecated(since = "12.0.8", forRemoval = true) public boolean isSystemClass(Class clazz) { - return _protectedClasses.match(clazz); - } - - /** - * @deprecated use {@link #isHiddenResource(String, URL)} - */ - @Deprecated(since = "12.0.8", forRemoval = true) - public boolean isServerResource(String name, URL url) - { - return _hiddenClasses.match(name, url); - } - - /** - * @deprecated use {@link #isProtectedResource(String, URL)} - */ - @Deprecated(since = "12.0.8", forRemoval = true) - public boolean isSystemResource(String name, URL url) - { - return _protectedClasses.match(name, url); + return isProtectedClass(clazz); } @Override diff --git a/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/WebAppClassLoaderTest.java b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/WebAppClassLoaderTest.java index c08c71724ea8..b3a55912f23b 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/WebAppClassLoaderTest.java +++ b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/WebAppClassLoaderTest.java @@ -75,7 +75,7 @@ public void init() throws Exception } @AfterEach - public void afterEach() throws Exception + public void afterEach() { IO.close(_loader); LifeCycle.stop(_server); @@ -315,7 +315,6 @@ public void testResources() throws Exception resources = Collections.list(_loader.getResources("org/acme/resource.txt")); - expected.clear(); expected.add(webappWebInfLibAcme); expected.add(webappWebInfClasses); expected.add(targetTestClasses); diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/ClassMatcher.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/ClassMatcher.java index d382b4cf4ac1..58ac7a04cadb 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/ClassMatcher.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/ClassMatcher.java @@ -18,11 +18,6 @@ import org.eclipse.jetty.util.IncludeExcludeSet; -/** - * @deprecated Use org.eclipse.jetty.util.ClassMatcher - */ - -@Deprecated(since = "12.0.8", forRemoval = true) public class ClassMatcher extends org.eclipse.jetty.util.ClassMatcher { public ClassMatcher() diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/Configuration.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/Configuration.java index bc0b23f3a682..39fa82a0c5c0 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/Configuration.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/Configuration.java @@ -104,7 +104,7 @@ default ClassMatcher getSystemClasses() } /** - * Get the system classes associated with this Configuration. + * Get the server classes associated with this Configuration. * * @return ClassMatcher of server classes. */ diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppClassLoader.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppClassLoader.java index f474fa96ceda..01e809657285 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppClassLoader.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppClassLoader.java @@ -20,28 +20,24 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.nio.file.Files; import java.nio.file.Path; import java.security.CodeSource; import java.security.PermissionCollection; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.Enumeration; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.StringTokenizer; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.stream.Stream; import org.eclipse.jetty.util.ClassVisibilityChecker; import org.eclipse.jetty.util.FileID; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.TypeUtil; -import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceCollators; import org.eclipse.jetty.util.resource.ResourceFactory; @@ -530,7 +526,6 @@ protected Class loadAsResource(final String name, boolean checkSystemResource if (webappUrl != null && (!checkSystemResource || !_context.isSystemResource(name, webappUrl))) { - webappClass = this.foundClass(name, webappUrl); resolveClass(webappClass); if (LOG.isDebugEnabled()) diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppContext.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppContext.java index 574cd0969a6e..6e63474b41ba 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppContext.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppContext.java @@ -55,7 +55,6 @@ import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.Attributes; -import org.eclipse.jetty.util.ClassMatcher; import org.eclipse.jetty.util.ExceptionUtil; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.StringUtil; @@ -673,7 +672,7 @@ public PermissionCollection getPermissions() /** * Set the server classes patterns. *

- * Server classes/packages are classes used to implement the server and are hidden + * These classes/packages are used to implement the server and are hidden * from the context. If the context needs to load these classes, it must have its * own copy of them in WEB-INF/lib or WEB-INF/classes. * @@ -688,7 +687,7 @@ public void setServerClassMatcher(ClassMatcher serverClasses) /** * Set the system classes patterns. *

- * System classes/packages are classes provided by the JVM and that + * These classes/packages are provided by the JVM and * cannot be replaced by classes of the same name from WEB-INF, * regardless of the value of {@link #setParentLoaderPriority(boolean)}. * @@ -753,11 +752,23 @@ public String[] getServerClasses() @Override public boolean isHiddenClass(Class clazz) { - return _serverClasses.match(clazz); + return isServerClass(clazz); } @Override public boolean isProtectedClass(Class clazz) + { + return isSystemClass(clazz); + } + + @Override + public boolean isServerClass(Class clazz) + { + return _serverClasses.match(clazz); + } + + @Override + public boolean isSystemClass(Class clazz) { return _systemClasses.match(clazz); } diff --git a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppClassLoaderTest.java b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppClassLoaderTest.java index af4e50031f41..6ab704340a11 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppClassLoaderTest.java +++ b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppClassLoaderTest.java @@ -26,7 +26,6 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.eclipse.jetty.util.ClassMatcher; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.resource.Resource; @@ -75,7 +74,7 @@ public void init() throws Exception } @AfterEach - public void afterEach() throws Exception + public void afterEach() { IO.close(_loader); LifeCycle.stop(_server); @@ -315,7 +314,6 @@ public void testResources() throws Exception resources = Collections.list(_loader.getResources("org/acme/resource.txt")); - expected.clear(); expected.add(webappWebInfLibAcme); expected.add(webappWebInfClasses); expected.add(targetTestClasses);