From cf09451ffb9cdc38a7a48a7e486d66fc7d325267 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 28 Oct 2020 21:13:08 -0700 Subject: [PATCH] Retain inner-class data on incremental compile Ensure that metadata sourced from inner-types is not deleted when performing an incremental compile. Prior to this commit, the source type was searched using the `Outer$Inner` format. This is not supported `Elements.getTypeElement` so we now convert the names to `Outer.Inner`. Closes gh-10886 --- .../boot/configurationprocessor/MetadataCollector.java | 2 +- .../IncrementalBuildMetadataGenerationTests.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataCollector.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataCollector.java index b9e4f0e3c6..ea06d3091b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataCollector.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataCollector.java @@ -111,7 +111,7 @@ public class MetadataCollector { } private boolean deletedInCurrentBuild(String sourceType) { - return this.processingEnvironment.getElementUtils().getTypeElement(sourceType) == null; + return this.processingEnvironment.getElementUtils().getTypeElement(sourceType.replace('$', '.')) == null; } private boolean processedInCurrentBuild(String sourceType) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/IncrementalBuildMetadataGenerationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/IncrementalBuildMetadataGenerationTests.java index dd7b1b6e78..8e2f91ae33 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/IncrementalBuildMetadataGenerationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/IncrementalBuildMetadataGenerationTests.java @@ -23,6 +23,7 @@ import org.springframework.boot.configurationprocessor.metadata.Metadata; import org.springframework.boot.configurationsample.incremental.BarProperties; import org.springframework.boot.configurationsample.incremental.FooProperties; import org.springframework.boot.configurationsample.incremental.RenamedBarProperties; +import org.springframework.boot.configurationsample.simple.ClassWithNestedProperties; import static org.assertj.core.api.Assertions.assertThat; @@ -92,4 +93,12 @@ class IncrementalBuildMetadataGenerationTests extends AbstractMetadataGeneration .has(Metadata.withProperty("bar.counter").withDefaultValue(0).fromSource(RenamedBarProperties.class)); } + @Test + void incrementalBuildDoesNotDeleteItems() throws Exception { + TestProject project = new TestProject(this.tempDir, ClassWithNestedProperties.class, FooProperties.class); + ConfigurationMetadata initialMetadata = project.fullBuild(); + ConfigurationMetadata updatedMetadata = project.incrementalBuild(FooProperties.class); + assertThat(initialMetadata.getItems()).isEqualTo(updatedMetadata.getItems()); + } + }