Skip to content

Commit

Permalink
EOL Global-Mask-Classes (#8785)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Dec 16, 2023
1 parent c4b9e81 commit 3f18801
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
17 changes: 2 additions & 15 deletions core/src/main/java/hudson/ClassicPluginStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ public class ClassicPluginStrategy implements PluginStrategy {

private final PluginManager pluginManager;

/**
* All the plugins eventually delegate this classloader to load core, servlet APIs, and SE runtime.
*/
private final MaskingClassLoader coreClassLoader = new MaskingClassLoader(getClass().getClassLoader());

public ClassicPluginStrategy(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}
Expand Down Expand Up @@ -235,16 +230,8 @@ private static Manifest loadLinkedManifest(File archive) throws IOException {

fix(atts, optionalDependencies);

// Register global classpath mask. This is useful for hiding JavaEE APIs that you might see from the container,
// such as database plugin for JPA support. The Mask-Classes attribute is insufficient because those classes
// also need to be masked by all the other plugins that depend on the database plugin.
String masked = atts.getValue("Global-Mask-Classes");
if (masked != null) {
for (String pkg : masked.trim().split("[ \t\r\n]+"))
coreClassLoader.add(pkg);
}

ClassLoader dependencyLoader = new DependencyClassLoader(coreClassLoader, archive, Util.join(dependencies, optionalDependencies), pluginManager);
ClassLoader dependencyLoader = new DependencyClassLoader(
getClass().getClassLoader(), archive, Util.join(dependencies, optionalDependencies), pluginManager);
dependencyLoader = getBaseClassLoader(atts, dependencyLoader);

return new PluginWrapper(pluginManager, archive, manifest, baseResourceURL,
Expand Down
20 changes: 6 additions & 14 deletions core/src/main/java/hudson/util/MaskingClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

/**
* {@link ClassLoader} that masks a specified set of classes
Expand All @@ -46,9 +46,9 @@ public class MaskingClassLoader extends ClassLoader {
/**
* Prefix of the packages that should be hidden.
*/
private final List<String> masksClasses = new CopyOnWriteArrayList<>();
private final List<String> masksClasses;

private final List<String> masksResources = new CopyOnWriteArrayList<>();
private final List<String> masksResources;

static {
registerAsParallelCapable();
Expand All @@ -60,14 +60,13 @@ public MaskingClassLoader(ClassLoader parent, String... masks) {

public MaskingClassLoader(ClassLoader parent, Collection<String> masks) {
super(parent);
this.masksClasses.addAll(masks);
this.masksClasses = List.copyOf(masks);

/*
* The name of a resource is a '/'-separated path name
*/
for (String mask : masks) {
masksResources.add(mask.replace('.', '/'));
}
this.masksResources =
masks.stream().map(mask -> mask.replace('.', '/')).collect(Collectors.toUnmodifiableList());
}

@Override
Expand All @@ -94,13 +93,6 @@ public Enumeration<URL> getResources(String name) throws IOException {
return super.getResources(name);
}

public void add(String prefix) {
masksClasses.add(prefix);
if (prefix != null) {
masksResources.add(prefix.replace('.', '/'));
}
}

private boolean isMasked(String name) {
for (String mask : masksResources) {
if (name.startsWith(mask))
Expand Down

0 comments on commit 3f18801

Please sign in to comment.