aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Sidorov <117445585+etojesaandro@users.noreply.github.com>2024-06-29 22:30:03 +0300
committerGitHub <noreply@github.com>2024-06-29 22:30:03 +0300
commitc6502786275ee53fdacee33ac35fc4d08faa7026 (patch)
treecbfac300d8df964c296c85ead4e845e739b9d765
parent2b556de60fadb263b9b40757d6e1fcc6f3363cb2 (diff)
downloadpf4j-c6502786275ee53fdacee33ac35fc4d08faa7026.tar.gz
pf4j-c6502786275ee53fdacee33ac35fc4d08faa7026.zip
Plugin Extensions should be detected with any ClassLoadingStrategy (#586)
-rw-r--r--pf4j/src/main/java/org/pf4j/PluginClassLoader.java15
-rw-r--r--pf4j/src/test/java/org/pf4j/PluginClassLoaderTest.java16
2 files changed, 28 insertions, 3 deletions
diff --git a/pf4j/src/main/java/org/pf4j/PluginClassLoader.java b/pf4j/src/main/java/org/pf4j/PluginClassLoader.java
index d11e7b9..cf0608c 100644
--- a/pf4j/src/main/java/org/pf4j/PluginClassLoader.java
+++ b/pf4j/src/main/java/org/pf4j/PluginClassLoader.java
@@ -181,8 +181,9 @@ public class PluginClassLoader extends URLClassLoader {
*/
@Override
public URL getResource(String name) {
+ ClassLoadingStrategy loadingStrategy = getClassLoadingStrategy(name);
log.trace("Received request to load resource '{}'", name);
- for (ClassLoadingStrategy.Source classLoadingSource : classLoadingStrategy.getSources()) {
+ for (ClassLoadingStrategy.Source classLoadingSource : loadingStrategy.getSources()) {
URL url = null;
switch (classLoadingSource) {
case APPLICATION:
@@ -210,9 +211,9 @@ public class PluginClassLoader extends URLClassLoader {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
List<URL> resources = new ArrayList<>();
-
+ ClassLoadingStrategy loadingStrategy = getClassLoadingStrategy(name);
log.trace("Received request to load resources '{}'", name);
- for (ClassLoadingStrategy.Source classLoadingSource : classLoadingStrategy.getSources()) {
+ for (ClassLoadingStrategy.Source classLoadingSource : loadingStrategy.getSources()) {
switch (classLoadingSource) {
case APPLICATION:
if (getParent() != null) {
@@ -231,6 +232,14 @@ public class PluginClassLoader extends URLClassLoader {
return Collections.enumeration(resources);
}
+ private ClassLoadingStrategy getClassLoadingStrategy(String name) {
+ ClassLoadingStrategy loadingStrategy = classLoadingStrategy;
+ if (LegacyExtensionFinder.EXTENSIONS_RESOURCE.equals(name)) {
+ loadingStrategy = ClassLoadingStrategy.PAD;
+ }
+ return loadingStrategy;
+ }
+
/**
* Closes this class loader.
* <p>
diff --git a/pf4j/src/test/java/org/pf4j/PluginClassLoaderTest.java b/pf4j/src/test/java/org/pf4j/PluginClassLoaderTest.java
index e74166e..b19bd3b 100644
--- a/pf4j/src/test/java/org/pf4j/PluginClassLoaderTest.java
+++ b/pf4j/src/test/java/org/pf4j/PluginClassLoaderTest.java
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import org.pf4j.processor.LegacyExtensionStorage;
import org.pf4j.test.PluginZip;
import org.pf4j.util.FileUtils;
@@ -74,6 +75,7 @@ class PluginClassLoaderTest {
createFile(parentClassPathBase.resolve("META-INF").resolve("file-in-both-parent-and-dependency-and-plugin"));
createFile(parentClassPathBase.resolve("META-INF").resolve("file-in-both-parent-and-dependency"));
createFile(parentClassPathBase.resolve("META-INF").resolve("file-in-both-parent-and-plugin"));
+ createFile(parentClassPathBase.resolve(LegacyExtensionStorage.EXTENSIONS_RESOURCE));
}
private static void createFile(Path pathToFile) throws IOException {
@@ -106,6 +108,7 @@ class PluginClassLoaderTest {
.addFile(Paths.get("classes/META-INF/dependency-file"), "dependency")
.addFile(Paths.get("classes/META-INF/file-in-both-parent-and-dependency-and-plugin"), "dependency")
.addFile(Paths.get("classes/META-INF/file-in-both-parent-and-dependency"), "dependency")
+ .addFile(Paths.get("classes/" + LegacyExtensionStorage.EXTENSIONS_RESOURCE), "dependency")
.build();
FileUtils.expandIfZip(pluginDependencyZip.path());
@@ -148,6 +151,7 @@ class PluginClassLoaderTest {
.addFile(Paths.get("classes/META-INF/plugin-file"), "plugin")
.addFile(Paths.get("classes/META-INF/file-in-both-parent-and-dependency-and-plugin"), "plugin")
.addFile(Paths.get("classes/META-INF/file-in-both-parent-and-plugin"), "plugin")
+ .addFile(Paths.get("classes/" + LegacyExtensionStorage.EXTENSIONS_RESOURCE), "plugin")
.build();
FileUtils.expandIfZip(pluginZip.path());
@@ -326,6 +330,18 @@ class PluginClassLoaderTest {
}
@Test
+ void parentFirstGetExtensionsIndexExistsInParentAndDependencyAndPlugin() throws URISyntaxException, IOException {
+ URL resource = parentLastPluginClassLoader.getResource(LegacyExtensionFinder.EXTENSIONS_RESOURCE);
+ assertFirstLine("plugin", resource);
+ }
+
+ @Test
+ void parentLastGetExtensionsIndexExistsInParentAndDependencyAndPlugin() throws URISyntaxException, IOException {
+ URL resource = parentLastPluginClassLoader.getResource(LegacyExtensionFinder.EXTENSIONS_RESOURCE);
+ assertFirstLine("plugin", resource);
+ }
+
+ @Test
void isClosed() throws IOException {
parentLastPluginClassLoader.close();
assertTrue(parentLastPluginClassLoader.isClosed());