Browse Source

Fix FileSystemException in windows on plugin delete (#322)

pf4j_3
hazemkmammu 6 years ago committed by Decebal Suiu
parent
commit
553a0753f5
  1. 20
      pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java

20
pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java

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

Loading…
Cancel
Save