|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
* Copyright 2012-2022 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,8 +16,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.configurationprocessor;
|
|
|
|
package org.springframework.boot.configurationprocessor;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
@ -37,15 +35,16 @@ import org.springframework.boot.configurationprocessor.metadata.TestJsonConverte
|
|
|
|
import org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty;
|
|
|
|
import org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty;
|
|
|
|
import org.springframework.boot.configurationsample.simple.SimpleProperties;
|
|
|
|
import org.springframework.boot.configurationsample.simple.SimpleProperties;
|
|
|
|
import org.springframework.boot.configurationsample.specific.SimpleConflictingProperties;
|
|
|
|
import org.springframework.boot.configurationsample.specific.SimpleConflictingProperties;
|
|
|
|
import org.springframework.util.FileCopyUtils;
|
|
|
|
import org.springframework.core.test.tools.CompilationException;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Metadata generation tests for merging additional metadata.
|
|
|
|
* Metadata generation tests for merging additional metadata.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
|
|
|
|
* @author Scott Frederick
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
|
|
|
|
|
|
|
@ -53,8 +52,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
void mergingOfAdditionalProperty() throws Exception {
|
|
|
|
void mergingOfAdditionalProperty() throws Exception {
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty(null, "foo", "java.lang.String",
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty(null, "foo", "java.lang.String",
|
|
|
|
AdditionalMetadata.class.getName(), null, null, null, null);
|
|
|
|
AdditionalMetadata.class.getName(), null, null, null, null);
|
|
|
|
writeAdditionalMetadata(property);
|
|
|
|
String additionalMetadata = buildAdditionalMetadata(property);
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("foo", String.class).fromSource(AdditionalMetadata.class));
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("foo", String.class).fromSource(AdditionalMetadata.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -63,8 +62,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
void mergingOfAdditionalPropertyMatchingGroup() throws Exception {
|
|
|
|
void mergingOfAdditionalPropertyMatchingGroup() throws Exception {
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty(null, "simple", "java.lang.String", null, null, null, null,
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty(null, "simple", "java.lang.String", null, null, null, null,
|
|
|
|
null);
|
|
|
|
null);
|
|
|
|
writeAdditionalMetadata(property);
|
|
|
|
String additionalMetadata = buildAdditionalMetadata(property);
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
|
|
|
|
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimpleProperties.class));
|
|
|
|
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimpleProperties.class));
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple", String.class));
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple", String.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -72,8 +71,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void mergeExistingPropertyDefaultValue() throws Exception {
|
|
|
|
void mergeExistingPropertyDefaultValue() throws Exception {
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", null, null, null, null, true, null);
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", null, null, null, null, true, null);
|
|
|
|
writeAdditionalMetadata(property);
|
|
|
|
String additionalMetadata = buildAdditionalMetadata(property);
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).fromSource(SimpleProperties.class)
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).fromSource(SimpleProperties.class)
|
|
|
|
.withDescription("A simple flag.").withDeprecation(null, null).withDefaultValue(true));
|
|
|
|
.withDescription("A simple flag.").withDeprecation(null, null).withDefaultValue(true));
|
|
|
|
assertThat(metadata.getItems()).hasSize(4);
|
|
|
|
assertThat(metadata.getItems()).hasSize(4);
|
|
|
@ -83,8 +82,9 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
void mergeExistingPropertyWithSeveralCandidates() throws Exception {
|
|
|
|
void mergeExistingPropertyWithSeveralCandidates() throws Exception {
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", Boolean.class.getName(), null, null, null,
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", Boolean.class.getName(), null, null, null,
|
|
|
|
true, null);
|
|
|
|
true, null);
|
|
|
|
writeAdditionalMetadata(property);
|
|
|
|
String additionalMetadata = buildAdditionalMetadata(property);
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class, SimpleConflictingProperties.class);
|
|
|
|
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class,
|
|
|
|
|
|
|
|
SimpleConflictingProperties.class);
|
|
|
|
assertThat(metadata.getItems()).hasSize(6);
|
|
|
|
assertThat(metadata.getItems()).hasSize(6);
|
|
|
|
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.getName().equals("simple.flag"))
|
|
|
|
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.getName().equals("simple.flag"))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
@ -107,8 +107,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
void mergeExistingPropertyDescription() throws Exception {
|
|
|
|
void mergeExistingPropertyDescription() throws Exception {
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, "A nice comparator.",
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, "A nice comparator.",
|
|
|
|
null, null);
|
|
|
|
null, null);
|
|
|
|
writeAdditionalMetadata(property);
|
|
|
|
String additionalMetadata = buildAdditionalMetadata(property);
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
|
|
|
|
.fromSource(SimpleProperties.class).withDescription("A nice comparator."));
|
|
|
|
.fromSource(SimpleProperties.class).withDescription("A nice comparator."));
|
|
|
|
assertThat(metadata.getItems()).hasSize(4);
|
|
|
|
assertThat(metadata.getItems()).hasSize(4);
|
|
|
@ -118,8 +118,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
void mergeExistingPropertyDeprecation() throws Exception {
|
|
|
|
void mergeExistingPropertyDeprecation() throws Exception {
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, null, null,
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, null, null,
|
|
|
|
new ItemDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
|
|
|
new ItemDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
|
|
|
writeAdditionalMetadata(property);
|
|
|
|
String additionalMetadata = buildAdditionalMetadata(property);
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
|
|
|
|
assertThat(metadata).has(
|
|
|
|
assertThat(metadata).has(
|
|
|
|
Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class)
|
|
|
|
Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class)
|
|
|
|
.withDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
|
|
|
.withDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
|
|
@ -130,8 +130,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
void mergeExistingPropertyDeprecationOverride() throws Exception {
|
|
|
|
void mergeExistingPropertyDeprecationOverride() throws Exception {
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, null, null, null, null,
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, null, null, null, null,
|
|
|
|
new ItemDeprecation("Don't use this.", "single.name"));
|
|
|
|
new ItemDeprecation("Don't use this.", "single.name"));
|
|
|
|
writeAdditionalMetadata(property);
|
|
|
|
String additionalMetadata = buildAdditionalMetadata(property);
|
|
|
|
ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class);
|
|
|
|
ConfigurationMetadata metadata = compile(additionalMetadata, DeprecatedSingleProperty.class);
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
|
|
|
.fromSource(DeprecatedSingleProperty.class).withDeprecation("Don't use this.", "single.name"));
|
|
|
|
.fromSource(DeprecatedSingleProperty.class).withDeprecation("Don't use this.", "single.name"));
|
|
|
|
assertThat(metadata.getItems()).hasSize(3);
|
|
|
|
assertThat(metadata.getItems()).hasSize(3);
|
|
|
@ -141,8 +141,8 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
void mergeExistingPropertyDeprecationOverrideLevel() throws Exception {
|
|
|
|
void mergeExistingPropertyDeprecationOverrideLevel() throws Exception {
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, null, null, null, null,
|
|
|
|
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, null, null, null, null,
|
|
|
|
new ItemDeprecation(null, null, "error"));
|
|
|
|
new ItemDeprecation(null, null, "error"));
|
|
|
|
writeAdditionalMetadata(property);
|
|
|
|
String additionalMetadata = buildAdditionalMetadata(property);
|
|
|
|
ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class);
|
|
|
|
ConfigurationMetadata metadata = compile(additionalMetadata, DeprecatedSingleProperty.class);
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
|
|
|
.fromSource(DeprecatedSingleProperty.class)
|
|
|
|
.fromSource(DeprecatedSingleProperty.class)
|
|
|
|
.withDeprecation("renamed", "singledeprecated.new-name", "error"));
|
|
|
|
.withDeprecation("renamed", "singledeprecated.new-name", "error"));
|
|
|
@ -151,17 +151,17 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void mergeOfInvalidAdditionalMetadata() throws IOException {
|
|
|
|
void mergeOfInvalidAdditionalMetadata() throws IOException {
|
|
|
|
File additionalMetadataFile = createAdditionalMetadataFile();
|
|
|
|
String metadata = "Hello World";
|
|
|
|
FileCopyUtils.copy("Hello World", new FileWriter(additionalMetadataFile));
|
|
|
|
assertThatExceptionOfType(CompilationException.class)
|
|
|
|
assertThatIllegalStateException().isThrownBy(() -> compile(SimpleProperties.class))
|
|
|
|
.isThrownBy(() -> compile(metadata, SimpleProperties.class))
|
|
|
|
.withMessage("Compilation failed");
|
|
|
|
.withMessageContaining("Invalid additional meta-data");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void mergingOfSimpleHint() throws Exception {
|
|
|
|
void mergingOfSimpleHint() throws Exception {
|
|
|
|
writeAdditionalHints(ItemHint.newHint("simple.the-name", new ItemHint.ValueHint("boot", "Bla bla"),
|
|
|
|
String hints = buildAdditionalHints(ItemHint.newHint("simple.the-name",
|
|
|
|
new ItemHint.ValueHint("spring", null)));
|
|
|
|
new ItemHint.ValueHint("boot", "Bla bla"), new ItemHint.ValueHint("spring", null)));
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
ConfigurationMetadata metadata = compile(hints, SimpleProperties.class);
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
|
|
|
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
|
|
|
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
|
|
|
.withDefaultValue("boot").withDeprecation(null, null));
|
|
|
|
.withDefaultValue("boot").withDeprecation(null, null));
|
|
|
@ -171,8 +171,9 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void mergingOfHintWithNonCanonicalName() throws Exception {
|
|
|
|
void mergingOfHintWithNonCanonicalName() throws Exception {
|
|
|
|
writeAdditionalHints(ItemHint.newHint("simple.theName", new ItemHint.ValueHint("boot", "Bla bla")));
|
|
|
|
String hints = buildAdditionalHints(
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
ItemHint.newHint("simple.theName", new ItemHint.ValueHint("boot", "Bla bla")));
|
|
|
|
|
|
|
|
ConfigurationMetadata metadata = compile(hints, SimpleProperties.class);
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
|
|
|
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
|
|
|
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
|
|
|
.withDefaultValue("boot").withDeprecation(null, null));
|
|
|
|
.withDefaultValue("boot").withDeprecation(null, null));
|
|
|
@ -181,10 +182,10 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void mergingOfHintWithProvider() throws Exception {
|
|
|
|
void mergingOfHintWithProvider() throws Exception {
|
|
|
|
writeAdditionalHints(new ItemHint("simple.theName", Collections.emptyList(),
|
|
|
|
String hints = buildAdditionalHints(new ItemHint("simple.theName", Collections.emptyList(),
|
|
|
|
Arrays.asList(new ItemHint.ValueProvider("first", Collections.singletonMap("target", "org.foo")),
|
|
|
|
Arrays.asList(new ItemHint.ValueProvider("first", Collections.singletonMap("target", "org.foo")),
|
|
|
|
new ItemHint.ValueProvider("second", null))));
|
|
|
|
new ItemHint.ValueProvider("second", null))));
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
ConfigurationMetadata metadata = compile(hints, SimpleProperties.class);
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
|
|
|
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
|
|
|
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
|
|
|
.withDefaultValue("boot").withDeprecation(null, null));
|
|
|
|
.withDefaultValue("boot").withDeprecation(null, null));
|
|
|
@ -194,58 +195,48 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void mergingOfAdditionalDeprecation() throws Exception {
|
|
|
|
void mergingOfAdditionalDeprecation() throws Exception {
|
|
|
|
writePropertyDeprecation(ItemMetadata.newProperty("simple", "wrongName", "java.lang.String", null, null, null,
|
|
|
|
String deprecations = buildPropertyDeprecations(ItemMetadata.newProperty("simple", "wrongName",
|
|
|
|
null, new ItemDeprecation("Lame name.", "simple.the-name")));
|
|
|
|
"java.lang.String", null, null, null, null, new ItemDeprecation("Lame name.", "simple.the-name")));
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
ConfigurationMetadata metadata = compile(deprecations, SimpleProperties.class);
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class).withDeprecation("Lame name.",
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class).withDeprecation("Lame name.",
|
|
|
|
"simple.the-name"));
|
|
|
|
"simple.the-name"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void mergingOfAdditionalMetadata() throws Exception {
|
|
|
|
void mergingOfAdditionalMetadata() throws Exception {
|
|
|
|
File metaInfDirectory = new File(getCompiler().getOutputLocation(), "META-INF");
|
|
|
|
|
|
|
|
metaInfDirectory.mkdirs();
|
|
|
|
|
|
|
|
File additionalMetadataFile = new File(metaInfDirectory, "additional-spring-configuration-metadata.json");
|
|
|
|
|
|
|
|
additionalMetadataFile.createNewFile();
|
|
|
|
|
|
|
|
JSONObject property = new JSONObject();
|
|
|
|
JSONObject property = new JSONObject();
|
|
|
|
property.put("name", "foo");
|
|
|
|
property.put("name", "foo");
|
|
|
|
property.put("type", "java.lang.String");
|
|
|
|
property.put("type", "java.lang.String");
|
|
|
|
property.put("sourceType", AdditionalMetadata.class.getName());
|
|
|
|
property.put("sourceType", AdditionalMetadata.class.getName());
|
|
|
|
JSONArray properties = new JSONArray();
|
|
|
|
JSONArray properties = new JSONArray();
|
|
|
|
properties.put(property);
|
|
|
|
properties.put(property);
|
|
|
|
JSONObject additionalMetadata = new JSONObject();
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
additionalMetadata.put("properties", properties);
|
|
|
|
json.put("properties", properties);
|
|
|
|
FileWriter writer = new FileWriter(additionalMetadataFile);
|
|
|
|
String additionalMetadata = json.toString();
|
|
|
|
writer.append(additionalMetadata.toString(2));
|
|
|
|
ConfigurationMetadata metadata = compile(additionalMetadata, SimpleProperties.class);
|
|
|
|
writer.flush();
|
|
|
|
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
|
|
|
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("foo", String.class).fromSource(AdditionalMetadata.class));
|
|
|
|
assertThat(metadata).has(Metadata.withProperty("foo", String.class).fromSource(AdditionalMetadata.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void writeAdditionalMetadata(ItemMetadata... metadata) throws Exception {
|
|
|
|
private String buildAdditionalMetadata(ItemMetadata... metadata) throws Exception {
|
|
|
|
TestJsonConverter converter = new TestJsonConverter();
|
|
|
|
TestJsonConverter converter = new TestJsonConverter();
|
|
|
|
File additionalMetadataFile = createAdditionalMetadataFile();
|
|
|
|
|
|
|
|
JSONObject additionalMetadata = new JSONObject();
|
|
|
|
JSONObject additionalMetadata = new JSONObject();
|
|
|
|
JSONArray properties = new JSONArray();
|
|
|
|
JSONArray properties = new JSONArray();
|
|
|
|
for (ItemMetadata itemMetadata : metadata) {
|
|
|
|
for (ItemMetadata itemMetadata : metadata) {
|
|
|
|
properties.put(converter.toJsonObject(itemMetadata));
|
|
|
|
properties.put(converter.toJsonObject(itemMetadata));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
additionalMetadata.put("properties", properties);
|
|
|
|
additionalMetadata.put("properties", properties);
|
|
|
|
writeMetadata(additionalMetadataFile, additionalMetadata);
|
|
|
|
return additionalMetadata.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void writeAdditionalHints(ItemHint... hints) throws Exception {
|
|
|
|
private String buildAdditionalHints(ItemHint... hints) throws Exception {
|
|
|
|
TestJsonConverter converter = new TestJsonConverter();
|
|
|
|
TestJsonConverter converter = new TestJsonConverter();
|
|
|
|
File additionalMetadataFile = createAdditionalMetadataFile();
|
|
|
|
|
|
|
|
JSONObject additionalMetadata = new JSONObject();
|
|
|
|
JSONObject additionalMetadata = new JSONObject();
|
|
|
|
additionalMetadata.put("hints", converter.toJsonArray(Arrays.asList(hints)));
|
|
|
|
additionalMetadata.put("hints", converter.toJsonArray(Arrays.asList(hints)));
|
|
|
|
writeMetadata(additionalMetadataFile, additionalMetadata);
|
|
|
|
return additionalMetadata.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void writePropertyDeprecation(ItemMetadata... items) throws Exception {
|
|
|
|
private String buildPropertyDeprecations(ItemMetadata... items) throws Exception {
|
|
|
|
File additionalMetadataFile = createAdditionalMetadataFile();
|
|
|
|
|
|
|
|
JSONArray propertiesArray = new JSONArray();
|
|
|
|
JSONArray propertiesArray = new JSONArray();
|
|
|
|
for (ItemMetadata item : items) {
|
|
|
|
for (ItemMetadata item : items) {
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
@ -269,21 +260,7 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSONObject additionalMetadata = new JSONObject();
|
|
|
|
JSONObject additionalMetadata = new JSONObject();
|
|
|
|
additionalMetadata.put("properties", propertiesArray);
|
|
|
|
additionalMetadata.put("properties", propertiesArray);
|
|
|
|
writeMetadata(additionalMetadataFile, additionalMetadata);
|
|
|
|
return additionalMetadata.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private File createAdditionalMetadataFile() throws IOException {
|
|
|
|
|
|
|
|
File metaInfDirectory = new File(getCompiler().getOutputLocation(), "META-INF");
|
|
|
|
|
|
|
|
metaInfDirectory.mkdirs();
|
|
|
|
|
|
|
|
File additionalMetadataFile = new File(metaInfDirectory, "additional-spring-configuration-metadata.json");
|
|
|
|
|
|
|
|
additionalMetadataFile.createNewFile();
|
|
|
|
|
|
|
|
return additionalMetadataFile;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void writeMetadata(File metadataFile, JSONObject metadata) throws Exception {
|
|
|
|
|
|
|
|
try (FileWriter writer = new FileWriter(metadataFile)) {
|
|
|
|
|
|
|
|
writer.append(metadata.toString(2));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static class AdditionalMetadata {
|
|
|
|
static class AdditionalMetadata {
|
|
|
|