From 4a00d76b85e28578b4959b09629e9da6f4362629 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sat, 13 Aug 2022 13:56:09 +0200 Subject: [PATCH] Adapt integration tests to proxy changes in Spring Framework --- .../boot/maven/AotGenerateTests.java | 53 ++++++++++++++++--- .../intTest/projects/aot-class-proxy/pom.xml | 36 +++++++++++++ .../main/java/org/test/SampleApplication.java | 33 ++++++++++++ .../src/main/java/org/test/SampleRunner.java | 30 +++++++++++ .../intTest/projects/aot-jdk-proxy/pom.xml | 36 +++++++++++++ .../main/java/org/test/SampleApplication.java | 46 ++++++++++++++++ 6 files changed, 227 insertions(+), 7 deletions(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/pom.xml create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/src/main/java/org/test/SampleApplication.java create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/src/main/java/org/test/SampleRunner.java create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jdk-proxy/pom.xml create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jdk-proxy/src/main/java/org/test/SampleApplication.java diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotGenerateTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotGenerateTests.java index 31e663e1e1..3ea70d6c1f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotGenerateTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotGenerateTests.java @@ -41,18 +41,48 @@ public class AotGenerateTests { Path aotDirectory = project.toPath().resolve("target/spring-aot/main"); assertThat(collectRelativePaths(aotDirectory.resolve("sources"))) .contains(Path.of("org", "test", "SampleApplication__ApplicationContextInitializer.java")); + }); + } + + @TestTemplate + void whenAotRunsResourcesAreGenerated(MavenBuild mavenBuild) { + mavenBuild.project("aot").goals("package").execute((project) -> { + Path aotDirectory = project.toPath().resolve("target/spring-aot/main"); assertThat(collectRelativePaths(aotDirectory.resolve("resources"))).containsOnly( Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot", "reflect-config.json"), Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot", "resource-config.json"), - Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot", - "proxy-config.json"), Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot", "native-image.properties")); }); } + @TestTemplate + void whenAotRunsWithJdkProxyResourcesIncludeProxyConfig(MavenBuild mavenBuild) { + mavenBuild.project("aot-jdk-proxy").goals("package").execute((project) -> { + Path aotDirectory = project.toPath().resolve("target/spring-aot/main"); + assertThat(collectRelativePaths(aotDirectory.resolve("resources"))).containsOnly( + Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot-jdk-proxy", + "reflect-config.json"), + Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot-jdk-proxy", + "resource-config.json"), + Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot-jdk-proxy", + "proxy-config.json"), + Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot-jdk-proxy", + "native-image.properties")); + }); + } + + @TestTemplate + void whenAotRunsWithClassProxyClassesAreGenerated(MavenBuild mavenBuild) { + mavenBuild.project("aot-class-proxy").goals("package").execute((project) -> { + Path aotDirectory = project.toPath().resolve("target/spring-aot/main"); + assertThat(collectRelativePaths(aotDirectory.resolve("classes"))) + .contains(Path.of("org", "test", "SampleRunner$$SpringCGLIB$$0.class")); + }); + } + @TestTemplate void whenAotRunsSourcesAreCompiled(MavenBuild mavenBuild) { mavenBuild.project("aot").goals("package").execute((project) -> { @@ -64,13 +94,22 @@ public class AotGenerateTests { @TestTemplate void whenAotRunsResourcesAreCopiedToTargetClasses(MavenBuild mavenBuild) { - mavenBuild.project("aot").goals("package").execute((project) -> { + mavenBuild.project("aot-jdk-proxy").goals("package").execute((project) -> { Path classesDirectory = project.toPath().resolve("target/classes/META-INF/native-image"); assertThat(collectRelativePaths(classesDirectory)).contains( - Path.of("org.springframework.boot.maven.it", "aot", "reflect-config.json"), - Path.of("org.springframework.boot.maven.it", "aot", "resource-config.json"), - Path.of("org.springframework.boot.maven.it", "aot", "proxy-config.json"), - Path.of("org.springframework.boot.maven.it", "aot", "native-image.properties")); + Path.of("org.springframework.boot.maven.it", "aot-jdk-proxy", "reflect-config.json"), + Path.of("org.springframework.boot.maven.it", "aot-jdk-proxy", "resource-config.json"), + Path.of("org.springframework.boot.maven.it", "aot-jdk-proxy", "proxy-config.json"), + Path.of("org.springframework.boot.maven.it", "aot-jdk-proxy", "native-image.properties")); + }); + } + + @TestTemplate + void whenAotRunsWithClassProxyClassesAreCopiedToTargetClasses(MavenBuild mavenBuild) { + mavenBuild.project("aot-class-proxy").goals("package").execute((project) -> { + Path classesDirectory = project.toPath().resolve("target/classes/"); + assertThat(collectRelativePaths(classesDirectory)) + .contains(Path.of("org", "test", "SampleRunner$$SpringCGLIB$$0.class")); }); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/pom.xml new file mode 100644 index 0000000000..c64f22307f --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + org.springframework.boot.maven.it + aot-class-proxy + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + @java.version@ + @java.version@ + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + aot-generate + + + + + + + + + org.springframework.boot + spring-boot + @project.version@ + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/src/main/java/org/test/SampleApplication.java new file mode 100644 index 0000000000..0daad56981 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2022 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.test; + +import org.springframework.boot.SpringApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; + +@Configuration(proxyBeanMethods = false) +@ComponentScan +@EnableAsync +public class SampleApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/src/main/java/org/test/SampleRunner.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/src/main/java/org/test/SampleRunner.java new file mode 100644 index 0000000000..a780a6fedc --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-class-proxy/src/main/java/org/test/SampleRunner.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2022 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.test; + +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +@Component +public class SampleRunner { + + @Async + public void run() { + + } +} + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jdk-proxy/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jdk-proxy/pom.xml new file mode 100644 index 0000000000..2299529463 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jdk-proxy/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + org.springframework.boot.maven.it + aot-jdk-proxy + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + @java.version@ + @java.version@ + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + aot-generate + + + + + + + + + org.springframework.boot + spring-boot + @project.version@ + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jdk-proxy/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jdk-proxy/src/main/java/org/test/SampleApplication.java new file mode 100644 index 0000000000..af17f2167e --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jdk-proxy/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2022 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.test; + +import org.test.SampleApplication.SampleApplicationRuntimeHints; + +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.support.RuntimeHintsUtils; +import org.springframework.boot.SpringApplication; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.stereotype.Service; + +@Configuration(proxyBeanMethods = false) +@ImportRuntimeHints(SampleApplicationRuntimeHints.class) +public class SampleApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleApplication.class, args); + } + + static class SampleApplicationRuntimeHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + // Force creation of at least one JDK proxy + RuntimeHintsUtils.registerAnnotation(hints, Service.class); + } + } + +}