in shenyu-web/src/main/java/org/apache/shenyu/web/loader/ShenyuPluginLoader.java [112:160]
public List<ShenyuLoaderResult> loadExtendPlugins(final String path) throws IOException {
File[] jarFiles = ShenyuPluginPathBuilder.getPluginFile(path).listFiles(file -> file.getName().endsWith(".jar"));
if (Objects.isNull(jarFiles)) {
return Collections.emptyList();
}
List<ShenyuLoaderResult> results = new ArrayList<>();
boolean loadNewPlugin = false;
for (File each : jarFiles) {
if (jars.stream().map(PluginJar::absolutePath).filter(StringUtils::hasText).anyMatch(p -> p.equals(each.getAbsolutePath()))) {
continue;
}
loadNewPlugin = true;
JarFile jar = new JarFile(each, true);
jars.add(new PluginJar(jar, each));
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
String entryName = jarEntry.getName();
if (entryName.endsWith(".class") && !entryName.contains("$")) {
String className = entryName.substring(0, entryName.length() - 6).replaceAll("/", ".");
if (checkExistence(className)) {
LOG.warn("The same plugin {} already exists", className);
} else {
names.add(className);
}
}
}
}
if (!loadNewPlugin) {
return results;
}
names.forEach(className -> {
Object instance;
try {
if (!uploadedJarClassByteArrayCache.containsKey(className)) {
instance = getOrCreateSpringBean(className);
if (Objects.nonNull(instance)) {
results.add(buildResult(instance));
LOG.info("The class successfully loaded into a ext-plugin {} is registered as a spring bean", className);
}
}
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
LOG.warn("Registering ext-plugins succeeds spring bean fails:{}", className);
}
});
return results;
}