mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
Delete plugins marked for uninstall
This commit is contained in:
@@ -45,6 +45,8 @@ import java.nio.file.Path;
|
|||||||
public final class InstalledPlugin implements Plugin
|
public final class InstalledPlugin implements Plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static final String UNINSTALL_MARKER_FILENAME = "uninstall";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new plugin wrapper.
|
* Constructs a new plugin wrapper.
|
||||||
* @param descriptor wrapped plugin
|
* @param descriptor wrapped plugin
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -78,12 +79,37 @@ public final class PluginBootstrap {
|
|||||||
LOG.info("core plugin extraction is disabled");
|
LOG.info("core plugin extraction is disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uninstallMarkedPlugins(pluginDirectory.toPath());
|
||||||
return PluginsInternal.collectPlugins(classLoaderLifeCycle, pluginDirectory.toPath());
|
return PluginsInternal.collectPlugins(classLoaderLifeCycle, pluginDirectory.toPath());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new PluginLoadException("could not load plugins", ex);
|
throw new PluginLoadException("could not load plugins", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void uninstallMarkedPlugins(Path pluginDirectory) {
|
||||||
|
try {
|
||||||
|
java.nio.file.Files.list(pluginDirectory)
|
||||||
|
.filter(java.nio.file.Files::isDirectory)
|
||||||
|
.filter(this::isMarkedForUninstall)
|
||||||
|
.forEach(this::uninstall);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.warn("error occurred while checking for plugins that should be uninstalled", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isMarkedForUninstall(Path path) {
|
||||||
|
return java.nio.file.Files.exists(path.resolve(InstalledPlugin.UNINSTALL_MARKER_FILENAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void uninstall(Path path) {
|
||||||
|
try {
|
||||||
|
LOG.info("deleting plugin directory {}", path);
|
||||||
|
IOUtil.delete(path.toFile());
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.warn("could not delete plugin directory {}", path, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void renameOldPluginsFolder(File pluginDirectory) {
|
private void renameOldPluginsFolder(File pluginDirectory) {
|
||||||
if (new File(pluginDirectory, "classpath.xml").exists()) {
|
if (new File(pluginDirectory, "classpath.xml").exists()) {
|
||||||
File backupDirectory = new File(pluginDirectory.getParentFile(), "plugins.v1");
|
File backupDirectory = new File(pluginDirectory.getParentFile(), "plugins.v1");
|
||||||
@@ -96,7 +122,6 @@ public final class PluginBootstrap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isCorePluginExtractionDisabled() {
|
private boolean isCorePluginExtractionDisabled() {
|
||||||
return Boolean.getBoolean("sonia.scm.boot.disable-core-plugin-extraction");
|
return Boolean.getBoolean("sonia.scm.boot.disable-core-plugin-extraction");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import com.google.inject.Singleton;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.NotFoundException;
|
import sonia.scm.NotFoundException;
|
||||||
import sonia.scm.ScmConstraintViolationException;
|
|
||||||
import sonia.scm.event.ScmEventBus;
|
import sonia.scm.event.ScmEventBus;
|
||||||
import sonia.scm.lifecycle.RestartEvent;
|
import sonia.scm.lifecycle.RestartEvent;
|
||||||
import sonia.scm.version.Version;
|
import sonia.scm.version.Version;
|
||||||
@@ -193,7 +192,7 @@ public class DefaultPluginManager implements PluginManager {
|
|||||||
dependencyTracker.removeInstalled(installed.getDescriptor());
|
dependencyTracker.removeInstalled(installed.getDescriptor());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.createFile(installed.getDirectory().resolve("uninstall"));
|
Files.createFile(installed.getDirectory().resolve(InstalledPlugin.UNINSTALL_MARKER_FILENAME));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PluginException("could not mark plugin " + name + " in path " + installed.getDirectory() + " for uninstall", e);
|
throw new PluginException("could not mark plugin " + name + " in path " + installed.getDirectory() + " for uninstall", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user