From 8efdc1e46dc4168774b9a683ea7140770ae30ebc Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 4 Mar 2024 10:07:28 +0000 Subject: [PATCH] Add CI for Java 22 Closes gh-39746 --- .github/workflows/ci.yml | 2 ++ .../logging/AbstractLoggingSystemTests.java | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab95d0fe1c6..607fb7b9381 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,8 @@ jobs: toolchain: false - version: 21 toolchain: true + - version: 22 + toolchain: true exclude: - os: name: Linux diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java index cba035869ff..b27ff6590d4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * 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. @@ -25,6 +25,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.io.TempDir; import org.slf4j.MDC; +import org.springframework.boot.ansi.AnsiOutput; +import org.springframework.boot.ansi.AnsiOutput.Enabled; import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.contentOf; @@ -42,18 +44,39 @@ public abstract class AbstractLoggingSystemTests { private String originalTempDirectory; + private AnsiOutput.Enabled ansiOutputEnabled; + @BeforeEach - void configureTempDir(@TempDir Path temp) { + void beforeEach(@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); System.setProperty(JAVA_IO_TMPDIR, temp.toAbsolutePath().toString()); MDC.clear(); } @AfterEach - void reinstateTempDir() { + void afterEach() { + reinstateTempDir(); + restoreAnsiOutputEnabled(); + } + + private void reinstateTempDir() { System.setProperty(JAVA_IO_TMPDIR, this.originalTempDirectory); } + private void restoreAnsiOutputEnabled() { + AnsiOutput.setEnabled(this.ansiOutputEnabled); + } + @AfterEach void clear() { for (LoggingSystemProperty property : LoggingSystemProperty.values()) {