From 527b2f2cac0096b32a386e487a8803938c8bf06a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 13 Aug 2023 18:18:48 -0700 Subject: [PATCH 1/5] Polish --- .../build/bom/bomr/UpgradeDependencies.java | 49 ++++++++++--------- .../batch/JobLauncherApplicationRunner.java | 5 +- .../logging/logback/LogbackLoggingSystem.java | 4 +- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java index adc91e88d7..49b93379bd 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java @@ -109,31 +109,13 @@ public abstract class UpgradeDependencies extends DefaultTask { Issue existingUpgradeIssue = findExistingUpgradeIssue(existingUpgradeIssues, upgrade); try { Path modified = upgradeApplicator.apply(upgrade); - int issueNumber; - if (existingUpgradeIssue != null && existingUpgradeIssue.getState() == Issue.State.OPEN) { - issueNumber = existingUpgradeIssue.getNumber(); - } - else { - issueNumber = repository.openIssue(title, - (existingUpgradeIssue != null) ? "Supersedes #" + existingUpgradeIssue.getNumber() : "", - issueLabels, milestone); - if (existingUpgradeIssue != null && existingUpgradeIssue.getState() == Issue.State.CLOSED) { - existingUpgradeIssue.label(Arrays.asList("type: task", "status: superseded")); - } - } - if (existingUpgradeIssue != null) { - if (existingUpgradeIssue.getState() == Issue.State.CLOSED) { - System.out.println(" Issue: " + issueNumber + " - " + title + " (supersedes #" - + existingUpgradeIssue.getNumber() + " " + existingUpgradeIssue.getTitle() + ")"); - } - else { - System.out - .println(" Issue: " + issueNumber + " - " + title + " (completes existing upgrade)"); - } - } - else { - System.out.println(" Issue: " + issueNumber + " - " + title); + int issueNumber = getOrOpenUpgradeIssue(repository, issueLabels, milestone, title, + existingUpgradeIssue); + if (existingUpgradeIssue != null && existingUpgradeIssue.getState() == Issue.State.CLOSED) { + existingUpgradeIssue.label(Arrays.asList("type: task", "status: superseded")); } + System.out.println(" Issue: " + issueNumber + " - " + title + + getExistingUpgradeIssueMessageDetails(existingUpgradeIssue)); if (new ProcessBuilder().command("git", "add", modified.toFile().getAbsolutePath()) .start() .waitFor() != 0) { @@ -154,6 +136,25 @@ public abstract class UpgradeDependencies extends DefaultTask { } } + private int getOrOpenUpgradeIssue(GitHubRepository repository, List issueLabels, Milestone milestone, + String title, Issue existingUpgradeIssue) { + if (existingUpgradeIssue != null && existingUpgradeIssue.getState() == Issue.State.OPEN) { + return existingUpgradeIssue.getNumber(); + } + String body = (existingUpgradeIssue != null) ? "Supersedes #" + existingUpgradeIssue.getNumber() : ""; + return repository.openIssue(title, body, issueLabels, milestone); + } + + private String getExistingUpgradeIssueMessageDetails(Issue existingUpgradeIssue) { + if (existingUpgradeIssue == null) { + return ""; + } + if (existingUpgradeIssue.getState() != Issue.State.CLOSED) { + return " (completes existing upgrade)"; + } + return " (supersedes #" + existingUpgradeIssue.getNumber() + " " + existingUpgradeIssue.getTitle() + ")"; + } + private List verifyLabels(GitHubRepository repository) { Set availableLabels = repository.getLabels(); List issueLabels = this.bom.getUpgrade().getGitHub().getIssueLabels(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java index ae28d64a7a..0c7afe5e6f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java @@ -117,9 +117,8 @@ public class JobLauncherApplicationRunner public void afterPropertiesSet() { if (StringUtils.hasText(this.jobNames)) { for (String jobName : jobsToRun()) { - if (!isLocalJob(jobName) && !isRegisteredJob(jobName)) { - throw new IllegalArgumentException("No job found with name '" + jobName + "'"); - } + Assert.isTrue(isLocalJob(jobName) || isRegisteredJob(jobName), + () -> "No job found with name '" + jobName + "'"); } } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java index 468fbd6c86..1875925b61 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java @@ -187,9 +187,7 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem { } IllegalStateException ex = new IllegalStateException( String.format("Logback configuration error detected: %n%s", errors)); - for (Throwable suppressedException : suppressedExceptions) { - ex.addSuppressed(suppressedException); - } + suppressedExceptions.forEach(ex::addSuppressed); throw ex; } From 46773dd5df8109b71a9effd367b97701f167bbe2 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 13 Aug 2023 18:19:05 -0700 Subject: [PATCH 2/5] Update copyright year of changed files --- .../boot/autoconfigure/security/SecurityProperties.java | 2 +- .../buildpack/platform/docker/ssl/KeyStoreFactoryTests.java | 2 +- .../boot/logging/logback/LogbackLoggingSystem.java | 2 +- .../boot/web/embedded/tomcat/SslConnectorCustomizer.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java index a81134f8f6..b11c67f6c9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ssl/KeyStoreFactoryTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ssl/KeyStoreFactoryTests.java index 5168e37b55..837f5c4017 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ssl/KeyStoreFactoryTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ssl/KeyStoreFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java index 1875925b61..91e6d4e189 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizer.java index 1aeb3c1a3a..d87e64059c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 980572341564b2d46f3ab02a98cfde1388ac2703 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 13 Aug 2023 18:50:13 -0700 Subject: [PATCH 3/5] Update copyright year of changed files --- .../concourse/releasescripts/sonatype/ArtifactCollector.java | 2 +- .../concourse/releasescripts/sonatype/SonatypeService.java | 2 +- .../ReactiveElasticsearchClientAutoConfiguration.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/ArtifactCollector.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/ArtifactCollector.java index d1d466f5b7..9a271cc001 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/ArtifactCollector.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/ArtifactCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java index ed57036621..ef1cd6ec5c 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ReactiveElasticsearchClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ReactiveElasticsearchClientAutoConfiguration.java index d02c60ef36..16c56ac08e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ReactiveElasticsearchClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ReactiveElasticsearchClientAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 2fdc29b885dc6ddf0208273a76faa9f3e4194d47 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 13 Aug 2023 19:00:04 -0700 Subject: [PATCH 4/5] Revert "Polish" This reverts commit 6a65ca13ea642bc7060cdae848bb3fa4e71576da since FileCopyUtils will close the reader/writer. --- .../test/AbstractDockerComposeIntegrationTests.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/test/AbstractDockerComposeIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/test/AbstractDockerComposeIntegrationTests.java index 970d9cb936..b282af843d 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/test/AbstractDockerComposeIntegrationTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/test/AbstractDockerComposeIntegrationTests.java @@ -83,14 +83,9 @@ public abstract class AbstractDockerComposeIntegrationTests { private File transformedComposeFile(File composeFile, DockerImageName imageName) { File tempComposeFile = Path.of(tempDir.toString(), composeFile.getName()).toFile(); try { - String composeFileContent; - try (FileReader reader = new FileReader(composeFile)) { - composeFileContent = FileCopyUtils.copyToString(reader); - } + String composeFileContent = FileCopyUtils.copyToString(new FileReader(composeFile)); composeFileContent = composeFileContent.replace("{imageName}", imageName.asCanonicalNameString()); - try (FileWriter writer = new FileWriter(tempComposeFile)) { - FileCopyUtils.copy(composeFileContent, writer); - } + FileCopyUtils.copy(composeFileContent, new FileWriter(tempComposeFile)); } catch (IOException ex) { fail("Error transforming Docker compose file '" + composeFile + "' to '" + tempComposeFile + "': " From 155300525e6b965650c8e8100424955a5f24177f Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 13 Aug 2023 19:15:38 -0700 Subject: [PATCH 5/5] 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; }