aboutsummaryrefslogtreecommitdiffstats
path: root/pf4j/src
diff options
context:
space:
mode:
authorJan Høydahl <janhoy@users.noreply.github.com>2017-04-03 15:25:07 +0200
committerDecebal Suiu <decebal.suiu@gmail.com>2017-04-03 16:25:07 +0300
commitf4ddddc61b8643bf4e34ce65b4de9bf2d2bd6831 (patch)
treee9f26477070ea9283be6c767942898a216a8a264 /pf4j/src
parenta77245a0da5bd69de8da3deb801fe1de0bd0b771 (diff)
downloadpf4j-f4ddddc61b8643bf4e34ce65b4de9bf2d2bd6831.tar.gz
pf4j-f4ddddc61b8643bf4e34ce65b4de9bf2d2bd6831.zip
Delete plugin zip on uninstall (#136)
Diffstat (limited to 'pf4j/src')
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginRepository.java2
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java29
-rw-r--r--pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java4
3 files changed, 34 insertions, 1 deletions
diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginRepository.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginRepository.java
index 953bc4e..f662bc4 100644
--- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginRepository.java
+++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginRepository.java
@@ -68,7 +68,7 @@ public class DefaultPluginRepository extends BasePluginRepository {
@Override
public boolean deletePluginPath(Path pluginPath) {
- // TODO remove plugin zip ?
+ FileUtils.optimisticDelete(FileUtils.findWithEnding(pluginPath, ".zip", ".ZIP", ".Zip"));
return super.deletePluginPath(pluginPath);
}
diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java b/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java
index 24f67fc..70b4e01 100644
--- a/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java
+++ b/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java
@@ -118,4 +118,33 @@ public class FileUtils {
}
}
}
+
+ /**
+ * Finds a path with various endings or null if not found
+ * @param basePath the base name
+ * @param endings a list of endings to search for
+ * @return new path or null if not found
+ */
+ public static Path findWithEnding(Path basePath, String... endings) {
+ for (String ending : endings) {
+ Path newPath = basePath.resolveSibling(basePath.getFileName() + ending);
+ if (Files.exists(newPath)) {
+ return newPath;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Delete a file (not recursively) and ignore any errors
+ * @param path the path to delete
+ */
+ public static void optimisticDelete(Path path) {
+ if (path == null) {
+ return;
+ }
+ try {
+ Files.delete(path);
+ } catch (IOException ignored) { }
+ }
}
diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java
index 0e85bdc..95c153b 100644
--- a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java
+++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java
@@ -44,6 +44,8 @@ public class DefaultPluginRepositoryTest {
testFolder.newFolder("plugin-1");
// Prove that we can delete a folder with a file inside
Files.createFile(Paths.get(testFolder.getRoot().getAbsolutePath()).resolve("plugin-1").resolve("myfile"));
+ // Create a zip file for plugin-1 to test that it is deleted when plugin is deleted
+ Files.createFile(Paths.get(testFolder.getRoot().getAbsolutePath()).resolve("plugin-1.zip"));
testFolder.newFolder("plugin-2");
testFolder.newFolder("plugin-3");
}
@@ -74,7 +76,9 @@ public class DefaultPluginRepositoryTest {
PluginRepository instance = new DefaultPluginRepository(pluginsRoot, false);
+ assertTrue(Files.exists(pluginsRoot.resolve("plugin-1.zip")));
assertTrue(instance.deletePluginPath(pluginsRoot.resolve("plugin-1")));
+ assertFalse(Files.exists(pluginsRoot.resolve("plugin-1.zip")));
assertTrue(instance.deletePluginPath(pluginsRoot.resolve("plugin-3")));
assertFalse(instance.deletePluginPath(pluginsRoot.resolve("plugin-4")));