Skip to content

Commit

Permalink
config: support multiple packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ibodrov committed Oct 1, 2024
1 parent 2a427cf commit 752ac45
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.*;
import java.net.URL;
import java.util.*;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;

//import com.typesafe.config.Config;
Expand All @@ -55,10 +57,21 @@ public class OllieConfigurationModule extends AbstractModule {
private final Set<Config> boundAnnotations;

public OllieConfigurationModule(String packageToScan, com.typesafe.config.Config config) {
this(Collections.singletonList(packageToScan), config);
}

public OllieConfigurationModule(Collection<String> packagesToScan, com.typesafe.config.Config config) {
FilterBuilder filter = new FilterBuilder()
.includePackage(packagesToScan.toArray(new String[0]));

Collection<URL> urls = packagesToScan.stream()
.flatMap(p -> ClasspathHelper.forPackage(p).stream())
.collect(Collectors.toList());

ConfigurationBuilder configBuilder =
new ConfigurationBuilder()
.filterInputsBy(new FilterBuilder().includePackage(packageToScan))
.setUrls(ClasspathHelper.forPackage(packageToScan))
.filterInputsBy(filter)
.setUrls(urls)
.setScanners(
new TypeAnnotationsScanner(),
new MethodParameterScanner(),
Expand Down

0 comments on commit 752ac45

Please sign in to comment.