*/
@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:
@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) {
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>
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;
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 {
.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());
.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());
assertNumberOfResourcesAndFirstLineOfFirstElement(3, "parent", resources);
}
+ @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();