|
|
@ -30,8 +30,10 @@ import java.net.URLClassLoader; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
import java.util.ServiceLoader; |
|
|
|
import java.util.ServiceLoader; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -80,7 +82,7 @@ public class DolphinPluginLoader { |
|
|
|
|
|
|
|
|
|
|
|
public void loadPlugins() |
|
|
|
public void loadPlugins() |
|
|
|
throws Exception { |
|
|
|
throws Exception { |
|
|
|
for (File file : listPluginDirs(installedPluginsDir)) { |
|
|
|
for (File file : listPluginInstanceDirs(installedPluginsDir)) { |
|
|
|
if (file.isDirectory()) { |
|
|
|
if (file.isDirectory()) { |
|
|
|
loadPlugin(file.getAbsolutePath()); |
|
|
|
loadPlugin(file.getAbsolutePath()); |
|
|
|
} |
|
|
|
} |
|
|
@ -145,7 +147,7 @@ public class DolphinPluginLoader { |
|
|
|
throws Exception { |
|
|
|
throws Exception { |
|
|
|
logger.info("Classpath for {}:", dir.getName()); |
|
|
|
logger.info("Classpath for {}:", dir.getName()); |
|
|
|
List<URL> urls = new ArrayList<>(); |
|
|
|
List<URL> urls = new ArrayList<>(); |
|
|
|
for (File file : listPluginDirs(dir)) { |
|
|
|
for (File file : listPluginInstanceJars(dir)) { |
|
|
|
logger.info(" {}", file); |
|
|
|
logger.info(" {}", file); |
|
|
|
urls.add(file.toURI().toURL()); |
|
|
|
urls.add(file.toURI().toURL()); |
|
|
|
} |
|
|
|
} |
|
|
@ -172,14 +174,30 @@ public class DolphinPluginLoader { |
|
|
|
return new DolphinPluginClassLoader(urls, parent, DOLPHIN_SPI_PACKAGES); |
|
|
|
return new DolphinPluginClassLoader(urls, parent, DOLPHIN_SPI_PACKAGES); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static List<File> listPluginDirs(File installedPluginsDir) { |
|
|
|
private static List<File> listPluginInstanceDirs(File installedPluginsDir) { |
|
|
|
if (installedPluginsDir != null && installedPluginsDir.isDirectory()) { |
|
|
|
if (installedPluginsDir != null && installedPluginsDir.isDirectory()) { |
|
|
|
File[] files = installedPluginsDir.listFiles(); |
|
|
|
File[] files = installedPluginsDir.listFiles(); |
|
|
|
if (files != null) { |
|
|
|
if (files != null) { |
|
|
|
|
|
|
|
Optional<File> isNotDir = Arrays.stream(files).filter(file -> !file.isDirectory()).findAny(); |
|
|
|
|
|
|
|
if (isNotDir.isPresent()) { |
|
|
|
|
|
|
|
return ImmutableList.of(installedPluginsDir); |
|
|
|
|
|
|
|
} else { |
|
|
|
Arrays.sort(files); |
|
|
|
Arrays.sort(files); |
|
|
|
return ImmutableList.copyOf(files); |
|
|
|
return ImmutableList.copyOf(files); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ImmutableList.of(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<File> listPluginInstanceJars(File installedPluginsDir) { |
|
|
|
|
|
|
|
if (installedPluginsDir != null && installedPluginsDir.isDirectory()) { |
|
|
|
|
|
|
|
File[] files = installedPluginsDir.listFiles(); |
|
|
|
|
|
|
|
if (files != null) { |
|
|
|
|
|
|
|
return ImmutableList.copyOf(Arrays.stream(files).filter(file -> file.isFile() && file.getName().endsWith(".jar")) |
|
|
|
|
|
|
|
.collect(Collectors.toList())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return ImmutableList.of(); |
|
|
|
return ImmutableList.of(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|