From 42ba41531897178348c4cf0328c4609adfd8874d Mon Sep 17 00:00:00 2001
From: Simone Bordet
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
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
- * 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);