mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
introduce Plugin interface
This commit is contained in:
@@ -42,21 +42,21 @@ import java.nio.file.Path;
|
||||
* @author Sebastian Sdorra
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public final class InstalledPlugin
|
||||
public final class InstalledPlugin implements Plugin
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs a new plugin wrapper.
|
||||
*
|
||||
* @param plugin wrapped plugin
|
||||
* @param descriptor wrapped plugin
|
||||
* @param classLoader plugin class loader
|
||||
* @param webResourceLoader web resource loader
|
||||
* @param directory plugin directory
|
||||
*/
|
||||
public InstalledPlugin(InstalledPluginDescriptor plugin, ClassLoader classLoader,
|
||||
public InstalledPlugin(InstalledPluginDescriptor descriptor, ClassLoader classLoader,
|
||||
WebResourceLoader webResourceLoader, Path directory)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.descriptor = descriptor;
|
||||
this.classLoader = classLoader;
|
||||
this.webResourceLoader = webResourceLoader;
|
||||
this.directory = directory;
|
||||
@@ -94,18 +94,19 @@ public final class InstalledPlugin
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return plugin.getInformation().getId();
|
||||
return descriptor.getInformation().getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plugin.
|
||||
* Returns the plugin descriptor.
|
||||
*
|
||||
*
|
||||
* @return plugin
|
||||
* @return plugin descriptor
|
||||
*/
|
||||
public InstalledPluginDescriptor getPlugin()
|
||||
@Override
|
||||
public InstalledPluginDescriptor getDescriptor()
|
||||
{
|
||||
return plugin;
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,6 +120,11 @@ public final class InstalledPlugin
|
||||
return webResourceLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginState getState() {
|
||||
return PluginState.INSTALLED;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** plugin class loader */
|
||||
@@ -128,7 +134,7 @@ public final class InstalledPlugin
|
||||
private final Path directory;
|
||||
|
||||
/** plugin */
|
||||
private final InstalledPluginDescriptor plugin;
|
||||
private final InstalledPluginDescriptor descriptor;
|
||||
|
||||
/** plugin web resource loader */
|
||||
private final WebResourceLoader webResourceLoader;
|
||||
|
||||
8
scm-core/src/main/java/sonia/scm/plugin/Plugin.java
Normal file
8
scm-core/src/main/java/sonia/scm/plugin/Plugin.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package sonia.scm.plugin;
|
||||
|
||||
public interface Plugin {
|
||||
|
||||
PluginDescriptor getDescriptor();
|
||||
PluginState getState();
|
||||
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class InstalledPluginResource {
|
||||
PluginPermissions.read().check();
|
||||
Optional<PluginDto> pluginDto = pluginLoader.getInstalledPlugins()
|
||||
.stream()
|
||||
.filter(plugin -> name.equals(plugin.getPlugin().getInformation().getName()))
|
||||
.filter(plugin -> name.equals(plugin.getDescriptor().getInformation().getName()))
|
||||
.map(mapper::map)
|
||||
.findFirst();
|
||||
if (pluginDto.isPresent()) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public abstract class PluginDtoMapper {
|
||||
private ResourceLinks resourceLinks;
|
||||
|
||||
public PluginDto map(InstalledPlugin plugin) {
|
||||
return map(plugin.getPlugin().getInformation());
|
||||
return map(plugin.getDescriptor().getInformation());
|
||||
}
|
||||
|
||||
public abstract PluginDto map(PluginInformation plugin);
|
||||
|
||||
@@ -27,7 +27,7 @@ public class UIPluginDtoMapper {
|
||||
|
||||
public UIPluginDto map(InstalledPlugin plugin) {
|
||||
UIPluginDto dto = new UIPluginDto(
|
||||
plugin.getPlugin().getInformation().getName(),
|
||||
plugin.getDescriptor().getInformation().getName(),
|
||||
getScriptResources(plugin)
|
||||
);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class UIPluginDtoMapper {
|
||||
}
|
||||
|
||||
private Set<String> getScriptResources(InstalledPlugin wrapper) {
|
||||
Set<String> scriptResources = wrapper.getPlugin().getResources().getScriptResources();
|
||||
Set<String> scriptResources = wrapper.getDescriptor().getResources().getScriptResources();
|
||||
if (scriptResources != null) {
|
||||
return scriptResources.stream()
|
||||
.map(this::addContextPath)
|
||||
|
||||
@@ -86,7 +86,7 @@ public class UIPluginResource {
|
||||
}
|
||||
|
||||
private boolean filter(InstalledPlugin plugin) {
|
||||
return plugin.getPlugin().getResources() != null;
|
||||
return plugin.getDescriptor().getResources() != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class DefaultPluginManager implements PluginManager
|
||||
|
||||
for (InstalledPlugin wrapper : pluginLoader.getInstalledPlugins())
|
||||
{
|
||||
InstalledPluginDescriptor plugin = wrapper.getPlugin();
|
||||
InstalledPluginDescriptor plugin = wrapper.getDescriptor();
|
||||
PluginInformation info = plugin.getInformation();
|
||||
|
||||
if ((info != null) && info.isValid())
|
||||
|
||||
@@ -202,7 +202,7 @@ public final class PluginsInternal
|
||||
@Override
|
||||
public InstalledPluginDescriptor apply(InstalledPlugin wrapper)
|
||||
{
|
||||
return wrapper.getPlugin();
|
||||
return wrapper.getDescriptor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class UIRootResourceTest {
|
||||
when(wrapper.getId()).thenReturn(id);
|
||||
|
||||
InstalledPluginDescriptor plugin = mock(InstalledPluginDescriptor.class);
|
||||
when(wrapper.getPlugin()).thenReturn(plugin);
|
||||
when(wrapper.getDescriptor()).thenReturn(plugin);
|
||||
when(plugin.getResources()).thenReturn(pluginResources);
|
||||
|
||||
PluginInformation information = mock(PluginInformation.class);
|
||||
|
||||
Reference in New Issue
Block a user