This commit is contained in:
Phillip Webb 2025-03-14 13:36:04 -07:00
parent 2d6eb6618b
commit 896b5767fe
3 changed files with 26 additions and 28 deletions

View File

@ -96,31 +96,17 @@ public abstract class CheckFactoriesFile extends DefaultTask {
} }
private void check(File factoriesFile) { private void check(File factoriesFile) {
Properties factories = load(factoriesFile); Properties properties = load(factoriesFile);
Map<String, List<String>> problems = new LinkedHashMap<>(); Map<String, List<String>> problems = new LinkedHashMap<>();
for (String key : factories.stringPropertyNames()) { for (String name : properties.stringPropertyNames()) {
List<String> values = Arrays String value = properties.getProperty(name);
.asList(StringUtils.commaDelimitedListToStringArray(factories.getProperty(key))); List<String> classNames = Arrays.asList(StringUtils.commaDelimitedListToStringArray(value));
for (String value : values) { collectProblems(problems, name, classNames);
boolean found = find(value); List<String> sortedValues = new ArrayList<>(classNames);
if (!found) {
List<String> 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<String> sortedValues = new ArrayList<>(values);
Collections.sort(sortedValues); Collections.sort(sortedValues);
if (!sortedValues.equals(values)) { if (!sortedValues.equals(classNames)) {
List<String> problemsForKey = problems.computeIfAbsent(key, (k) -> new ArrayList<>()); List<String> problemsForClassName = problems.computeIfAbsent(name, (k) -> new ArrayList<>());
problemsForKey.add("Entries should be sorted alphabetically"); problemsForClassName.add("Entries should be sorted alphabetically");
} }
} }
File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile(); File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile();
@ -130,6 +116,21 @@ public abstract class CheckFactoriesFile extends DefaultTask {
} }
} }
private void collectProblems(Map<String, List<String>> problems, String key, List<String> classNames) {
for (String className : classNames) {
if (!find(className)) {
addNoFoundProblem(className, problems.computeIfAbsent(key, (k) -> new ArrayList<>()));
}
}
}
private void addNoFoundProblem(String className, List<String> 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) { private boolean find(String className) {
for (File root : this.classpath.getFiles()) { for (File root : this.classpath.getFiles()) {
String classFilePath = className.replace(".", "/") + ".class"; String classFilePath = className.replace(".", "/") + ".class";

View File

@ -167,10 +167,7 @@ abstract class HttpClientTransport implements HttpTransport {
return null; return null;
} }
try (InputStream stream = entity.getContent()) { try (InputStream stream = entity.getContent()) {
if (stream == null) { return (stream != null) ? stream.readAllBytes() : null;
return null;
}
return stream.readAllBytes();
} }
} }

View File

@ -96,7 +96,7 @@ dependencies {
optional("org.yaml:snakeyaml") optional("org.yaml:snakeyaml")
optional("org.jetbrains.kotlin:kotlin-reflect") optional("org.jetbrains.kotlin:kotlin-reflect")
optional("org.jetbrains.kotlin:kotlin-stdlib") optional("org.jetbrains.kotlin:kotlin-stdlib")
testFixturesCompileOnly("jakarta.servlet:jakarta.servlet-api") testFixturesCompileOnly("jakarta.servlet:jakarta.servlet-api")
testFixturesCompileOnly("org.mockito:mockito-core") testFixturesCompileOnly("org.mockito:mockito-core")
testFixturesCompileOnly("org.springframework:spring-web") testFixturesCompileOnly("org.springframework:spring-web")