Merge branch '3.2.x' into 3.3.x

Closes gh-43060
This commit is contained in:
Andy Wilkinson 2024-11-07 12:38:36 +00:00
commit 32c61a99e4
2 changed files with 27 additions and 5 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.boot.configurationprocessor; package org.springframework.boot.configurationprocessor;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata;
@ -74,7 +73,6 @@ class IncrementalBuildMetadataGenerationTests extends AbstractMetadataGeneration
} }
@Test @Test
@Disabled("gh-26271")
void incrementalBuildTypeRenamed() { void incrementalBuildTypeRenamed() {
TestProject project = new TestProject(FooProperties.class, BarProperties.class); TestProject project = new TestProject(FooProperties.class, BarProperties.class);
ConfigurationMetadata metadata = project.compile(); ConfigurationMetadata metadata = project.compile();
@ -85,7 +83,7 @@ class IncrementalBuildMetadataGenerationTests extends AbstractMetadataGeneration
assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter").fromSource(RenamedBarProperties.class)); assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter").fromSource(RenamedBarProperties.class));
project.delete(BarProperties.class); project.delete(BarProperties.class);
project.add(RenamedBarProperties.class); project.add(RenamedBarProperties.class);
metadata = project.compile(); metadata = project.compile(metadata);
assertThat(metadata) assertThat(metadata)
.has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0)); .has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class).withDefaultValue(0));
assertThat(metadata) assertThat(metadata)

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,17 +16,22 @@
package org.springframework.boot.configurationprocessor; package org.springframework.boot.configurationprocessor;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata;
import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller;
import org.springframework.boot.configurationprocessor.test.CompiledMetadataReader; import org.springframework.boot.configurationprocessor.test.CompiledMetadataReader;
import org.springframework.boot.configurationprocessor.test.TestConfigurationMetadataAnnotationProcessor; import org.springframework.boot.configurationprocessor.test.TestConfigurationMetadataAnnotationProcessor;
import org.springframework.boot.configurationsample.ConfigurationProperties; import org.springframework.boot.configurationsample.ConfigurationProperties;
import org.springframework.boot.configurationsample.NestedConfigurationProperty; import org.springframework.boot.configurationsample.NestedConfigurationProperty;
import org.springframework.core.test.tools.ResourceFile;
import org.springframework.core.test.tools.SourceFile; import org.springframework.core.test.tools.SourceFile;
import org.springframework.core.test.tools.SourceFiles; import org.springframework.core.test.tools.SourceFiles;
import org.springframework.core.test.tools.TestCompiler; import org.springframework.core.test.tools.TestCompiler;
@ -55,14 +60,33 @@ public class TestProject {
} }
public ConfigurationMetadata compile() { public ConfigurationMetadata compile() {
return compile(null);
}
public ConfigurationMetadata compile(ConfigurationMetadata previousMetadata) {
TestConfigurationMetadataAnnotationProcessor processor = new TestConfigurationMetadataAnnotationProcessor(); TestConfigurationMetadataAnnotationProcessor processor = new TestConfigurationMetadataAnnotationProcessor();
TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor); TestCompiler compiler = TestCompiler.forSystem().withProcessors(processor);
if (previousMetadata != null) {
compiler = compiler.withResources(
ResourceFile.of("META-INF/spring-configuration-metadata.json", asBytes(previousMetadata)));
}
AtomicReference<ConfigurationMetadata> configurationMetadata = new AtomicReference<>(); AtomicReference<ConfigurationMetadata> configurationMetadata = new AtomicReference<>();
compiler.compile(this.sources, compiler.compile(this.sources,
(compiled) -> configurationMetadata.set(CompiledMetadataReader.getMetadata(compiled))); (compiled) -> configurationMetadata.set(CompiledMetadataReader.getMetadata(compiled)));
return configurationMetadata.get(); return configurationMetadata.get();
} }
private byte[] asBytes(ConfigurationMetadata previousMetadata) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
new JsonMarshaller().write(previousMetadata, output);
}
catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return output.toByteArray();
}
/** /**
* Add source code at the end of file, just before last '}' * Add source code at the end of file, just before last '}'
* @param target the target * @param target the target