renamed Plugin to InstalledPluginDescriptor and added PluginDescriptor interface

This commit is contained in:
Sebastian Sdorra
2019-08-20 08:05:41 +02:00
parent ae19ad9327
commit 1a01216f62
19 changed files with 74 additions and 58 deletions

View File

@@ -36,7 +36,7 @@ package sonia.scm.plugin;
import java.nio.file.Path;
/**
* Wrapper for a {@link Plugin}. The wrapper holds the directory,
* Wrapper for a {@link InstalledPluginDescriptor}. The wrapper holds the directory,
* {@link ClassLoader} and {@link WebResourceLoader} of a plugin.
*
* @author Sebastian Sdorra
@@ -53,7 +53,7 @@ public final class InstalledPlugin
* @param webResourceLoader web resource loader
* @param directory plugin directory
*/
public InstalledPlugin(Plugin plugin, ClassLoader classLoader,
public InstalledPlugin(InstalledPluginDescriptor plugin, ClassLoader classLoader,
WebResourceLoader webResourceLoader, Path directory)
{
this.plugin = plugin;
@@ -103,7 +103,7 @@ public final class InstalledPlugin
*
* @return plugin
*/
public Plugin getPlugin()
public InstalledPluginDescriptor getPlugin()
{
return plugin;
}
@@ -128,7 +128,7 @@ public final class InstalledPlugin
private final Path directory;
/** plugin */
private final Plugin plugin;
private final InstalledPluginDescriptor plugin;
/** plugin web resource loader */
private final WebResourceLoader webResourceLoader;

View File

@@ -54,14 +54,14 @@ import java.util.Set;
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public final class Plugin extends ScmModule
public final class InstalledPluginDescriptor extends ScmModule implements PluginDescriptor
{
/**
* Constructs ...
*
*/
Plugin() {}
InstalledPluginDescriptor() {}
/**
* Constructs ...
@@ -74,7 +74,7 @@ public final class Plugin extends ScmModule
* @param childFirstClassLoader
* @param dependencies
*/
public Plugin(int scmVersion, PluginInformation information,
public InstalledPluginDescriptor(int scmVersion, PluginInformation information,
PluginResources resources, PluginCondition condition,
boolean childFirstClassLoader, Set<String> dependencies)
{
@@ -109,7 +109,7 @@ public final class Plugin extends ScmModule
return false;
}
final Plugin other = (Plugin) obj;
final InstalledPluginDescriptor other = (InstalledPluginDescriptor) obj;
return Objects.equal(scmVersion, other.scmVersion)
&& Objects.equal(condition, other.condition)
@@ -161,6 +161,7 @@ public final class Plugin extends ScmModule
*
* @return
*/
@Override
public PluginCondition getCondition()
{
return condition;
@@ -174,6 +175,7 @@ public final class Plugin extends ScmModule
*
* @since 2.0.0
*/
@Override
public Set<String> getDependencies()
{
if (dependencies == null)
@@ -190,6 +192,7 @@ public final class Plugin extends ScmModule
*
* @return
*/
@Override
public PluginInformation getInformation()
{
return information;

View File

@@ -0,0 +1,13 @@
package sonia.scm.plugin;
import java.util.Set;
public interface PluginDescriptor {
PluginInformation getInformation();
PluginCondition getCondition();
Set<String> getDependencies();
}

View File

@@ -65,7 +65,7 @@ public final class Plugins
{
try
{
context = JAXBContext.newInstance(Plugin.class, ScmModule.class);
context = JAXBContext.newInstance(InstalledPluginDescriptor.class, ScmModule.class);
}
catch (JAXBException ex)
{
@@ -91,7 +91,7 @@ public final class Plugins
*
* @return
*/
public static Plugin parsePluginDescriptor(Path path)
public static InstalledPluginDescriptor parsePluginDescriptor(Path path)
{
return parsePluginDescriptor(Files.asByteSource(path.toFile()));
}
@@ -104,15 +104,15 @@ public final class Plugins
*
* @return
*/
public static Plugin parsePluginDescriptor(ByteSource data)
public static InstalledPluginDescriptor parsePluginDescriptor(ByteSource data)
{
Preconditions.checkNotNull(data, "data parameter is required");
Plugin plugin;
InstalledPluginDescriptor plugin;
try (InputStream stream = data.openStream())
{
plugin = (Plugin) context.createUnmarshaller().unmarshal(stream);
plugin = (InstalledPluginDescriptor) context.createUnmarshaller().unmarshal(stream);
}
catch (JAXBException ex)
{

View File

@@ -206,7 +206,7 @@ public final class SmpArchive
*
* @throws IOException
*/
public Plugin getPlugin() throws IOException
public InstalledPluginDescriptor getPlugin() throws IOException
{
if (plugin == null)
{
@@ -245,9 +245,9 @@ public final class SmpArchive
*
* @throws IOException
*/
private Plugin createPlugin() throws IOException
private InstalledPluginDescriptor createPlugin() throws IOException
{
Plugin p = null;
InstalledPluginDescriptor p = null;
NonClosingZipInputStream zis = null;
try
@@ -412,5 +412,5 @@ public final class SmpArchive
private final ByteSource archive;
/** Field description */
private Plugin plugin;
private InstalledPluginDescriptor plugin;
}

View File

@@ -113,7 +113,7 @@ public class SmpArchiveTest
public void testGetPlugin() throws IOException
{
File archive = createArchive("sonia.sample", "1.0");
Plugin plugin = SmpArchive.create(archive).getPlugin();
InstalledPluginDescriptor plugin = SmpArchive.create(archive).getPlugin();
assertNotNull(plugin);

View File

@@ -3,7 +3,7 @@ package sonia.scm.api.v2.resources;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.InstalledPluginDescriptor;
import sonia.scm.plugin.PluginInformation;
import sonia.scm.plugin.PluginManager;
import sonia.scm.plugin.PluginPermissions;
@@ -83,7 +83,7 @@ public class AvailablePluginResource {
if (plugin.isPresent()) {
return Response.ok(mapper.map(plugin.get())).build();
} else {
throw notFound(entity(Plugin.class, name));
throw notFound(entity(InstalledPluginDescriptor.class, name));
}
}

View File

@@ -3,7 +3,7 @@ package sonia.scm.api.v2.resources;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.InstalledPluginDescriptor;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.plugin.PluginManager;
import sonia.scm.plugin.PluginPermissions;
@@ -83,7 +83,7 @@ public class InstalledPluginResource {
if (pluginDto.isPresent()) {
return Response.ok(pluginDto.get()).build();
} else {
throw notFound(entity(Plugin.class, name));
throw notFound(entity(InstalledPluginDescriptor.class, name));
}
}
}

View File

@@ -9,7 +9,7 @@ import sonia.scm.SCMContext;
import sonia.scm.lifecycle.classloading.ClassLoaderLifeCycle;
import sonia.scm.migration.UpdateException;
import sonia.scm.plugin.DefaultPluginLoader;
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.InstalledPluginDescriptor;
import sonia.scm.plugin.PluginException;
import sonia.scm.plugin.PluginLoadException;
import sonia.scm.plugin.PluginLoader;
@@ -105,7 +105,7 @@ public final class PluginBootstrap {
PluginIndexEntry entry) throws IOException {
URL url = context.getResource(PLUGIN_DIRECTORY.concat(entry.getName()));
SmpArchive archive = SmpArchive.create(url);
Plugin plugin = archive.getPlugin();
InstalledPluginDescriptor plugin = archive.getPlugin();
File directory = PluginsInternal.createPluginDirectory(pluginDirectory, plugin);
File checksumFile = PluginsInternal.getChecksumFile(directory);

View File

@@ -95,7 +95,7 @@ public class DefaultPluginLoader implements PluginLoader
try
{
JAXBContext context = JAXBContext.newInstance(ScmModule.class,
Plugin.class);
InstalledPluginDescriptor.class);
modules = getInstalled(parent, context, PATH_MODULECONFIG);
@@ -178,7 +178,7 @@ public class DefaultPluginLoader implements PluginLoader
*
* @return
*/
private Iterable<Plugin> unwrap()
private Iterable<InstalledPluginDescriptor> unwrap()
{
return PluginsInternal.unwrap(installedPlugins);
}

View File

@@ -131,7 +131,7 @@ public class DefaultPluginManager implements PluginManager
for (InstalledPlugin wrapper : pluginLoader.getInstalledPlugins())
{
Plugin plugin = wrapper.getPlugin();
InstalledPluginDescriptor plugin = wrapper.getPlugin();
PluginInformation info = plugin.getInformation();
if ((info != null) && info.isValid())
@@ -192,7 +192,7 @@ public class DefaultPluginManager implements PluginManager
plugin.setState(PluginState.INSTALLED);
// ugly workaround
Plugin newPlugin = new Plugin();
InstalledPluginDescriptor newPlugin = new InstalledPluginDescriptor();
// TODO check
// newPlugin.setInformation(plugin);
@@ -220,8 +220,8 @@ public class DefaultPluginManager implements PluginManager
{
new ZipUnArchiver().extractArchive(packageStream, tempDirectory);
Plugin plugin = JAXB.unmarshal(new File(tempDirectory, "plugin.xml"),
Plugin.class);
InstalledPluginDescriptor plugin = JAXB.unmarshal(new File(tempDirectory, "plugin.xml"),
InstalledPluginDescriptor.class);
PluginCondition condition = plugin.getCondition();
@@ -262,7 +262,7 @@ public class DefaultPluginManager implements PluginManager
{
PluginPermissions.manage().check();
Plugin plugin = installedPlugins.get(id);
InstalledPluginDescriptor plugin = installedPlugins.get(id);
if (plugin == null)
{
@@ -457,7 +457,7 @@ public class DefaultPluginManager implements PluginManager
Set<PluginInformation> infoSet = new LinkedHashSet<>();
for (Plugin plugin : installedPlugins.values())
for (InstalledPluginDescriptor plugin : installedPlugins.values())
{
infoSet.add(plugin.getInformation());
}
@@ -647,7 +647,7 @@ public class DefaultPluginManager implements PluginManager
{
boolean core = false;
for (Plugin installedPlugin : installedPlugins.values())
for (InstalledPluginDescriptor installedPlugin : installedPlugins.values())
{
PluginInformation installed = installedPlugin.getInformation();
@@ -715,5 +715,5 @@ public class DefaultPluginManager implements PluginManager
private final SCMContextProvider context;
/** Field description */
private final Map<String, Plugin> installedPlugins;
private final Map<String, InstalledPluginDescriptor> installedPlugins;
}

View File

@@ -63,7 +63,7 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
* @param path
* @param plugin
*/
ExplodedSmp(Path path, Plugin plugin)
ExplodedSmp(Path path, InstalledPluginDescriptor plugin)
{
logger.trace("create exploded scm for plugin {} and dependencies {}", plugin.getInformation().getName(), plugin.getDependencies());
this.path = path;
@@ -163,7 +163,7 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
*
* @return plugin descriptor
*/
public Plugin getPlugin()
public InstalledPluginDescriptor getPlugin()
{
return plugin;
}
@@ -202,5 +202,5 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
private final Path path;
/** plugin object */
private final Plugin plugin;
private final InstalledPluginDescriptor plugin;
}

View File

@@ -123,7 +123,7 @@ public final class PluginProcessor
try
{
this.context = JAXBContext.newInstance(Plugin.class);
this.context = JAXBContext.newInstance(InstalledPluginDescriptor.class);
}
catch (JAXBException ex)
{
@@ -371,7 +371,7 @@ public final class PluginProcessor
ClassLoader classLoader;
URL[] urlArray = urls.toArray(new URL[urls.size()]);
Plugin plugin = smp.getPlugin();
InstalledPluginDescriptor plugin = smp.getPlugin();
String id = plugin.getInformation().getName(false);
@@ -441,7 +441,7 @@ public final class PluginProcessor
*
* @return
*/
private Plugin createPlugin(ClassLoader classLoader, Path descriptor)
private InstalledPluginDescriptor createPlugin(ClassLoader classLoader, Path descriptor)
{
ClassLoader ctxcl = Thread.currentThread().getContextClassLoader();
@@ -449,7 +449,7 @@ public final class PluginProcessor
try
{
return (Plugin) context.createUnmarshaller().unmarshal(
return (InstalledPluginDescriptor) context.createUnmarshaller().unmarshal(
descriptor.toFile());
}
catch (JAXBException ex)
@@ -486,7 +486,7 @@ public final class PluginProcessor
{
ClassLoader cl = createClassLoader(classLoader, smp);
Plugin plugin = createPlugin(cl, descriptor);
InstalledPluginDescriptor plugin = createPlugin(cl, descriptor);
WebResourceLoader resourceLoader = createWebResourceLoader(directory);

View File

@@ -86,7 +86,7 @@ public final class PluginTree
for (ExplodedSmp smp : smpOrdered)
{
Plugin plugin = smp.getPlugin();
InstalledPluginDescriptor plugin = smp.getPlugin();
if (plugin.getScmVersion() != SCM_VERSION)
{

View File

@@ -105,7 +105,7 @@ public final class PluginsInternal
*
* @return
*/
public static File createPluginDirectory(File parent, Plugin plugin)
public static File createPluginDirectory(File parent, InstalledPluginDescriptor plugin)
{
PluginInformation info = plugin.getInformation();
@@ -159,7 +159,7 @@ public final class PluginsInternal
*
* @return
*/
public static Iterable<Plugin> unwrap(Iterable<InstalledPlugin> wrapped)
public static Iterable<InstalledPluginDescriptor> unwrap(Iterable<InstalledPlugin> wrapped)
{
return Iterables.transform(wrapped, new Unwrap());
}
@@ -188,7 +188,7 @@ public final class PluginsInternal
* @version Enter version here..., 14/06/05
* @author Enter your name here...
*/
private static class Unwrap implements Function<InstalledPlugin, Plugin>
private static class Unwrap implements Function<InstalledPlugin, InstalledPluginDescriptor>
{
/**
@@ -200,7 +200,7 @@ public final class PluginsInternal
* @return
*/
@Override
public Plugin apply(InstalledPlugin wrapper)
public InstalledPluginDescriptor apply(InstalledPlugin wrapper)
{
return wrapper.getPlugin();
}

View File

@@ -16,7 +16,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.InstalledPluginDescriptor;
import sonia.scm.plugin.PluginInformation;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.plugin.PluginState;
@@ -106,7 +106,7 @@ class InstalledPluginResourceTest {
pluginInformation.setVersion("2.0.0");
pluginInformation.setName("pluginName");
pluginInformation.setState(PluginState.INSTALLED);
Plugin plugin = new Plugin(2, pluginInformation, null, null, false, null);
InstalledPluginDescriptor plugin = new InstalledPluginDescriptor(2, pluginInformation, null, null, false, null);
InstalledPlugin installedPlugin = new InstalledPlugin(plugin, null, null, null);
when(pluginLoader.getInstalledPlugins()).thenReturn(Collections.singletonList(installedPlugin));

View File

@@ -188,7 +188,7 @@ public class UIRootResourceTest {
InstalledPlugin wrapper = mock(InstalledPlugin.class);
when(wrapper.getId()).thenReturn(id);
Plugin plugin = mock(Plugin.class);
InstalledPluginDescriptor plugin = mock(InstalledPluginDescriptor.class);
when(wrapper.getPlugin()).thenReturn(plugin);
when(plugin.getResources()).thenReturn(pluginResources);

View File

@@ -133,7 +133,7 @@ public class ExplodedSmpTest
info.setName(name);
info.setVersion(version);
Plugin plugin = new Plugin(2, info, null, null, false,
InstalledPluginDescriptor plugin = new InstalledPluginDescriptor(2, info, null, null, false,
Sets.newSet(dependencies));
return new ExplodedSmp(null, plugin);

View File

@@ -71,7 +71,7 @@ public class PluginTreeTest
{
PluginCondition condition = new PluginCondition("999",
new ArrayList<String>(), "hit");
Plugin plugin = new Plugin(2, createInfo("a", "1"), null, condition,
InstalledPluginDescriptor plugin = new InstalledPluginDescriptor(2, createInfo("a", "1"), null, condition,
false, null);
ExplodedSmp smp = createSmp(plugin);
@@ -114,7 +114,7 @@ public class PluginTreeTest
@Test(expected = PluginException.class)
public void testScmVersion() throws IOException
{
Plugin plugin = new Plugin(1, createInfo("a", "1"), null, null, false,
InstalledPluginDescriptor plugin = new InstalledPluginDescriptor(1, createInfo("a", "1"), null, null, false,
null);
ExplodedSmp smp = createSmp(plugin);
@@ -182,7 +182,7 @@ public class PluginTreeTest
*
* @throws IOException
*/
private ExplodedSmp createSmp(Plugin plugin) throws IOException
private ExplodedSmp createSmp(InstalledPluginDescriptor plugin) throws IOException
{
return new ExplodedSmp(tempFolder.newFile().toPath(), plugin);
}
@@ -199,7 +199,7 @@ public class PluginTreeTest
*/
private ExplodedSmp createSmp(String name) throws IOException
{
return createSmp(new Plugin(2, createInfo(name, "1.0.0"), null, null,
return createSmp(new InstalledPluginDescriptor(2, createInfo(name, "1.0.0"), null, null,
false, null));
}
@@ -225,7 +225,7 @@ public class PluginTreeTest
dependencySet.add(d);
}
Plugin plugin = new Plugin(2, createInfo(name, "1"), null, null,
InstalledPluginDescriptor plugin = new InstalledPluginDescriptor(2, createInfo(name, "1"), null, null,
false, dependencySet);
return createSmp(plugin);