From 9aca87af94560d0380e2ec98a7097a30c2a79149 Mon Sep 17 00:00:00 2001 From: Anton Platonov Date: Tue, 13 Aug 2024 10:25:40 +0300 Subject: [PATCH] fix: use URLClassLoader with ResourceProvider in Maven plugins Fixes vaadin/hilla#2637 ResourceProvider ignored the actual project's resources when using the default ClassLoader. This resulted in loading `vaadin-featureflags.properties` from the vaadin-dev-bundle jar, even though there is a file in the project. --- .../main/java/com/vaadin/flow/utils/LookupImpl.java | 2 +- .../com/vaadin/flow/utils/ResourceProviderImpl.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/utils/LookupImpl.java b/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/utils/LookupImpl.java index 2f57fd6724a..6883a392103 100644 --- a/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/utils/LookupImpl.java +++ b/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/utils/LookupImpl.java @@ -45,7 +45,7 @@ public LookupImpl(ClassFinder classFinder) { @Override public T lookup(Class serviceClass) { if (ResourceProvider.class.isAssignableFrom(serviceClass)) { - return serviceClass.cast(new ResourceProviderImpl()); + return serviceClass.cast(new ResourceProviderImpl(classFinder.getClassLoader())); } return lookupAll(serviceClass).stream().findFirst().orElse(null); } diff --git a/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/utils/ResourceProviderImpl.java b/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/utils/ResourceProviderImpl.java index 1d3db410ea6..402cf9dcb61 100644 --- a/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/utils/ResourceProviderImpl.java +++ b/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/utils/ResourceProviderImpl.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.net.URLClassLoader; import java.util.Collections; import java.util.List; @@ -31,6 +32,16 @@ */ class ResourceProviderImpl implements ResourceProvider { + private ClassLoader classLoader; + + ResourceProviderImpl() { + this(ResourceProviderImpl.class.getClassLoader()); + } + + ResourceProviderImpl(ClassLoader classLoader) { + this.classLoader = classLoader; + } + @Override public URL getApplicationResource(String path) { return ResourceProviderImpl.class.getClassLoader().getResource(path);