]> source.dussan.org Git - pf4j.git/commitdiff
Recreate FileSystemException in windows on plugin delete (#321)
authorhazemkmammu <hazemkmammu@users.noreply.github.com>
Tue, 4 Jun 2019 09:32:55 +0000 (15:02 +0530)
committerDecebal Suiu <decebal.suiu@gmail.com>
Tue, 4 Jun 2019 09:32:55 +0000 (12:32 +0300)
pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java [new file with mode: 0644]

diff --git a/pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java b/pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java
new file mode 100644 (file)
index 0000000..fe2cac2
--- /dev/null
@@ -0,0 +1,69 @@
+package org.pf4j;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.pf4j.plugin.PluginJar;
+
+public class LegacyExtensionFinderTest {
+
+    @TempDir
+    public Path pluginsPath;
+
+    public static class TestPlugin extends Plugin {
+
+        public TestPlugin(PluginWrapper wrapper) {
+            super(wrapper);
+        }
+    }
+
+    @Extension
+    public static class TestExtension implements ExtensionPoint {
+
+    }
+
+    private static boolean systemIsWindows() {
+        String os = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
+        return os.startsWith("win");
+    }
+
+    @Test
+    public void shouldUnlockFileAfterReadingExtensionsFromPlugin() throws IOException, PluginException {
+
+        assumeTrue(systemIsWindows());
+        final Path pluginJarPath = pluginsPath.resolve("test-plugin.jar");
+        PluginJar pluginJar = new PluginJar.Builder(pluginJarPath, "test-plugin")
+                .pluginClass(TestPlugin.class.getName())
+                .pluginVersion("1.2.3")
+                .extension(TestExtension.class.getName())
+                .build();
+
+        JarPluginManager pluginManager = new JarPluginManager(pluginsPath);
+
+        pluginManager.loadPlugins();
+        LegacyExtensionFinder extensionFinder = new LegacyExtensionFinder(pluginManager);
+        Map<String, Set<String>> pluginStorages = extensionFinder.readPluginsStorages();
+        pluginManager.unloadPlugin(pluginJar.pluginId());
+        boolean fileDeleted = pluginJarPath.toFile().delete();
+
+        assertThat(pluginStorages, is(notNullValue()));
+        assertThat(pluginStorages.get(pluginJar.pluginId()), is(notNullValue()));
+        assertThat(pluginStorages.get(pluginJar.pluginId()).size(), is(equalTo(1)));
+        assertThat(pluginStorages.get(pluginJar.pluginId()),
+                contains("org.pf4j.LegacyExtensionFinderTest$TestExtension"));
+        assertThat(fileDeleted, is(equalTo(true)));
+    }
+
+}