diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java index 3ff028c67f..33295022b5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java @@ -45,16 +45,17 @@ public class AotTests { } @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"))).contains( - Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot", + void whenAotRunsResourcesAreGeneratedAndCopiedToTargetClasses(MavenBuild mavenBuild) { + mavenBuild.project("aot-resource-generation").goals("package").execute((project) -> { + Path targetClasses = project.toPath().resolve("target/classes"); + assertThat(collectRelativePaths(targetClasses)).contains( + Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot-resource-generation", "reflect-config.json"), - Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot", + Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot-resource-generation", "resource-config.json"), - Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot", - "native-image.properties")); + Path.of("META-INF", "native-image", "org.springframework.boot.maven.it", "aot-resource-generation", + "native-image.properties"), + Path.of("generated-resource"), Path.of("nested/generated-resource")); }); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/pom.xml new file mode 100644 index 0000000000..d0e99dea0c --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + org.springframework.boot.maven.it + aot-resource-generation + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + @java.version@ + @java.version@ + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + process-aot + + + + + + + + + org.springframework.boot + spring-boot + @project.version@ + + + jakarta.servlet + jakarta.servlet-api + @jakarta-servlet.version@ + provided + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/src/main/java/org/test/ResourceRegisteringAotProcessor.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/src/main/java/org/test/ResourceRegisteringAotProcessor.java new file mode 100644 index 0000000000..dd82f588ed --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/src/main/java/org/test/ResourceRegisteringAotProcessor.java @@ -0,0 +1,41 @@ +/* + * 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.aot.generate.GenerationContext; +import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution; +import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor; +import org.springframework.beans.factory.aot.BeanFactoryInitializationCode; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; + +class ResourceRegisteringAotProcessor implements BeanFactoryInitializationAotProcessor { + + @Override + public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { + return new BeanFactoryInitializationAotContribution() { + + @Override + public void applyTo(GenerationContext generationContext, + BeanFactoryInitializationCode beanFactoryInitializationCode) { + generationContext.getGeneratedFiles().addResourceFile("generated-resource", "content"); + generationContext.getGeneratedFiles().addResourceFile("nested/generated-resource", "nested content"); + } + + }; + } + +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/src/main/java/org/test/SampleApplication.java new file mode 100644 index 0000000000..f74b538faa --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,29 @@ +/* + * 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.Configuration; + +@Configuration(proxyBeanMethods = false) +public class SampleApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleApplication.class, args); + } + +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/src/main/resources/META-INF/spring/aot.factories b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/src/main/resources/META-INF/spring/aot.factories new file mode 100644 index 0000000000..6f18348d92 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-resource-generation/src/main/resources/META-INF/spring/aot.factories @@ -0,0 +1,2 @@ +org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor=\ +org.test.ResourceRegisteringAotProcessor \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessAotMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessAotMojo.java index 11c9adcee8..314f94510b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessAotMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessAotMojo.java @@ -93,8 +93,7 @@ public class ProcessAotMojo extends AbstractAotMojo { URL[] classPath = getClassPath(); generateAotAssets(classPath, AOT_PROCESSOR_CLASS_NAME, getAotArguments(applicationClass)); compileSourceFiles(classPath, this.generatedSources, this.classesDirectory); - copyAll(this.generatedResources.toPath().resolve("META-INF/native-image"), - this.classesDirectory.toPath().resolve("META-INF/native-image")); + copyAll(this.generatedResources.toPath(), this.classesDirectory.toPath()); copyAll(this.generatedClasses.toPath(), this.classesDirectory.toPath()); }