aboutsummaryrefslogtreecommitdiff
path: root/spark-velocity/src/main
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2021-11-14 19:10:46 +0000
committerLuck <git@lucko.me>2021-11-14 19:10:46 +0000
commit49fc0ba47fac077a2fe965c44fd382a1ab02089c (patch)
tree2261bfdb4fd50b56a51fc1386eb4ac77d2fee939 /spark-velocity/src/main
parenteed8b8d38260fb16f114ab856e486904ae6dc937 (diff)
downloadspark-49fc0ba47fac077a2fe965c44fd382a1ab02089c.tar.gz
spark-49fc0ba47fac077a2fe965c44fd382a1ab02089c.tar.bz2
spark-49fc0ba47fac077a2fe965c44fd382a1ab02089c.zip
Improve Velocity ClassSourceLookup
Diffstat (limited to 'spark-velocity/src/main')
-rw-r--r--spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityClassSourceLookup.java20
1 files changed, 12 insertions, 8 deletions
diff --git a/spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityClassSourceLookup.java b/spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityClassSourceLookup.java
index 4989bf4..bcb8176 100644
--- a/spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityClassSourceLookup.java
+++ b/spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityClassSourceLookup.java
@@ -27,6 +27,9 @@ import me.lucko.spark.common.util.ClassSourceLookup;
import org.checkerframework.checker.nullness.qual.Nullable;
+import java.util.HashMap;
+import java.util.Map;
+
public class VelocityClassSourceLookup extends ClassSourceLookup.ByClassLoader {
private static final Class<?> PLUGIN_CLASS_LOADER;
@@ -38,21 +41,22 @@ public class VelocityClassSourceLookup extends ClassSourceLookup.ByClassLoader {
}
}
- private final PluginManager pluginManager;
+ private final Map<ClassLoader, String> classLoadersToPlugin;
public VelocityClassSourceLookup(PluginManager pluginManager) {
- this.pluginManager = pluginManager;
+ this.classLoadersToPlugin = new HashMap<>();
+ for (PluginContainer plugin : pluginManager.getPlugins()) {
+ plugin.getInstance().ifPresent(instance -> {
+ String id = plugin.getDescription().getName().orElseGet(() -> plugin.getDescription().getId());
+ this.classLoadersToPlugin.put(instance.getClass().getClassLoader(), id);
+ });
+ }
}
@Override
public @Nullable String identify(ClassLoader loader) {
if (PLUGIN_CLASS_LOADER.isInstance(loader)) {
- for (PluginContainer plugin : this.pluginManager.getPlugins()) {
- Object instance = plugin.getInstance().orElse(null);
- if (instance != null && instance.getClass().getClassLoader() == loader) {
- return plugin.getDescription().getName().orElseGet(() -> plugin.getDescription().getId());
- }
- }
+ return this.classLoadersToPlugin.get(loader);
}
return null;
}