|
|
@ -146,6 +146,36 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
return startedPlugins; |
|
|
|
return startedPlugins; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String loadPlugin(File pluginArchiveFile) { |
|
|
|
|
|
|
|
if (pluginArchiveFile == null || !pluginArchiveFile.exists()) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException(String.format("Specified plugin %s does not exist!", pluginArchiveFile)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File pluginDirectory = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
pluginDirectory = expandPluginArchive(pluginArchiveFile); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (pluginDirectory == null || !pluginDirectory.exists()) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException(String.format("Failed to expand %s", pluginArchiveFile)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
PluginWrapper pluginWrapper = loadPluginDirectory(pluginDirectory); |
|
|
|
|
|
|
|
// TODO uninstalled plugin dependencies?
|
|
|
|
|
|
|
|
unresolvedPlugins.remove(pluginWrapper); |
|
|
|
|
|
|
|
resolvedPlugins.add(pluginWrapper); |
|
|
|
|
|
|
|
compoundClassLoader.addLoader(pluginWrapper.getPluginClassLoader()); |
|
|
|
|
|
|
|
extensionFinder.reset(); |
|
|
|
|
|
|
|
return pluginWrapper.getDescriptor().getPluginId(); |
|
|
|
|
|
|
|
} catch (PluginException e) { |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Start all active plugins. |
|
|
|
* Start all active plugins. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -284,10 +314,10 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
// load any plugin from plugins directory
|
|
|
|
// load any plugin from plugins directory
|
|
|
|
for (File directory : directories) { |
|
|
|
for (File directory : directories) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
loadPlugin(directory); |
|
|
|
loadPluginDirectory(directory); |
|
|
|
} catch (PluginException e) { |
|
|
|
} catch (PluginException e) { |
|
|
|
log.error(e.getMessage(), e); |
|
|
|
log.error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// resolve 'unresolvedPlugins'
|
|
|
|
// resolve 'unresolvedPlugins'
|
|
|
@ -319,6 +349,7 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
plugins.remove(pluginId); |
|
|
|
plugins.remove(pluginId); |
|
|
|
resolvedPlugins.remove(pluginWrapper); |
|
|
|
resolvedPlugins.remove(pluginWrapper); |
|
|
|
pathToIdMap.remove(pluginWrapper.getPluginPath()); |
|
|
|
pathToIdMap.remove(pluginWrapper.getPluginPath()); |
|
|
|
|
|
|
|
extensionFinder.reset(); |
|
|
|
|
|
|
|
|
|
|
|
// remove the classloader
|
|
|
|
// remove the classloader
|
|
|
|
if (pluginClassLoaders.containsKey(pluginId)) { |
|
|
|
if (pluginClassLoaders.containsKey(pluginId)) { |
|
|
@ -425,7 +456,7 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
return plugin; |
|
|
|
return plugin; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.warn("Failed to find the plugin for {}", clazz); |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -527,14 +558,14 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
System.setProperty("pf4j.pluginsDir", pluginsDirectory.getAbsolutePath()); |
|
|
|
System.setProperty("pf4j.pluginsDir", pluginsDirectory.getAbsolutePath()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void loadPlugin(File pluginDirectory) throws PluginException { |
|
|
|
private PluginWrapper loadPluginDirectory(File pluginDirectory) throws PluginException { |
|
|
|
// try to load the plugin
|
|
|
|
// try to load the plugin
|
|
|
|
String pluginName = pluginDirectory.getName(); |
|
|
|
String pluginName = pluginDirectory.getName(); |
|
|
|
String pluginPath = "/".concat(pluginName); |
|
|
|
String pluginPath = "/".concat(pluginName); |
|
|
|
|
|
|
|
|
|
|
|
// test for plugin duplication
|
|
|
|
// test for plugin duplication
|
|
|
|
if (plugins.get(pathToIdMap.get(pluginPath)) != null) { |
|
|
|
if (plugins.get(pathToIdMap.get(pluginPath)) != null) { |
|
|
|
return; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// retrieves the plugin descriptor
|
|
|
|
// retrieves the plugin descriptor
|
|
|
@ -547,7 +578,7 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
// test for disabled plugin
|
|
|
|
// test for disabled plugin
|
|
|
|
if (isPluginDisabled(pluginDescriptor.getPluginId())) { |
|
|
|
if (isPluginDisabled(pluginDescriptor.getPluginId())) { |
|
|
|
log.info("Plugin '{}' is disabled", pluginPath); |
|
|
|
log.info("Plugin '{}' is disabled", pluginPath); |
|
|
|
return; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// load plugin
|
|
|
|
// load plugin
|
|
|
@ -571,9 +602,11 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
// add plugin class loader to the list with class loaders
|
|
|
|
// add plugin class loader to the list with class loaders
|
|
|
|
PluginClassLoader pluginClassLoader = pluginLoader.getPluginClassLoader(); |
|
|
|
PluginClassLoader pluginClassLoader = pluginLoader.getPluginClassLoader(); |
|
|
|
pluginClassLoaders.put(pluginId, pluginClassLoader); |
|
|
|
pluginClassLoaders.put(pluginId, pluginClassLoader); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pluginWrapper; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void expandPluginArchive(File pluginArchiveFile) throws IOException { |
|
|
|
private File expandPluginArchive(File pluginArchiveFile) throws IOException { |
|
|
|
String fileName = pluginArchiveFile.getName(); |
|
|
|
String fileName = pluginArchiveFile.getName(); |
|
|
|
long pluginArchiveDate = pluginArchiveFile.lastModified(); |
|
|
|
long pluginArchiveDate = pluginArchiveFile.lastModified(); |
|
|
|
String pluginName = fileName.substring(0, fileName.length() - 4); |
|
|
|
String pluginName = fileName.substring(0, fileName.length() - 4); |
|
|
@ -581,6 +614,12 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
// check if exists directory or the '.zip' file is "newer" than directory
|
|
|
|
// check if exists directory or the '.zip' file is "newer" than directory
|
|
|
|
if (!pluginDirectory.exists() || (pluginArchiveDate > pluginDirectory.lastModified())) { |
|
|
|
if (!pluginDirectory.exists() || (pluginArchiveDate > pluginDirectory.lastModified())) { |
|
|
|
log.debug("Expand plugin archive '{}' in '{}'", pluginArchiveFile, pluginDirectory); |
|
|
|
log.debug("Expand plugin archive '{}' in '{}'", pluginArchiveFile, pluginDirectory); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// do not overwrite an old version, remove it
|
|
|
|
|
|
|
|
if (pluginDirectory.exists()) { |
|
|
|
|
|
|
|
FileUtils.delete(pluginDirectory); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// create directory for plugin
|
|
|
|
// create directory for plugin
|
|
|
|
pluginDirectory.mkdirs(); |
|
|
|
pluginDirectory.mkdirs(); |
|
|
|
|
|
|
|
|
|
|
@ -590,6 +629,7 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
unzip.setDestination(pluginDirectory); |
|
|
|
unzip.setDestination(pluginDirectory); |
|
|
|
unzip.extract(); |
|
|
|
unzip.extract(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return pluginDirectory; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void resolvePlugins() throws PluginException { |
|
|
|
private void resolvePlugins() throws PluginException { |
|
|
|