Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xtermi2 opened this issue Mar 30, 2022 · 3 comments
Open

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

xtermi2 opened this issue Mar 30, 2022 · 3 comments

Comments

@xtermi2
Copy link

xtermi2 commented Mar 30, 2022

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
Copy link
Author

xtermi2 commented Oct 3, 2022

Nobody any hint or suggestion how to do this?

@RiVogel
Copy link

RiVogel commented Nov 2, 2023

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) 

@potatoxf
Copy link

potatoxf commented Nov 2, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants