reflections icon indicating copy to clipboard operation
reflections copied to clipboard

Question: Migration 0.9.x to 0.10.x Resource scanner

Open xtermi2 opened this issue 4 years ago • 3 comments

Hi,

I currently can't manage to migrate my 0.9.x code to 0.10.x:

# 0.9.x code
String location = "test.";
Collection<URL> urls = ClasspathHelper.forPackage(location);
Reflections reflections = new Reflections(new ConfigurationBuilder()
                    .setScanners(new ResourcesScanner())
                    .filterInputsBy(new FilterBuilder().includePackage(location))
                    .setUrls(urls));
Set<String> resources = reflections.getResources(this::isValidFilename);

private boolean isValidFilename(String fileName) {
        return hasValidSuffix(fileName)
                && fileName.startsWith(this.prefix);
}

private boolean hasValidSuffix(String fileName) {
        return this.suffixes
                .stream()
                .anyMatch(suffix -> fileName.toLowerCase().endsWith(suffix.toLowerCase()));
}

I tried a lot different options in 0.10.x but nothing worked like in 0.9.x and creating a regexp pattern matching my isValidFilename logic would be really complex. Isn't there any option to do something like reflections.getResources(<predicate>) which was possible in 0.9.x?

Thanks for your help

xtermi2 avatar Mar 30 '22 21:03 xtermi2

Nobody any hint or suggestion how to do this?

xtermi2 avatar Oct 03 '22 19:10 xtermi2

I also do not see any easy way to do that here. I guess you need to choose two steps:

  1. Getting all files with file prefix
  2. Post process this list of files with isValidFilename method.

Otherwise did you try to go over reflections.get method with following signature?

>public <T> Set<T> get(QueryFunction<Store, T> query) 

RiVogel avatar Nov 02 '23 10:11 RiVogel

这是来自QQ邮箱的自动回复邮件。   您好,我已经收到您的邮件

Terraqo avatar Nov 02 '23 10:11 Terraqo