From 88480664d73184efa5e0369bc40b27c02ac16129 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 22 Jul 2024 19:59:27 +0100 Subject: [PATCH] Polish --- .../autoconfigure/mail/MailProperties.java | 14 ++++---- .../MailSenderPropertiesConfiguration.java | 4 +-- .../ProxyConnectionFactoryCustomizer.java | 10 +++--- .../compose/lifecycle/StartCommand.java | 33 +++++++++++-------- .../docker/compose/lifecycle/StopCommand.java | 33 +++++++++++-------- .../postgres/PostgresEnvironment.java | 4 +-- .../platform/build/BuildRequest.java | 1 + .../NestedConfigurationProperty.java | 1 + .../boot/jms/ConnectionFactoryUnwrapper.java | 15 +++++---- 9 files changed, 63 insertions(+), 52 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailProperties.java index 6ed2e906c3e0..2b2e182998a2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailProperties.java @@ -148,19 +148,17 @@ public Ssl getSsl() { public static class Ssl { /** - * Whether to enable SSL support. If enabled, {@code mail..ssl.enable} - * property is set to {@code true}. + * Whether to enable SSL support. If enabled, 'mail.(protocol).ssl.enable' + * property is set to 'true'. */ private boolean enabled = false; /** - * SSL bundle name. If not null, {@code mail..ssl.socketFactory} - * property is set to a {@code SSLSocketFactory} obtained from the corresponding - * SSL bundle. + * SSL bundle name. If set, 'mail.(protocol).ssl.socketFactory' property is set to + * an SSLSocketFactory obtained from the corresponding SSL bundle. *

- * Note that the {@code STARTTLS} command can use the corresponding - * {@code SSLSocketFactory}, even if {@code mail..ssl.enable} property - * is not set. + * Note that the STARTTLS command can use the corresponding SSLSocketFactory, even + * if the 'mail.(protocol).ssl.enable' property is not set. */ private String bundle; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java index 7466dcd9d77f..94cabfaa1cb1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java @@ -64,9 +64,7 @@ private void applyProperties(MailProperties properties, JavaMailSenderImpl sende } Properties javaMailProperties = asProperties(properties.getProperties()); String protocol = properties.getProtocol(); - if (!StringUtils.hasLength(protocol)) { - protocol = "smtp"; - } + protocol = (!StringUtils.hasLength(protocol)) ? "smtp" : protocol; Ssl ssl = properties.getSsl(); if (ssl.isEnabled()) { javaMailProperties.setProperty("mail." + protocol + ".ssl.enable", "true"); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/r2dbc/ProxyConnectionFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/r2dbc/ProxyConnectionFactoryCustomizer.java index d969ae5aa7b1..013367d863de 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/r2dbc/ProxyConnectionFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/r2dbc/ProxyConnectionFactoryCustomizer.java @@ -16,21 +16,21 @@ package org.springframework.boot.autoconfigure.r2dbc; -import io.r2dbc.proxy.ProxyConnectionFactory; +import io.r2dbc.proxy.ProxyConnectionFactory.Builder; /** - * Callback interface that can be used to customize a - * {@link ProxyConnectionFactory.Builder}. + * Callback interface that can be used to customize a {@link Builder}. * * @author Tadaya Tsuyukubo * @since 3.4.0 */ +@FunctionalInterface public interface ProxyConnectionFactoryCustomizer { /** - * Callback to customize a {@link ProxyConnectionFactory.Builder} instance. + * Callback to customize a {@link Builder} instance. * @param builder the builder to customize */ - void customize(ProxyConnectionFactory.Builder builder); + void customize(Builder builder); } diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StartCommand.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StartCommand.java index b33bb370290f..4db5c1a0db9c 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StartCommand.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StartCommand.java @@ -34,23 +34,28 @@ public enum StartCommand { /** * Start using {@code docker compose up}. */ - UP { - @Override - void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List arguments) { - dockerCompose.up(logLevel, arguments); - } - }, + UP(DockerCompose::up), /** * Start using {@code docker compose start}. */ - START { - @Override - void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List arguments) { - dockerCompose.start(logLevel, arguments); - } - }; - - abstract void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List arguments); + START(DockerCompose::start); + + private final Command command; + + StartCommand(Command command) { + this.command = command; + } + + void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List arguments) { + this.command.applyTo(dockerCompose, logLevel, arguments); + } + + @FunctionalInterface + private interface Command { + + void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List arguments); + + } } diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StopCommand.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StopCommand.java index 839b1dc23904..2deaf5d1935a 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StopCommand.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StopCommand.java @@ -34,23 +34,28 @@ public enum StopCommand { /** * Stop using {@code docker compose down}. */ - DOWN { - @Override - void applyTo(DockerCompose dockerCompose, Duration timeout, List arguments) { - dockerCompose.down(timeout, arguments); - } - }, + DOWN(DockerCompose::down), /** * Stop using {@code docker compose stop}. */ - STOP { - @Override - void applyTo(DockerCompose dockerCompose, Duration timeout, List arguments) { - dockerCompose.stop(timeout, arguments); - } - }; - - abstract void applyTo(DockerCompose dockerCompose, Duration timeout, List arguments); + STOP(DockerCompose::stop); + + private final Command command; + + StopCommand(Command command) { + this.command = command; + } + + void applyTo(DockerCompose dockerCompose, Duration timeout, List arguments) { + this.command.applyTo(dockerCompose, timeout, arguments); + } + + @FunctionalInterface + private interface Command { + + void applyTo(DockerCompose dockerCompose, Duration timeout, List arguments); + + } } diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java index 91649a79fe08..0f0055b68df9 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java @@ -45,7 +45,7 @@ class PostgresEnvironment { } private String extractPassword(Map env) { - if (hasTrustHostAuthMethod(env)) { + if (isUsingTrustHostAuthMethod(env)) { return null; } String password = env.getOrDefault("POSTGRES_PASSWORD", env.get("POSTGRESQL_PASSWORD")); @@ -53,7 +53,7 @@ private String extractPassword(Map env) { return password; } - private Boolean hasTrustHostAuthMethod(Map env) { + private boolean isUsingTrustHostAuthMethod(Map env) { String hostAuthMethod = env.get("POSTGRES_HOST_AUTH_METHOD"); return "trust".equals(hostAuthMethod); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildRequest.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildRequest.java index 76bedefd106d..0b0a4c5d3272 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildRequest.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildRequest.java @@ -175,6 +175,7 @@ public BuildRequest withBuilder(ImageReference builder) { * @param trustBuilder {@code true} if the builder should be treated as trusted, * {@code false} otherwise * @return an updated build request + * @since 3.4.0 */ public BuildRequest withTrustBuilder(boolean trustBuilder) { return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env, diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NestedConfigurationProperty.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NestedConfigurationProperty.java index 3701772d4bd5..c54aaa9984fa 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NestedConfigurationProperty.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NestedConfigurationProperty.java @@ -74,6 +74,7 @@ * * @author Stephane Nicoll * @author Phillip Webb + * @author Jared Bates * @since 1.2.0 */ @Target({ ElementType.FIELD, ElementType.RECORD_COMPONENT, ElementType.METHOD }) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jms/ConnectionFactoryUnwrapper.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jms/ConnectionFactoryUnwrapper.java index 65429c38d209..681d70e5325a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jms/ConnectionFactoryUnwrapper.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jms/ConnectionFactoryUnwrapper.java @@ -26,9 +26,12 @@ * pooling. * * @author Stephane Nicoll - * @since 6.4.0 + * @since 3.4.0 */ -public abstract class ConnectionFactoryUnwrapper { +public final class ConnectionFactoryUnwrapper { + + private ConnectionFactoryUnwrapper() { + } /** * Return the native {@link ConnectionFactory} by unwrapping it from a cache or pool @@ -38,8 +41,8 @@ public abstract class ConnectionFactoryUnwrapper { * @return the native connection factory that it wraps, if any */ public static ConnectionFactory unwrap(ConnectionFactory connectionFactory) { - if (connectionFactory instanceof CachingConnectionFactory ccf) { - return unwrap(ccf.getTargetConnectionFactory()); + if (connectionFactory instanceof CachingConnectionFactory cachingConnectionFactory) { + return unwrap(cachingConnectionFactory.getTargetConnectionFactory()); } ConnectionFactory unwrapedConnectionFactory = unwrapFromJmsPoolConnectionFactory(connectionFactory); return (unwrapedConnectionFactory != null) ? unwrap(unwrapedConnectionFactory) : connectionFactory; @@ -47,8 +50,8 @@ public static ConnectionFactory unwrap(ConnectionFactory connectionFactory) { private static ConnectionFactory unwrapFromJmsPoolConnectionFactory(ConnectionFactory connectionFactory) { try { - if (connectionFactory instanceof JmsPoolConnectionFactory poolConnectionFactory) { - return (ConnectionFactory) poolConnectionFactory.getConnectionFactory(); + if (connectionFactory instanceof JmsPoolConnectionFactory jmsPoolConnectionFactory) { + return (ConnectionFactory) jmsPoolConnectionFactory.getConnectionFactory(); } } catch (Throwable ex) {