PluginInstaller deletes old plugins on exit
@@ -9,6 +9,11 @@ import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.URL;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
@@ -93,23 +98,23 @@ public class PluginInstaller {
// Delete matching target plugin
private static void deleteMatchingPlugin(File newPlugin, File pluginsFolder) throws IOException {
- String pluginName = getPluginName(newPlugin.getName());
-
- for(File file : findMatchingPlugins(pluginsFolder, pluginName)) {
+ for(File file : findMatchingPlugins(pluginsFolder, newPlugin)) {
if(file.isDirectory()) {
- FileUtils.deleteFolder(file);
+ recursiveDeleteOnExit(file.toPath());
}
else {
- file.delete();
+ file.deleteOnExit();
}
}
}
- private static File[] findMatchingPlugins(File pluginsFolder, final String pluginName) {
+ private static File[] findMatchingPlugins(File pluginsFolder, File newPlugin) {
+ String pluginName = getPluginName(newPlugin.getName());
+
return pluginsFolder.listFiles(new FileFilter() {
public boolean accept(File file) {
String targetPluginName = getPluginName(file.getName());
- return targetPluginName.equals(pluginName);
+ return targetPluginName.equals(pluginName) && !newPlugin.getName().equals(file.getName());
}
});
}
@@ -150,4 +155,21 @@ public class PluginInstaller {
url = FileLocator.resolve(url);
return new File(url.getPath()).getParentFile();
}
+
+ static void recursiveDeleteOnExit(Path path) throws IOException {
+ Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
+
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
+ file.toFile().deleteOnExit();
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
+ dir.toFile().deleteOnExit();
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ }
}
