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