Merge pull request #33013 from biergit

* gh-33013:
  Polish "Polish ImportCandidates"
  Polish ImportCandidates

Closes gh-33013
pull/33648/head
Andy Wilkinson 2 years ago
commit e44b114c81

@ -73,12 +73,12 @@ public final class ImportCandidates implements Iterable<String> {
ClassLoader classLoaderToUse = decideClassloader(classLoader);
String location = String.format(LOCATION, annotation.getName());
Enumeration<URL> urls = findUrlsInClasspath(classLoaderToUse, location);
List<String> autoConfigurations = new ArrayList<>();
List<String> importCandidates = new ArrayList<>();
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
autoConfigurations.addAll(readAutoConfigurations(url));
importCandidates.addAll(readCandidateConfigurations(url));
}
return new ImportCandidates(autoConfigurations);
return new ImportCandidates(importCandidates);
}
private static ClassLoader decideClassloader(ClassLoader classLoader) {
@ -93,15 +93,14 @@ public final class ImportCandidates implements Iterable<String> {
return classLoader.getResources(location);
}
catch (IOException ex) {
throw new IllegalArgumentException("Failed to load autoconfigurations from location [" + location + "]",
ex);
throw new IllegalArgumentException("Failed to load configurations from location [" + location + "]", ex);
}
}
private static List<String> readAutoConfigurations(URL url) {
private static List<String> readCandidateConfigurations(URL url) {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(new UrlResource(url).getInputStream(), StandardCharsets.UTF_8))) {
List<String> autoConfigurations = new ArrayList<>();
List<String> candidates = new ArrayList<>();
String line;
while ((line = reader.readLine()) != null) {
line = stripComment(line);
@ -109,12 +108,12 @@ public final class ImportCandidates implements Iterable<String> {
if (line.isEmpty()) {
continue;
}
autoConfigurations.add(line);
candidates.add(line);
}
return autoConfigurations;
return candidates;
}
catch (IOException ex) {
throw new IllegalArgumentException("Unable to load autoconfigurations from location [" + url + "]", ex);
throw new IllegalArgumentException("Unable to load configurations from location [" + url + "]", ex);
}
}

Loading…
Cancel
Save