From 508b5121f671495a5ebe600843c13f8af70e76a7 Mon Sep 17 00:00:00 2001 From: cwisniew Date: Sat, 31 Aug 2024 22:41:27 +0930 Subject: [PATCH 1/4] small fix for installUsingReflection() --- .../net/rptools/maptool/client/AppSetup.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/AppSetup.java b/src/main/java/net/rptools/maptool/client/AppSetup.java index 5543850fac..7a0c3ebb1d 100644 --- a/src/main/java/net/rptools/maptool/client/AppSetup.java +++ b/src/main/java/net/rptools/maptool/client/AppSetup.java @@ -20,6 +20,7 @@ import java.net.URL; import java.util.Set; import java.util.regex.Pattern; +import java.util.stream.Collectors; import javax.swing.*; import net.rptools.lib.FileUtil; import net.rptools.maptool.model.AssetManager; @@ -29,6 +30,8 @@ import org.apache.logging.log4j.Logger; import org.reflections.Reflections; import org.reflections.scanners.ResourcesScanner; +import org.reflections.scanners.Scanners; +import org.reflections.util.ConfigurationBuilder; /** Executes only the first time the application is run. */ public class AppSetup { @@ -67,10 +70,15 @@ private static void installPredefinedProperties() { } private static void installUsingReflection(String source, File dir, String name) { - if (isNotEmpty(dir)) return; - - Reflections reflections = new Reflections(source, new ResourcesScanner()); - Set resourcePathSet = reflections.getResources(Pattern.compile(".*")); + if (isNotEmpty(dir)) { + return; + } + Set resourcePathSet = + new Reflections( + new ConfigurationBuilder().forPackage(source).setScanners(Scanners.Resources)) + .getResources(Pattern.compile(".*")).stream() + .filter(s -> s.startsWith(source)) + .collect(Collectors.toSet()); for (String resourcePath : resourcePathSet) { URL inputUrl = AppSetup.class.getClassLoader().getResource(resourcePath); @@ -78,7 +86,10 @@ private static void installUsingReflection(String source, File dir, String name) File resourceFile = new File(dir, resourceName); try { - log.info("Installing " + name + " in:" + resourceFile); + log.info("Installing " + + + + name + " in:" + resourceFile); FileUtils.copyURLToFile(inputUrl, resourceFile); } catch (IOException e) { log.error("ERROR copying " + inputUrl + " to " + resourceFile, e); From 2a4ab3479c8886b8b03104d0bf04d284feb5a1b0 Mon Sep 17 00:00:00 2001 From: cwisniew Date: Sat, 31 Aug 2024 22:42:56 +0930 Subject: [PATCH 2/4] Formatting fix --- src/main/java/net/rptools/maptool/client/AppSetup.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/AppSetup.java b/src/main/java/net/rptools/maptool/client/AppSetup.java index 7a0c3ebb1d..1813eb4dab 100644 --- a/src/main/java/net/rptools/maptool/client/AppSetup.java +++ b/src/main/java/net/rptools/maptool/client/AppSetup.java @@ -86,10 +86,7 @@ private static void installUsingReflection(String source, File dir, String name) File resourceFile = new File(dir, resourceName); try { - log.info("Installing " + - - - name + " in:" + resourceFile); + log.info("Installing name in:" + resourceFile); FileUtils.copyURLToFile(inputUrl, resourceFile); } catch (IOException e) { log.error("ERROR copying " + inputUrl + " to " + resourceFile, e); From 087b639d5f4e9cbbf2573304cb4b00d47d103adf Mon Sep 17 00:00:00 2001 From: cwisniew Date: Sat, 31 Aug 2024 22:44:41 +0930 Subject: [PATCH 3/4] Formatting fix --- src/main/java/net/rptools/maptool/client/AppSetup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/rptools/maptool/client/AppSetup.java b/src/main/java/net/rptools/maptool/client/AppSetup.java index 1813eb4dab..8a778eaa31 100644 --- a/src/main/java/net/rptools/maptool/client/AppSetup.java +++ b/src/main/java/net/rptools/maptool/client/AppSetup.java @@ -86,7 +86,7 @@ private static void installUsingReflection(String source, File dir, String name) File resourceFile = new File(dir, resourceName); try { - log.info("Installing name in:" + resourceFile); + log.info("Installing " + name + " in:" + resourceFile); FileUtils.copyURLToFile(inputUrl, resourceFile); } catch (IOException e) { log.error("ERROR copying " + inputUrl + " to " + resourceFile, e); From e7274eff5b151296e40cc6f6b3267f2cb94ca474 Mon Sep 17 00:00:00 2001 From: cwisniew Date: Sat, 31 Aug 2024 23:08:10 +0930 Subject: [PATCH 4/4] fix for second use of ResourcesScanner --- .../net/rptools/maptool/client/AppSetup.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/AppSetup.java b/src/main/java/net/rptools/maptool/client/AppSetup.java index 8a778eaa31..3bbf22149e 100644 --- a/src/main/java/net/rptools/maptool/client/AppSetup.java +++ b/src/main/java/net/rptools/maptool/client/AppSetup.java @@ -29,7 +29,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.reflections.Reflections; -import org.reflections.scanners.ResourcesScanner; import org.reflections.scanners.Scanners; import org.reflections.util.ConfigurationBuilder; @@ -105,9 +104,18 @@ private static boolean isNotEmpty(File dir) { */ public static void installDefaultUIThemes() { if (!themesInstalled) { - Reflections reflections = - new Reflections(AppConstants.DEFAULT_UI_THEMES, new ResourcesScanner()); - Set resourcePathSet = reflections.getResources(Pattern.compile(".*\\.theme")); + Set resourcePathSet = + new Reflections( + new ConfigurationBuilder() + .forPackage(AppConstants.DEFAULT_UI_THEMES) + .setScanners(Scanners.Resources)) + .getResources(Pattern.compile(".*")).stream() + .filter(s -> s.startsWith(AppConstants.DEFAULT_UI_THEMES)) + .collect(Collectors.toSet()) + .stream() + .filter(s -> s.endsWith(".theme")) + .filter(s -> s.startsWith(AppConstants.DEFAULT_UI_THEMES)) + .collect(Collectors.toSet()); for (String resourcePath : resourcePathSet) { URL inputUrl = AppSetup.class.getClassLoader().getResource(resourcePath);