2525import java .lang .annotation .Annotation ;
2626import java .lang .reflect .InvocationTargetException ;
2727import java .lang .reflect .Method ;
28+ import java .net .URI ;
2829import java .net .URL ;
2930import java .net .URLDecoder ;
3031import java .nio .charset .StandardCharsets ;
3334import java .nio .file .Paths ;
3435import java .util .Arrays ;
3536import java .util .Collections ;
36- import java .util .Enumeration ;
3737import java .util .HashSet ;
3838import java .util .List ;
3939import java .util .Locale ;
6262import com .vaadin .base .devserver .viteproxy .ViteWebsocketEndpoint ;
6363import com .vaadin .experimental .FeatureFlags ;
6464import com .vaadin .flow .di .Lookup ;
65+ import com .vaadin .flow .di .ResourceProvider ;
6566import com .vaadin .flow .internal .DevModeHandler ;
6667import com .vaadin .flow .server .Constants ;
6768import com .vaadin .flow .server .ExecutionFailedException ;
@@ -273,8 +274,10 @@ public static DevModeHandler initDevModeHandler(Set<Class<?>> classes,
273274 options .createMissingPackageJson (true );
274275 }
275276
276- Set <File > frontendLocations = getFrontendLocationsFromClassloader (
277- DevModeStartupListener .class .getClassLoader ());
277+ ResourceProvider resourceProvider = lookup
278+ .lookup (ResourceProvider .class );
279+ Set <File > frontendLocations = getFrontendLocationsFromResourceProvider (
280+ resourceProvider );
278281
279282 boolean useByteCodeScanner = config .getBooleanProperty (
280283 SERVLET_PARAMETER_DEVMODE_OPTIMIZE_BUNDLE ,
@@ -387,15 +390,17 @@ private static Logger log() {
387390 * META-INF/resources/frontend and META-INF/resources/themes folder. We
388391 * don't use URLClassLoader because will fail in Java 9+
389392 */
390- static Set <File > getFrontendLocationsFromClassloader (
391- ClassLoader classLoader ) throws VaadinInitializerException {
393+ static Set <File > getFrontendLocationsFromResourceProvider (
394+ ResourceProvider resourceProvider )
395+ throws VaadinInitializerException {
392396 Set <File > frontendFiles = new HashSet <>();
393- frontendFiles .addAll (getFrontendLocationsFromClassloader (classLoader ,
394- Constants .RESOURCES_FRONTEND_DEFAULT ));
395- frontendFiles .addAll (getFrontendLocationsFromClassloader (classLoader ,
396- Constants .COMPATIBILITY_RESOURCES_FRONTEND_DEFAULT ));
397- frontendFiles .addAll (getFrontendLocationsFromClassloader (classLoader ,
398- Constants .RESOURCES_THEME_JAR_DEFAULT ));
397+ frontendFiles .addAll (getFrontendLocationsFromResourceProvider (
398+ resourceProvider , Constants .RESOURCES_FRONTEND_DEFAULT ));
399+ frontendFiles .addAll (
400+ getFrontendLocationsFromResourceProvider (resourceProvider ,
401+ Constants .COMPATIBILITY_RESOURCES_FRONTEND_DEFAULT ));
402+ frontendFiles .addAll (getFrontendLocationsFromResourceProvider (
403+ resourceProvider , Constants .RESOURCES_THEME_JAR_DEFAULT ));
399404 return frontendFiles ;
400405 }
401406
@@ -410,22 +415,22 @@ private static void runNodeTasks(NodeTasks tasks) {
410415 }
411416 }
412417
413- private static Set <File > getFrontendLocationsFromClassloader (
414- ClassLoader classLoader , String resourcesFolder )
418+ private static Set <File > getFrontendLocationsFromResourceProvider (
419+ ResourceProvider resourceProvider , String resourcesFolder )
415420 throws VaadinInitializerException {
416421 Set <File > frontendFiles = new HashSet <>();
417422 try {
418- Enumeration <URL > en = classLoader .getResources (resourcesFolder );
423+ List <URL > en = resourceProvider
424+ .getApplicationResources (resourcesFolder );
419425 if (en == null ) {
420426 return frontendFiles ;
421427 }
422428 Set <String > vfsJars = new HashSet <>();
423- while (en .hasMoreElements ()) {
424- URL url = en .nextElement ();
429+ for (URL url : en ) {
425430 String urlString = url .toString ();
426431
427432 String path = URLDecoder .decode (url .getPath (),
428- StandardCharsets .UTF_8 . name () );
433+ StandardCharsets .UTF_8 );
429434 Matcher jarMatcher = JAR_FILE_REGEX .matcher (path );
430435 Matcher zipProtocolJarMatcher = ZIP_PROTOCOL_JAR_FILE_REGEX
431436 .matcher (path );
@@ -439,12 +444,14 @@ private static Set<File> getFrontendLocationsFromClassloader(
439444 if (jarVfsMatcher .find ()) {
440445 String vfsJar = jarVfsMatcher .group (1 );
441446 if (vfsJars .add (vfsJar )) { // NOSONAR
442- frontendFiles .add (
443- getPhysicalFileOfJBossVfsJar ( new URL ( vfsJar )));
447+ frontendFiles .add (getPhysicalFileOfJBossVfsJar (
448+ URI . create ( vfsJar ). toURL ( )));
444449 }
445450 } else if (dirVfsMatcher .find ()) {
446- URL vfsDirUrl = new URL (urlString .substring (0 ,
447- urlString .lastIndexOf (resourcesFolder )));
451+ URL vfsDirUrl = URI
452+ .create (urlString .substring (0 ,
453+ urlString .lastIndexOf (resourcesFolder )))
454+ .toURL ();
448455 frontendFiles
449456 .add (getPhysicalFileOfJBossVfsDirectory (vfsDirUrl ));
450457 } else if (jarMatcher .find ()) {
@@ -476,7 +483,7 @@ private static File getPhysicalFileOfJBossVfsDirectory(URL url)
476483 throws IOException , VaadinInitializerException {
477484 try {
478485 Object virtualFile = url .openConnection ().getContent ();
479- Class virtualFileClass = virtualFile .getClass ();
486+ Class <?> virtualFileClass = virtualFile .getClass ();
480487
481488 // Reflection as we cannot afford a dependency to
482489 // WildFly or JBoss
@@ -492,7 +499,7 @@ private static File getPhysicalFileOfJBossVfsDirectory(URL url)
492499 // are created. Later, these physical files are scanned
493500 // to collect
494501 // their resources.
495- List virtualFiles = (List ) getChildrenRecursivelyMethod
502+ List <?> virtualFiles = (List <?> ) getChildrenRecursivelyMethod
496503 .invoke (virtualFile );
497504 File rootDirectory = (File ) getPhysicalFileMethod
498505 .invoke (virtualFile );
@@ -539,15 +546,15 @@ private static void generateJarFromJBossVfsFolder(Object jarVirtualFile,
539546 // We should use reflection to use JBoss VFS API as we cannot
540547 // afford a
541548 // dependency to WildFly or JBoss
542- Class virtualFileClass = jarVirtualFile .getClass ();
549+ Class <?> virtualFileClass = jarVirtualFile .getClass ();
543550 Method getChildrenRecursivelyMethod = virtualFileClass
544551 .getMethod ("getChildrenRecursively" );
545552 Method openStreamMethod = virtualFileClass .getMethod ("openStream" );
546553 Method isFileMethod = virtualFileClass .getMethod ("isFile" );
547554 Method getPathNameRelativeToMethod = virtualFileClass
548555 .getMethod ("getPathNameRelativeTo" , virtualFileClass );
549556
550- List jarVirtualChildren = (List ) getChildrenRecursivelyMethod
557+ List <?> jarVirtualChildren = (List <?> ) getChildrenRecursivelyMethod
551558 .invoke (jarVirtualFile );
552559 try (ZipOutputStream zipOutputStream = new ZipOutputStream (
553560 Files .newOutputStream (tempJar ))) {
0 commit comments