Skip to content

Commit

Permalink
Merge pull request #4910 from cwisniew/reapply-4884
Browse files Browse the repository at this point in the history
small fix for installUsingReflection() (Reapply #4884)
  • Loading branch information
cwisniew authored Sep 23, 2024
2 parents c7ff5c5 + 243347f commit a9f7856
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/main/java/net/rptools/maptool/client/AppSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,8 @@
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;

/** Executes only the first time the application is run. */
public class AppSetup {
Expand Down Expand Up @@ -67,10 +69,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<String> resourcePathSet = reflections.getResources(Pattern.compile(".*"));
if (isNotEmpty(dir)) {
return;
}
Set<String> 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);
Expand All @@ -97,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<String> resourcePathSet = reflections.getResources(Pattern.compile(".*\\.theme"));
Set<String> 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);
Expand Down

0 comments on commit a9f7856

Please sign in to comment.