Skip to content

Commit 6c84674

Browse files
committed
Relocate EnvironmentPostProcessor and implementations out of env
Move the `EnvironmentPostProcessor` from `org.springframework.boot.env` to `org.springframework.boot` so that we can make the `env` package foundational. Most `EnvironmentPostProcessor` implementation has also been relocated to a new `org.springframework.boot.support` package. See gh-47232
1 parent 4ebf09a commit 6c84674

File tree

41 files changed

+103
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+103
-55
lines changed

config/checkstyle/import-control.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<subpackage name="bootstrap">
1818
<disallow pkg="org.springframework.boot" exact-match="true"/>
1919
</subpackage>
20+
<subpackage name="env">
21+
<disallow pkg="org.springframework.boot" exact-match="true"/>
22+
</subpackage>
2023
<subpackage name="ssl">
2124
<disallow pkg="org.springframework.boot" exact-match="true"/>
2225
</subpackage>
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.env;
17+
package org.springframework.boot;
1818

19-
import org.springframework.boot.SpringApplication;
2019
import org.springframework.boot.bootstrap.BootstrapContext;
2120
import org.springframework.boot.bootstrap.BootstrapRegistry;
2221
import org.springframework.boot.bootstrap.ConfigurableBootstrapContext;
@@ -34,8 +33,8 @@
3433
* interface or use an {@link org.springframework.core.annotation.Order @Order} annotation
3534
* if they wish to be invoked in specific order.
3635
* <p>
37-
* Since Spring Boot 2.4, {@code EnvironmentPostProcessor} implementations may optionally
38-
* take the following constructor parameters:
36+
* {@code EnvironmentPostProcessor} implementations may optionally take the following
37+
* constructor parameters:
3938
* <ul>
4039
* <li>{@link DeferredLogFactory} - A factory that can be used to create loggers with
4140
* output deferred until the application has been fully prepared (allowing the environment
@@ -47,7 +46,7 @@
4746
*
4847
* @author Andy Wilkinson
4948
* @author Stephane Nicoll
50-
* @since 1.3.0
49+
* @since 4.0.0
5150
*/
5251
@FunctionalInterface
5352
public interface EnvironmentPostProcessor {

core/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.apache.commons.logging.Log;
2626
import org.jspecify.annotations.Nullable;
2727

28+
import org.springframework.boot.EnvironmentPostProcessor;
2829
import org.springframework.boot.SpringApplication;
2930
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
30-
import org.springframework.boot.env.EnvironmentPostProcessor;
3131
import org.springframework.boot.json.JsonParser;
3232
import org.springframework.boot.json.JsonParserFactory;
3333
import org.springframework.boot.logging.DeferredLogFactory;

core/spring-boot/src/main/java/org/springframework/boot/context/config/AnsiOutputApplicationListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.springframework.boot.ansi.AnsiOutput.Enabled;
2121
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
2222
import org.springframework.boot.context.properties.bind.Binder;
23-
import org.springframework.boot.env.EnvironmentPostProcessorApplicationListener;
23+
import org.springframework.boot.support.EnvironmentPostProcessorApplicationListener;
2424
import org.springframework.context.ApplicationListener;
2525
import org.springframework.core.Ordered;
2626
import org.springframework.core.env.ConfigurableEnvironment;

core/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import org.apache.commons.logging.Log;
2525
import org.jspecify.annotations.Nullable;
2626

27+
import org.springframework.boot.EnvironmentPostProcessor;
2728
import org.springframework.boot.SpringApplication;
2829
import org.springframework.boot.bootstrap.ConfigurableBootstrapContext;
2930
import org.springframework.boot.bootstrap.DefaultBootstrapContext;
30-
import org.springframework.boot.env.EnvironmentPostProcessor;
3131
import org.springframework.boot.logging.DeferredLogFactory;
3232
import org.springframework.core.Ordered;
3333
import org.springframework.core.env.ConfigurableEnvironment;

core/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaderContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.boot.context.config;
1818

19+
import org.springframework.boot.EnvironmentPostProcessor;
1920
import org.springframework.boot.bootstrap.ConfigurableBootstrapContext;
20-
import org.springframework.boot.env.EnvironmentPostProcessor;
2121

2222
/**
2323
* Context provided to {@link ConfigDataLoader} methods.

core/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolverContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import org.jspecify.annotations.Nullable;
2020

21+
import org.springframework.boot.EnvironmentPostProcessor;
2122
import org.springframework.boot.bootstrap.ConfigurableBootstrapContext;
2223
import org.springframework.boot.context.properties.bind.Binder;
23-
import org.springframework.boot.env.EnvironmentPostProcessor;
2424

2525
/**
2626
* Context provided to {@link ConfigDataLocationResolver} methods.

core/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.jspecify.annotations.Nullable;
2929

3030
import org.springframework.core.env.ConfigurableEnvironment;
31+
import org.springframework.core.env.Environment;
3132
import org.springframework.core.env.MutablePropertySources;
3233
import org.springframework.core.env.PropertySource;
3334
import org.springframework.core.env.StandardEnvironment;
@@ -143,11 +144,21 @@ private Object getRandomBytes() {
143144
return HexFormat.of().withLowerCase().formatHex(bytes);
144145
}
145146

147+
/**
148+
* Add a {@link RandomValuePropertySource} to the given {@link Environment}.
149+
* @param environment the environment to add the random property source to
150+
*/
146151
public static void addToEnvironment(ConfigurableEnvironment environment) {
147152
addToEnvironment(environment, logger);
148153
}
149154

150-
static void addToEnvironment(ConfigurableEnvironment environment, Log logger) {
155+
/**
156+
* Add a {@link RandomValuePropertySource} to the given {@link Environment}.
157+
* @param environment the environment to add the random property source to
158+
* @param logger logger used for debug and trace information
159+
* @since 4.0.0
160+
*/
161+
public static void addToEnvironment(ConfigurableEnvironment environment, Log logger) {
151162
MutablePropertySources sources = environment.getPropertySources();
152163
PropertySource<?> existing = sources.get(RANDOM_PROPERTY_SOURCE_NAME);
153164
if (existing != null) {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.env;
17+
package org.springframework.boot.support;
1818

1919
import java.util.Arrays;
2020
import java.util.List;
@@ -33,6 +33,7 @@
3333
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
3434
import org.springframework.beans.factory.aot.BeanFactoryInitializationCode;
3535
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
36+
import org.springframework.boot.EnvironmentPostProcessor;
3637
import org.springframework.boot.SpringApplication;
3738
import org.springframework.boot.bootstrap.ConfigurableBootstrapContext;
3839
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
@@ -57,7 +58,7 @@
5758
*
5859
* @author Phillip Webb
5960
* @author Stephane Nicoll
60-
* @since 2.4.0
61+
* @since 4.0.0
6162
*/
6263
public class EnvironmentPostProcessorApplicationListener implements SmartApplicationListener, Ordered {
6364

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.env;
17+
package org.springframework.boot.support;
1818

1919
import java.util.List;
2020

2121
import org.jspecify.annotations.Nullable;
2222

23+
import org.springframework.boot.EnvironmentPostProcessor;
2324
import org.springframework.boot.bootstrap.ConfigurableBootstrapContext;
2425
import org.springframework.boot.logging.DeferredLogFactory;
2526
import org.springframework.core.io.support.SpringFactoriesLoader;
@@ -29,7 +30,7 @@
2930
* create the {@link EnvironmentPostProcessor} instances.
3031
*
3132
* @author Phillip Webb
32-
* @since 2.4.0
33+
* @since 4.0.0
3334
*/
3435
@FunctionalInterface
3536
public interface EnvironmentPostProcessorsFactory {

0 commit comments

Comments
 (0)