mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
use jaxb to parse plugin descriptor
This commit is contained in:
@@ -42,11 +42,11 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.ScmContextListener;
|
||||
import sonia.scm.plugin.Plugin;
|
||||
import sonia.scm.plugin.PluginException;
|
||||
import sonia.scm.plugin.PluginId;
|
||||
import sonia.scm.plugin.PluginLoadException;
|
||||
import sonia.scm.plugin.PluginWrapper;
|
||||
import sonia.scm.plugin.Plugins;
|
||||
import sonia.scm.plugin.PluginsInternal;
|
||||
import sonia.scm.plugin.SmpArchive;
|
||||
import sonia.scm.util.ClassLoaders;
|
||||
import sonia.scm.util.IOUtil;
|
||||
@@ -152,7 +152,7 @@ public class BootstrapContextListener implements ServletContextListener
|
||||
ClassLoader cl =
|
||||
ClassLoaders.getContextClassLoader(BootstrapContextListener.class);
|
||||
|
||||
Set<PluginWrapper> plugins = Plugins.collectPlugins(cl,
|
||||
Set<PluginWrapper> plugins = PluginsInternal.collectPlugins(cl,
|
||||
pluginDirectory.toPath());
|
||||
|
||||
contextListener = new ScmContextListener(cl, plugins);
|
||||
@@ -182,23 +182,24 @@ public class BootstrapContextListener implements ServletContextListener
|
||||
{
|
||||
URL url = context.getResource(PLUGIN_DIRECTORY.concat(entry.getName()));
|
||||
SmpArchive archive = SmpArchive.create(url);
|
||||
PluginId id = archive.getPluginId();
|
||||
Plugin plugin = archive.getPlugin();
|
||||
|
||||
File directory = Plugins.createPluginDirectory(pluginDirectory, id);
|
||||
File checksumFile = Plugins.getChecksumFile(directory);
|
||||
File directory = PluginsInternal.createPluginDirectory(pluginDirectory,
|
||||
plugin);
|
||||
File checksumFile = PluginsInternal.getChecksumFile(directory);
|
||||
|
||||
if (!directory.exists())
|
||||
{
|
||||
logger.warn("install plugin {}", id);
|
||||
Plugins.extract(archive, entry.getChecksum(), directory, checksumFile,
|
||||
true);
|
||||
logger.warn("install plugin {}", plugin.getInformation().getId());
|
||||
PluginsInternal.extract(archive, entry.getChecksum(), directory,
|
||||
checksumFile, true);
|
||||
}
|
||||
else if (!checksumFile.exists())
|
||||
{
|
||||
logger.warn("plugin directory {} exists without checksum file.",
|
||||
directory);
|
||||
Plugins.extract(archive, entry.getChecksum(), directory, checksumFile,
|
||||
true);
|
||||
PluginsInternal.extract(archive, entry.getChecksum(), directory,
|
||||
checksumFile, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -206,13 +207,15 @@ public class BootstrapContextListener implements ServletContextListener
|
||||
|
||||
if (checksum.equals(entry.getChecksum()))
|
||||
{
|
||||
logger.debug("plugin {} is up to date", id);
|
||||
logger.debug("plugin {} is up to date",
|
||||
plugin.getInformation().getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("checksum mismatch of pluing {}, start update", id);
|
||||
Plugins.extract(archive, entry.getChecksum(), directory, checksumFile,
|
||||
true);
|
||||
logger.warn("checksum mismatch of pluing {}, start update",
|
||||
plugin.getInformation().getId());
|
||||
PluginsInternal.extract(archive, entry.getChecksum(), directory,
|
||||
checksumFile, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class DefaultPluginLoader implements PluginLoader
|
||||
Builder<Plugin> builder = ImmutableSet.builder();
|
||||
|
||||
builder.addAll(ips);
|
||||
builder.addAll(Plugins.unwrap(wrappedPlugins));
|
||||
builder.addAll(PluginsInternal.unwrap(wrappedPlugins));
|
||||
plugins = builder.build();
|
||||
|
||||
appendExtensions(multiple, single, extensions, modules);
|
||||
|
||||
@@ -34,20 +34,14 @@ package sonia.scm.plugin;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.util.XmlUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -56,8 +50,6 @@ import java.util.Collection;
|
||||
public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
{
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -65,12 +57,12 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
* @param path
|
||||
* @param pluginId
|
||||
* @param dependencies
|
||||
* @param plugin
|
||||
*/
|
||||
ExplodedSmp(Path path, PluginId pluginId, Collection<String> dependencies)
|
||||
ExplodedSmp(Path path, Plugin plugin)
|
||||
{
|
||||
this.path = path;
|
||||
this.pluginId = pluginId;
|
||||
this.dependencies = dependencies;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -87,35 +79,9 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
*/
|
||||
public static ExplodedSmp create(Path directory) throws IOException
|
||||
{
|
||||
ExplodedSmp smp;
|
||||
Path desc = directory.resolve(PluginConstants.FILE_DESCRIPTOR);
|
||||
|
||||
Path descriptor = directory.resolve(PluginConstants.FILE_DESCRIPTOR);
|
||||
|
||||
try (InputStream in = Files.newInputStream(descriptor))
|
||||
{
|
||||
//J-
|
||||
Multimap<String,String> values = XmlUtil.values(in,
|
||||
PluginConstants.EL_GROUPID,
|
||||
PluginConstants.EL_ARTIFACTID,
|
||||
PluginConstants.EL_VERSION,
|
||||
PluginConstants.EL_DEPENDENCY
|
||||
);
|
||||
|
||||
PluginId pluginId = new PluginId(
|
||||
Util.getFirst(values, PluginConstants.EL_GROUPID),
|
||||
Util.getFirst(values, PluginConstants.EL_ARTIFACTID),
|
||||
Util.getFirst(values, PluginConstants.EL_VERSION)
|
||||
);
|
||||
|
||||
smp = new ExplodedSmp(
|
||||
directory,
|
||||
pluginId,
|
||||
values.get(PluginConstants.EL_DEPENDENCY)
|
||||
);
|
||||
//J+
|
||||
}
|
||||
|
||||
return smp;
|
||||
return new ExplodedSmp(directory, Plugins.parsePluginDescriptor(desc));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,24 +97,27 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
{
|
||||
int result;
|
||||
|
||||
if (dependencies.isEmpty() && o.dependencies.isEmpty())
|
||||
Set<String> depends = plugin.getDependencies();
|
||||
Set<String> odepends = o.plugin.getDependencies();
|
||||
|
||||
if (depends.isEmpty() && odepends.isEmpty())
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else if (dependencies.isEmpty() &&!o.dependencies.isEmpty())
|
||||
else if (depends.isEmpty() &&!odepends.isEmpty())
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
else if (!dependencies.isEmpty() && o.dependencies.isEmpty())
|
||||
else if (!depends.isEmpty() && odepends.isEmpty())
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
String id = pluginId.getIdWithoutVersion();
|
||||
String oid = o.pluginId.getIdWithoutVersion();
|
||||
String id = plugin.getInformation().getId(false);
|
||||
String oid = o.plugin.getInformation().getId(false);
|
||||
|
||||
if (dependencies.contains(oid) && o.dependencies.contains(id))
|
||||
if (depends.contains(oid) && odepends.contains(id))
|
||||
{
|
||||
StringBuilder b = new StringBuilder("circular dependency detected: ");
|
||||
|
||||
@@ -157,11 +126,11 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
|
||||
throw new PluginCircularDependencyException(b.toString());
|
||||
}
|
||||
else if (dependencies.contains(oid))
|
||||
else if (depends.contains(oid))
|
||||
{
|
||||
result = 999;
|
||||
}
|
||||
else if (o.dependencies.contains(id))
|
||||
else if (odepends.contains(id))
|
||||
{
|
||||
result = -999;
|
||||
}
|
||||
@@ -176,17 +145,6 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<String> getDependencies()
|
||||
{
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -204,9 +162,9 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PluginId getPluginId()
|
||||
public Plugin getPlugin()
|
||||
{
|
||||
return pluginId;
|
||||
return plugin;
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
@@ -246,12 +204,9 @@ public final class ExplodedSmp implements Comparable<ExplodedSmp>
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final Collection<String> dependencies;
|
||||
|
||||
/** Field description */
|
||||
private final Path path;
|
||||
|
||||
/** Field description */
|
||||
private final PluginId pluginId;
|
||||
private final Plugin plugin;
|
||||
}
|
||||
|
||||
@@ -451,16 +451,17 @@ public final class PluginProcessor
|
||||
|
||||
SmpArchive smp = SmpArchive.create(archive);
|
||||
|
||||
logger.debug("extract plugin {}", smp.getPluginId());
|
||||
logger.debug("extract plugin {}", smp.getPlugin());
|
||||
|
||||
File directory = Plugins.createPluginDirectory(pluginDirectory.toFile(),
|
||||
smp.getPluginId());
|
||||
File directory =
|
||||
PluginsInternal.createPluginDirectory(pluginDirectory.toFile(),
|
||||
smp.getPlugin());
|
||||
|
||||
String checksum = com.google.common.io.Files.hash(archiveFile,
|
||||
Hashing.sha256()).toString();
|
||||
File checksumFile = Plugins.getChecksumFile(directory);
|
||||
File checksumFile = PluginsInternal.getChecksumFile(directory);
|
||||
|
||||
Plugins.extract(smp, checksum, directory, checksumFile, false);
|
||||
PluginsInternal.extract(smp, checksum, directory, checksumFile, false);
|
||||
moveArchive(archive);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,13 +56,14 @@ import java.util.Set;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public final class Plugins
|
||||
public final class PluginsInternal
|
||||
{
|
||||
|
||||
/**
|
||||
* the logger for Plugins
|
||||
* the logger for PluginsInternal
|
||||
*/
|
||||
private static final Logger logger = LoggerFactory.getLogger(Plugins.class);
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(PluginsInternal.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
@@ -70,7 +71,7 @@ public final class Plugins
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
private Plugins() {}
|
||||
private PluginsInternal() {}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -99,13 +100,15 @@ public final class Plugins
|
||||
*
|
||||
*
|
||||
* @param parent
|
||||
* @param id
|
||||
* @param plugin
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File createPluginDirectory(File parent, PluginId id)
|
||||
public static File createPluginDirectory(File parent, Plugin plugin)
|
||||
{
|
||||
return new File(new File(parent, id.getGroupId()), id.getArtifactId());
|
||||
PluginInformation info = plugin.getInformation();
|
||||
|
||||
return new File(new File(parent, info.getGroupId()), info.getArtifactId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,13 +130,14 @@ public final class Plugins
|
||||
if (directory.exists())
|
||||
{
|
||||
logger.debug("delete directory {} for plugin extraction",
|
||||
archive.getPluginId());
|
||||
archive.getPlugin().getInformation().getId(false));
|
||||
IOUtil.delete(directory);
|
||||
}
|
||||
|
||||
IOUtil.mkdirs(directory);
|
||||
|
||||
logger.debug("extract plugin {}", archive.getPluginId());
|
||||
logger.debug("extract plugin {}",
|
||||
archive.getPlugin().getInformation().getId(false));
|
||||
archive.extract(directory);
|
||||
Files.write(checksum, checksumFile, Charsets.UTF_8);
|
||||
|
||||
Reference in New Issue
Block a user