|
|
@ -48,67 +48,131 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin |
|
|
|
public <T> List<ExtensionWrapper<T>> find(Class<T> type) { |
|
|
|
public <T> List<ExtensionWrapper<T>> find(Class<T> type) { |
|
|
|
log.debug("Finding extensions of extension point '{}'", type.getName()); |
|
|
|
log.debug("Finding extensions of extension point '{}'", type.getName()); |
|
|
|
Map<String, Set<String>> entries = getEntries(); |
|
|
|
Map<String, Set<String>> entries = getEntries(); |
|
|
|
|
|
|
|
List<ExtensionWrapper<T>> result = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add extensions found in classpath
|
|
|
|
|
|
|
|
List<ExtensionWrapper<T>> classpathExtensions = find(type, null); |
|
|
|
|
|
|
|
result.addAll(classpathExtensions); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add extensions found in each plugin
|
|
|
|
|
|
|
|
for (String pluginId : entries.keySet()) { |
|
|
|
|
|
|
|
List<ExtensionWrapper<T>> pluginExtensions = find(type, pluginId); |
|
|
|
|
|
|
|
result.addAll(pluginExtensions); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entries.isEmpty()) { |
|
|
|
|
|
|
|
log.debug("No extensions found for extension point '{}'", type.getName()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.debug("Found {} extensions for extension point '{}'", result.size(), type.getName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sort by "ordinal" property
|
|
|
|
|
|
|
|
Collections.sort(result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
|
|
|
public <T> List<ExtensionWrapper<T>> find(Class<T> type, String pluginId) { |
|
|
|
|
|
|
|
log.debug("Finding extensions of extension point '{}' for plugin '{}'", type.getName(), pluginId); |
|
|
|
List<ExtensionWrapper<T>> result = new ArrayList<>(); |
|
|
|
List<ExtensionWrapper<T>> result = new ArrayList<>(); |
|
|
|
for (Map.Entry<String, Set<String>> entry : entries.entrySet()) { |
|
|
|
|
|
|
|
if (entry.getValue().isEmpty()) { |
|
|
|
Set<String> classNames = findClassNames(pluginId); |
|
|
|
continue; |
|
|
|
if (classNames.isEmpty()) { |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pluginId != null) { |
|
|
|
|
|
|
|
PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId); |
|
|
|
|
|
|
|
if (PluginState.STARTED != pluginWrapper.getPluginState()) { |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String pluginId = entry.getKey(); |
|
|
|
log.trace("Checking extensions from plugin '{}'", pluginId); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.trace("Checking extensions from classpath"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ClassLoader classLoader = (pluginId != null) ? pluginManager.getPluginClassLoader(pluginId) : getClass().getClassLoader(); |
|
|
|
|
|
|
|
|
|
|
|
if (pluginId != null) { |
|
|
|
for (String className : classNames) { |
|
|
|
PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId); |
|
|
|
try { |
|
|
|
if (PluginState.STARTED != pluginWrapper.getPluginState()) { |
|
|
|
log.debug("Loading class '{}' using class loader '{}'", className, classLoader); |
|
|
|
continue; |
|
|
|
Class<?> extensionClass = classLoader.loadClass(className); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.debug("Checking extension type '{}'", className); |
|
|
|
|
|
|
|
if (type.isAssignableFrom(extensionClass)) { |
|
|
|
|
|
|
|
ExtensionWrapper extensionWrapper = createExtensionWrapper(extensionClass); |
|
|
|
|
|
|
|
result.add(extensionWrapper); |
|
|
|
|
|
|
|
log.debug("Added extension '{}' with ordinal {}", className, extensionWrapper.getOrdinal()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.trace("'{}' is not an extension for extension point '{}'", className, type.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result.isEmpty()) { |
|
|
|
|
|
|
|
log.debug("No extensions found for extension point '{}'", type.getName()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.debug("Found {} extensions for extension point '{}'", result.size(), type.getName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.trace("Checking extensions from plugin '{}'", pluginId); |
|
|
|
// sort by "ordinal" property
|
|
|
|
} else { |
|
|
|
Collections.sort(result); |
|
|
|
log.trace("Checking extensions from classpath"); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public List<ExtensionWrapper> find(String pluginId) { |
|
|
|
|
|
|
|
log.debug("Finding extensions from plugin '{}'", pluginId); |
|
|
|
|
|
|
|
List<ExtensionWrapper> result = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<String> classNames = findClassNames(pluginId); |
|
|
|
|
|
|
|
if (classNames.isEmpty()) { |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pluginId != null) { |
|
|
|
|
|
|
|
PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId); |
|
|
|
|
|
|
|
if (PluginState.STARTED != pluginWrapper.getPluginState()) { |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ClassLoader classLoader = (pluginId != null) ? pluginManager.getPluginClassLoader(pluginId) : getClass().getClassLoader(); |
|
|
|
log.trace("Checking extensions from plugin '{}'", pluginId); |
|
|
|
|
|
|
|
} else { |
|
|
|
for (String className : entry.getValue()) { |
|
|
|
log.trace("Checking extensions from classpath"); |
|
|
|
try { |
|
|
|
} |
|
|
|
log.debug("Loading class '{}' using class loader '{}'", className, classLoader); |
|
|
|
|
|
|
|
Class<?> extensionClass = classLoader.loadClass(className); |
|
|
|
ClassLoader classLoader = (pluginId != null) ? pluginManager.getPluginClassLoader(pluginId) : getClass().getClassLoader(); |
|
|
|
|
|
|
|
|
|
|
|
log.debug("Checking extension type '{}'", className); |
|
|
|
for (String className : classNames) { |
|
|
|
if (type.isAssignableFrom(extensionClass)) { |
|
|
|
try { |
|
|
|
ExtensionDescriptor descriptor = new ExtensionDescriptor(); |
|
|
|
log.debug("Loading class '{}' using class loader '{}'", className, classLoader); |
|
|
|
int ordinal = 0; |
|
|
|
Class<?> extensionClass = classLoader.loadClass(className); |
|
|
|
if (extensionClass.isAnnotationPresent(Extension.class)) { |
|
|
|
|
|
|
|
ordinal = extensionClass.getAnnotation(Extension.class).ordinal(); |
|
|
|
ExtensionWrapper extensionWrapper = createExtensionWrapper(extensionClass); |
|
|
|
} |
|
|
|
result.add(extensionWrapper); |
|
|
|
descriptor.setOrdinal(ordinal); |
|
|
|
log.debug("Added extension '{}' with ordinal {}", className, extensionWrapper.getOrdinal()); |
|
|
|
descriptor.setExtensionClass(extensionClass); |
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
ExtensionWrapper extensionWrapper = new ExtensionWrapper<>(descriptor); |
|
|
|
|
|
|
|
extensionWrapper.setExtensionFactory(pluginManager.getExtensionFactory()); |
|
|
|
|
|
|
|
result.add(extensionWrapper); |
|
|
|
|
|
|
|
log.debug("Added extension '{}' with ordinal {}", className, ordinal); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.trace("'{}' is not an extension for extension point '{}'", className, type.getName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (entries.isEmpty()) { |
|
|
|
if (result.isEmpty()) { |
|
|
|
log.debug("No extensions found for extension point '{}'", type.getName()); |
|
|
|
log.debug("No extensions found for plugin '{}'", pluginId); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log.debug("Found {} extensions for extension point '{}'", result.size(), type.getName()); |
|
|
|
log.debug("Found {} extensions for plugin '{}'", result.size(), pluginId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// sort by "ordinal" property
|
|
|
|
// sort by "ordinal" property
|
|
|
|
Collections.sort(result); |
|
|
|
Collections.sort(result); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Set<String> findClassNames(String pluginId) { |
|
|
|
public Set<String> findClassNames(String pluginId) { |
|
|
@ -122,6 +186,17 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin |
|
|
|
entries = null; |
|
|
|
entries = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void logExtensions(Set<String> extensions) { |
|
|
|
|
|
|
|
if (extensions.isEmpty()) { |
|
|
|
|
|
|
|
log.debug("No extensions found"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.debug("Found possible {} extensions:", extensions.size()); |
|
|
|
|
|
|
|
for (String extension : extensions) { |
|
|
|
|
|
|
|
log.debug(" " + extension); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Set<String>> readStorages() { |
|
|
|
private Map<String, Set<String>> readStorages() { |
|
|
|
Map<String, Set<String>> result = new LinkedHashMap<>(); |
|
|
|
Map<String, Set<String>> result = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
@ -139,4 +214,19 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin |
|
|
|
return entries; |
|
|
|
return entries; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ExtensionWrapper createExtensionWrapper(Class<?> extensionClass) { |
|
|
|
|
|
|
|
ExtensionDescriptor descriptor = new ExtensionDescriptor(); |
|
|
|
|
|
|
|
int ordinal = 0; |
|
|
|
|
|
|
|
if (extensionClass.isAnnotationPresent(Extension.class)) { |
|
|
|
|
|
|
|
ordinal = extensionClass.getAnnotation(Extension.class).ordinal(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
descriptor.setOrdinal(ordinal); |
|
|
|
|
|
|
|
descriptor.setExtensionClass(extensionClass); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExtensionWrapper extensionWrapper = new ExtensionWrapper<>(descriptor); |
|
|
|
|
|
|
|
extensionWrapper.setExtensionFactory(pluginManager.getExtensionFactory()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return extensionWrapper; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|