Search in sources :

Example 1 with ItemMetadata

use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method mergeExistingPropertyDescription.

@Test
public void mergeExistingPropertyDescription() throws Exception {
    ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, "A nice comparator.", null, null);
    writeAdditionalMetadata(property);
    ConfigurationMetadata metadata = compile(SimpleProperties.class);
    assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class).withDescription("A nice comparator."));
    assertThat(metadata.getItems()).hasSize(4);
}
Also used : ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata) Test(org.junit.Test)

Example 2 with ItemMetadata

use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method writePropertyDeprecation.

private void writePropertyDeprecation(ItemMetadata... items) throws Exception {
    File additionalMetadataFile = createAdditionalMetadataFile();
    JSONArray propertiesArray = new JSONArray();
    for (ItemMetadata item : items) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", item.getName());
        if (item.getType() != null) {
            jsonObject.put("type", item.getType());
        }
        ItemDeprecation deprecation = item.getDeprecation();
        if (deprecation != null) {
            JSONObject deprecationJson = new JSONObject();
            if (deprecation.getReason() != null) {
                deprecationJson.put("reason", deprecation.getReason());
            }
            if (deprecation.getReplacement() != null) {
                deprecationJson.put("replacement", deprecation.getReplacement());
            }
            jsonObject.put("deprecation", deprecationJson);
        }
        propertiesArray.put(jsonObject);
    }
    JSONObject additionalMetadata = new JSONObject();
    additionalMetadata.put("properties", propertiesArray);
    writeMetadata(additionalMetadataFile, additionalMetadata);
}
Also used : JSONObject(org.json.JSONObject) ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation) JSONArray(org.json.JSONArray) File(java.io.File) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata)

Example 3 with ItemMetadata

use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method mergeExistingPropertyDeprecation.

@Test
public void mergeExistingPropertyDeprecation() throws Exception {
    ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, null, null, new ItemDeprecation("Don't use this.", "simple.complex-comparator"));
    writeAdditionalMetadata(property);
    ConfigurationMetadata metadata = compile(SimpleProperties.class);
    assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class).withDeprecation("Don't use this.", "simple.complex-comparator"));
    assertThat(metadata.getItems()).hasSize(4);
}
Also used : ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation) ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata) Test(org.junit.Test)

Example 4 with ItemMetadata

use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method mergeExistingPropertyDefaultValue.

@Test
public void mergeExistingPropertyDefaultValue() throws Exception {
    ItemMetadata property = ItemMetadata.newProperty("simple", "flag", null, null, null, null, true, null);
    writeAdditionalMetadata(property);
    ConfigurationMetadata metadata = compile(SimpleProperties.class);
    assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).fromSource(SimpleProperties.class).withDescription("A simple flag.").withDeprecation(null, null).withDefaultValue(true));
    assertThat(metadata.getItems()).hasSize(4);
}
Also used : ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata) Test(org.junit.Test)

Example 5 with ItemMetadata

use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessor method processExecutableElement.

private void processExecutableElement(String prefix, ExecutableElement element) {
    if (element.getModifiers().contains(Modifier.PUBLIC) && (TypeKind.VOID != element.getReturnType().getKind())) {
        Element returns = this.processingEnv.getTypeUtils().asElement(element.getReturnType());
        if (returns instanceof TypeElement) {
            ItemMetadata group = ItemMetadata.newGroup(prefix, this.typeUtils.getQualifiedName(returns), this.typeUtils.getQualifiedName(element.getEnclosingElement()), element.toString());
            if (this.metadataCollector.hasSimilarGroup(group)) {
                this.processingEnv.getMessager().printMessage(Kind.ERROR, "Duplicate `@ConfigurationProperties` definition for prefix '" + prefix + "'", element);
            } else {
                this.metadataCollector.add(group);
                processTypeElement(prefix, (TypeElement) returns, element);
            }
        }
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata)

Aggregations

ItemMetadata (org.springframework.boot.configurationprocessor.metadata.ItemMetadata)8 Test (org.junit.Test)5 ConfigurationMetadata (org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata)5 ItemDeprecation (org.springframework.boot.configurationprocessor.metadata.ItemDeprecation)3 File (java.io.File)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 TestJsonConverter (org.springframework.boot.configurationprocessor.metadata.TestJsonConverter)1