Merge manual item meta-data
Previously, manual meta-data were added to the existing set of entries which could lead to duplicates if a manual entry is meant to complement a property that is detected via the processor. We now match the name and type of the item against the auto-detected entries. If no match is found, we add the extra entry as we did before. If a match is found we override the description, default value and deprecation information. Closes gh-3562
This commit is contained in:
@@ -348,16 +348,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
|
||||
@Test
|
||||
public void mergingOfAdditionalProperty() throws Exception {
|
||||
File additionalMetadataFile = createAdditionalMetadataFile();
|
||||
JSONObject property = new JSONObject();
|
||||
property.put("name", "foo");
|
||||
property.put("type", "java.lang.String");
|
||||
property.put("sourceType", AdditionalMetadata.class.getName());
|
||||
JSONArray properties = new JSONArray();
|
||||
properties.put(property);
|
||||
JSONObject additionalMetadata = new JSONObject();
|
||||
additionalMetadata.put("properties", properties);
|
||||
writeMetadata(additionalMetadataFile, additionalMetadata);
|
||||
ItemMetadata property = ItemMetadata.newProperty(null, "foo",
|
||||
"java.lang.String", AdditionalMetadata.class.getName(), null, null, null,null);
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata, containsProperty("simple.comparator"));
|
||||
assertThat(metadata,
|
||||
@@ -365,6 +358,65 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
.fromSource(AdditionalMetadata.class));
|
||||
}
|
||||
|
||||
@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,
|
||||
containsProperty("simple.flag", Boolean.class)
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.")
|
||||
.withDefaultValue(is(true)));
|
||||
assertThat(metadata.getItems().size(), is(4));
|
||||
}
|
||||
|
||||
@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,
|
||||
containsProperty("simple.comparator", "java.util.Comparator<?>")
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("A nice comparator."));
|
||||
assertThat(metadata.getItems().size(), is(4));
|
||||
}
|
||||
|
||||
@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,
|
||||
containsProperty("simple.comparator", "java.util.Comparator<?>")
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDeprecation("Don't use this.", "simple.complex-comparator"));
|
||||
assertThat(metadata.getItems().size(), is(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeExistingPropertyDeprecationOverride() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null,
|
||||
null, null, null, null, new ItemDeprecation("Don't use this.",
|
||||
"single.name"));
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class);
|
||||
assertThat(
|
||||
metadata,
|
||||
containsProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class)
|
||||
.withDeprecation("Don't use this.", "single.name"));
|
||||
assertThat(metadata.getItems().size(), is(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeOfInvalidAdditionalMetadata() throws IOException {
|
||||
File additionalMetadataFile = createAdditionalMetadataFile();
|
||||
@@ -532,6 +584,13 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
return processor.getMetadata();
|
||||
}
|
||||
|
||||
private void writeAdditionalMetadata(ItemMetadata... metadata) throws IOException {
|
||||
File additionalMetadataFile = createAdditionalMetadataFile();
|
||||
JSONObject additionalMetadata = new JSONObject();
|
||||
additionalMetadata.put("properties", metadata);
|
||||
writeMetadata(additionalMetadataFile, additionalMetadata);
|
||||
}
|
||||
|
||||
private void writeAdditionalHints(ItemHint... hints) throws IOException {
|
||||
File additionalMetadataFile = createAdditionalMetadataFile();
|
||||
JSONObject additionalMetadata = new JSONObject();
|
||||
|
||||
Reference in New Issue
Block a user