From 99e8978a912f8970ca835a4e971e1fc58c28931a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Wed, 3 Jul 2024 09:57:22 +0200 Subject: [PATCH] Restore binary backward compatibility for GeneratedFiles See gh-31331 --- .../generate/FileSystemGeneratedFiles.java | 2 +- .../aot/generate/GeneratedFiles.java | 30 +++++++++---------- .../aot/generate/InMemoryGeneratedFiles.java | 2 +- .../aot/generate/GeneratedFilesTests.java | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/aot/generate/FileSystemGeneratedFiles.java b/spring-core/src/main/java/org/springframework/aot/generate/FileSystemGeneratedFiles.java index e0b3d8049325..d51c17bfae56 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/FileSystemGeneratedFiles.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/FileSystemGeneratedFiles.java @@ -40,7 +40,7 @@ * @author Stephane Nicoll * @since 6.0 */ -public class FileSystemGeneratedFiles extends GeneratedFiles { +public class FileSystemGeneratedFiles implements GeneratedFiles { private final Function roots; diff --git a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedFiles.java b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedFiles.java index 297589297e02..d042567a458e 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedFiles.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedFiles.java @@ -39,14 +39,14 @@ * @see InMemoryGeneratedFiles * @see FileSystemGeneratedFiles */ -public abstract class GeneratedFiles { +public interface GeneratedFiles { /** * Add a generated {@link Kind#SOURCE source file} with content from the * given {@link JavaFile}. * @param javaFile the java file to add */ - public void addSourceFile(JavaFile javaFile) { + default void addSourceFile(JavaFile javaFile) { validatePackage(javaFile.packageName, javaFile.typeSpec.name); String className = javaFile.packageName + "." + javaFile.typeSpec.name; addSourceFile(className, javaFile::writeTo); @@ -59,7 +59,7 @@ public void addSourceFile(JavaFile javaFile) { * of the file * @param content the contents of the file */ - public void addSourceFile(String className, CharSequence content) { + default void addSourceFile(String className, CharSequence content) { addSourceFile(className, appendable -> appendable.append(content)); } @@ -71,7 +71,7 @@ public void addSourceFile(String className, CharSequence content) { * @param content a {@link ThrowingConsumer} that accepts an * {@link Appendable} which will receive the file contents */ - public void addSourceFile(String className, ThrowingConsumer content) { + default void addSourceFile(String className, ThrowingConsumer content) { addFile(Kind.SOURCE, getClassNamePath(className), content); } @@ -83,7 +83,7 @@ public void addSourceFile(String className, ThrowingConsumer content * @param content an {@link InputStreamSource} that will provide an input * stream containing the file contents */ - public void addSourceFile(String className, InputStreamSource content) { + default void addSourceFile(String className, InputStreamSource content) { addFile(Kind.SOURCE, getClassNamePath(className), content); } @@ -93,7 +93,7 @@ public void addSourceFile(String className, InputStreamSource content) { * @param path the relative path of the file * @param content the contents of the file */ - public void addResourceFile(String path, CharSequence content) { + default void addResourceFile(String path, CharSequence content) { addResourceFile(path, appendable -> appendable.append(content)); } @@ -104,7 +104,7 @@ public void addResourceFile(String path, CharSequence content) { * @param content a {@link ThrowingConsumer} that accepts an * {@link Appendable} which will receive the file contents */ - public void addResourceFile(String path, ThrowingConsumer content) { + default void addResourceFile(String path, ThrowingConsumer content) { addFile(Kind.RESOURCE, path, content); } @@ -115,7 +115,7 @@ public void addResourceFile(String path, ThrowingConsumer content) { * @param content an {@link InputStreamSource} that will provide an input * stream containing the file contents */ - public void addResourceFile(String path, InputStreamSource content) { + default void addResourceFile(String path, InputStreamSource content) { addFile(Kind.RESOURCE, path, content); } @@ -126,7 +126,7 @@ public void addResourceFile(String path, InputStreamSource content) { * @param content an {@link InputStreamSource} that will provide an input * stream containing the file contents */ - public void addClassFile(String path, InputStreamSource content) { + default void addClassFile(String path, InputStreamSource content) { addFile(Kind.CLASS, path, content); } @@ -137,7 +137,7 @@ public void addClassFile(String path, InputStreamSource content) { * @param path the relative path of the file * @param content the contents of the file */ - public void addFile(Kind kind, String path, CharSequence content) { + default void addFile(Kind kind, String path, CharSequence content) { addFile(kind, path, appendable -> appendable.append(content)); } @@ -149,7 +149,7 @@ public void addFile(Kind kind, String path, CharSequence content) { * @param content a {@link ThrowingConsumer} that accepts an * {@link Appendable} which will receive the file contents */ - public void addFile(Kind kind, String path, ThrowingConsumer content) { + default void addFile(Kind kind, String path, ThrowingConsumer content) { Assert.notNull(content, "'content' must not be null"); addFile(kind, path, new AppendableConsumerInputStreamSource(content)); } @@ -162,7 +162,7 @@ public void addFile(Kind kind, String path, ThrowingConsumer content * @param content an {@link InputStreamSource} that will provide an input * stream containing the file contents */ - public void addFile(Kind kind, String path, InputStreamSource content) { + default void addFile(Kind kind, String path, InputStreamSource content) { Assert.notNull(kind, "'kind' must not be null"); Assert.hasLength(path, "'path' must not be empty"); Assert.notNull(content, "'content' must not be null"); @@ -179,7 +179,7 @@ public void addFile(Kind kind, String path, InputStreamSource content) { * @param handler a consumer of a {@link FileHandler} for the file * @since 6.2 */ - public abstract void handleFile(Kind kind, String path, ThrowingConsumer handler); + void handleFile(Kind kind, String path, ThrowingConsumer handler); private static String getClassNamePath(String className) { Assert.hasLength(className, "'className' must not be empty"); @@ -214,7 +214,7 @@ private static boolean isJavaIdentifier(String className) { /** * The various kinds of generated files that are supported. */ - public enum Kind { + enum Kind { /** * A source file containing Java code that should be compiled. @@ -241,7 +241,7 @@ public enum Kind { * * @since 6.2 */ - public abstract static class FileHandler { + abstract class FileHandler { private final boolean exists; diff --git a/spring-core/src/main/java/org/springframework/aot/generate/InMemoryGeneratedFiles.java b/spring-core/src/main/java/org/springframework/aot/generate/InMemoryGeneratedFiles.java index 885b5f30f216..b79a0b3318bc 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/InMemoryGeneratedFiles.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/InMemoryGeneratedFiles.java @@ -35,7 +35,7 @@ * @author Stephane Nicoll * @since 6.0 */ -public class InMemoryGeneratedFiles extends GeneratedFiles { +public class InMemoryGeneratedFiles implements GeneratedFiles { private final Map> files = new HashMap<>(); diff --git a/spring-core/src/test/java/org/springframework/aot/generate/GeneratedFilesTests.java b/spring-core/src/test/java/org/springframework/aot/generate/GeneratedFilesTests.java index 7dad54957e7b..35468973500f 100644 --- a/spring-core/src/test/java/org/springframework/aot/generate/GeneratedFilesTests.java +++ b/spring-core/src/test/java/org/springframework/aot/generate/GeneratedFilesTests.java @@ -223,7 +223,7 @@ private GeneratedFileAssert assertThatFileAdded(Kind kind, String path) } - static class TestGeneratedFiles extends GeneratedFiles { + static class TestGeneratedFiles implements GeneratedFiles { private Kind kind;