From 896b5767fe0b43059afa18c3a2ff1eadd7a02b1c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 14 Mar 2025 13:36:04 -0700 Subject: [PATCH] Polish --- .../springframework/CheckFactoriesFile.java | 47 ++++++++++--------- .../docker/transport/HttpClientTransport.java | 5 +- spring-boot-project/spring-boot/build.gradle | 2 +- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/springframework/CheckFactoriesFile.java b/buildSrc/src/main/java/org/springframework/boot/build/springframework/CheckFactoriesFile.java index 766f443aea7..9c4227fd1b5 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/springframework/CheckFactoriesFile.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/springframework/CheckFactoriesFile.java @@ -96,31 +96,17 @@ public abstract class CheckFactoriesFile extends DefaultTask { } private void check(File factoriesFile) { - Properties factories = load(factoriesFile); + Properties properties = load(factoriesFile); Map> problems = new LinkedHashMap<>(); - for (String key : factories.stringPropertyNames()) { - List values = Arrays - .asList(StringUtils.commaDelimitedListToStringArray(factories.getProperty(key))); - for (String value : values) { - boolean found = find(value); - if (!found) { - List problemsForKey = problems.computeIfAbsent(key, (k) -> new ArrayList<>()); - String binaryName = binaryNameOf(value); - found = find(binaryName); - if (found) { - problemsForKey - .add("'%s' should be listed using its binary name '%s'".formatted(value, binaryName)); - } - else { - problemsForKey.add("'%s' was not found".formatted(value)); - } - } - } - List sortedValues = new ArrayList<>(values); + for (String name : properties.stringPropertyNames()) { + String value = properties.getProperty(name); + List classNames = Arrays.asList(StringUtils.commaDelimitedListToStringArray(value)); + collectProblems(problems, name, classNames); + List sortedValues = new ArrayList<>(classNames); Collections.sort(sortedValues); - if (!sortedValues.equals(values)) { - List problemsForKey = problems.computeIfAbsent(key, (k) -> new ArrayList<>()); - problemsForKey.add("Entries should be sorted alphabetically"); + if (!sortedValues.equals(classNames)) { + List problemsForClassName = problems.computeIfAbsent(name, (k) -> new ArrayList<>()); + problemsForClassName.add("Entries should be sorted alphabetically"); } } File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile(); @@ -130,6 +116,21 @@ public abstract class CheckFactoriesFile extends DefaultTask { } } + private void collectProblems(Map> problems, String key, List classNames) { + for (String className : classNames) { + if (!find(className)) { + addNoFoundProblem(className, problems.computeIfAbsent(key, (k) -> new ArrayList<>())); + } + } + } + + private void addNoFoundProblem(String className, List problemsForClassName) { + String binaryName = binaryNameOf(className); + boolean foundBinaryForm = find(binaryName); + problemsForClassName.add(!foundBinaryForm ? "'%s' was not found".formatted(className) + : "'%s' should be listed using its binary name '%s'".formatted(className, binaryName)); + } + private boolean find(String className) { for (File root : this.classpath.getFiles()) { String classFilePath = className.replace(".", "/") + ".class"; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java index 7ea5f00f3d2..7f8ecc9e9e2 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java @@ -167,10 +167,7 @@ abstract class HttpClientTransport implements HttpTransport { return null; } try (InputStream stream = entity.getContent()) { - if (stream == null) { - return null; - } - return stream.readAllBytes(); + return (stream != null) ? stream.readAllBytes() : null; } } diff --git a/spring-boot-project/spring-boot/build.gradle b/spring-boot-project/spring-boot/build.gradle index 998dc8711fb..459677c3536 100644 --- a/spring-boot-project/spring-boot/build.gradle +++ b/spring-boot-project/spring-boot/build.gradle @@ -96,7 +96,7 @@ dependencies { optional("org.yaml:snakeyaml") optional("org.jetbrains.kotlin:kotlin-reflect") optional("org.jetbrains.kotlin:kotlin-stdlib") - + testFixturesCompileOnly("jakarta.servlet:jakarta.servlet-api") testFixturesCompileOnly("org.mockito:mockito-core") testFixturesCompileOnly("org.springframework:spring-web")