|
|
|
@ -10,6 +10,7 @@ import java.net.URLClassLoader;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
@ -101,7 +102,7 @@ public class PluginLoader
|
|
|
|
|
int counter = 0;
|
|
|
|
|
for(String item : pluginsToLoad)
|
|
|
|
|
{
|
|
|
|
|
LOGGER.debug("Attempting to load {}.", item);
|
|
|
|
|
LOGGER.debug("Attempting to preload {}.", item);
|
|
|
|
|
|
|
|
|
|
Class<?> clazz;
|
|
|
|
|
try
|
|
|
|
@ -117,23 +118,28 @@ public class PluginLoader
|
|
|
|
|
// Class doesn't implement IPlugin, or doesn't have @Plugin annotation.
|
|
|
|
|
if(!clazz.isAnnotationPresent(Plugin.class) || !IPlugin.class.isAssignableFrom(clazz))
|
|
|
|
|
{
|
|
|
|
|
LOGGER.debug("Class does not implement IPlugin or doesn't gave @Plugin annotation.");
|
|
|
|
|
LOGGER.debug("Class does not implement IPlugin or doesn't have @Plugin annotation.");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
plugins.put(clazz.getAnnotation(Plugin.class).id(), new PluginWrapper(clazz.asSubclass(IPlugin.class), classLoader));
|
|
|
|
|
LOGGER.debug("Plugin {} {} preloaded.", clazz.getAnnotation(Plugin.class).id(), clazz.getAnnotation(Plugin.class).version());
|
|
|
|
|
counter++;
|
|
|
|
|
}
|
|
|
|
|
catch(IllegalAccessException | InstantiationException e)
|
|
|
|
|
if(plugins.containsKey(clazz.getAnnotation(Plugin.class).id()))
|
|
|
|
|
LOGGER.warn("Found duplicate plugin with id {}. Newly found plugin won't be preloaded.", clazz.getAnnotation(Plugin.class).id());
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOGGER.warn("Plugin " + clazz.getAnnotation(Plugin.class).id() + " failed to preload.", e);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
plugins.put(clazz.getAnnotation(Plugin.class).id(), new PluginWrapper(clazz.asSubclass(IPlugin.class), classLoader));
|
|
|
|
|
LOGGER.debug("Plugin {} {} preloaded.", clazz.getAnnotation(Plugin.class).id(), clazz.getAnnotation(Plugin.class).version());
|
|
|
|
|
counter++;
|
|
|
|
|
}
|
|
|
|
|
catch(IllegalAccessException | InstantiationException e)
|
|
|
|
|
{
|
|
|
|
|
LOGGER.warn("Plugin " + clazz.getAnnotation(Plugin.class).id() + " failed to preload.", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGGER.debug("Loaded up {} plugins from {}.", counter, target.getFileName());
|
|
|
|
|
LOGGER.debug("Preloaded {} plugins from {}.", counter, target.getFileName());
|
|
|
|
|
return counter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -286,4 +292,12 @@ public class PluginLoader
|
|
|
|
|
LOGGER.info("Unloaded plugin {}.", id);
|
|
|
|
|
plugin.setState(PluginState.UNLOADED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all plugins and their state.
|
|
|
|
|
*/
|
|
|
|
|
public Map<String, PluginWrapper> getPlugins()
|
|
|
|
|
{
|
|
|
|
|
return Collections.unmodifiableMap(plugins);
|
|
|
|
|
}
|
|
|
|
|
}
|