Skip to content

Commit 8dff5c5

Browse files
committed
fix checkstyle
1 parent 6d7d7d9 commit 8dff5c5

File tree

3 files changed

+40
-37
lines changed

3 files changed

+40
-37
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/EnvironmentVariableProtocolResolver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.springframework.core.io.ProtocolResolver;
2020
import org.springframework.core.io.Resource;
2121
import org.springframework.core.io.ResourceLoader;
22-
import org.springframework.stereotype.Component;
2322

2423
/**
2524
* {@link ProtocolResolver} for resources contained in environment variables.

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/EnvironmentVariableResource.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@
1717
package org.springframework.boot.env;
1818

1919
import java.io.ByteArrayInputStream;
20-
import java.io.File;
2120
import java.io.IOException;
2221
import java.io.InputStream;
2322
import java.nio.charset.StandardCharsets;
24-
import java.nio.file.Path;
2523
import java.util.Base64;
2624

2725
import org.springframework.core.io.AbstractResource;
2826
import org.springframework.core.io.Resource;
29-
import org.springframework.core.io.WritableResource;
3027

3128
/**
3229
* {@link Resource} implementation for system environment variables.
3330
*
3431
* @author Francisco Bento
32+
* @since 3.5.0
3533
*/
3634
public class EnvironmentVariableResource extends AbstractResource {
3735

36+
/** Pseudo URL prefix for loading from an environment variable: "env:" */
3837
public static final String PSEUDO_URL_PREFIX = "env:";
3938

40-
private static final String BASE64_ENCODED_PREFIX = "base64:";
39+
/** Pseudo URL prefix indicating that the environment variable is base64-encoded. */
40+
public static final String BASE64_ENCODED_PREFIX = "base64:";
4141

4242
private final String envVar;
4343

@@ -63,12 +63,12 @@ public static EnvironmentVariableResource fromUri(String url) {
6363

6464
@Override
6565
public boolean exists() {
66-
return System.getenv(envVar) != null;
66+
return System.getenv(this.envVar) != null;
6767
}
6868

6969
@Override
7070
public String getDescription() {
71-
return "Environment variable '" + envVar + "'";
71+
return "Environment variable '" + this.envVar + "'";
7272
}
7373

7474
@Override
@@ -77,8 +77,8 @@ public InputStream getInputStream() throws IOException {
7777
}
7878

7979
protected byte[] getContents() {
80-
String value = System.getenv(envVar);
81-
if (isBase64) {
80+
String value = System.getenv(this.envVar);
81+
if (this.isBase64) {
8282
return Base64.getDecoder().decode(value);
8383
}
8484
return value.getBytes(StandardCharsets.UTF_8);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@
6868
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
6969
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
7070
import static org.assertj.core.api.Assertions.assertThatNoException;
71-
import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariable;
72-
import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariables;
7371

7472
/**
7573
* Integration tests for {@link ConfigDataEnvironmentPostProcessor}.
@@ -628,50 +626,56 @@ void runWhenImportWithProfileVariantOrdersPropertySourcesCorrectly() {
628626

629627
@Test
630628
void runWhenImportYamlFromEnvironmentVariable() throws Exception {
631-
ConfigurableApplicationContext context = withEnvironmentVariable("MY_CONFIG_YAML", """
632-
my:
633-
value: from-env-first-doc
634-
---
635-
my:
636-
value: from-env-second-doc
637-
""").execute(() -> this.application
638-
.run("--spring.config.location=classpath:application-import-yaml-from-environment.properties"));
629+
ConfigurableApplicationContext context = uk.org.webcompere.systemstubs.SystemStubs
630+
.withEnvironmentVariable("MY_CONFIG_YAML", """
631+
my:
632+
value: from-env-first-doc
633+
---
634+
my:
635+
value: from-env-second-doc
636+
""")
637+
.execute(() -> this.application
638+
.run("--spring.config.location=classpath:application-import-yaml-from-environment.properties"));
639639
assertThat(context.getEnvironment().getProperty("my.value")).isEqualTo("from-env-second-doc");
640640
}
641641

642642
@Test
643643
void runWhenImportYamlFromEnvironmentVariableWithProfileVariant() throws Exception {
644644
this.application.setAdditionalProfiles("dev");
645-
ConfigurableApplicationContext context = withEnvironmentVariables("MY_CONFIG_YAML", """
646-
my:
647-
value: my_config_yaml
648-
""", "MY_CONFIG_YAML_DEV", """
649-
my:
650-
value: my_config_yaml_dev
651-
""").execute(() -> this.application.run(
652-
"--spring.config.location=classpath:application-import-yaml-from-environment-with-profile-variant.properties"));
645+
ConfigurableApplicationContext context = uk.org.webcompere.systemstubs.SystemStubs
646+
.withEnvironmentVariables("MY_CONFIG_YAML", """
647+
my:
648+
value: my_config_yaml
649+
""", "MY_CONFIG_YAML_DEV", """
650+
my:
651+
value: my_config_yaml_dev
652+
""")
653+
.execute(() -> this.application.run(
654+
"--spring.config.location=classpath:application-import-yaml-from-environment-with-profile-variant.properties"));
653655
assertThat(context.getEnvironment().getProperty("my.value")).isEqualTo("my_config_yaml_dev");
654656
}
655657

656658
@Test
657659
void runWhenImportBase64YamlFromEnvironmentVariable() throws Exception {
658-
ConfigurableApplicationContext context = withEnvironmentVariable("MY_CONFIG_BASE64_YAML",
659-
Base64.getEncoder().encodeToString("""
660-
my:
661-
value: from-base64-yaml
662-
""".getBytes(StandardCharsets.UTF_8)))
660+
ConfigurableApplicationContext context = uk.org.webcompere.systemstubs.SystemStubs
661+
.withEnvironmentVariable("MY_CONFIG_BASE64_YAML", Base64.getEncoder().encodeToString("""
662+
my:
663+
value: from-base64-yaml
664+
""".getBytes(StandardCharsets.UTF_8)))
663665
.execute(() -> this.application
664666
.run("--spring.config.location=classpath:application-import-base64-yaml-from-environment.properties"));
665667
assertThat(context.getEnvironment().getProperty("my.value")).isEqualTo("from-base64-yaml");
666668
}
667669

668670
@Test
669671
void runWhenImportPropertiesFromEnvironmentVariable() throws Exception {
670-
ConfigurableApplicationContext context = withEnvironmentVariable("MY_CONFIG_PROPERTIES", """
671-
my.value1: from-properties-1
672-
my.value2: from-properties-2
673-
""").execute(() -> this.application
674-
.run("--spring.config.location=classpath:application-import-properties-from-environment.properties"));
672+
ConfigurableApplicationContext context = uk.org.webcompere.systemstubs.SystemStubs
673+
.withEnvironmentVariable("MY_CONFIG_PROPERTIES", """
674+
my.value1: from-properties-1
675+
my.value2: from-properties-2
676+
""")
677+
.execute(() -> this.application
678+
.run("--spring.config.location=classpath:application-import-properties-from-environment.properties"));
675679
assertThat(context.getEnvironment().getProperty("my.value1")).isEqualTo("from-properties-1");
676680
assertThat(context.getEnvironment().getProperty("my.value2")).isEqualTo("from-properties-2");
677681
}

0 commit comments

Comments
 (0)