From 155300525e6b965650c8e8100424955a5f24177f Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 13 Aug 2023 19:15:38 -0700 Subject: [PATCH] Polish --- ...ImportAutoConfigurationImportSelector.java | 23 +++++++++---------- .../core/DockerCliIntegrationTests.java | 12 +++------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java index 9d23cc5116..f19ff33322 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelector.java @@ -96,20 +96,15 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec if (classes.length > 0) { return Arrays.asList(classes); } - Collection factoryNames = loadFactoryNames(source); - return factoryNames.stream().map((name) -> { - if (name.startsWith(OPTIONAL_PREFIX)) { - name = name.substring(OPTIONAL_PREFIX.length()); - if (!present(name)) { - return null; - } - } - return name; - }).filter(Objects::nonNull).toList(); + return loadFactoryNames(source).stream().map(this::mapFactoryName).filter(Objects::nonNull).toList(); } - protected Collection loadFactoryNames(Class source) { - return ImportCandidates.load(source, getBeanClassLoader()).getCandidates(); + private String mapFactoryName(String name) { + if (!name.startsWith(OPTIONAL_PREFIX)) { + return name; + } + name = name.substring(OPTIONAL_PREFIX.length()); + return (!present(name)) ? null : name; } private boolean present(String className) { @@ -117,6 +112,10 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec return new ClassPathResource(resourcePath).exists(); } + protected Collection loadFactoryNames(Class source) { + return ImportCandidates.load(source, getBeanClassLoader()).getCandidates(); + } + @Override protected Set getExclusions(AnnotationMetadata metadata, AnnotationAttributes attributes) { Set exclusions = new LinkedHashSet<>(); diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java index ee5efe52eb..b405ff587e 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java @@ -89,8 +89,7 @@ class DockerCliIntegrationTests { cli.run(new ComposeStop(Duration.ofSeconds(10))); ps = cli.run(new ComposePs()); assertThat(ps).isEmpty(); - // Run start, verify that service is there, then run down and verify they are - // gone + // Run start, verify service is there, then run down and verify they are gone cli.run(new ComposeStart(LogLevel.INFO)); ps = cli.run(new ComposePs()); assertThat(ps).hasSize(1); @@ -116,15 +115,10 @@ class DockerCliIntegrationTests { private static File createComposeFile() throws IOException { File composeFile = new ClassPathResource("redis-compose.yaml", DockerCliIntegrationTests.class).getFile(); File tempComposeFile = Path.of(tempDir.toString(), composeFile.getName()).toFile(); - String composeFileContent; - try (FileReader reader = new FileReader(composeFile)) { - composeFileContent = FileCopyUtils.copyToString(reader); - } + String composeFileContent = FileCopyUtils.copyToString(new FileReader(composeFile)); composeFileContent = composeFileContent.replace("{imageName}", DockerImageNames.redis().asCanonicalNameString()); - try (FileWriter writer = new FileWriter(tempComposeFile)) { - FileCopyUtils.copy(composeFileContent, writer); - } + FileCopyUtils.copy(composeFileContent, new FileWriter(tempComposeFile)); return tempComposeFile; }