introduce Plugin interface

This commit is contained in:
Sebastian Sdorra
2019-08-20 08:10:30 +02:00
parent 1a01216f62
commit 0aaec1174a
9 changed files with 32 additions and 18 deletions

View File

@@ -42,21 +42,21 @@ import java.nio.file.Path;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 2.0.0 * @since 2.0.0
*/ */
public final class InstalledPlugin public final class InstalledPlugin implements Plugin
{ {
/** /**
* Constructs a new plugin wrapper. * Constructs a new plugin wrapper.
* *
* @param plugin wrapped plugin * @param descriptor wrapped plugin
* @param classLoader plugin class loader * @param classLoader plugin class loader
* @param webResourceLoader web resource loader * @param webResourceLoader web resource loader
* @param directory plugin directory * @param directory plugin directory
*/ */
public InstalledPlugin(InstalledPluginDescriptor plugin, ClassLoader classLoader, public InstalledPlugin(InstalledPluginDescriptor descriptor, ClassLoader classLoader,
WebResourceLoader webResourceLoader, Path directory) WebResourceLoader webResourceLoader, Path directory)
{ {
this.plugin = plugin; this.descriptor = descriptor;
this.classLoader = classLoader; this.classLoader = classLoader;
this.webResourceLoader = webResourceLoader; this.webResourceLoader = webResourceLoader;
this.directory = directory; this.directory = directory;
@@ -94,18 +94,19 @@ public final class InstalledPlugin
*/ */
public String getId() 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; return webResourceLoader;
} }
@Override
public PluginState getState() {
return PluginState.INSTALLED;
}
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** plugin class loader */ /** plugin class loader */
@@ -128,7 +134,7 @@ public final class InstalledPlugin
private final Path directory; private final Path directory;
/** plugin */ /** plugin */
private final InstalledPluginDescriptor plugin; private final InstalledPluginDescriptor descriptor;
/** plugin web resource loader */ /** plugin web resource loader */
private final WebResourceLoader webResourceLoader; private final WebResourceLoader webResourceLoader;

View File

@@ -0,0 +1,8 @@
package sonia.scm.plugin;
public interface Plugin {
PluginDescriptor getDescriptor();
PluginState getState();
}

View File

@@ -77,7 +77,7 @@ public class InstalledPluginResource {
PluginPermissions.read().check(); PluginPermissions.read().check();
Optional<PluginDto> pluginDto = pluginLoader.getInstalledPlugins() Optional<PluginDto> pluginDto = pluginLoader.getInstalledPlugins()
.stream() .stream()
.filter(plugin -> name.equals(plugin.getPlugin().getInformation().getName())) .filter(plugin -> name.equals(plugin.getDescriptor().getInformation().getName()))
.map(mapper::map) .map(mapper::map)
.findFirst(); .findFirst();
if (pluginDto.isPresent()) { if (pluginDto.isPresent()) {

View File

@@ -21,7 +21,7 @@ public abstract class PluginDtoMapper {
private ResourceLinks resourceLinks; private ResourceLinks resourceLinks;
public PluginDto map(InstalledPlugin plugin) { public PluginDto map(InstalledPlugin plugin) {
return map(plugin.getPlugin().getInformation()); return map(plugin.getDescriptor().getInformation());
} }
public abstract PluginDto map(PluginInformation plugin); public abstract PluginDto map(PluginInformation plugin);

View File

@@ -27,7 +27,7 @@ public class UIPluginDtoMapper {
public UIPluginDto map(InstalledPlugin plugin) { public UIPluginDto map(InstalledPlugin plugin) {
UIPluginDto dto = new UIPluginDto( UIPluginDto dto = new UIPluginDto(
plugin.getPlugin().getInformation().getName(), plugin.getDescriptor().getInformation().getName(),
getScriptResources(plugin) getScriptResources(plugin)
); );
@@ -41,7 +41,7 @@ public class UIPluginDtoMapper {
} }
private Set<String> getScriptResources(InstalledPlugin wrapper) { private Set<String> getScriptResources(InstalledPlugin wrapper) {
Set<String> scriptResources = wrapper.getPlugin().getResources().getScriptResources(); Set<String> scriptResources = wrapper.getDescriptor().getResources().getScriptResources();
if (scriptResources != null) { if (scriptResources != null) {
return scriptResources.stream() return scriptResources.stream()
.map(this::addContextPath) .map(this::addContextPath)

View File

@@ -86,7 +86,7 @@ public class UIPluginResource {
} }
private boolean filter(InstalledPlugin plugin) { private boolean filter(InstalledPlugin plugin) {
return plugin.getPlugin().getResources() != null; return plugin.getDescriptor().getResources() != null;
} }
} }

View File

@@ -131,7 +131,7 @@ public class DefaultPluginManager implements PluginManager
for (InstalledPlugin wrapper : pluginLoader.getInstalledPlugins()) for (InstalledPlugin wrapper : pluginLoader.getInstalledPlugins())
{ {
InstalledPluginDescriptor plugin = wrapper.getPlugin(); InstalledPluginDescriptor plugin = wrapper.getDescriptor();
PluginInformation info = plugin.getInformation(); PluginInformation info = plugin.getInformation();
if ((info != null) && info.isValid()) if ((info != null) && info.isValid())

View File

@@ -202,7 +202,7 @@ public final class PluginsInternal
@Override @Override
public InstalledPluginDescriptor apply(InstalledPlugin wrapper) public InstalledPluginDescriptor apply(InstalledPlugin wrapper)
{ {
return wrapper.getPlugin(); return wrapper.getDescriptor();
} }
} }
} }

View File

@@ -189,7 +189,7 @@ public class UIRootResourceTest {
when(wrapper.getId()).thenReturn(id); when(wrapper.getId()).thenReturn(id);
InstalledPluginDescriptor plugin = mock(InstalledPluginDescriptor.class); InstalledPluginDescriptor plugin = mock(InstalledPluginDescriptor.class);
when(wrapper.getPlugin()).thenReturn(plugin); when(wrapper.getDescriptor()).thenReturn(plugin);
when(plugin.getResources()).thenReturn(pluginResources); when(plugin.getResources()).thenReturn(pluginResources);
PluginInformation information = mock(PluginInformation.class); PluginInformation information = mock(PluginInformation.class);