geforkt von Mirrors/Paper
Add support for transitive depends in load access warning
By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Ursprung
d1676c9727
Commit
99378a8c91
@ -1,6 +1,10 @@
|
||||
package org.bukkit.plugin;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.graph.GraphBuilder;
|
||||
import com.google.common.graph.Graphs;
|
||||
import com.google.common.graph.MutableGraph;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
@ -44,6 +48,7 @@ public final class SimplePluginManager implements PluginManager {
|
||||
private final Map<Pattern, PluginLoader> fileAssociations = new HashMap<Pattern, PluginLoader>();
|
||||
private final List<Plugin> plugins = new ArrayList<Plugin>();
|
||||
private final Map<String, Plugin> lookupNames = new HashMap<String, Plugin>();
|
||||
private MutableGraph<String> dependencyGraph = GraphBuilder.directed().build();
|
||||
private File updateDirectory;
|
||||
private final SimpleCommandMap commandMap;
|
||||
private final Map<String, Permission> permissions = new HashMap<String, Permission>();
|
||||
@ -168,11 +173,19 @@ public final class SimplePluginManager implements PluginManager {
|
||||
} else {
|
||||
softDependencies.put(description.getName(), new LinkedList<String>(softDependencySet));
|
||||
}
|
||||
|
||||
for (String depend : softDependencySet) {
|
||||
dependencyGraph.putEdge(description.getName(), depend);
|
||||
}
|
||||
}
|
||||
|
||||
Collection<String> dependencySet = description.getDepend();
|
||||
if (dependencySet != null && !dependencySet.isEmpty()) {
|
||||
dependencies.put(description.getName(), new LinkedList<String>(dependencySet));
|
||||
|
||||
for (String depend : dependencySet) {
|
||||
dependencyGraph.putEdge(description.getName(), depend);
|
||||
}
|
||||
}
|
||||
|
||||
Collection<String> loadBeforeSet = description.getLoadBefore();
|
||||
@ -186,6 +199,8 @@ public final class SimplePluginManager implements PluginManager {
|
||||
shortSoftDependency.add(description.getName());
|
||||
softDependencies.put(loadBeforeTarget, shortSoftDependency);
|
||||
}
|
||||
|
||||
dependencyGraph.putEdge(loadBeforeTarget, description.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -480,6 +495,7 @@ public final class SimplePluginManager implements PluginManager {
|
||||
disablePlugins();
|
||||
plugins.clear();
|
||||
lookupNames.clear();
|
||||
dependencyGraph = GraphBuilder.directed().build();
|
||||
HandlerList.unregisterAll();
|
||||
fileAssociations.clear();
|
||||
permissions.clear();
|
||||
@ -780,6 +796,13 @@ public final class SimplePluginManager implements PluginManager {
|
||||
return new HashSet<Permission>(permissions.values());
|
||||
}
|
||||
|
||||
public boolean isTransitiveDepend(@NotNull PluginDescriptionFile plugin, @NotNull Plugin depend) {
|
||||
Preconditions.checkArgument(plugin != null, "plugin");
|
||||
Preconditions.checkArgument(depend != null, "depend");
|
||||
|
||||
return Graphs.reachableNodes(dependencyGraph, plugin.getName()).contains(depend.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useTimings() {
|
||||
return useTimings;
|
||||
|
@ -22,6 +22,7 @@ import java.util.logging.Level;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.plugin.InvalidPluginException;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -113,12 +114,15 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
|
||||
if (provider != plugin
|
||||
&& !seenIllegalAccess.contains(providerName)
|
||||
&& !description.getDepend().contains(providerName)
|
||||
&& !description.getSoftDepend().contains(providerName)
|
||||
&& !provider.getDescription().getLoadBefore().contains(description.getName())) {
|
||||
&& !((SimplePluginManager) loader.server.getPluginManager()).isTransitiveDepend(description, provider)) {
|
||||
|
||||
seenIllegalAccess.add(providerName);
|
||||
plugin.getLogger().log(Level.WARNING, "Loaded class {0} from {1} which is not a depend, softdepend or loadbefore of this plugin.", new Object[]{name, provider.getDescription().getFullName()});
|
||||
if (plugin != null) {
|
||||
plugin.getLogger().log(Level.WARNING, "Loaded class {0} from {1} which is not a depend, softdepend or loadbefore of this plugin.", new Object[]{name, provider.getDescription().getFullName()});
|
||||
} else {
|
||||
// In case the bad access occurs on construction
|
||||
loader.server.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend, softdepend or loadbefore of this plugin.", new Object[]{description.getName(), name, provider.getDescription().getFullName()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren