Skip to content

Commit

Permalink
add custom plugin library loader
Browse files Browse the repository at this point in the history
  • Loading branch information
LinzN committed Mar 19, 2023
1 parent 6613254 commit 113926d
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,44 @@ private STEMPlugin initPlugin(String pluginName, String classPath, String versio
} catch (ClassCastException ex) {
throw new InvalidPluginException("Main class `" + classPath + "' does not extend Plugin");
}
this.loadPluginLibraryFiles(pluginName);

STEMPlugin plugin = pluginClass.getDeclaredConstructor().newInstance();
plugin.setUp(pluginName, version, buildJobName, buildNumber, classPath);
return plugin;
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new InvalidPluginException("No public constructor");
} catch (InstantiationException ex) {
throw new InvalidPluginException("Abnormal plugin type");
} catch (MalformedURLException e) {
throw new InvalidPluginException("Plugin libraries not loaded");
}
}

public synchronized void loadPluginLibraryFiles(String pluginName) throws MalformedURLException {
File pluginDirectory = new File(PluginModule.pluginDirectory, pluginName);
if (pluginDirectory.exists() && pluginDirectory.isDirectory()) {
File dependencyDirectory = new File(pluginDirectory, "libraries");
if (dependencyDirectory.exists() && dependencyDirectory.isDirectory()) {
if (dependencyDirectory.exists() && dependencyDirectory.isDirectory()) {
File[] files = dependencyDirectory.listFiles();
STEMSystemApp.LOGGER.INFO("Library directory found for plugin: " + pluginName);
for (File file : files) {
if (file.isFile()) {
if (file.getName().endsWith(".jar")) {
STEMSystemApp.LOGGER.INFO("Loading library " + file.getName() + " for plugin: " + pluginName);
this.addJarFileToPlugin(file);
}
}
}
}
}
}
}


public synchronized void addJarFileToPlugin(File jarFile) throws MalformedURLException {
this.addURL(jarFile.toURI().toURL());
STEMSystemApp.LOGGER.DEBUG("LOAD PLUGIN LIBRARY FILE: " + jarFile.getName());
}
}

0 comments on commit 113926d

Please sign in to comment.