Call meta-data processor regardless of annotations
Update ConfigurationMetadataAnnotationProcessor so that it gets called even if the source code doesn't include any @ConfigurationProperties items. See gh-1830
This commit is contained in:
@@ -39,6 +39,7 @@ import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
@@ -57,7 +58,7 @@ import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller;
|
||||
* @author Phillip Webb
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@SupportedAnnotationTypes({ ConfigurationMetadataAnnotationProcessor.CONFIGURATION_PROPERTIES_ANNOTATION })
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor {
|
||||
|
||||
@@ -103,10 +104,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations,
|
||||
RoundEnvironment roundEnv) {
|
||||
for (TypeElement annotation : annotations) {
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
|
||||
processElement(element);
|
||||
}
|
||||
Elements elementUtils = this.processingEnv.getElementUtils();
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(elementUtils
|
||||
.getTypeElement(configurationPropertiesAnnotation()))) {
|
||||
processElement(element);
|
||||
}
|
||||
if (roundEnv.processingOver()) {
|
||||
writeMetaData(this.metadata);
|
||||
@@ -290,7 +291,6 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,9 +41,9 @@ import org.springframework.boot.configurationsample.specific.InnerClassPropertie
|
||||
import org.springframework.boot.configurationsample.specific.InnerClassRootConfig;
|
||||
import org.springframework.boot.configurationsample.specific.SimplePojo;
|
||||
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.containsGroup;
|
||||
import static org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.containsProperty;
|
||||
@@ -63,7 +63,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
public void notAnnotated() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(NotAnnotated.class);
|
||||
assertThat("No config metadata file should have been generated when "
|
||||
+ "no metadata is discovered", metadata, nullValue());
|
||||
+ "no metadata is discovered", metadata.getItems(), empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,8 +173,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
@Test
|
||||
public void simpleMethodConfig() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(SimpleMethodConfig.class);
|
||||
assertThat(metadata, containsGroup("foo")
|
||||
.fromSource(SimpleMethodConfig.class));
|
||||
assertThat(metadata, containsGroup("foo").fromSource(SimpleMethodConfig.class));
|
||||
assertThat(
|
||||
metadata,
|
||||
containsProperty("foo.name", String.class).fromSource(
|
||||
@@ -258,7 +257,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
return processor.getMetadata();
|
||||
}
|
||||
|
||||
@SupportedAnnotationTypes({ TestConfigurationMetadataAnnotationProcessor.CONFIGURATION_PROPERTIES_ANNOTATION })
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
private static class TestConfigurationMetadataAnnotationProcessor extends
|
||||
ConfigurationMetadataAnnotationProcessor {
|
||||
|
||||
Reference in New Issue
Block a user