]> source.dussan.org Git - pf4j.git/commitdiff
Fix FileSystemException in windows on plugin delete (#322)
authorhazemkmammu <hazemkmammu@users.noreply.github.com>
Tue, 4 Jun 2019 21:33:11 +0000 (03:03 +0530)
committerDecebal Suiu <decebal.suiu@gmail.com>
Tue, 4 Jun 2019 21:33:11 +0000 (00:33 +0300)
pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java

index 99e13134094547ed5505d91e40e6a75795054661..33adc277b974f3df0e7baf9ce77126dcd3ee282c 100644 (file)
@@ -20,6 +20,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
@@ -81,11 +82,14 @@ public class LegacyExtensionFinder extends AbstractExtensionFinder {
             Set<String> bucket = new HashSet<>();
 
             try {
-                Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource());
-                if (urls.hasMoreElements()) {
-                    collectExtensions(urls, bucket);
-                } else {
-                    log.debug("Cannot find '{}'", getExtensionsResource());
+                log.debug("Read '{}'", getExtensionsResource());
+                ClassLoader pluginClassLoader = plugin.getPluginClassLoader();
+                try (InputStream resourceStream = pluginClassLoader.getResourceAsStream(getExtensionsResource())) {
+                    if (resourceStream == null) {
+                        log.debug("Cannot find '{}'", getExtensionsResource());
+                    } else {
+                        collectExtensions(resourceStream, bucket);
+                    }
                 }
 
                 debugExtensions(bucket);
@@ -103,9 +107,13 @@ public class LegacyExtensionFinder extends AbstractExtensionFinder {
         while (urls.hasMoreElements()) {
             URL url = urls.nextElement();
             log.debug("Read '{}'", url.getFile());
-            try (Reader reader = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)) {
-                LegacyExtensionStorage.read(reader, bucket);
-            }
+            collectExtensions(url.openStream(), bucket);
+        }
+    }
+
+    private void collectExtensions(InputStream inputStream, Set<String> bucket) throws IOException {
+        try (Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
+            LegacyExtensionStorage.read(reader, bucket);
         }
     }