mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 22:15:45 +01:00
improve plugin installation and backup installed archives
This commit is contained in:
@@ -10,12 +10,19 @@ package sonia.scm.plugin;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.io.File;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -29,6 +36,13 @@ import java.util.Set;
|
||||
public final class Plugins
|
||||
{
|
||||
|
||||
/**
|
||||
* the logger for Plugins
|
||||
*/
|
||||
private static final Logger logger = LoggerFactory.getLogger(Plugins.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -56,11 +70,68 @@ public final class Plugins
|
||||
|
||||
return processor.collectPlugins(classLoader);
|
||||
}
|
||||
|
||||
public static File createPluginDirectory(File parent, PluginId id){
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param parent
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File createPluginDirectory(File parent, PluginId id)
|
||||
{
|
||||
return new File(new File(parent, id.getGroupId()), id.getArtifactId());
|
||||
}
|
||||
|
||||
/** Field description */
|
||||
private static final String FILE_CHECKSUM = "checksum";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param archive
|
||||
* @param checksum
|
||||
* @param directory
|
||||
* @param checksumFile
|
||||
* @param core
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void extract(SmpArchive archive, String checksum,
|
||||
File directory, File checksumFile, boolean core)
|
||||
throws IOException
|
||||
{
|
||||
if (directory.exists())
|
||||
{
|
||||
logger.debug("delete directory {} for plugin extraction",
|
||||
archive.getPluginId());
|
||||
IOUtil.delete(directory);
|
||||
}
|
||||
|
||||
IOUtil.mkdirs(directory);
|
||||
|
||||
logger.debug("extract plugin {}", archive.getPluginId());
|
||||
archive.extract(directory);
|
||||
Files.write(checksum, checksumFile, Charsets.UTF_8);
|
||||
|
||||
if (core)
|
||||
{
|
||||
if (!new File(directory, "core").createNewFile())
|
||||
{
|
||||
throw new IOException("could not create core plugin marker");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static File getChecksumFile(File pluginDirectory){
|
||||
return new File(pluginDirectory, FILE_CHECKSUM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user