fix: plugin null bugs

This commit is contained in:
CaiHQ 2021-11-08 14:18:41 +08:00
parent 1a444240a0
commit 305cd51854

View File

@ -131,10 +131,10 @@ public class CMHttpServer {
FileActions.setTextFileSuffixes(cmdConf.textFileSuffixes);
// plugins
CMHttpHandler.wsPluginActions = cmdConf.wsPluginActions.split(",");
MasterClientFrameHandler.clientToAgentPlugins = cmdConf.clientToAgentPlugins.split(",");
NodeCenterClientHandler.clientToClusterPlugins = cmdConf.clientToClusterPlugins.split(",");
TCPClientFrameHandler.tcpPlugins = cmdConf.tcpPlugins.split(",");
CMHttpHandler.wsPluginActions = parseStrAsList(cmdConf.wsPluginActions);
MasterClientFrameHandler.clientToAgentPlugins = parseStrAsList(cmdConf.clientToAgentPlugins);
NodeCenterClientHandler.clientToClusterPlugins = parseStrAsList(cmdConf.clientToClusterPlugins);
TCPClientFrameHandler.tcpPlugins = parseStrAsList(cmdConf.tcpPlugins);
if (!cmdConf.debug.isEmpty()) {
try {
@ -152,6 +152,12 @@ public class CMHttpServer {
}
}
private static String[] parseStrAsList(String str) {
if (str == null)
return new String[]{};
return str.split(",");
}
private static void addDirToPath(String s) {
try {
LOGGER.info("add to path: " + s);
@ -251,14 +257,19 @@ public class CMHttpServer {
// if (ContractManager.reconnectPort < 0) ContractManager.reconnectPort = 1630;
File[] pluginJar = new File("./pluginLib/")
.listFiles(pathname -> pathname.getName().endsWith(".jar"));
URL[] urls = new URL[pluginJar.length];
for (int i = 0; i < pluginJar.length; i++) {
try {
urls[i] = pluginJar[i].toURI().toURL();
LOGGER.info("add plugin:" + pluginJar[i].getName());
} catch (MalformedURLException e) {
e.printStackTrace();
URL[] urls;
if (pluginJar != null && pluginJar.length > 0) {
urls = new URL[pluginJar.length];
for (int i = 0; i < pluginJar.length; i++) {
try {
urls[i] = pluginJar[i].toURI().toURL();
LOGGER.info("add plugin:" + pluginJar[i].getName());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
} else {
urls = new URL[]{};
}
pluginLoader = new URLClassLoader(urls, CMHttpServer.class.getClassLoader());
if (port >= 18000 && port < 18100) {