Skip to content

Commit

Permalink
Addendum to #11566. (#11722)
Browse files Browse the repository at this point in the history
* 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 <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed May 2, 2024
1 parent cfee4fe commit 42ba415
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 103 deletions.
Expand Up @@ -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)
Expand Down
Expand Up @@ -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
*
Expand All @@ -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.
Expand All @@ -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
*
Expand All @@ -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.
Expand Down
Expand Up @@ -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;
Expand All @@ -33,16 +31,16 @@ 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.
if (CdiConfiguration.class.getClassLoader().getResource("META-INF/services/jakarta.enterprise.inject.spi.CDIProvider") == null)
return new String[]{"jakarta.enterprise.", "jakarta.decorator."};
return new String[0];
}
}
}
Expand Up @@ -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<String> _after;
private final List<String> _before;
private final ClassMatcher _system;
private final ClassMatcher _server;
private final ClassMatcher _protected;
private final ClassMatcher _hidden;

public static class Builder
{
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
Expand All @@ -171,15 +173,15 @@ public Collection<String> getDependencies()
}

@Override
public ClassMatcher getSystemClasses()
public ClassMatcher getProtectedClasses()
{
return _system;
return _protected;
}

@Override
public ClassMatcher getServerClasses()
public ClassMatcher getHiddenClasses()
{
return _server;
return _hidden;
}

@Override
Expand Down
Expand Up @@ -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
{
Expand Down
Expand Up @@ -17,6 +17,7 @@
import java.util.Collections;
import java.util.ServiceLoader;

import org.eclipse.jetty.util.ClassMatcher;
import org.eclipse.jetty.util.TopologicalSort;

/**
Expand All @@ -43,8 +44,8 @@
* (eg {@link JndiConfiguration}, {@link JaasConfiguration}} etc.) can be added or removed without concern
* for ordering.
* </p>
* <p>Also since Jetty-9.4, Configurations are responsible for providing {@link #getServerClasses()} and
* {@link #getSystemClasses()} to configure the {@link WebAppClassLoader} for each context.
* <p>Also since Jetty-9.4, Configurations are responsible for providing {@link #getHiddenClasses()} and
* {@link #getProtectedClasses()} to configure the {@link WebAppClassLoader} for each context.
* </p>
*/
public interface Configuration
Expand Down Expand Up @@ -93,25 +94,43 @@ default Collection<String> 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.
* <p>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -115,9 +111,33 @@ public interface Context extends ClassVisibilityChecker

List<Resource> 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;
}
}

/**
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 42ba415

Please sign in to comment.