Upgrade to spring-javaformat 0.0.11
This commit is contained in:
@@ -111,25 +111,21 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
super.init(env);
|
||||
this.typeUtils = new TypeUtils(env);
|
||||
this.metadataStore = new MetadataStore(env);
|
||||
this.metadataCollector = new MetadataCollector(env,
|
||||
this.metadataStore.readMetadata());
|
||||
this.metadataCollector = new MetadataCollector(env, this.metadataStore.readMetadata());
|
||||
try {
|
||||
this.fieldValuesParser = new JavaCompilerFieldValuesParser(env);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
this.fieldValuesParser = FieldValuesParser.NONE;
|
||||
logWarning("Field value processing of @ConfigurationProperty meta-data is "
|
||||
+ "not supported");
|
||||
logWarning("Field value processing of @ConfigurationProperty meta-data is " + "not supported");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations,
|
||||
RoundEnvironment roundEnv) {
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
this.metadataCollector.processing(roundEnv);
|
||||
Elements elementUtils = this.processingEnv.getElementUtils();
|
||||
TypeElement annotationType = elementUtils
|
||||
.getTypeElement(configurationPropertiesAnnotation());
|
||||
TypeElement annotationType = elementUtils.getTypeElement(configurationPropertiesAnnotation());
|
||||
if (annotationType != null) { // Is @ConfigurationProperties available
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(annotationType)) {
|
||||
processElement(element);
|
||||
@@ -148,8 +144,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
|
||||
private void processElement(Element element) {
|
||||
try {
|
||||
AnnotationMirror annotation = getAnnotation(element,
|
||||
configurationPropertiesAnnotation());
|
||||
AnnotationMirror annotation = getAnnotation(element, configurationPropertiesAnnotation());
|
||||
if (annotation != null) {
|
||||
String prefix = getPrefix(annotation);
|
||||
if (element instanceof TypeElement) {
|
||||
@@ -161,8 +156,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(
|
||||
"Error processing configuration meta-data on " + element, ex);
|
||||
throw new IllegalStateException("Error processing configuration meta-data on " + element, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,20 +167,14 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
}
|
||||
|
||||
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 (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());
|
||||
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);
|
||||
"Duplicate `@ConfigurationProperties` definition for prefix '" + prefix + "'", element);
|
||||
}
|
||||
else {
|
||||
this.metadataCollector.add(group);
|
||||
@@ -196,10 +184,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
}
|
||||
}
|
||||
|
||||
private void processTypeElement(String prefix, TypeElement element,
|
||||
ExecutableElement source) {
|
||||
TypeElementMembers members = new TypeElementMembers(this.processingEnv,
|
||||
this.fieldValuesParser, element);
|
||||
private void processTypeElement(String prefix, TypeElement element, ExecutableElement source) {
|
||||
TypeElementMembers members = new TypeElementMembers(this.processingEnv, this.fieldValuesParser, element);
|
||||
Map<String, Object> fieldValues = members.getFieldValues();
|
||||
processSimpleTypes(prefix, element, source, members, fieldValues);
|
||||
processSimpleLombokTypes(prefix, element, source, members, fieldValues);
|
||||
@@ -207,18 +193,15 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
processNestedLombokTypes(prefix, element, source, members);
|
||||
}
|
||||
|
||||
private void processSimpleTypes(String prefix, TypeElement element,
|
||||
ExecutableElement source, TypeElementMembers members,
|
||||
Map<String, Object> fieldValues) {
|
||||
for (Map.Entry<String, ExecutableElement> entry : members.getPublicGetters()
|
||||
.entrySet()) {
|
||||
private void processSimpleTypes(String prefix, TypeElement element, ExecutableElement source,
|
||||
TypeElementMembers members, Map<String, Object> fieldValues) {
|
||||
for (Map.Entry<String, ExecutableElement> entry : members.getPublicGetters().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
ExecutableElement getter = entry.getValue();
|
||||
TypeMirror returnType = getter.getReturnType();
|
||||
ExecutableElement setter = members.getPublicSetter(name, returnType);
|
||||
VariableElement field = members.getFields().get(name);
|
||||
Element returnTypeElement = this.processingEnv.getTypeUtils()
|
||||
.asElement(returnType);
|
||||
Element returnTypeElement = this.processingEnv.getTypeUtils().asElement(returnType);
|
||||
boolean isExcluded = this.typeExcludeFilter.isExcluded(returnType);
|
||||
boolean isNested = isNested(returnTypeElement, field, element);
|
||||
boolean isCollection = this.typeUtils.isCollectionOrMap(returnType);
|
||||
@@ -227,18 +210,15 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
String sourceType = this.typeUtils.getQualifiedName(element);
|
||||
String description = this.typeUtils.getJavaDoc(field);
|
||||
Object defaultValue = fieldValues.get(name);
|
||||
boolean deprecated = isDeprecated(getter) || isDeprecated(setter)
|
||||
|| isDeprecated(source);
|
||||
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name,
|
||||
dataType, sourceType, null, description, defaultValue,
|
||||
(deprecated ? getItemDeprecation(getter) : null)));
|
||||
boolean deprecated = isDeprecated(getter) || isDeprecated(setter) || isDeprecated(source);
|
||||
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null,
|
||||
description, defaultValue, (deprecated ? getItemDeprecation(getter) : null)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemDeprecation getItemDeprecation(ExecutableElement getter) {
|
||||
AnnotationMirror annotation = getAnnotation(getter,
|
||||
deprecatedConfigurationPropertyAnnotation());
|
||||
AnnotationMirror annotation = getAnnotation(getter, deprecatedConfigurationPropertyAnnotation());
|
||||
String reason = null;
|
||||
String replacement = null;
|
||||
if (annotation != null) {
|
||||
@@ -246,13 +226,11 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
reason = (String) elementValues.get("reason");
|
||||
replacement = (String) elementValues.get("replacement");
|
||||
}
|
||||
return new ItemDeprecation(("".equals(reason) ? null : reason),
|
||||
("".equals(replacement) ? null : replacement));
|
||||
return new ItemDeprecation(("".equals(reason) ? null : reason), ("".equals(replacement) ? null : replacement));
|
||||
}
|
||||
|
||||
private void processSimpleLombokTypes(String prefix, TypeElement element,
|
||||
ExecutableElement source, TypeElementMembers members,
|
||||
Map<String, Object> fieldValues) {
|
||||
private void processSimpleLombokTypes(String prefix, TypeElement element, ExecutableElement source,
|
||||
TypeElementMembers members, Map<String, Object> fieldValues) {
|
||||
for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
VariableElement field = entry.getValue();
|
||||
@@ -260,8 +238,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
continue;
|
||||
}
|
||||
TypeMirror returnType = field.asType();
|
||||
Element returnTypeElement = this.processingEnv.getTypeUtils()
|
||||
.asElement(returnType);
|
||||
Element returnTypeElement = this.processingEnv.getTypeUtils().asElement(returnType);
|
||||
boolean isExcluded = this.typeExcludeFilter.isExcluded(returnType);
|
||||
boolean isNested = isNested(returnTypeElement, field, element);
|
||||
boolean isCollection = this.typeUtils.isCollectionOrMap(returnType);
|
||||
@@ -272,34 +249,30 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
String description = this.typeUtils.getJavaDoc(field);
|
||||
Object defaultValue = fieldValues.get(name);
|
||||
boolean deprecated = isDeprecated(field) || isDeprecated(source);
|
||||
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name,
|
||||
dataType, sourceType, null, description, defaultValue,
|
||||
(deprecated ? new ItemDeprecation() : null)));
|
||||
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null,
|
||||
description, defaultValue, (deprecated ? new ItemDeprecation() : null)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processNestedTypes(String prefix, TypeElement element,
|
||||
ExecutableElement source, TypeElementMembers members) {
|
||||
for (Map.Entry<String, ExecutableElement> entry : members.getPublicGetters()
|
||||
.entrySet()) {
|
||||
private void processNestedTypes(String prefix, TypeElement element, ExecutableElement source,
|
||||
TypeElementMembers members) {
|
||||
for (Map.Entry<String, ExecutableElement> entry : members.getPublicGetters().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
ExecutableElement getter = entry.getValue();
|
||||
VariableElement field = members.getFields().get(name);
|
||||
processNestedType(prefix, element, source, name, getter, field,
|
||||
getter.getReturnType());
|
||||
processNestedType(prefix, element, source, name, getter, field, getter.getReturnType());
|
||||
}
|
||||
}
|
||||
|
||||
private void processNestedLombokTypes(String prefix, TypeElement element,
|
||||
ExecutableElement source, TypeElementMembers members) {
|
||||
private void processNestedLombokTypes(String prefix, TypeElement element, ExecutableElement source,
|
||||
TypeElementMembers members) {
|
||||
for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) {
|
||||
String name = entry.getKey();
|
||||
VariableElement field = entry.getValue();
|
||||
if (isLombokField(field, element)) {
|
||||
ExecutableElement getter = members.getPublicGetter(name, field.asType());
|
||||
processNestedType(prefix, element, source, name, getter, field,
|
||||
field.asType());
|
||||
processNestedType(prefix, element, source, name, getter, field, field.asType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,8 +282,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
}
|
||||
|
||||
private boolean hasLombokSetter(VariableElement field, TypeElement element) {
|
||||
return !field.getModifiers().contains(Modifier.FINAL)
|
||||
&& hasLombokPublicAccessor(field, element, false);
|
||||
return !field.getModifiers().contains(Modifier.FINAL) && hasLombokPublicAccessor(field, element, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,16 +294,13 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
* write accessor
|
||||
* @return {@code true} if this field has a public accessor of the specified type
|
||||
*/
|
||||
private boolean hasLombokPublicAccessor(VariableElement field, TypeElement element,
|
||||
boolean getter) {
|
||||
String annotation = (getter ? LOMBOK_GETTER_ANNOTATION
|
||||
: LOMBOK_SETTER_ANNOTATION);
|
||||
private boolean hasLombokPublicAccessor(VariableElement field, TypeElement element, boolean getter) {
|
||||
String annotation = (getter ? LOMBOK_GETTER_ANNOTATION : LOMBOK_SETTER_ANNOTATION);
|
||||
AnnotationMirror lombokMethodAnnotationOnField = getAnnotation(field, annotation);
|
||||
if (lombokMethodAnnotationOnField != null) {
|
||||
return isAccessLevelPublic(lombokMethodAnnotationOnField);
|
||||
}
|
||||
AnnotationMirror lombokMethodAnnotationOnElement = getAnnotation(element,
|
||||
annotation);
|
||||
AnnotationMirror lombokMethodAnnotationOnElement = getAnnotation(element, annotation);
|
||||
if (lombokMethodAnnotationOnElement != null) {
|
||||
return isAccessLevelPublic(lombokMethodAnnotationOnElement);
|
||||
}
|
||||
@@ -344,39 +313,32 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
return (value == null || value.toString().equals(LOMBOK_ACCESS_LEVEL_PUBLIC));
|
||||
}
|
||||
|
||||
private void processNestedType(String prefix, TypeElement element,
|
||||
ExecutableElement source, String name, ExecutableElement getter,
|
||||
VariableElement field, TypeMirror returnType) {
|
||||
private void processNestedType(String prefix, TypeElement element, ExecutableElement source, String name,
|
||||
ExecutableElement getter, VariableElement field, TypeMirror returnType) {
|
||||
Element returnElement = this.processingEnv.getTypeUtils().asElement(returnType);
|
||||
boolean isNested = isNested(returnElement, field, element);
|
||||
AnnotationMirror annotation = getAnnotation(getter,
|
||||
configurationPropertiesAnnotation());
|
||||
if (returnElement != null && returnElement instanceof TypeElement
|
||||
&& annotation == null && isNested) {
|
||||
AnnotationMirror annotation = getAnnotation(getter, configurationPropertiesAnnotation());
|
||||
if (returnElement != null && returnElement instanceof TypeElement && annotation == null && isNested) {
|
||||
String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, name);
|
||||
this.metadataCollector.add(ItemMetadata.newGroup(nestedPrefix,
|
||||
this.typeUtils.getQualifiedName(returnElement),
|
||||
this.typeUtils.getQualifiedName(element),
|
||||
(getter != null) ? getter.toString() : null));
|
||||
this.metadataCollector
|
||||
.add(ItemMetadata.newGroup(nestedPrefix, this.typeUtils.getQualifiedName(returnElement),
|
||||
this.typeUtils.getQualifiedName(element), (getter != null) ? getter.toString() : null));
|
||||
processTypeElement(nestedPrefix, (TypeElement) returnElement, source);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNested(Element returnType, VariableElement field,
|
||||
TypeElement element) {
|
||||
private boolean isNested(Element returnType, VariableElement field, TypeElement element) {
|
||||
if (hasAnnotation(field, nestedConfigurationPropertyAnnotation())) {
|
||||
return true;
|
||||
}
|
||||
return this.typeUtils.isEnclosedIn(returnType, element)
|
||||
&& returnType.getKind() != ElementKind.ENUM;
|
||||
return this.typeUtils.isEnclosedIn(returnType, element) && returnType.getKind() != ElementKind.ENUM;
|
||||
}
|
||||
|
||||
private boolean isDeprecated(Element element) {
|
||||
if (isElementDeprecated(element)) {
|
||||
return true;
|
||||
}
|
||||
if (element != null && (element instanceof VariableElement
|
||||
|| element instanceof ExecutableElement)) {
|
||||
if (element != null && (element instanceof VariableElement || element instanceof ExecutableElement)) {
|
||||
return isElementDeprecated(element.getEnclosingElement());
|
||||
}
|
||||
return false;
|
||||
@@ -417,10 +379,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
|
||||
private Map<String, Object> getAnnotationElementValues(AnnotationMirror annotation) {
|
||||
Map<String, Object> values = new LinkedHashMap<String, Object>();
|
||||
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation
|
||||
.getElementValues().entrySet()) {
|
||||
values.put(entry.getKey().getSimpleName().toString(),
|
||||
entry.getValue().getValue());
|
||||
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation.getElementValues()
|
||||
.entrySet()) {
|
||||
values.put(entry.getKey().getSimpleName().toString(), entry.getValue().getValue());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
@@ -435,8 +396,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
return null;
|
||||
}
|
||||
|
||||
private ConfigurationMetadata mergeAdditionalMetadata(
|
||||
ConfigurationMetadata metadata) {
|
||||
private ConfigurationMetadata mergeAdditionalMetadata(ConfigurationMetadata metadata) {
|
||||
try {
|
||||
ConfigurationMetadata merged = new ConfigurationMetadata(metadata);
|
||||
merged.merge(this.metadataStore.readAdditionalMetadata());
|
||||
|
||||
@@ -54,8 +54,7 @@ public class MetadataCollector {
|
||||
* @param processingEnvironment the processing environment of the build
|
||||
* @param previousMetadata any previous metadata or {@code null}
|
||||
*/
|
||||
public MetadataCollector(ProcessingEnvironment processingEnvironment,
|
||||
ConfigurationMetadata previousMetadata) {
|
||||
public MetadataCollector(ProcessingEnvironment processingEnvironment, ConfigurationMetadata previousMetadata) {
|
||||
this.processingEnvironment = processingEnvironment;
|
||||
this.previousMetadata = previousMetadata;
|
||||
this.typeUtils = new TypeUtils(processingEnvironment);
|
||||
@@ -82,8 +81,7 @@ public class MetadataCollector {
|
||||
throw new IllegalStateException("item " + metadata + " must be a group");
|
||||
}
|
||||
for (ItemMetadata existing : this.metadataItems) {
|
||||
if (existing.isOfItemType(ItemMetadata.ItemType.GROUP)
|
||||
&& existing.getName().equals(metadata.getName())
|
||||
if (existing.isOfItemType(ItemMetadata.ItemType.GROUP) && existing.getName().equals(metadata.getName())
|
||||
&& existing.getType().equals(metadata.getType())) {
|
||||
return true;
|
||||
}
|
||||
@@ -109,13 +107,11 @@ public class MetadataCollector {
|
||||
|
||||
private boolean shouldBeMerged(ItemMetadata itemMetadata) {
|
||||
String sourceType = itemMetadata.getSourceType();
|
||||
return (sourceType != null && !deletedInCurrentBuild(sourceType)
|
||||
&& !processedInCurrentBuild(sourceType));
|
||||
return (sourceType != null && !deletedInCurrentBuild(sourceType) && !processedInCurrentBuild(sourceType));
|
||||
}
|
||||
|
||||
private boolean deletedInCurrentBuild(String sourceType) {
|
||||
return this.processingEnvironment.getElementUtils()
|
||||
.getTypeElement(sourceType) == null;
|
||||
return this.processingEnvironment.getElementUtils().getTypeElement(sourceType) == null;
|
||||
}
|
||||
|
||||
private boolean processedInCurrentBuild(String sourceType) {
|
||||
|
||||
@@ -88,8 +88,7 @@ public class MetadataStore {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new InvalidConfigurationMetadataException(
|
||||
"Invalid additional meta-data in '" + METADATA_PATH + "': "
|
||||
+ ex.getMessage(),
|
||||
"Invalid additional meta-data in '" + METADATA_PATH + "': " + ex.getMessage(),
|
||||
Diagnostic.Kind.ERROR);
|
||||
}
|
||||
finally {
|
||||
@@ -98,46 +97,40 @@ public class MetadataStore {
|
||||
}
|
||||
|
||||
private FileObject getMetadataResource() throws IOException {
|
||||
FileObject resource = this.environment.getFiler()
|
||||
.getResource(StandardLocation.CLASS_OUTPUT, "", METADATA_PATH);
|
||||
FileObject resource = this.environment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", METADATA_PATH);
|
||||
return resource;
|
||||
}
|
||||
|
||||
private FileObject createMetadataResource() throws IOException {
|
||||
FileObject resource = this.environment.getFiler()
|
||||
.createResource(StandardLocation.CLASS_OUTPUT, "", METADATA_PATH);
|
||||
FileObject resource = this.environment.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
|
||||
METADATA_PATH);
|
||||
return resource;
|
||||
}
|
||||
|
||||
private InputStream getAdditionalMetadataStream() throws IOException {
|
||||
// Most build systems will have copied the file to the class output location
|
||||
FileObject fileObject = this.environment.getFiler()
|
||||
.getResource(StandardLocation.CLASS_OUTPUT, "", ADDITIONAL_METADATA_PATH);
|
||||
FileObject fileObject = this.environment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "",
|
||||
ADDITIONAL_METADATA_PATH);
|
||||
File file = locateAdditionalMetadataFile(new File(fileObject.toUri()));
|
||||
return (file.exists() ? new FileInputStream(file)
|
||||
: fileObject.toUri().toURL().openStream());
|
||||
return (file.exists() ? new FileInputStream(file) : fileObject.toUri().toURL().openStream());
|
||||
}
|
||||
|
||||
File locateAdditionalMetadataFile(File standardLocation) throws IOException {
|
||||
if (standardLocation.exists()) {
|
||||
return standardLocation;
|
||||
}
|
||||
return new File(locateGradleResourcesFolder(standardLocation),
|
||||
ADDITIONAL_METADATA_PATH);
|
||||
return new File(locateGradleResourcesFolder(standardLocation), ADDITIONAL_METADATA_PATH);
|
||||
}
|
||||
|
||||
private File locateGradleResourcesFolder(File standardAdditionalMetadataLocation)
|
||||
throws FileNotFoundException {
|
||||
private File locateGradleResourcesFolder(File standardAdditionalMetadataLocation) throws FileNotFoundException {
|
||||
String path = standardAdditionalMetadataLocation.getPath();
|
||||
int index = path.lastIndexOf(CLASSES_FOLDER);
|
||||
if (index < 0) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
String buildFolderPath = path.substring(0, index);
|
||||
File classOutputLocation = standardAdditionalMetadataLocation.getParentFile()
|
||||
.getParentFile();
|
||||
return new File(buildFolderPath,
|
||||
RESOURCES_FOLDER + '/' + classOutputLocation.getName());
|
||||
File classOutputLocation = standardAdditionalMetadataLocation.getParentFile().getParentFile();
|
||||
return new File(buildFolderPath, RESOURCES_FOLDER + '/' + classOutputLocation.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,8 +59,7 @@ class TypeElementMembers {
|
||||
|
||||
private final FieldValuesParser fieldValuesParser;
|
||||
|
||||
TypeElementMembers(ProcessingEnvironment env, FieldValuesParser fieldValuesParser,
|
||||
TypeElement element) {
|
||||
TypeElementMembers(ProcessingEnvironment env, FieldValuesParser fieldValuesParser, TypeElement element) {
|
||||
this.env = env;
|
||||
this.typeUtils = new TypeUtils(this.env);
|
||||
this.fieldValuesParser = fieldValuesParser;
|
||||
@@ -68,17 +67,14 @@ class TypeElementMembers {
|
||||
}
|
||||
|
||||
private void process(TypeElement element) {
|
||||
for (ExecutableElement method : ElementFilter
|
||||
.methodsIn(element.getEnclosedElements())) {
|
||||
for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())) {
|
||||
processMethod(method);
|
||||
}
|
||||
for (VariableElement field : ElementFilter
|
||||
.fieldsIn(element.getEnclosedElements())) {
|
||||
for (VariableElement field : ElementFilter.fieldsIn(element.getEnclosedElements())) {
|
||||
processField(field);
|
||||
}
|
||||
try {
|
||||
Map<String, Object> fieldValues = this.fieldValuesParser
|
||||
.getFieldValues(element);
|
||||
Map<String, Object> fieldValues = this.fieldValuesParser.getFieldValues(element);
|
||||
for (Map.Entry<String, Object> entry : fieldValues.entrySet()) {
|
||||
if (!this.fieldValues.containsKey(entry.getKey())) {
|
||||
this.fieldValues.put(entry.getKey(), entry.getValue());
|
||||
@@ -90,8 +86,7 @@ class TypeElementMembers {
|
||||
}
|
||||
|
||||
Element superType = this.env.getTypeUtils().asElement(element.getSuperclass());
|
||||
if (superType != null && superType instanceof TypeElement
|
||||
&& !OBJECT_CLASS_NAME.equals(superType.toString())) {
|
||||
if (superType != null && superType instanceof TypeElement && !OBJECT_CLASS_NAME.equals(superType.toString())) {
|
||||
process((TypeElement) superType);
|
||||
}
|
||||
}
|
||||
@@ -104,8 +99,7 @@ class TypeElementMembers {
|
||||
}
|
||||
else if (isSetter(method)) {
|
||||
String propertyName = getAccessorName(name);
|
||||
List<ExecutableElement> matchingSetters = this.publicSetters
|
||||
.get(propertyName);
|
||||
List<ExecutableElement> matchingSetters = this.publicSetters.get(propertyName);
|
||||
if (matchingSetters == null) {
|
||||
matchingSetters = new ArrayList<ExecutableElement>();
|
||||
this.publicSetters.put(propertyName, matchingSetters);
|
||||
@@ -118,8 +112,7 @@ class TypeElementMembers {
|
||||
}
|
||||
}
|
||||
|
||||
private ExecutableElement getMatchingSetter(List<ExecutableElement> candidates,
|
||||
TypeMirror type) {
|
||||
private ExecutableElement getMatchingSetter(List<ExecutableElement> candidates, TypeMirror type) {
|
||||
for (ExecutableElement candidate : candidates) {
|
||||
TypeMirror paramType = candidate.getParameters().get(0).asType();
|
||||
if (this.env.getTypeUtils().isSameType(paramType, type)) {
|
||||
@@ -131,27 +124,24 @@ class TypeElementMembers {
|
||||
|
||||
private boolean isGetter(ExecutableElement method) {
|
||||
String name = method.getSimpleName().toString();
|
||||
return ((name.startsWith("get") && name.length() > 3)
|
||||
|| (name.startsWith("is") && name.length() > 2))
|
||||
&& method.getParameters().isEmpty()
|
||||
&& (TypeKind.VOID != method.getReturnType().getKind());
|
||||
return ((name.startsWith("get") && name.length() > 3) || (name.startsWith("is") && name.length() > 2))
|
||||
&& method.getParameters().isEmpty() && (TypeKind.VOID != method.getReturnType().getKind());
|
||||
}
|
||||
|
||||
private boolean isSetter(ExecutableElement method) {
|
||||
final String name = method.getSimpleName().toString();
|
||||
return (name.startsWith("set") && name.length() > 3
|
||||
&& method.getParameters().size() == 1 && isSetterReturnType(method));
|
||||
return (name.startsWith("set") && name.length() > 3 && method.getParameters().size() == 1
|
||||
&& isSetterReturnType(method));
|
||||
}
|
||||
|
||||
private boolean isSetterReturnType(ExecutableElement method) {
|
||||
TypeMirror returnType = method.getReturnType();
|
||||
return (TypeKind.VOID == returnType.getKind() || this.env.getTypeUtils()
|
||||
.isSameType(method.getEnclosingElement().asType(), returnType));
|
||||
return (TypeKind.VOID == returnType.getKind()
|
||||
|| this.env.getTypeUtils().isSameType(method.getEnclosingElement().asType(), returnType));
|
||||
}
|
||||
|
||||
private String getAccessorName(String methodName) {
|
||||
String name = (methodName.startsWith("is") ? methodName.substring(2)
|
||||
: methodName.substring(3));
|
||||
String name = (methodName.startsWith("is") ? methodName.substring(2) : methodName.substring(3));
|
||||
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
|
||||
return name;
|
||||
}
|
||||
@@ -179,8 +169,7 @@ class TypeElementMembers {
|
||||
return candidate;
|
||||
}
|
||||
TypeMirror alternative = this.typeUtils.getWrapperOrPrimitiveFor(type);
|
||||
if (alternative != null
|
||||
&& this.env.getTypeUtils().isSameType(returnType, alternative)) {
|
||||
if (alternative != null && this.env.getTypeUtils().isSameType(returnType, alternative)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,14 +83,12 @@ class TypeUtils {
|
||||
this.mapType = getDeclaredType(types, Map.class, 2);
|
||||
}
|
||||
|
||||
private TypeMirror getDeclaredType(Types types, Class<?> typeClass,
|
||||
int numberOfTypeArgs) {
|
||||
private TypeMirror getDeclaredType(Types types, Class<?> typeClass, int numberOfTypeArgs) {
|
||||
TypeMirror[] typeArgs = new TypeMirror[numberOfTypeArgs];
|
||||
for (int i = 0; i < typeArgs.length; i++) {
|
||||
typeArgs[i] = types.getWildcardType(null, null);
|
||||
}
|
||||
TypeElement typeElement = this.env.getElementUtils()
|
||||
.getTypeElement(typeClass.getName());
|
||||
TypeElement typeElement = this.env.getElementUtils().getTypeElement(typeClass.getName());
|
||||
try {
|
||||
return types.getDeclaredType(typeElement, typeArgs);
|
||||
}
|
||||
@@ -139,8 +137,7 @@ class TypeUtils {
|
||||
}
|
||||
|
||||
public String getJavaDoc(Element element) {
|
||||
String javadoc = (element != null)
|
||||
? this.env.getElementUtils().getDocComment(element) : null;
|
||||
String javadoc = (element != null) ? this.env.getElementUtils().getDocComment(element) : null;
|
||||
if (javadoc != null) {
|
||||
javadoc = javadoc.replaceAll("[\r\n]+", "").trim();
|
||||
}
|
||||
@@ -150,8 +147,7 @@ class TypeUtils {
|
||||
public TypeMirror getWrapperOrPrimitiveFor(TypeMirror typeMirror) {
|
||||
Class<?> candidate = getWrapperFor(typeMirror);
|
||||
if (candidate != null) {
|
||||
return this.env.getElementUtils().getTypeElement(candidate.getName())
|
||||
.asType();
|
||||
return this.env.getElementUtils().getTypeElement(candidate.getName()).asType();
|
||||
}
|
||||
TypeKind primitiveKind = getPrimitiveFor(typeMirror);
|
||||
if (primitiveKind != null) {
|
||||
@@ -184,8 +180,7 @@ class TypeUtils {
|
||||
public String visitDeclared(DeclaredType type, Void none) {
|
||||
TypeElement enclosingElement = getEnclosingTypeElement(type);
|
||||
if (enclosingElement != null) {
|
||||
return getQualifiedName(enclosingElement) + "$"
|
||||
+ type.asElement().getSimpleName().toString();
|
||||
return getQualifiedName(enclosingElement) + "$" + type.asElement().getSimpleName().toString();
|
||||
}
|
||||
String qualifiedName = getQualifiedName(type.asElement());
|
||||
if (type.getTypeArguments().isEmpty()) {
|
||||
@@ -228,14 +223,12 @@ class TypeUtils {
|
||||
TypeElement enclosingElement = getEnclosingTypeElement(element.asType());
|
||||
if (enclosingElement != null) {
|
||||
return getQualifiedName(enclosingElement) + "$"
|
||||
+ ((DeclaredType) element.asType()).asElement().getSimpleName()
|
||||
.toString();
|
||||
+ ((DeclaredType) element.asType()).asElement().getSimpleName().toString();
|
||||
}
|
||||
if (element instanceof TypeElement) {
|
||||
return ((TypeElement) element).getQualifiedName().toString();
|
||||
}
|
||||
throw new IllegalStateException(
|
||||
"Could not extract qualified name from " + element);
|
||||
throw new IllegalStateException("Could not extract qualified name from " + element);
|
||||
}
|
||||
|
||||
private TypeElement getEnclosingTypeElement(TypeMirror type) {
|
||||
|
||||
@@ -31,20 +31,15 @@ class ExpressionTree extends ReflectionWrapper {
|
||||
|
||||
private final Class<?> literalTreeType = findClass("com.sun.source.tree.LiteralTree");
|
||||
|
||||
private final Method literalValueMethod = findMethod(this.literalTreeType,
|
||||
"getValue");
|
||||
private final Method literalValueMethod = findMethod(this.literalTreeType, "getValue");
|
||||
|
||||
private final Class<?> methodInvocationTreeType = findClass(
|
||||
"com.sun.source.tree.MethodInvocationTree");
|
||||
private final Class<?> methodInvocationTreeType = findClass("com.sun.source.tree.MethodInvocationTree");
|
||||
|
||||
private final Method methodInvocationArgumentsMethod = findMethod(
|
||||
this.methodInvocationTreeType, "getArguments");
|
||||
private final Method methodInvocationArgumentsMethod = findMethod(this.methodInvocationTreeType, "getArguments");
|
||||
|
||||
private final Class<?> newArrayTreeType = findClass(
|
||||
"com.sun.source.tree.NewArrayTree");
|
||||
private final Class<?> newArrayTreeType = findClass("com.sun.source.tree.NewArrayTree");
|
||||
|
||||
private final Method arrayValueMethod = findMethod(this.newArrayTreeType,
|
||||
"getInitializers");
|
||||
private final Method arrayValueMethod = findMethod(this.newArrayTreeType, "getInitializers");
|
||||
|
||||
ExpressionTree(Object instance) {
|
||||
super(instance);
|
||||
@@ -63,8 +58,7 @@ class ExpressionTree extends ReflectionWrapper {
|
||||
|
||||
public Object getFactoryValue() throws Exception {
|
||||
if (this.methodInvocationTreeType.isAssignableFrom(getInstance().getClass())) {
|
||||
List<?> arguments = (List<?>) this.methodInvocationArgumentsMethod
|
||||
.invoke(getInstance());
|
||||
List<?> arguments = (List<?>) this.methodInvocationArgumentsMethod.invoke(getInstance());
|
||||
if (arguments.size() == 1) {
|
||||
return new ExpressionTree(arguments.get(0)).getLiteralValue();
|
||||
}
|
||||
|
||||
@@ -122,8 +122,7 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private Object getValue(ExpressionTree expression, Object defaultValue)
|
||||
throws Exception {
|
||||
private Object getValue(ExpressionTree expression, Object defaultValue) throws Exception {
|
||||
Object literalValue = expression.getLiteralValue();
|
||||
if (literalValue != null) {
|
||||
return literalValue;
|
||||
|
||||
@@ -67,8 +67,7 @@ class ReflectionWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
protected static Method findMethod(Class<?> type, String name,
|
||||
Class<?>... parameterTypes) {
|
||||
protected static Method findMethod(Class<?> type, String name, Class<?>... parameterTypes) {
|
||||
try {
|
||||
return type.getMethod(name, parameterTypes);
|
||||
}
|
||||
|
||||
@@ -30,22 +30,17 @@ class Tree extends ReflectionWrapper {
|
||||
|
||||
private final Class<?> treeVisitorType = findClass("com.sun.source.tree.TreeVisitor");
|
||||
|
||||
private final Method acceptMethod = findMethod("accept", this.treeVisitorType,
|
||||
Object.class);
|
||||
private final Method acceptMethod = findMethod("accept", this.treeVisitorType, Object.class);
|
||||
|
||||
private final Method GET_CLASS_TREE_MEMBERS = findMethod(
|
||||
findClass("com.sun.source.tree.ClassTree"), "getMembers");
|
||||
private final Method GET_CLASS_TREE_MEMBERS = findMethod(findClass("com.sun.source.tree.ClassTree"), "getMembers");
|
||||
|
||||
Tree(Object instance) {
|
||||
super("com.sun.source.tree.Tree", instance);
|
||||
}
|
||||
|
||||
public void accept(TreeVisitor visitor) throws Exception {
|
||||
this.acceptMethod.invoke(getInstance(),
|
||||
Proxy.newProxyInstance(getInstance().getClass().getClassLoader(),
|
||||
new Class<?>[] { this.treeVisitorType },
|
||||
new TreeVisitorInvocationHandler(visitor)),
|
||||
0);
|
||||
this.acceptMethod.invoke(getInstance(), Proxy.newProxyInstance(getInstance().getClass().getClassLoader(),
|
||||
new Class<?>[] { this.treeVisitorType }, new TreeVisitorInvocationHandler(visitor)), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,16 +56,13 @@ class Tree extends ReflectionWrapper {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object invoke(Object proxy, Method method, Object[] args)
|
||||
throws Throwable {
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if (method.getName().equals("visitClass")) {
|
||||
if ((Integer) args[1] == 0) {
|
||||
Iterable members = (Iterable) Tree.this.GET_CLASS_TREE_MEMBERS
|
||||
.invoke(args[0]);
|
||||
Iterable members = (Iterable) Tree.this.GET_CLASS_TREE_MEMBERS.invoke(args[0]);
|
||||
for (Object member : members) {
|
||||
if (member != null) {
|
||||
Tree.this.acceptMethod.invoke(member, proxy,
|
||||
((Integer) args[1]) + 1);
|
||||
Tree.this.acceptMethod.invoke(member, proxy, ((Integer) args[1]) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ class VariableTree extends ReflectionWrapper {
|
||||
if (modifiers == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return (Set<Modifier>) findMethod(findClass("com.sun.source.tree.ModifiersTree"),
|
||||
"getFlags").invoke(modifiers);
|
||||
return (Set<Modifier>) findMethod(findClass("com.sun.source.tree.ModifiersTree"), "getFlags").invoke(modifiers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -169,8 +169,7 @@ public class ConfigurationMetadata {
|
||||
|
||||
private List<ItemMetadata> getCandidates(String name) {
|
||||
List<ItemMetadata> candidates = this.items.get(name);
|
||||
return (candidates != null) ? new ArrayList<ItemMetadata>(candidates)
|
||||
: new ArrayList<ItemMetadata>();
|
||||
return (candidates != null) ? new ArrayList<ItemMetadata>(candidates) : new ArrayList<ItemMetadata>();
|
||||
}
|
||||
|
||||
private boolean nullSafeEquals(Object o1, Object o2) {
|
||||
@@ -194,8 +193,7 @@ public class ConfigurationMetadata {
|
||||
if (SEPARATORS.contains(current)) {
|
||||
dashed.append("-");
|
||||
}
|
||||
else if (Character.isUpperCase(current) && previous != null
|
||||
&& !SEPARATORS.contains(previous)) {
|
||||
else if (Character.isUpperCase(current) && previous != null && !SEPARATORS.contains(previous)) {
|
||||
dashed.append("-").append(current);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -77,8 +77,7 @@ public class ItemDeprecation {
|
||||
return false;
|
||||
}
|
||||
ItemDeprecation other = (ItemDeprecation) o;
|
||||
return nullSafeEquals(this.reason, other.reason)
|
||||
&& nullSafeEquals(this.replacement, other.replacement)
|
||||
return nullSafeEquals(this.reason, other.reason) && nullSafeEquals(this.replacement, other.replacement)
|
||||
&& nullSafeEquals(this.level, other.level);
|
||||
}
|
||||
|
||||
@@ -92,9 +91,8 @@ public class ItemDeprecation {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemDeprecation{" + "reason='" + this.reason + '\'' + ", "
|
||||
+ "replacement='" + this.replacement + '\'' + ", " + "level='"
|
||||
+ this.level + '\'' + '}';
|
||||
return "ItemDeprecation{" + "reason='" + this.reason + '\'' + ", " + "replacement='" + this.replacement + '\''
|
||||
+ ", " + "level='" + this.level + '\'' + '}';
|
||||
}
|
||||
|
||||
private boolean nullSafeEquals(Object o1, Object o2) {
|
||||
|
||||
@@ -44,10 +44,8 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
|
||||
public ItemHint(String name, List<ValueHint> values, List<ValueProvider> providers) {
|
||||
this.name = toCanonicalName(name);
|
||||
this.values = (values != null) ? new ArrayList<ValueHint>(values)
|
||||
: new ArrayList<ValueHint>();
|
||||
this.providers = (providers != null) ? new ArrayList<ValueProvider>(providers)
|
||||
: new ArrayList<ValueProvider>();
|
||||
this.values = (values != null) ? new ArrayList<ValueHint>(values) : new ArrayList<ValueHint>();
|
||||
this.providers = (providers != null) ? new ArrayList<ValueProvider>(providers) : new ArrayList<ValueProvider>();
|
||||
}
|
||||
|
||||
private String toCanonicalName(String name) {
|
||||
@@ -78,14 +76,12 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
}
|
||||
|
||||
public static ItemHint newHint(String name, ValueHint... values) {
|
||||
return new ItemHint(name, Arrays.asList(values),
|
||||
Collections.<ValueProvider>emptyList());
|
||||
return new ItemHint(name, Arrays.asList(values), Collections.<ValueProvider>emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ItemHint{" + "name='" + this.name + "', values=" + this.values
|
||||
+ ", providers=" + this.providers + '}';
|
||||
return "ItemHint{" + "name='" + this.name + "', values=" + this.values + ", providers=" + this.providers + '}';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,8 +108,7 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ValueHint{" + "value=" + this.value + ", description='"
|
||||
+ this.description + '\'' + '}';
|
||||
return "ValueHint{" + "value=" + this.value + ", description='" + this.description + '\'' + '}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -142,8 +137,7 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ValueProvider{" + "name='" + this.name + "', parameters="
|
||||
+ this.parameters + '}';
|
||||
return "ValueProvider{" + "name='" + this.name + "', parameters=" + this.parameters + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,9 +42,8 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
|
||||
|
||||
private ItemDeprecation deprecation;
|
||||
|
||||
ItemMetadata(ItemType itemType, String prefix, String name, String type,
|
||||
String sourceType, String sourceMethod, String description,
|
||||
Object defaultValue, ItemDeprecation deprecation) {
|
||||
ItemMetadata(ItemType itemType, String prefix, String name, String type, String sourceType, String sourceMethod,
|
||||
String description, Object defaultValue, ItemDeprecation deprecation) {
|
||||
super();
|
||||
this.itemType = itemType;
|
||||
this.name = buildName(prefix, name);
|
||||
@@ -132,8 +131,7 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
|
||||
this.deprecation = deprecation;
|
||||
}
|
||||
|
||||
protected void buildToStringProperty(StringBuilder string, String property,
|
||||
Object value) {
|
||||
protected void buildToStringProperty(StringBuilder string, String property, Object value) {
|
||||
if (value != null) {
|
||||
string.append(" ").append(property).append(":").append(value);
|
||||
}
|
||||
@@ -148,10 +146,8 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
|
||||
return false;
|
||||
}
|
||||
ItemMetadata other = (ItemMetadata) o;
|
||||
return nullSafeEquals(this.itemType, other.itemType)
|
||||
&& nullSafeEquals(this.name, other.name)
|
||||
&& nullSafeEquals(this.type, other.type)
|
||||
&& nullSafeEquals(this.description, other.description)
|
||||
return nullSafeEquals(this.itemType, other.itemType) && nullSafeEquals(this.name, other.name)
|
||||
&& nullSafeEquals(this.type, other.type) && nullSafeEquals(this.description, other.description)
|
||||
&& nullSafeEquals(this.sourceType, other.sourceType)
|
||||
&& nullSafeEquals(this.sourceMethod, other.sourceMethod)
|
||||
&& nullSafeEquals(this.defaultValue, other.defaultValue)
|
||||
@@ -201,17 +197,14 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
|
||||
return getName().compareTo(o.getName());
|
||||
}
|
||||
|
||||
public static ItemMetadata newGroup(String name, String type, String sourceType,
|
||||
String sourceMethod) {
|
||||
return new ItemMetadata(ItemType.GROUP, name, null, type, sourceType,
|
||||
sourceMethod, null, null, null);
|
||||
public static ItemMetadata newGroup(String name, String type, String sourceType, String sourceMethod) {
|
||||
return new ItemMetadata(ItemType.GROUP, name, null, type, sourceType, sourceMethod, null, null, null);
|
||||
}
|
||||
|
||||
public static ItemMetadata newProperty(String prefix, String name, String type,
|
||||
String sourceType, String sourceMethod, String description,
|
||||
Object defaultValue, ItemDeprecation deprecation) {
|
||||
return new ItemMetadata(ItemType.PROPERTY, prefix, name, type, sourceType,
|
||||
sourceMethod, description, defaultValue, deprecation);
|
||||
public static ItemMetadata newProperty(String prefix, String name, String type, String sourceType,
|
||||
String sourceMethod, String description, Object defaultValue, ItemDeprecation deprecation) {
|
||||
return new ItemMetadata(ItemType.PROPERTY, prefix, name, type, sourceType, sourceMethod, description,
|
||||
defaultValue, deprecation);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.boot.configurationprocessor.metadata.ItemMetadata.Ite
|
||||
*/
|
||||
class JsonConverter {
|
||||
|
||||
public JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType)
|
||||
throws Exception {
|
||||
public JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType) throws Exception {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (ItemMetadata item : metadata.getItems()) {
|
||||
if (item.isOfItemType(itemType)) {
|
||||
@@ -115,8 +114,7 @@ class JsonConverter {
|
||||
return providers;
|
||||
}
|
||||
|
||||
private JSONObject getItemHintProvider(ItemHint.ValueProvider provider)
|
||||
throws Exception {
|
||||
private JSONObject getItemHintProvider(ItemHint.ValueProvider provider) throws Exception {
|
||||
JSONObject result = new JSONOrderedObject();
|
||||
result.put("name", provider.getName());
|
||||
if (provider.getParameters() != null && !provider.getParameters().isEmpty()) {
|
||||
@@ -129,8 +127,7 @@ class JsonConverter {
|
||||
return result;
|
||||
}
|
||||
|
||||
private void putIfPresent(JSONObject jsonObject, String name, Object value)
|
||||
throws Exception {
|
||||
private void putIfPresent(JSONObject jsonObject, String name, Object value) throws Exception {
|
||||
if (value != null) {
|
||||
jsonObject.put(name, value);
|
||||
}
|
||||
|
||||
@@ -44,8 +44,7 @@ public class JsonMarshaller {
|
||||
|
||||
private static final int BUFFER_SIZE = 4098;
|
||||
|
||||
public void write(ConfigurationMetadata metadata, OutputStream outputStream)
|
||||
throws IOException {
|
||||
public void write(ConfigurationMetadata metadata, OutputStream outputStream) throws IOException {
|
||||
try {
|
||||
JSONObject object = new JSONOrderedObject();
|
||||
JsonConverter converter = new JsonConverter();
|
||||
@@ -77,8 +76,7 @@ public class JsonMarshaller {
|
||||
JSONArray properties = object.optJSONArray("properties");
|
||||
if (properties != null) {
|
||||
for (int i = 0; i < properties.length(); i++) {
|
||||
metadata.add(toItemMetadata((JSONObject) properties.get(i),
|
||||
ItemType.PROPERTY));
|
||||
metadata.add(toItemMetadata((JSONObject) properties.get(i), ItemType.PROPERTY));
|
||||
}
|
||||
}
|
||||
JSONArray hints = object.optJSONArray("hints");
|
||||
@@ -90,8 +88,7 @@ public class JsonMarshaller {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private ItemMetadata toItemMetadata(JSONObject object, ItemType itemType)
|
||||
throws Exception {
|
||||
private ItemMetadata toItemMetadata(JSONObject object, ItemType itemType) throws Exception {
|
||||
String name = object.getString("name");
|
||||
String type = object.optString("type", null);
|
||||
String description = object.optString("description", null);
|
||||
@@ -99,8 +96,8 @@ public class JsonMarshaller {
|
||||
String sourceMethod = object.optString("sourceMethod", null);
|
||||
Object defaultValue = readItemValue(object.opt("defaultValue"));
|
||||
ItemDeprecation deprecation = toItemDeprecation(object);
|
||||
return new ItemMetadata(itemType, name, null, type, sourceType, sourceMethod,
|
||||
description, defaultValue, deprecation);
|
||||
return new ItemMetadata(itemType, name, null, type, sourceType, sourceMethod, description, defaultValue,
|
||||
deprecation);
|
||||
}
|
||||
|
||||
private ItemDeprecation toItemDeprecation(JSONObject object) throws Exception {
|
||||
@@ -109,8 +106,7 @@ public class JsonMarshaller {
|
||||
ItemDeprecation deprecation = new ItemDeprecation();
|
||||
deprecation.setLevel(deprecationJsonObject.optString("level", null));
|
||||
deprecation.setReason(deprecationJsonObject.optString("reason", null));
|
||||
deprecation
|
||||
.setReplacement(deprecationJsonObject.optString("replacement", null));
|
||||
deprecation.setReplacement(deprecationJsonObject.optString("replacement", null));
|
||||
return deprecation;
|
||||
}
|
||||
return (object.optBoolean("deprecated") ? new ItemDeprecation() : null);
|
||||
|
||||
@@ -114,15 +114,12 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
@Test
|
||||
public void simpleProperties() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(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.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));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class)
|
||||
.fromSource(SimpleProperties.class).withDescription("A simple flag.")
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.counter"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.size"));
|
||||
@@ -131,78 +128,54 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
@Test
|
||||
public void simplePrefixValueProperties() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(SimplePrefixValueProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("simple")
|
||||
.fromSource(SimplePrefixValueProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.name", String.class)
|
||||
.fromSource(SimplePrefixValueProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimplePrefixValueProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.name", String.class).fromSource(SimplePrefixValueProperties.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleTypeProperties() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(SimpleTypeProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("simple.type").fromSource(SimpleTypeProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-string", String.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-byte", Byte.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-char", Character.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-char", Character.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-boolean", Boolean.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-short", Short.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-short", Short.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-integer", Integer.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-integer", Integer.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-long", Long.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-long", Long.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-double", Double.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-double", Double.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-float", Float.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-float", Float.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("simple.type").fromSource(SimpleTypeProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-string", String.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-byte", Byte.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-char", Character.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-char", Character.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-boolean", Boolean.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-short", Short.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-short", Short.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-integer", Integer.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-integer", Integer.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-long", Long.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-long", Long.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-double", Double.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-double", Double.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-float", Float.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-float", Float.class));
|
||||
assertThat(metadata.getItems().size()).isEqualTo(18);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hierarchicalProperties() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(HierarchicalProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("hierarchical")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.first", String.class)
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("hierarchical.second", String.class)
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.third", String.class)
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("hierarchical").fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("hierarchical.first", String.class).fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("hierarchical.second", String.class).fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("hierarchical.third", String.class).fromSource(HierarchicalProperties.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descriptionProperties() {
|
||||
ConfigurationMetadata metadata = compile(DescriptionProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("description")
|
||||
.fromSource(DescriptionProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("description").fromSource(DescriptionProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("description.simple", String.class)
|
||||
.fromSource(DescriptionProperties.class)
|
||||
.withDescription("A simple description."));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("description.multi-line", String.class)
|
||||
.fromSource(DescriptionProperties.class).withDescription("A simple description."));
|
||||
assertThat(metadata).has(Metadata.withProperty("description.multi-line", String.class)
|
||||
.fromSource(DescriptionProperties.class).withDescription(
|
||||
"This is a lengthy description that spans across multiple lines to showcase that the line separators are cleaned automatically."));
|
||||
}
|
||||
@@ -213,11 +186,10 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
Class<?> type = org.springframework.boot.configurationsample.simple.DeprecatedProperties.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("deprecated").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("deprecated.name", String.class)
|
||||
.fromSource(type).withDeprecation(null, null));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("deprecated.description", String.class)
|
||||
.fromSource(type).withDeprecation(null, null));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("deprecated.name", String.class).fromSource(type).withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("deprecated.description", String.class).fromSource(type)
|
||||
.withDeprecation(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -225,11 +197,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
Class<?> type = DeprecatedSingleProperty.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("singledeprecated").fromSource(type));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("singledeprecated.new-name", String.class)
|
||||
.fromSource(type));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("singledeprecated.name", String.class).fromSource(type)
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.new-name", String.class).fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class).fromSource(type)
|
||||
.withDeprecation("renamed", "singledeprecated.new-name"));
|
||||
}
|
||||
|
||||
@@ -238,12 +207,10 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
Class<?> type = DeprecatedUnrelatedMethodPojo.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("not.deprecated").fromSource(type));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("not.deprecated.counter", Integer.class).withNoDeprecation().fromSource(type));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("not.deprecated.counter", Integer.class)
|
||||
.withNoDeprecation().fromSource(type));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("not.deprecated.flag", Boolean.class)
|
||||
.withNoDeprecation().fromSource(type));
|
||||
.has(Metadata.withProperty("not.deprecated.flag", Boolean.class).withNoDeprecation().fromSource(type));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -251,10 +218,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
Class<?> type = BoxingPojo.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("boxing").fromSource(type));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("boxing.flag", Boolean.class).fromSource(type));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("boxing.counter", Integer.class).fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("boxing.flag", Boolean.class).fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("boxing.counter", Integer.class).fromSource(type));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -263,17 +228,13 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
// getter and setter
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.integers-to-names",
|
||||
"java.util.Map<java.lang.Integer,java.lang.String>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.longs",
|
||||
"java.util.Collection<java.lang.Long>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.floats",
|
||||
"java.util.List<java.lang.Float>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.longs", "java.util.Collection<java.lang.Long>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.floats", "java.util.List<java.lang.Float>"));
|
||||
// getter only
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.names-to-integers",
|
||||
"java.util.Map<java.lang.String,java.lang.Integer>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.bytes",
|
||||
"java.util.Collection<java.lang.Byte>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.doubles",
|
||||
"java.util.List<java.lang.Double>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.bytes", "java.util.Collection<java.lang.Byte>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.doubles", "java.util.List<java.lang.Double>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.names-to-holders",
|
||||
"java.util.Map<java.lang.String,org.springframework.boot.configurationsample.simple.SimpleCollectionProperties.Holder<java.lang.String>>"));
|
||||
}
|
||||
@@ -281,47 +242,43 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
@Test
|
||||
public void parseArrayConfig() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(SimpleArrayProperties.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("array").ofType(SimpleArrayProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("array.primitive", "java.lang.Integer[]"));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("array.simple", "java.lang.String[]"));
|
||||
assertThat(metadata).has(Metadata.withGroup("array").ofType(SimpleArrayProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("array.primitive", "java.lang.Integer[]"));
|
||||
assertThat(metadata).has(Metadata.withProperty("array.simple", "java.lang.String[]"));
|
||||
assertThat(metadata).has(Metadata.withProperty("array.inner",
|
||||
"org.springframework.boot.configurationsample.simple.SimpleArrayProperties$Holder[]"));
|
||||
assertThat(metadata).has(Metadata.withProperty("array.name-to-integer",
|
||||
"java.util.Map<java.lang.String,java.lang.Integer>[]"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("array.name-to-integer", "java.util.Map<java.lang.String,java.lang.Integer>[]"));
|
||||
assertThat(metadata.getItems()).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleMethodConfig() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(SimpleMethodConfig.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(SimpleMethodConfig.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("foo").fromSource(SimpleMethodConfig.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
|
||||
.fromSource(SimpleMethodConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
|
||||
.fromSource(SimpleMethodConfig.Foo.class));
|
||||
.has(Metadata.withProperty("foo.name", String.class).fromSource(SimpleMethodConfig.Foo.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.flag", Boolean.class).fromSource(SimpleMethodConfig.Foo.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidMethodConfig() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(InvalidMethodConfig.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("something.name", String.class)
|
||||
.fromSource(InvalidMethodConfig.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("something.name", String.class).fromSource(InvalidMethodConfig.class));
|
||||
assertThat(metadata).isNotEqualTo(Metadata.withProperty("invalid.name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodAndClassConfig() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(MethodAndClassConfig.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("conflict.name", String.class)
|
||||
.fromSource(MethodAndClassConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("conflict.flag", Boolean.class)
|
||||
.fromSource(MethodAndClassConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("conflict.value", String.class)
|
||||
.fromSource(MethodAndClassConfig.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("conflict.name", String.class).fromSource(MethodAndClassConfig.Foo.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("conflict.flag", Boolean.class).fromSource(MethodAndClassConfig.Foo.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("conflict.value", String.class).fromSource(MethodAndClassConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,11 +293,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
|
||||
.fromSource(DeprecatedMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
.fromSource(DeprecatedMethodConfig.Foo.class).withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
|
||||
.fromSource(DeprecatedMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
.fromSource(DeprecatedMethodConfig.Foo.class).withDeprecation(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -350,12 +305,10 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
|
||||
.fromSource(
|
||||
org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
|
||||
.fromSource(
|
||||
org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
}
|
||||
|
||||
@@ -368,20 +321,17 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
@Test
|
||||
public void innerClassProperties() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(InnerClassProperties.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config").fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("config.first").ofType(InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config").fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first").ofType(InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.bar.name"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("config.the-second", InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.the-second", InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.the-second.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.the-second.bar.name"));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.third")
|
||||
.ofType(SimplePojo.class).fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("config.third").ofType(SimplePojo.class).fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.third.value"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.fourth"));
|
||||
assertThat(metadata).isNotEqualTo(Metadata.withGroup("config.fourth"));
|
||||
@@ -398,16 +348,12 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
@Test
|
||||
public void nestedClassChildProperties() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(ClassWithNestedProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("nestedChildProps")
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("nestedChildProps.child-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class)
|
||||
.withDefaultValue(20));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("nestedChildProps.parent-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class)
|
||||
.withDefaultValue(10));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("nestedChildProps").fromSource(ClassWithNestedProperties.NestedChildClass.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.child-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(20));
|
||||
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.parent-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -454,40 +400,36 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
@Test
|
||||
public void genericTypes() throws IOException {
|
||||
ConfigurationMetadata metadata = compile(GenericConfig.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("generic").ofType(
|
||||
"org.springframework.boot.configurationsample.specific.GenericConfig"));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.foo").ofType(
|
||||
"org.springframework.boot.configurationsample.specific.GenericConfig$Foo"));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar").ofType(
|
||||
"org.springframework.boot.configurationsample.specific.GenericConfig$Bar"));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar.biz").ofType(
|
||||
"org.springframework.boot.configurationsample.specific.GenericConfig$Bar$Biz"));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.name")
|
||||
.ofType(String.class).fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-bar")
|
||||
.ofType("java.util.Map<java.lang.String,org.springframework.boot.configurationsample.specific.GenericConfig.Bar<java.lang.Integer>>")
|
||||
assertThat(metadata).has(Metadata.withGroup("generic")
|
||||
.ofType("org.springframework.boot.configurationsample.specific.GenericConfig"));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.foo")
|
||||
.ofType("org.springframework.boot.configurationsample.specific.GenericConfig$Foo"));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar")
|
||||
.ofType("org.springframework.boot.configurationsample.specific.GenericConfig$Bar"));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar.biz")
|
||||
.ofType("org.springframework.boot.configurationsample.specific.GenericConfig$Bar$Biz"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("generic.foo.name").ofType(String.class).fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-bar").ofType(
|
||||
"java.util.Map<java.lang.String,org.springframework.boot.configurationsample.specific.GenericConfig.Bar<java.lang.Integer>>")
|
||||
.fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-integer")
|
||||
.ofType("java.util.Map<java.lang.String,java.lang.Integer>")
|
||||
.fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.name")
|
||||
.ofType("java.lang.String").fromSource(GenericConfig.Bar.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.biz.name")
|
||||
.ofType("java.lang.String").fromSource(GenericConfig.Bar.Biz.class));
|
||||
.ofType("java.util.Map<java.lang.String,java.lang.Integer>").fromSource(GenericConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.name").ofType("java.lang.String")
|
||||
.fromSource(GenericConfig.Bar.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.biz.name").ofType("java.lang.String")
|
||||
.fromSource(GenericConfig.Bar.Biz.class));
|
||||
assertThat(metadata.getItems()).hasSize(9);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wildcardTypes() throws IOException {
|
||||
ConfigurationMetadata metadata = compile(WildcardConfig.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("wildcard").ofType(WildcardConfig.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("wildcard").ofType(WildcardConfig.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("wildcard.string-to-number")
|
||||
.ofType("java.util.Map<java.lang.String,? extends java.lang.Number>")
|
||||
.fromSource(WildcardConfig.class));
|
||||
.ofType("java.util.Map<java.lang.String,? extends java.lang.Number>").fromSource(WildcardConfig.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("wildcard.integers")
|
||||
.ofType("java.util.List<? super java.lang.Integer>")
|
||||
.fromSource(WildcardConfig.class));
|
||||
.ofType("java.util.List<? super java.lang.Integer>").fromSource(WildcardConfig.class));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@@ -506,63 +448,51 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
@Test
|
||||
public void lombokExplicitProperties() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(LombokExplicitProperties.class);
|
||||
assertSimpleLombokProperties(metadata, LombokExplicitProperties.class,
|
||||
"explicit");
|
||||
assertSimpleLombokProperties(metadata, LombokExplicitProperties.class, "explicit");
|
||||
assertThat(metadata.getItems()).hasSize(6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokAccessLevelProperties() {
|
||||
ConfigurationMetadata metadata = compile(LombokAccessLevelProperties.class);
|
||||
assertAccessLevelLombokProperties(metadata, LombokAccessLevelProperties.class,
|
||||
"accesslevel", 2);
|
||||
assertAccessLevelLombokProperties(metadata, LombokAccessLevelProperties.class, "accesslevel", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokAccessLevelOverwriteDataProperties() {
|
||||
ConfigurationMetadata metadata = compile(
|
||||
LombokAccessLevelOverwriteDataProperties.class);
|
||||
assertAccessLevelOverwriteLombokProperties(metadata,
|
||||
LombokAccessLevelOverwriteDataProperties.class,
|
||||
ConfigurationMetadata metadata = compile(LombokAccessLevelOverwriteDataProperties.class);
|
||||
assertAccessLevelOverwriteLombokProperties(metadata, LombokAccessLevelOverwriteDataProperties.class,
|
||||
"accesslevel.overwrite.data");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokAccessLevelOverwriteExplicitProperties() {
|
||||
ConfigurationMetadata metadata = compile(
|
||||
LombokAccessLevelOverwriteExplicitProperties.class);
|
||||
assertAccessLevelOverwriteLombokProperties(metadata,
|
||||
LombokAccessLevelOverwriteExplicitProperties.class,
|
||||
ConfigurationMetadata metadata = compile(LombokAccessLevelOverwriteExplicitProperties.class);
|
||||
assertAccessLevelOverwriteLombokProperties(metadata, LombokAccessLevelOverwriteExplicitProperties.class,
|
||||
"accesslevel.overwrite.explicit");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokAccessLevelOverwriteDefaultProperties() {
|
||||
ConfigurationMetadata metadata = compile(
|
||||
LombokAccessLevelOverwriteDefaultProperties.class);
|
||||
assertAccessLevelOverwriteLombokProperties(metadata,
|
||||
LombokAccessLevelOverwriteDefaultProperties.class,
|
||||
ConfigurationMetadata metadata = compile(LombokAccessLevelOverwriteDefaultProperties.class);
|
||||
assertAccessLevelOverwriteLombokProperties(metadata, LombokAccessLevelOverwriteDefaultProperties.class,
|
||||
"accesslevel.overwrite.default");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokInnerClassProperties() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(LombokInnerClassProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("config")
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first")
|
||||
.ofType(LombokInnerClassProperties.Foo.class)
|
||||
assertThat(metadata).has(Metadata.withGroup("config").fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first").ofType(LombokInnerClassProperties.Foo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.bar.name"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("config.second", LombokInnerClassProperties.Foo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.second", LombokInnerClassProperties.Foo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.second.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.second.bar.name"));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config.third").ofType(SimpleLombokPojo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.third").ofType(SimpleLombokPojo.class)
|
||||
.fromSource(LombokInnerClassProperties.class));
|
||||
// For some reason the annotation processor resolves a type for SimpleLombokPojo
|
||||
// that is resolved (compiled) and the source annotations are gone. Because we
|
||||
// don't see the @Data annotation anymore, no field is harvested. What is crazy is
|
||||
@@ -575,14 +505,11 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
|
||||
@Test
|
||||
public void lombokInnerClassWithGetterProperties() throws IOException {
|
||||
ConfigurationMetadata metadata = compile(
|
||||
LombokInnerClassWithGetterProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("config")
|
||||
.fromSource(LombokInnerClassWithGetterProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first")
|
||||
.ofType(LombokInnerClassWithGetterProperties.Foo.class)
|
||||
.fromSourceMethod("getFirst()")
|
||||
.fromSource(LombokInnerClassWithGetterProperties.class));
|
||||
ConfigurationMetadata metadata = compile(LombokInnerClassWithGetterProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("config").fromSource(LombokInnerClassWithGetterProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config.first").ofType(LombokInnerClassWithGetterProperties.Foo.class)
|
||||
.fromSourceMethod("getFirst()").fromSource(LombokInnerClassWithGetterProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
@@ -594,84 +521,72 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfAdditionalPropertyMatchingGroup() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty(null, "simple",
|
||||
"java.lang.String", null, null, null, null, null);
|
||||
ItemMetadata property = ItemMetadata.newProperty(null, "simple", "java.lang.String", null, null, null, null,
|
||||
null);
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public 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);
|
||||
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).has(Metadata.withProperty("simple.flag", Boolean.class).fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.").withDeprecation(null, null).withDefaultValue(true));
|
||||
assertThat(metadata.getItems()).hasSize(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeExistingPropertyDescription() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null,
|
||||
null, null, "A nice comparator.", null, null);
|
||||
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).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
|
||||
.fromSource(SimpleProperties.class).withDescription("A nice comparator."));
|
||||
assertThat(metadata.getItems()).hasSize(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", "error"));
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, null, null,
|
||||
new ItemDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
||||
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", "error"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class)
|
||||
.withDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
||||
assertThat(metadata.getItems()).hasSize(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public 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"));
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class)
|
||||
.withDeprecation("Don't use this.", "single.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class).withDeprecation("Don't use this.", "single.name"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeExistingPropertyDeprecationOverrideLevel() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null,
|
||||
null, null, null, null, new ItemDeprecation(null, null, "error"));
|
||||
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, null, null, null, null,
|
||||
new ItemDeprecation(null, null, "error"));
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class).withDeprecation(
|
||||
"renamed", "singledeprecated.new-name", "error"));
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class)
|
||||
.withDeprecation("renamed", "singledeprecated.new-name", "error"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@@ -687,65 +602,55 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
|
||||
@Test
|
||||
public void mergingOfSimpleHint() throws Exception {
|
||||
writeAdditionalHints(ItemHint.newHint("simple.the-name",
|
||||
new ItemHint.ValueHint("boot", "Bla bla"),
|
||||
writeAdditionalHints(ItemHint.newHint("simple.the-name", new ItemHint.ValueHint("boot", "Bla bla"),
|
||||
new ItemHint.ValueHint("spring", null)));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.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));
|
||||
assertThat(metadata).has(Metadata.withHint("simple.the-name")
|
||||
.withValue(0, "boot", "Bla bla").withValue(1, "spring", null));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla").withValue(1, "spring", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfHintWithNonCanonicalName() throws Exception {
|
||||
writeAdditionalHints(ItemHint.newHint("simple.theName",
|
||||
new ItemHint.ValueHint("boot", "Bla bla")));
|
||||
writeAdditionalHints(ItemHint.newHint("simple.theName", new ItemHint.ValueHint("boot", "Bla bla")));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.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));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla"));
|
||||
assertThat(metadata).has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfHintWithProvider() throws Exception {
|
||||
writeAdditionalHints(new ItemHint("simple.theName",
|
||||
Collections.<ItemHint.ValueHint>emptyList(),
|
||||
writeAdditionalHints(new ItemHint("simple.theName", Collections.<ItemHint.ValueHint>emptyList(),
|
||||
Arrays.asList(
|
||||
new ItemHint.ValueProvider("first",
|
||||
Collections.<String, Object>singletonMap("target",
|
||||
"org.foo")),
|
||||
Collections.<String, Object>singletonMap("target", "org.foo")),
|
||||
new ItemHint.ValueProvider("second", null))));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.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));
|
||||
assertThat(metadata).has(Metadata.withHint("simple.the-name")
|
||||
.withProvider("first", "target", "org.foo").withProvider("second"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withHint("simple.the-name").withProvider("first", "target", "org.foo").withProvider("second"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfAdditionalDeprecation() throws Exception {
|
||||
writePropertyDeprecation(ItemMetadata.newProperty("simple", "wrongName",
|
||||
"java.lang.String", null, null, null, null,
|
||||
new ItemDeprecation("Lame name.", "simple.the-name")));
|
||||
writePropertyDeprecation(ItemMetadata.newProperty("simple", "wrongName", "java.lang.String", null, null, null,
|
||||
null, new ItemDeprecation("Lame name.", "simple.the-name")));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class)
|
||||
.withDeprecation("Lame name.", "simple.the-name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class).withDeprecation("Lame name.",
|
||||
"simple.the-name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfAdditionalMetadata() throws Exception {
|
||||
File metaInfFolder = new File(this.compiler.getOutputLocation(), "META-INF");
|
||||
metaInfFolder.mkdirs();
|
||||
File additionalMetadataFile = new File(metaInfFolder,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadataFile = new File(metaInfFolder, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadataFile.createNewFile();
|
||||
JSONObject property = new JSONObject();
|
||||
property.put("name", "foo");
|
||||
@@ -761,28 +666,21 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
writer.close();
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incrementalBuild() throws Exception {
|
||||
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class,
|
||||
BarProperties.class);
|
||||
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class, BarProperties.class);
|
||||
assertThat(project.getOutputFile(MetadataStore.METADATA_PATH).exists()).isFalse();
|
||||
ConfigurationMetadata metadata = project.fullBuild();
|
||||
assertThat(project.getOutputFile(MetadataStore.METADATA_PATH).exists()).isTrue();
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
|
||||
metadata = project.incrementalBuild(BarProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
|
||||
project.addSourceCode(BarProperties.class,
|
||||
BarProperties.class.getResourceAsStream("BarProperties.snippet"));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
|
||||
project.addSourceCode(BarProperties.class, BarProperties.class.getResourceAsStream("BarProperties.snippet"));
|
||||
metadata = project.incrementalBuild(BarProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.extra"));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter"));
|
||||
@@ -796,13 +694,11 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
|
||||
@Test
|
||||
public void incrementalBuildAnnotationRemoved() throws Exception {
|
||||
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class,
|
||||
BarProperties.class);
|
||||
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class, BarProperties.class);
|
||||
ConfigurationMetadata metadata = project.fullBuild();
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter"));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter"));
|
||||
project.replaceText(BarProperties.class, "@ConfigurationProperties",
|
||||
"//@ConfigurationProperties");
|
||||
project.replaceText(BarProperties.class, "@ConfigurationProperties", "//@ConfigurationProperties");
|
||||
metadata = project.incrementalBuild(BarProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter"));
|
||||
assertThat(metadata).isNotEqualTo(Metadata.withProperty("bar.counter"));
|
||||
@@ -810,51 +706,42 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
|
||||
@Test
|
||||
public void incrementalBuildTypeRenamed() throws Exception {
|
||||
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class,
|
||||
BarProperties.class);
|
||||
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class, BarProperties.class);
|
||||
ConfigurationMetadata metadata = project.fullBuild();
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter")
|
||||
.fromSource(RenamedBarProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter").fromSource(RenamedBarProperties.class));
|
||||
project.delete(BarProperties.class);
|
||||
project.add(RenamedBarProperties.class);
|
||||
metadata = project.incrementalBuild(RenamedBarProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
|
||||
assertThat(metadata).doesNotHave(
|
||||
Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter")
|
||||
.fromSource(RenamedBarProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter").fromSource(RenamedBarProperties.class));
|
||||
}
|
||||
|
||||
private void assertSimpleLombokProperties(ConfigurationMetadata metadata,
|
||||
Class<?> source, String prefix) {
|
||||
private void assertSimpleLombokProperties(ConfigurationMetadata metadata, Class<?> source, String prefix) {
|
||||
assertThat(metadata).has(Metadata.withGroup(prefix).fromSource(source));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty(prefix + ".id"));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".name", String.class)
|
||||
.fromSource(source).withDescription("Name description."));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".name", String.class).fromSource(source)
|
||||
.withDescription("Name description."));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".description"));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".counter"));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".number")
|
||||
.fromSource(source).withDefaultValue(0).withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".number").fromSource(source).withDefaultValue(0)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".items"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty(prefix + ".ignored"));
|
||||
}
|
||||
|
||||
private void assertAccessLevelOverwriteLombokProperties(
|
||||
ConfigurationMetadata metadata, Class<?> source, String prefix) {
|
||||
private void assertAccessLevelOverwriteLombokProperties(ConfigurationMetadata metadata, Class<?> source,
|
||||
String prefix) {
|
||||
assertAccessLevelLombokProperties(metadata, source, prefix, 7);
|
||||
}
|
||||
|
||||
private void assertAccessLevelLombokProperties(ConfigurationMetadata metadata,
|
||||
Class<?> source, String prefix, int countNameFields) {
|
||||
private void assertAccessLevelLombokProperties(ConfigurationMetadata metadata, Class<?> source, String prefix,
|
||||
int countNameFields) {
|
||||
assertThat(metadata).has(Metadata.withGroup(prefix).fromSource(source));
|
||||
for (int i = 0; i < countNameFields; i++) {
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty(prefix + ".name" + i, String.class));
|
||||
assertThat(metadata).has(Metadata.withProperty(prefix + ".name" + i, String.class));
|
||||
}
|
||||
assertThat(metadata.getItems()).hasSize(1 + countNameFields);
|
||||
}
|
||||
@@ -917,8 +804,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
private File createAdditionalMetadataFile() throws IOException {
|
||||
File metaInfFolder = new File(this.compiler.getOutputLocation(), "META-INF");
|
||||
metaInfFolder.mkdirs();
|
||||
File additionalMetadataFile = new File(metaInfFolder,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadataFile = new File(metaInfFolder, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadataFile.createNewFile();
|
||||
return additionalMetadataFile;
|
||||
}
|
||||
|
||||
@@ -92,9 +92,8 @@ public final class Metadata {
|
||||
this(itemType, name, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public MetadataItemCondition(ItemType itemType, String name, String type,
|
||||
Class<?> sourceType, String sourceMethod, String description,
|
||||
Object defaultValue, ItemDeprecation deprecation) {
|
||||
public MetadataItemCondition(ItemType itemType, String name, String type, Class<?> sourceType,
|
||||
String sourceMethod, String description, Object defaultValue, ItemDeprecation deprecation) {
|
||||
this.itemType = itemType;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
@@ -139,87 +138,73 @@ public final class Metadata {
|
||||
if (this.type != null && !this.type.equals(itemMetadata.getType())) {
|
||||
return false;
|
||||
}
|
||||
if (this.sourceType != null
|
||||
&& !this.sourceType.getName().equals(itemMetadata.getSourceType())) {
|
||||
if (this.sourceType != null && !this.sourceType.getName().equals(itemMetadata.getSourceType())) {
|
||||
return false;
|
||||
}
|
||||
if (this.sourceMethod != null
|
||||
&& !this.sourceMethod.equals(itemMetadata.getSourceMethod())) {
|
||||
if (this.sourceMethod != null && !this.sourceMethod.equals(itemMetadata.getSourceMethod())) {
|
||||
return false;
|
||||
}
|
||||
if (this.defaultValue != null && !ObjectUtils
|
||||
.nullSafeEquals(this.defaultValue, itemMetadata.getDefaultValue())) {
|
||||
if (this.defaultValue != null
|
||||
&& !ObjectUtils.nullSafeEquals(this.defaultValue, itemMetadata.getDefaultValue())) {
|
||||
return false;
|
||||
}
|
||||
if (this.description != null
|
||||
&& !this.description.equals(itemMetadata.getDescription())) {
|
||||
if (this.description != null && !this.description.equals(itemMetadata.getDescription())) {
|
||||
return false;
|
||||
}
|
||||
if (this.deprecation == null && itemMetadata.getDeprecation() != null) {
|
||||
return false;
|
||||
}
|
||||
if (this.deprecation != null
|
||||
&& !this.deprecation.equals(itemMetadata.getDeprecation())) {
|
||||
if (this.deprecation != null && !this.deprecation.equals(itemMetadata.getDeprecation())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public MetadataItemCondition ofType(Class<?> dataType) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType.getName(),
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType.getName(), this.sourceType,
|
||||
this.sourceMethod, this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition ofType(String dataType) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType,
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType, this.sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition fromSource(Class<?> sourceType) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
sourceType, this.sourceMethod, this.description, this.defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition fromSourceMethod(String sourceMethod) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, sourceMethod, this.description, this.defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, sourceMethod,
|
||||
this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDescription(String description) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, description, this.defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDefaultValue(Object defaultValue) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, this.description, defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
this.description, defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDeprecation(String reason, String replacement) {
|
||||
return withDeprecation(reason, replacement, null);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDeprecation(String reason, String replacement,
|
||||
String level) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, new ItemDeprecation(reason, replacement, level));
|
||||
public MetadataItemCondition withDeprecation(String reason, String replacement, String level) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, new ItemDeprecation(reason, replacement, level));
|
||||
}
|
||||
|
||||
public MetadataItemCondition withNoDeprecation() {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, null);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, null);
|
||||
}
|
||||
|
||||
private ItemMetadata getFirstItemWithName(ConfigurationMetadata metadata,
|
||||
String name) {
|
||||
private ItemMetadata getFirstItemWithName(ConfigurationMetadata metadata, String name) {
|
||||
for (ItemMetadata item : metadata.getItems()) {
|
||||
if (item.isOfItemType(this.itemType) && name.equals(item.getName())) {
|
||||
return item;
|
||||
@@ -244,8 +229,7 @@ public final class Metadata {
|
||||
this.providerConditions = Collections.emptyList();
|
||||
}
|
||||
|
||||
public MetadataHintCondition(String name,
|
||||
List<ItemHintValueCondition> valueConditions,
|
||||
public MetadataHintCondition(String name, List<ItemHintValueCondition> valueConditions,
|
||||
List<ItemHintProviderCondition> providerConditions) {
|
||||
this.name = name;
|
||||
this.valueConditions = valueConditions;
|
||||
@@ -271,12 +255,10 @@ public final class Metadata {
|
||||
if (itemHint == null) {
|
||||
return false;
|
||||
}
|
||||
return matches(itemHint, this.valueConditions)
|
||||
&& matches(itemHint, this.providerConditions);
|
||||
return matches(itemHint, this.valueConditions) && matches(itemHint, this.providerConditions);
|
||||
}
|
||||
|
||||
private boolean matches(ItemHint itemHint,
|
||||
List<? extends Condition<ItemHint>> conditions) {
|
||||
private boolean matches(ItemHint itemHint, List<? extends Condition<ItemHint>> conditions) {
|
||||
for (Condition<ItemHint> condition : conditions) {
|
||||
if (!condition.matches(itemHint)) {
|
||||
return false;
|
||||
@@ -285,8 +267,7 @@ public final class Metadata {
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemHint getFirstHintWithName(ConfigurationMetadata metadata,
|
||||
String name) {
|
||||
private ItemHint getFirstHintWithName(ConfigurationMetadata metadata, String name) {
|
||||
for (ItemHint hint : metadata.getHints()) {
|
||||
if (name.equals(hint.getName())) {
|
||||
return hint;
|
||||
@@ -295,11 +276,9 @@ public final class Metadata {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MetadataHintCondition withValue(int index, Object value,
|
||||
String description) {
|
||||
public MetadataHintCondition withValue(int index, Object value, String description) {
|
||||
return new MetadataHintCondition(this.name,
|
||||
add(this.valueConditions,
|
||||
new ItemHintValueCondition(index, value, description)),
|
||||
add(this.valueConditions, new ItemHintValueCondition(index, value, description)),
|
||||
this.providerConditions);
|
||||
}
|
||||
|
||||
@@ -307,17 +286,13 @@ public final class Metadata {
|
||||
return withProvider(this.providerConditions.size(), provider, null);
|
||||
}
|
||||
|
||||
public MetadataHintCondition withProvider(String provider, String key,
|
||||
Object value) {
|
||||
return withProvider(this.providerConditions.size(), provider,
|
||||
Collections.singletonMap(key, value));
|
||||
public MetadataHintCondition withProvider(String provider, String key, Object value) {
|
||||
return withProvider(this.providerConditions.size(), provider, Collections.singletonMap(key, value));
|
||||
}
|
||||
|
||||
public MetadataHintCondition withProvider(int index, String provider,
|
||||
Map<String, Object> parameters) {
|
||||
public MetadataHintCondition withProvider(int index, String provider, Map<String, Object> parameters) {
|
||||
return new MetadataHintCondition(this.name, this.valueConditions,
|
||||
add(this.providerConditions,
|
||||
new ItemHintProviderCondition(index, provider, parameters)));
|
||||
add(this.providerConditions, new ItemHintProviderCondition(index, provider, parameters)));
|
||||
}
|
||||
|
||||
private <T> List<T> add(List<T> items, T item) {
|
||||
@@ -364,8 +339,7 @@ public final class Metadata {
|
||||
if (this.value != null && !this.value.equals(valueHint.getValue())) {
|
||||
return false;
|
||||
}
|
||||
if (this.description != null
|
||||
&& !this.description.equals(valueHint.getDescription())) {
|
||||
if (this.description != null && !this.description.equals(valueHint.getDescription())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -381,8 +355,7 @@ public final class Metadata {
|
||||
|
||||
private final Map<String, Object> parameters;
|
||||
|
||||
ItemHintProviderCondition(int index, String name,
|
||||
Map<String, Object> parameters) {
|
||||
ItemHintProviderCondition(int index, String name, Map<String, Object> parameters) {
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
this.parameters = parameters;
|
||||
|
||||
@@ -38,8 +38,7 @@ public class MetadataStoreTests {
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
private final MetadataStore metadataStore = new MetadataStore(
|
||||
mock(ProcessingEnvironment.class));
|
||||
private final MetadataStore metadataStore = new MetadataStore(mock(ProcessingEnvironment.class));
|
||||
|
||||
@Test
|
||||
public void additionalMetadataIsLocatedInMavenBuild() throws IOException {
|
||||
@@ -47,13 +46,11 @@ public class MetadataStoreTests {
|
||||
File classesLocation = new File(app, "target/classes");
|
||||
File metaInf = new File(classesLocation, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(
|
||||
this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation,
|
||||
"META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,13 +60,11 @@ public class MetadataStoreTests {
|
||||
File resourcesLocation = new File(app, "build/resources/main");
|
||||
File metaInf = new File(resourcesLocation, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(
|
||||
this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation,
|
||||
"META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,13 +74,11 @@ public class MetadataStoreTests {
|
||||
File resourcesLocation = new File(app, "build/resources/main");
|
||||
File metaInf = new File(resourcesLocation, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(
|
||||
this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation,
|
||||
"META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller;
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
public class TestConfigurationMetadataAnnotationProcessor
|
||||
extends ConfigurationMetadataAnnotationProcessor {
|
||||
public class TestConfigurationMetadataAnnotationProcessor extends ConfigurationMetadataAnnotationProcessor {
|
||||
|
||||
static final String CONFIGURATION_PROPERTIES_ANNOTATION = "org.springframework.boot.configurationsample.ConfigurationProperties";
|
||||
|
||||
@@ -73,11 +72,9 @@ public class TestConfigurationMetadataAnnotationProcessor
|
||||
protected ConfigurationMetadata writeMetaData() throws Exception {
|
||||
super.writeMetaData();
|
||||
try {
|
||||
File metadataFile = new File(this.outputLocation,
|
||||
"META-INF/spring-configuration-metadata.json");
|
||||
File metadataFile = new File(this.outputLocation, "META-INF/spring-configuration-metadata.json");
|
||||
if (metadataFile.isFile()) {
|
||||
this.metadata = new JsonMarshaller()
|
||||
.read(new FileInputStream(metadataFile));
|
||||
this.metadata = new JsonMarshaller().read(new FileInputStream(metadataFile));
|
||||
}
|
||||
else {
|
||||
this.metadata = new ConfigurationMetadata();
|
||||
|
||||
@@ -65,8 +65,7 @@ public class TestProject {
|
||||
|
||||
private Set<File> sourceFiles = new LinkedHashSet<File>();
|
||||
|
||||
public TestProject(TemporaryFolder tempFolder, Class<?>... classes)
|
||||
throws IOException {
|
||||
public TestProject(TemporaryFolder tempFolder, Class<?>... classes) throws IOException {
|
||||
this.sourceFolder = tempFolder.newFolder();
|
||||
this.compiler = new TestCompiler(tempFolder) {
|
||||
@Override
|
||||
@@ -135,15 +134,12 @@ public class TestProject {
|
||||
* @param snippetStream the snippet stream
|
||||
* @throws Exception if the source cannot be added
|
||||
*/
|
||||
public void addSourceCode(Class<?> target, InputStream snippetStream)
|
||||
throws Exception {
|
||||
public void addSourceCode(Class<?> target, InputStream snippetStream) throws Exception {
|
||||
File targetFile = getSourceFile(target);
|
||||
String contents = getContents(targetFile);
|
||||
int insertAt = contents.lastIndexOf('}');
|
||||
String additionalSource = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(snippetStream));
|
||||
contents = contents.substring(0, insertAt) + additionalSource
|
||||
+ contents.substring(insertAt);
|
||||
String additionalSource = FileCopyUtils.copyToString(new InputStreamReader(snippetStream));
|
||||
contents = contents.substring(0, insertAt) + additionalSource + contents.substring(insertAt);
|
||||
putContents(targetFile, contents);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,14 +84,12 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
assertThat(values.get("stringArrayNone")).isNull();
|
||||
assertThat(values.get("stringEmptyArray")).isEqualTo(new Object[0]);
|
||||
assertThat(values.get("stringArrayConst")).isEqualTo(new Object[] { "OK", "KO" });
|
||||
assertThat(values.get("stringArrayConstElements"))
|
||||
.isEqualTo(new Object[] { "c" });
|
||||
assertThat(values.get("stringArrayConstElements")).isEqualTo(new Object[] { "c" });
|
||||
assertThat(values.get("integerArray")).isEqualTo(new Object[] { 42, 24 });
|
||||
assertThat(values.get("unknownArray")).isNull();
|
||||
}
|
||||
|
||||
@SupportedAnnotationTypes({
|
||||
"org.springframework.boot.configurationsample.ConfigurationProperties" })
|
||||
@SupportedAnnotationTypes({ "org.springframework.boot.configurationsample.ConfigurationProperties" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
private class TestProcessor extends AbstractProcessor {
|
||||
|
||||
@@ -105,14 +103,12 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations,
|
||||
RoundEnvironment roundEnv) {
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
for (TypeElement annotation : annotations) {
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
|
||||
if (element instanceof TypeElement) {
|
||||
try {
|
||||
this.values.putAll(
|
||||
this.processor.getFieldValues((TypeElement) element));
|
||||
this.values.putAll(this.processor.getFieldValues((TypeElement) element));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
|
||||
@@ -28,8 +28,7 @@ import static org.junit.Assume.assumeNoException;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class JavaCompilerFieldValuesProcessorTests
|
||||
extends AbstractFieldValuesProcessorTests {
|
||||
public class JavaCompilerFieldValuesProcessorTests extends AbstractFieldValuesProcessorTests {
|
||||
|
||||
@Override
|
||||
protected FieldValuesParser createProcessor(ProcessingEnvironment env) {
|
||||
|
||||
@@ -44,14 +44,12 @@ public class ConfigurationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void toDashedCaseWordsUnderscore() {
|
||||
assertThat(toDashedCase("Word_With_underscore"))
|
||||
.isEqualTo("word-with-underscore");
|
||||
assertThat(toDashedCase("Word_With_underscore")).isEqualTo("word-with-underscore");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toDashedCaseWordsSeveralUnderscores() {
|
||||
assertThat(toDashedCase("Word___With__underscore"))
|
||||
.isEqualTo("word---with--underscore");
|
||||
assertThat(toDashedCase("Word___With__underscore")).isEqualTo("word---with--underscore");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -39,50 +39,35 @@ public class JsonMarshallerTests {
|
||||
@Test
|
||||
public void marshallAndUnmarshal() throws Exception {
|
||||
ConfigurationMetadata metadata = new ConfigurationMetadata();
|
||||
metadata.add(ItemMetadata.newProperty("a", "b", StringBuffer.class.getName(),
|
||||
InputStream.class.getName(), "sourceMethod", "desc", "x",
|
||||
new ItemDeprecation("Deprecation comment", "b.c.d")));
|
||||
metadata.add(ItemMetadata.newProperty("b.c.d", null, null, null, null, null, null,
|
||||
null));
|
||||
metadata.add(
|
||||
ItemMetadata.newProperty("c", null, null, null, null, null, 123, null));
|
||||
metadata.add(
|
||||
ItemMetadata.newProperty("d", null, null, null, null, null, true, null));
|
||||
metadata.add(ItemMetadata.newProperty("e", null, null, null, null, null,
|
||||
new String[] { "y", "n" }, null));
|
||||
metadata.add(ItemMetadata.newProperty("f", null, null, null, null, null,
|
||||
new Boolean[] { true, false }, null));
|
||||
metadata.add(ItemMetadata.newProperty("a", "b", StringBuffer.class.getName(), InputStream.class.getName(),
|
||||
"sourceMethod", "desc", "x", new ItemDeprecation("Deprecation comment", "b.c.d")));
|
||||
metadata.add(ItemMetadata.newProperty("b.c.d", null, null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("c", null, null, null, null, null, 123, null));
|
||||
metadata.add(ItemMetadata.newProperty("d", null, null, null, null, null, true, null));
|
||||
metadata.add(ItemMetadata.newProperty("e", null, null, null, null, null, new String[] { "y", "n" }, null));
|
||||
metadata.add(ItemMetadata.newProperty("f", null, null, null, null, null, new Boolean[] { true, false }, null));
|
||||
metadata.add(ItemMetadata.newGroup("d", null, null, null));
|
||||
metadata.add(ItemHint.newHint("a.b"));
|
||||
metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"),
|
||||
new ItemHint.ValueHint(456, null)));
|
||||
metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"), new ItemHint.ValueHint(456, null)));
|
||||
metadata.add(new ItemHint("d", null,
|
||||
Arrays.asList(
|
||||
new ItemHint.ValueProvider("first",
|
||||
Collections.<String, Object>singletonMap("target",
|
||||
"foo")),
|
||||
new ItemHint.ValueProvider("first", Collections.<String, Object>singletonMap("target", "foo")),
|
||||
new ItemHint.ValueProvider("second", null))));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
marshaller.write(metadata, outputStream);
|
||||
ConfigurationMetadata read = marshaller
|
||||
.read(new ByteArrayInputStream(outputStream.toByteArray()));
|
||||
assertThat(read).has(Metadata.withProperty("a.b", StringBuffer.class)
|
||||
.fromSource(InputStream.class).withDescription("desc")
|
||||
.withDefaultValue("x").withDeprecation("Deprecation comment", "b.c.d"));
|
||||
ConfigurationMetadata read = marshaller.read(new ByteArrayInputStream(outputStream.toByteArray()));
|
||||
assertThat(read).has(Metadata.withProperty("a.b", StringBuffer.class).fromSource(InputStream.class)
|
||||
.withDescription("desc").withDefaultValue("x").withDeprecation("Deprecation comment", "b.c.d"));
|
||||
assertThat(read).has(Metadata.withProperty("b.c.d"));
|
||||
assertThat(read).has(Metadata.withProperty("c").withDefaultValue(123));
|
||||
assertThat(read).has(Metadata.withProperty("d").withDefaultValue(true));
|
||||
assertThat(read).has(
|
||||
Metadata.withProperty("e").withDefaultValue(new String[] { "y", "n" }));
|
||||
assertThat(read).has(Metadata.withProperty("f")
|
||||
.withDefaultValue(new Object[] { true, false }));
|
||||
assertThat(read).has(Metadata.withProperty("e").withDefaultValue(new String[] { "y", "n" }));
|
||||
assertThat(read).has(Metadata.withProperty("f").withDefaultValue(new Object[] { true, false }));
|
||||
assertThat(read).has(Metadata.withGroup("d"));
|
||||
assertThat(read).has(Metadata.withHint("a.b"));
|
||||
assertThat(read).has(
|
||||
Metadata.withHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
|
||||
assertThat(read).has(Metadata.withHint("d").withProvider("first", "target", "foo")
|
||||
.withProvider("second"));
|
||||
assertThat(read).has(Metadata.withHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
|
||||
assertThat(read).has(Metadata.withHint("d").withProvider("first", "target", "foo").withProvider("second"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,7 @@ public class DeprecatedSingleProperty {
|
||||
private String newName;
|
||||
|
||||
@Deprecated
|
||||
@DeprecatedConfigurationProperty(reason = "renamed",
|
||||
replacement = "singledeprecated.new-name")
|
||||
@DeprecatedConfigurationProperty(reason = "renamed", replacement = "singledeprecated.new-name")
|
||||
public String getName() {
|
||||
return getNewName();
|
||||
}
|
||||
|
||||
@@ -21,8 +21,7 @@ package org.springframework.boot.configurationsample.simple;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class HierarchicalPropertiesParent
|
||||
extends HierarchicalPropertiesGrandparent {
|
||||
public abstract class HierarchicalPropertiesParent extends HierarchicalPropertiesGrandparent {
|
||||
|
||||
private String second;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user