mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-06-30 00:36:49 +08:00
Merge branch '3.2.x'
This commit is contained in:
commit
f6b431eb4f
|
@ -75,7 +75,6 @@ include "spring-boot-project:spring-boot-test"
|
||||||
include "spring-boot-project:spring-boot-testcontainers"
|
include "spring-boot-project:spring-boot-testcontainers"
|
||||||
include "spring-boot-project:spring-boot-test-autoconfigure"
|
include "spring-boot-project:spring-boot-test-autoconfigure"
|
||||||
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-configuration-processor-tests"
|
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-configuration-processor-tests"
|
||||||
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-console-tests"
|
|
||||||
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-launch-script-tests"
|
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-launch-script-tests"
|
||||||
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-loader-tests"
|
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-loader-tests"
|
||||||
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-loader-classic-tests"
|
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-loader-classic-tests"
|
||||||
|
|
|
@ -25,8 +25,6 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
|
|
||||||
import org.springframework.boot.ansi.AnsiOutput;
|
|
||||||
import org.springframework.boot.ansi.AnsiOutput.Enabled;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.contentOf;
|
import static org.assertj.core.api.Assertions.contentOf;
|
||||||
|
@ -44,39 +42,18 @@ public abstract class AbstractLoggingSystemTests {
|
||||||
|
|
||||||
private String originalTempDirectory;
|
private String originalTempDirectory;
|
||||||
|
|
||||||
private AnsiOutput.Enabled ansiOutputEnabled;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void beforeEach(@TempDir Path temp) {
|
void configureTempDir(@TempDir Path temp) {
|
||||||
disableAnsiOutput();
|
|
||||||
configureTempDir(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void disableAnsiOutput() {
|
|
||||||
this.ansiOutputEnabled = AnsiOutput.getEnabled();
|
|
||||||
AnsiOutput.setEnabled(Enabled.NEVER);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void configureTempDir(@TempDir Path temp) {
|
|
||||||
this.originalTempDirectory = System.getProperty(JAVA_IO_TMPDIR);
|
this.originalTempDirectory = System.getProperty(JAVA_IO_TMPDIR);
|
||||||
System.setProperty(JAVA_IO_TMPDIR, temp.toAbsolutePath().toString());
|
System.setProperty(JAVA_IO_TMPDIR, temp.toAbsolutePath().toString());
|
||||||
MDC.clear();
|
MDC.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
void afterEach() {
|
void reinstateTempDir() {
|
||||||
reinstateTempDir();
|
|
||||||
restoreAnsiOutputEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void reinstateTempDir() {
|
|
||||||
System.setProperty(JAVA_IO_TMPDIR, this.originalTempDirectory);
|
System.setProperty(JAVA_IO_TMPDIR, this.originalTempDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreAnsiOutputEnabled() {
|
|
||||||
AnsiOutput.setEnabled(this.ansiOutputEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
void clear() {
|
void clear() {
|
||||||
for (LoggingSystemProperty property : LoggingSystemProperty.values()) {
|
for (LoggingSystemProperty property : LoggingSystemProperty.values()) {
|
||||||
|
|
|
@ -185,4 +185,12 @@ class JavaLoggingSystemTests extends AbstractLoggingSystemTests {
|
||||||
.isEqualTo(new LoggerConfiguration(getClass().getName(), LogLevel.DEBUG, LogLevel.DEBUG));
|
.isEqualTo(new LoggerConfiguration(getClass().getName(), LogLevel.DEBUG, LogLevel.DEBUG));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotContainAnsiEscapeCodes(CapturedOutput output) {
|
||||||
|
this.loggingSystem.beforeInitialize();
|
||||||
|
this.loggingSystem.initialize(null, null, null);
|
||||||
|
this.logger.info("Hello world");
|
||||||
|
assertThat(output).doesNotContain("\033[");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -651,6 +651,14 @@ class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
|
||||||
.doesNotContain("myapp");
|
.doesNotContain("myapp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotContainAnsiEscapeCodes(CapturedOutput output) {
|
||||||
|
this.loggingSystem.beforeInitialize();
|
||||||
|
this.loggingSystem.initialize(this.initializationContext, null, null);
|
||||||
|
this.logger.info("Hello world");
|
||||||
|
assertThat(output).doesNotContain("\033[");
|
||||||
|
}
|
||||||
|
|
||||||
private String getRelativeClasspathLocation(String fileName) {
|
private String getRelativeClasspathLocation(String fileName) {
|
||||||
String defaultPath = ClassUtils.getPackageName(getClass());
|
String defaultPath = ClassUtils.getPackageName(getClass());
|
||||||
defaultPath = defaultPath.replace('.', '/');
|
defaultPath = defaultPath.replace('.', '/');
|
||||||
|
|
|
@ -876,6 +876,14 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
||||||
assertThat(output).doesNotContain("WARN");
|
assertThat(output).doesNotContain("WARN");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotContainAnsiEscapeCodes(CapturedOutput output) {
|
||||||
|
this.loggingSystem.beforeInitialize();
|
||||||
|
initialize(this.initializationContext, null, null);
|
||||||
|
this.logger.info("Hello world");
|
||||||
|
assertThat(output).doesNotContain("\033[");
|
||||||
|
}
|
||||||
|
|
||||||
private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
|
private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
|
||||||
this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
|
this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
|
||||||
this.loggingSystem.beforeInitialize();
|
this.loggingSystem.beforeInitialize();
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
plugins {
|
|
||||||
id "java"
|
|
||||||
id "org.springframework.boot.conventions"
|
|
||||||
id "org.springframework.boot.integration-test"
|
|
||||||
}
|
|
||||||
|
|
||||||
description = "Spring Boot Console Integration Tests"
|
|
||||||
|
|
||||||
configurations {
|
|
||||||
app
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
app project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "mavenRepository")
|
|
||||||
app project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository")
|
|
||||||
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter", configuration: "mavenRepository")
|
|
||||||
|
|
||||||
intTestImplementation(enforcedPlatform(project(":spring-boot-project:spring-boot-parent")))
|
|
||||||
intTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
|
|
||||||
intTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
|
|
||||||
intTestImplementation("org.testcontainers:junit-jupiter")
|
|
||||||
intTestImplementation("org.testcontainers:testcontainers")
|
|
||||||
}
|
|
||||||
|
|
||||||
task syncMavenRepository(type: Sync) {
|
|
||||||
from configurations.app
|
|
||||||
into "${buildDir}/int-test-maven-repository"
|
|
||||||
}
|
|
||||||
|
|
||||||
task syncAppSource(type: org.springframework.boot.build.SyncAppSource) {
|
|
||||||
sourceDirectory = file("spring-boot-console-tests-app")
|
|
||||||
destinationDirectory = file("${buildDir}/spring-boot-console-tests-app")
|
|
||||||
}
|
|
||||||
|
|
||||||
task buildApp(type: GradleBuild) {
|
|
||||||
dependsOn syncAppSource, syncMavenRepository
|
|
||||||
dir = "${buildDir}/spring-boot-console-tests-app"
|
|
||||||
startParameter.buildCacheEnabled = false
|
|
||||||
tasks = ["build"]
|
|
||||||
}
|
|
||||||
|
|
||||||
intTest {
|
|
||||||
dependsOn buildApp
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
plugins {
|
|
||||||
id "java"
|
|
||||||
id "org.springframework.boot"
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: "io.spring.dependency-management"
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
maven { url "file:${rootDir}/../int-test-maven-repository"}
|
|
||||||
mavenCentral()
|
|
||||||
maven { url "https://repo.spring.io/snapshot" }
|
|
||||||
maven { url "https://repo.spring.io/milestone" }
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation("org.springframework.boot:spring-boot-starter")
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
pluginManagement {
|
|
||||||
repositories {
|
|
||||||
maven { url "file:${rootDir}/../int-test-maven-repository"}
|
|
||||||
mavenCentral()
|
|
||||||
maven { url "https://repo.spring.io/snapshot" }
|
|
||||||
maven { url "https://repo.spring.io/milestone" }
|
|
||||||
}
|
|
||||||
resolutionStrategy {
|
|
||||||
eachPlugin {
|
|
||||||
if (requested.id.id == "org.springframework.boot") {
|
|
||||||
useModule "org.springframework.boot:spring-boot-gradle-plugin:${requested.version}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2024 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.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.consoleapp;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.ansi.AnsiOutput;
|
|
||||||
import org.springframework.boot.ansi.AnsiOutput.Enabled;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class ConsoleTestApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("System.console() is " + System.console());
|
|
||||||
SpringApplication.run(ConsoleTestApplication.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,125 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2024 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.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.console;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.testcontainers.containers.GenericContainer;
|
|
||||||
import org.testcontainers.containers.output.ToStringConsumer;
|
|
||||||
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy;
|
|
||||||
import org.testcontainers.utility.DockerImageName;
|
|
||||||
import org.testcontainers.utility.MountableFile;
|
|
||||||
|
|
||||||
import org.springframework.boot.system.JavaVersion;
|
|
||||||
import org.springframework.boot.testsupport.testcontainers.DisabledIfDockerUnavailable;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Integration tests that checks ANSI output is not turned on in JDK 22 or later.
|
|
||||||
*
|
|
||||||
* @author Yong-Hyun Kim
|
|
||||||
*/
|
|
||||||
@DisabledIfDockerUnavailable
|
|
||||||
class ConsoleIntegrationTests {
|
|
||||||
|
|
||||||
private static final String ENCODE_START = "\033[";
|
|
||||||
|
|
||||||
private static final JavaRuntime JDK_17_RUNTIME = JavaRuntime.openJdk(JavaVersion.SEVENTEEN);
|
|
||||||
|
|
||||||
private static final JavaRuntime JDK_22_RUNTIME = JavaRuntime.openJdk(JavaVersion.TWENTY_TWO);
|
|
||||||
|
|
||||||
private final ToStringConsumer output = new ToStringConsumer().withRemoveAnsiCodes(false);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void runJarOn17() {
|
|
||||||
try (GenericContainer<?> container = createContainer(JDK_17_RUNTIME)) {
|
|
||||||
container.start();
|
|
||||||
assertThat(this.output.toString(StandardCharsets.UTF_8)).contains("System.console() is null")
|
|
||||||
.doesNotContain(ENCODE_START);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void runJarOn22() {
|
|
||||||
try (GenericContainer<?> container = createContainer(JDK_22_RUNTIME)) {
|
|
||||||
container.start();
|
|
||||||
assertThat(this.output.toString(StandardCharsets.UTF_8)).doesNotContain("System.console() is null")
|
|
||||||
.doesNotContain(ENCODE_START);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private GenericContainer<?> createContainer(JavaRuntime javaRuntime) {
|
|
||||||
return javaRuntime.getContainer()
|
|
||||||
.withLogConsumer(this.output)
|
|
||||||
.withCopyFileToContainer(findApplication(), "/app.jar")
|
|
||||||
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5)))
|
|
||||||
.withCommand("java", "-jar", "app.jar");
|
|
||||||
}
|
|
||||||
|
|
||||||
private MountableFile findApplication() {
|
|
||||||
return MountableFile.forHostPath(findJarFile().toPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
private File findJarFile() {
|
|
||||||
String path = String.format("build/%1$s/build/libs/%1$s.jar", "spring-boot-console-tests-app");
|
|
||||||
File jar = new File(path);
|
|
||||||
Assert.state(jar.isFile(), () -> "Could not find " + path + ". Have you built it?");
|
|
||||||
return jar;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class JavaRuntime {
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
private final JavaVersion version;
|
|
||||||
|
|
||||||
private final Supplier<GenericContainer<?>> container;
|
|
||||||
|
|
||||||
private JavaRuntime(String name, JavaVersion version, Supplier<GenericContainer<?>> container) {
|
|
||||||
this.name = name;
|
|
||||||
this.version = version;
|
|
||||||
this.container = container;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isCompatible() {
|
|
||||||
return this.version.isEqualOrNewerThan(JavaVersion.getJavaVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
GenericContainer<?> getContainer() {
|
|
||||||
return this.container.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static JavaRuntime openJdk(JavaVersion version) {
|
|
||||||
String imageVersion = version.toString();
|
|
||||||
DockerImageName image = DockerImageName.parse("bellsoft/liberica-openjdk-debian:" + imageVersion);
|
|
||||||
return new JavaRuntime("OpenJDK " + imageVersion, version, () -> new GenericContainer<>(image));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration>
|
|
||||||
<include resource="org/springframework/boot/logging/logback/base.xml"/>
|
|
||||||
</configuration>
|
|
Loading…
Reference in New Issue
Block a user