*/
package org.pf4j;
+import org.pf4j.processor.LegacyExtensionStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.pf4j.processor.LegacyExtensionStorage;
import java.io.IOException;
import java.io.InputStreamReader;
Set<String> bucket = new HashSet<>();
try {
Enumeration<URL> urls = getClass().getClassLoader().getResources(getExtensionsResource());
- 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(urls, bucket);
debugExtensions(bucket);
try {
Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource());
- if (urls == null || !urls.hasMoreElements()) {
- log.debug("Cannot find '{}'", getExtensionsResource());
+ if (urls.hasMoreElements()) {
+ collectExtensions(urls, bucket);
} else {
- 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);
- }
- }
+ log.debug("Cannot find '{}'", getExtensionsResource());
}
debugExtensions(bucket);
return result;
}
+ private void collectExtensions(Enumeration<URL> urls, Set<String> bucket) throws IOException {
+ 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);
+ }
+ }
+ }
+
private static String getExtensionsResource() {
return LegacyExtensionStorage.EXTENSIONS_RESOURCE;
}
try {
URL url = getClass().getClassLoader().getResource(getExtensionsResource());
if (url != null) {
- Path extensionPath;
- if (url.toURI().getScheme().equals("jar")) {
- extensionPath = FileUtils.getPath(url.toURI(), getExtensionsResource());
- } else {
- extensionPath = Paths.get(url.toURI());
- }
-
- bucket.addAll(readExtensions(extensionPath));
+ collectExtensions(url, bucket);
}
debugExtensions(bucket);
try {
Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource());
- if (urls == null || !urls.hasMoreElements()) {
- log.debug("Cannot find '{}'", getExtensionsResource());
- } else {
+ if (urls.hasMoreElements()) {
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
- Path extensionPath;
- if (url.toURI().getScheme().equals("jar")) {
- extensionPath = FileUtils.getPath(url.toURI(), getExtensionsResource());
- } else {
- extensionPath = Paths.get(url.toURI());
- }
-
- bucket.addAll(readExtensions(extensionPath));
+ collectExtensions(url, bucket);
}
+ } else {
+ log.debug("Cannot find '{}'", getExtensionsResource());
}
debugExtensions(bucket);
return result;
}
+ private void collectExtensions(URL url, Set<String> bucket) throws URISyntaxException, IOException {
+ Path extensionPath;
+ if (url.toURI().getScheme().equals("jar")) {
+ extensionPath = FileUtils.getPath(url.toURI(), getExtensionsResource());
+ } else {
+ extensionPath = Paths.get(url.toURI());
+ }
+
+ bucket.addAll(readExtensions(extensionPath));
+ }
+
private static String getExtensionsResource() {
return ServiceProviderExtensionStorage.EXTENSIONS_RESOURCE;
}