Relocate projects to spring-boot-project
Move projects to better reflect the way that Spring Boot is released. The following projects are under `spring-boot-project`: - `spring-boot` - `spring-boot-autoconfigure` - `spring-boot-tools` - `spring-boot-starters` - `spring-boot-actuator` - `spring-boot-actuator-autoconfigure` - `spring-boot-test` - `spring-boot-test-autoconfigure` - `spring-boot-devtools` - `spring-boot-cli` - `spring-boot-docs` See gh-9316
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Gather a collection of {@link ConfigurationMetadataProperty properties} that are
|
||||
* sharing a {@link #getId() common prefix}. Provide access to all the
|
||||
* {@link ConfigurationMetadataSource sources} that have contributed properties to the
|
||||
* group.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ConfigurationMetadataGroup implements Serializable {
|
||||
|
||||
private final String id;
|
||||
|
||||
private final Map<String, ConfigurationMetadataSource> sources = new HashMap<>();
|
||||
|
||||
private final Map<String, ConfigurationMetadataProperty> properties = new HashMap<>();
|
||||
|
||||
public ConfigurationMetadataGroup(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the id of the group, used as a common prefix for all properties associated
|
||||
* to it.
|
||||
* @return the id of the group
|
||||
*/
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link ConfigurationMetadataSource sources} defining the properties of
|
||||
* this group.
|
||||
* @return the sources of the group
|
||||
*/
|
||||
public Map<String, ConfigurationMetadataSource> getSources() {
|
||||
return this.sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link ConfigurationMetadataProperty properties} defined in this group.
|
||||
* <p>
|
||||
* A property may appear more than once for a given source, potentially with
|
||||
* conflicting type or documentation. This is a "merged" view of the properties of
|
||||
* this group.
|
||||
* @return the properties of the group
|
||||
* @see ConfigurationMetadataSource#getProperties()
|
||||
*/
|
||||
public Map<String, ConfigurationMetadataProperty> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A raw view of a hint used for parsing only.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
class ConfigurationMetadataHint {
|
||||
|
||||
private static final String KEY_SUFFIX = ".keys";
|
||||
|
||||
private static final String VALUE_SUFFIX = ".values";
|
||||
|
||||
private String id;
|
||||
|
||||
private final List<ValueHint> valueHints = new ArrayList<>();
|
||||
|
||||
private final List<ValueProvider> valueProviders = new ArrayList<>();
|
||||
|
||||
public boolean isMapKeyHints() {
|
||||
return (this.id != null && this.id.endsWith(KEY_SUFFIX));
|
||||
}
|
||||
|
||||
public boolean isMapValueHints() {
|
||||
return (this.id != null && this.id.endsWith(VALUE_SUFFIX));
|
||||
}
|
||||
|
||||
public String resolveId() {
|
||||
if (isMapKeyHints()) {
|
||||
return this.id.substring(0, this.id.length() - KEY_SUFFIX.length());
|
||||
}
|
||||
if (isMapValueHints()) {
|
||||
return this.id.substring(0, this.id.length() - VALUE_SUFFIX.length());
|
||||
}
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<ValueHint> getValueHints() {
|
||||
return this.valueHints;
|
||||
}
|
||||
|
||||
public List<ValueProvider> getValueProviders() {
|
||||
return this.valueProviders;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
/**
|
||||
* An extension of {@link ConfigurationMetadataProperty} that provides a reference to its
|
||||
* source.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
class ConfigurationMetadataItem extends ConfigurationMetadataProperty {
|
||||
|
||||
private String sourceType;
|
||||
|
||||
private String sourceMethod;
|
||||
|
||||
/**
|
||||
* The class name of the source that contributed this property. For example, if the
|
||||
* property was from a class annotated with {@code @ConfigurationProperties} this
|
||||
* attribute would contain the fully qualified name of that class.
|
||||
* @return the source type
|
||||
*/
|
||||
public String getSourceType() {
|
||||
return this.sourceType;
|
||||
}
|
||||
|
||||
public void setSourceType(String sourceType) {
|
||||
this.sourceType = sourceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The full name of the method (including parenthesis and argument types) that
|
||||
* contributed this property. For example, the name of a getter in a
|
||||
* {@code @ConfigurationProperties} annotated class.
|
||||
* @return the source method
|
||||
*/
|
||||
public String getSourceMethod() {
|
||||
return this.sourceMethod;
|
||||
}
|
||||
|
||||
public void setSourceMethod(String sourceMethod) {
|
||||
this.sourceMethod = sourceMethod;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Define a configuration property. Each property is fully identified by its
|
||||
* {@link #getId() id} which is composed of a namespace prefix (the
|
||||
* {@link ConfigurationMetadataGroup#getId() group id}), if any and the {@link #getName()
|
||||
* name} of the property.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ConfigurationMetadataProperty implements Serializable {
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String type;
|
||||
|
||||
private String description;
|
||||
|
||||
private String shortDescription;
|
||||
|
||||
private Object defaultValue;
|
||||
|
||||
private final Hints hints = new Hints();
|
||||
|
||||
private Deprecation deprecation;
|
||||
|
||||
/**
|
||||
* The full identifier of the property, in lowercase dashed form (e.g.
|
||||
* my.group.simple-property)
|
||||
* @return the property id
|
||||
*/
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the property, in lowercase dashed form (e.g. simple-property). If this
|
||||
* item does not belong to any group, the id is returned.
|
||||
* @return the property name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The class name of the data type of the property. For example,
|
||||
* {@code java.lang.String}.
|
||||
* <p>
|
||||
* For consistency, the type of a primitive is specified using its wrapper
|
||||
* counterpart, i.e. {@code boolean} becomes {@code java.lang.Boolean}. If the type
|
||||
* holds generic information, these are provided as well, i.e. a {@code HashMap} of
|
||||
* String to Integer would be defined as {@code java.util.HashMap
|
||||
* <java.lang.String,java.lang.Integer>}.
|
||||
* <p>
|
||||
* Note that this class may be a complex type that gets converted from a String as
|
||||
* values are bound.
|
||||
* @return the property type
|
||||
*/
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* A description of the property, if any. Can be multi-lines.
|
||||
* @return the property description
|
||||
* @see #getShortDescription()
|
||||
*/
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* A single-line, single-sentence description of this property, if any.
|
||||
* @return the property short description
|
||||
* @see #getDescription()
|
||||
*/
|
||||
public String getShortDescription() {
|
||||
return this.shortDescription;
|
||||
}
|
||||
|
||||
public void setShortDescription(String shortDescription) {
|
||||
this.shortDescription = shortDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default value, if any.
|
||||
* @return the default value
|
||||
*/
|
||||
public Object getDefaultValue() {
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(Object defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the hints of this item.
|
||||
* @return the hints
|
||||
*/
|
||||
public Hints getHints() {
|
||||
return this.hints;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link Deprecation} for this property, if any.
|
||||
* @return the deprecation
|
||||
* @see #isDeprecated()
|
||||
*/
|
||||
public Deprecation getDeprecation() {
|
||||
return this.deprecation;
|
||||
}
|
||||
|
||||
public void setDeprecation(Deprecation deprecation) {
|
||||
this.deprecation = deprecation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if the property is deprecated.
|
||||
* @return if the property is deprecated
|
||||
* @see #getDeprecation()
|
||||
*/
|
||||
public boolean isDeprecated() {
|
||||
return this.deprecation != null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A repository of configuration metadata.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public interface ConfigurationMetadataRepository {
|
||||
|
||||
/**
|
||||
* Defines the name of the "root" group, that is the group that gathers all the
|
||||
* properties that aren't attached to a specific group.
|
||||
*/
|
||||
String ROOT_GROUP = "_ROOT_GROUP_";
|
||||
|
||||
/**
|
||||
* Return the groups, indexed by id.
|
||||
* @return all configuration meta-data groups
|
||||
*/
|
||||
Map<String, ConfigurationMetadataGroup> getAllGroups();
|
||||
|
||||
/**
|
||||
* Return the properties, indexed by id.
|
||||
* @return all configuration meta-data properties
|
||||
*/
|
||||
Map<String, ConfigurationMetadataProperty> getAllProperties();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Load a {@link ConfigurationMetadataRepository} from the content of arbitrary
|
||||
* resource(s).
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
|
||||
/**
|
||||
* UTF-8 Charset.
|
||||
*/
|
||||
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private Charset defaultCharset = UTF_8;
|
||||
|
||||
private final JsonReader reader = new JsonReader();
|
||||
|
||||
private final List<SimpleConfigurationMetadataRepository> repositories = new ArrayList<>();
|
||||
|
||||
private ConfigurationMetadataRepositoryJsonBuilder(Charset defaultCharset) {
|
||||
this.defaultCharset = defaultCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the content of a {@link ConfigurationMetadataRepository} defined by the
|
||||
* specified {@link InputStream} json document using the default charset. If this
|
||||
* metadata repository holds items that were loaded previously, these are ignored.
|
||||
* <p>
|
||||
* Leaves the stream open when done.
|
||||
* @param inputStream the source input stream
|
||||
* @return this builder
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public ConfigurationMetadataRepositoryJsonBuilder withJsonResource(
|
||||
InputStream inputStream) throws IOException {
|
||||
return withJsonResource(inputStream, this.defaultCharset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the content of a {@link ConfigurationMetadataRepository} defined by the
|
||||
* specified {@link InputStream} json document using the specified {@link Charset}. If
|
||||
* this metadata repository holds items that were loaded previously, these are
|
||||
* ignored.
|
||||
* <p>
|
||||
* Leaves the stream open when done.
|
||||
* @param inputStream the source input stream
|
||||
* @param charset the charset of the input
|
||||
* @return this builder
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public ConfigurationMetadataRepositoryJsonBuilder withJsonResource(
|
||||
InputStream inputStream, Charset charset) throws IOException {
|
||||
if (inputStream == null) {
|
||||
throw new IllegalArgumentException("InputStream must not be null.");
|
||||
}
|
||||
this.repositories.add(add(inputStream, charset));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a {@link ConfigurationMetadataRepository} with the current state of this
|
||||
* builder.
|
||||
* @return this builder
|
||||
*/
|
||||
public ConfigurationMetadataRepository build() {
|
||||
SimpleConfigurationMetadataRepository result = new SimpleConfigurationMetadataRepository();
|
||||
for (SimpleConfigurationMetadataRepository repository : this.repositories) {
|
||||
result.include(repository);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private SimpleConfigurationMetadataRepository add(InputStream in, Charset charset)
|
||||
throws IOException {
|
||||
try {
|
||||
RawConfigurationMetadata metadata = this.reader.read(in, charset);
|
||||
return create(metadata);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to read configuration metadata", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private SimpleConfigurationMetadataRepository create(
|
||||
RawConfigurationMetadata metadata) {
|
||||
SimpleConfigurationMetadataRepository repository = new SimpleConfigurationMetadataRepository();
|
||||
repository.add(metadata.getSources());
|
||||
for (ConfigurationMetadataItem item : metadata.getItems()) {
|
||||
ConfigurationMetadataSource source = getSource(metadata, item);
|
||||
repository.add(item, source);
|
||||
}
|
||||
Map<String, ConfigurationMetadataProperty> allProperties = repository
|
||||
.getAllProperties();
|
||||
for (ConfigurationMetadataHint hint : metadata.getHints()) {
|
||||
ConfigurationMetadataProperty property = allProperties.get(hint.getId());
|
||||
if (property != null) {
|
||||
addValueHints(property, hint);
|
||||
}
|
||||
else {
|
||||
String id = hint.resolveId();
|
||||
property = allProperties.get(id);
|
||||
if (property != null) {
|
||||
if (hint.isMapKeyHints()) {
|
||||
addMapHints(property, hint);
|
||||
}
|
||||
else {
|
||||
addValueHints(property, hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return repository;
|
||||
}
|
||||
|
||||
private void addValueHints(ConfigurationMetadataProperty property,
|
||||
ConfigurationMetadataHint hint) {
|
||||
property.getHints().getValueHints().addAll(hint.getValueHints());
|
||||
property.getHints().getValueProviders().addAll(hint.getValueProviders());
|
||||
}
|
||||
|
||||
private void addMapHints(ConfigurationMetadataProperty property,
|
||||
ConfigurationMetadataHint hint) {
|
||||
property.getHints().getKeyHints().addAll(hint.getValueHints());
|
||||
property.getHints().getKeyProviders().addAll(hint.getValueProviders());
|
||||
}
|
||||
|
||||
private ConfigurationMetadataSource getSource(RawConfigurationMetadata metadata,
|
||||
ConfigurationMetadataItem item) {
|
||||
if (item.getSourceType() != null) {
|
||||
return metadata.getSource(item.getSourceType());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder instance using {@link #UTF_8} as the default charset and the
|
||||
* specified json resource.
|
||||
* @param inputStreams the source input streams
|
||||
* @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance.
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public static ConfigurationMetadataRepositoryJsonBuilder create(
|
||||
InputStream... inputStreams) throws IOException {
|
||||
ConfigurationMetadataRepositoryJsonBuilder builder = create();
|
||||
for (InputStream inputStream : inputStreams) {
|
||||
builder = builder.withJsonResource(inputStream);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder instance using {@link #UTF_8} as the default charset.
|
||||
* @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance.
|
||||
*/
|
||||
public static ConfigurationMetadataRepositoryJsonBuilder create() {
|
||||
return create(UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder instance using the specified default {@link Charset}.
|
||||
* @param defaultCharset the default charset to use
|
||||
* @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance.
|
||||
*/
|
||||
public static ConfigurationMetadataRepositoryJsonBuilder create(
|
||||
Charset defaultCharset) {
|
||||
return new ConfigurationMetadataRepositoryJsonBuilder(defaultCharset);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A source of configuration metadata. Also defines where the source is declared, for
|
||||
* instance if it is defined as a {@code @Bean}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ConfigurationMetadataSource implements Serializable {
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String type;
|
||||
|
||||
private String description;
|
||||
|
||||
private String shortDescription;
|
||||
|
||||
private String sourceType;
|
||||
|
||||
private String sourceMethod;
|
||||
|
||||
private final Map<String, ConfigurationMetadataProperty> properties = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The identifier of the group to which this source is associated.
|
||||
* @return the group id
|
||||
*/
|
||||
public String getGroupId() {
|
||||
return this.groupId;
|
||||
}
|
||||
|
||||
void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the source. Usually this is the fully qualified name of a class that
|
||||
* defines configuration items. This class may or may not be available at runtime.
|
||||
* @return the type
|
||||
*/
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* A description of this source, if any. Can be multi-lines.
|
||||
* @return the description
|
||||
* @see #getShortDescription()
|
||||
*/
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* A single-line, single-sentence description of this source, if any.
|
||||
* @return the short description
|
||||
* @see #getDescription()
|
||||
*/
|
||||
public String getShortDescription() {
|
||||
return this.shortDescription;
|
||||
}
|
||||
|
||||
public void setShortDescription(String shortDescription) {
|
||||
this.shortDescription = shortDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type where this source is defined. This can be identical to the
|
||||
* {@link #getType() type} if the source is self-defined.
|
||||
* @return the source type
|
||||
*/
|
||||
public String getSourceType() {
|
||||
return this.sourceType;
|
||||
}
|
||||
|
||||
void setSourceType(String sourceType) {
|
||||
this.sourceType = sourceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The method name that defines this source, if any.
|
||||
* @return the source method
|
||||
*/
|
||||
public String getSourceMethod() {
|
||||
return this.sourceMethod;
|
||||
}
|
||||
|
||||
void setSourceMethod(String sourceMethod) {
|
||||
this.sourceMethod = sourceMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the properties defined by this source.
|
||||
* @return the properties
|
||||
*/
|
||||
public Map<String, ConfigurationMetadataProperty> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Indicate that a property is deprecated. Provide additional information about the
|
||||
* deprecation.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class Deprecation implements Serializable {
|
||||
|
||||
private Level level = Level.WARNING;
|
||||
|
||||
private String reason;
|
||||
|
||||
private String replacement;
|
||||
|
||||
/**
|
||||
* Define the {@link Level} of deprecation.
|
||||
* @return the deprecation level
|
||||
*/
|
||||
public Level getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
public void setLevel(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* A reason why the related property is deprecated, if any. Can be multi-lines.
|
||||
* @return the deprecation reason
|
||||
*/
|
||||
public String getReason() {
|
||||
return this.reason;
|
||||
}
|
||||
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* The full name of the property that replaces the related deprecated property, if
|
||||
* any.
|
||||
* @return the replacement property name
|
||||
*/
|
||||
public String getReplacement() {
|
||||
return this.replacement;
|
||||
}
|
||||
|
||||
public void setReplacement(String replacement) {
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Deprecation{" + "level='" + this.level + '\'' + ", reason='" + this.reason
|
||||
+ '\'' + ", replacement='" + this.replacement + '\'' + '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the deprecation level.
|
||||
*/
|
||||
public enum Level {
|
||||
|
||||
/**
|
||||
* The property is still bound.
|
||||
*/
|
||||
WARNING,
|
||||
|
||||
/**
|
||||
* The property has been removed and is no longer bound.
|
||||
*/
|
||||
ERROR
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.text.BreakIterator;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Utility to extract a description.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class DescriptionExtractor {
|
||||
|
||||
private static final String NEW_LINE = System.getProperty("line.separator");
|
||||
|
||||
public String getShortDescription(String description) {
|
||||
if (description == null) {
|
||||
return null;
|
||||
}
|
||||
int dot = description.indexOf(".");
|
||||
if (dot != -1) {
|
||||
BreakIterator breakIterator = BreakIterator.getSentenceInstance(Locale.US);
|
||||
breakIterator.setText(description);
|
||||
String text = description
|
||||
.substring(breakIterator.first(), breakIterator.next()).trim();
|
||||
return removeSpaceBetweenLine(text);
|
||||
}
|
||||
else {
|
||||
String[] lines = description.split(NEW_LINE);
|
||||
return lines[0].trim();
|
||||
}
|
||||
}
|
||||
|
||||
private String removeSpaceBetweenLine(String text) {
|
||||
String[] lines = text.split(NEW_LINE);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String line : lines) {
|
||||
sb.append(line.trim()).append(" ");
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Hints of an item to provide the list of values and/or the name of the provider
|
||||
* responsible to identify suitable values. If the type of the related item is a
|
||||
* {@link java.util.Map} it can have both key and value hints.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public class Hints {
|
||||
|
||||
private final List<ValueHint> keyHints = new ArrayList<>();
|
||||
|
||||
private final List<ValueProvider> keyProviders = new ArrayList<>();
|
||||
|
||||
private final List<ValueHint> valueHints = new ArrayList<>();
|
||||
|
||||
private final List<ValueProvider> valueProviders = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The list of well-defined keys, if any. Only applicable if the type of the related
|
||||
* item is a {@link java.util.Map}. If no extra {@link ValueProvider provider} is
|
||||
* specified, these values are to be considered a closed-set of the available keys for
|
||||
* the map.
|
||||
* @return the key hints
|
||||
*/
|
||||
public List<ValueHint> getKeyHints() {
|
||||
return this.keyHints;
|
||||
}
|
||||
|
||||
/**
|
||||
* The value providers that are applicable to the keys of this item. Only applicable
|
||||
* if the type of the related item is a {@link java.util.Map}. Only one
|
||||
* {@link ValueProvider} is enabled for a key: the first in the list that is supported
|
||||
* should be used.
|
||||
* @return the key providers
|
||||
*/
|
||||
public List<ValueProvider> getKeyProviders() {
|
||||
return this.keyProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of well-defined values, if any. If no extra {@link ValueProvider provider}
|
||||
* is specified, these values are to be considered a closed-set of the available
|
||||
* values for this item.
|
||||
* @return the value hints
|
||||
*/
|
||||
public List<ValueHint> getValueHints() {
|
||||
return this.valueHints;
|
||||
}
|
||||
|
||||
/**
|
||||
* The value providers that are applicable to this item. Only one
|
||||
* {@link ValueProvider} is enabled for an item: the first in the list that is
|
||||
* supported should be used.
|
||||
* @return the value providers
|
||||
*/
|
||||
public List<ValueProvider> getValueProviders() {
|
||||
return this.valueProviders;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Read standard json metadata format as {@link ConfigurationMetadataRepository}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
class JsonReader {
|
||||
|
||||
private static final int BUFFER_SIZE = 4096;
|
||||
|
||||
private final DescriptionExtractor descriptionExtractor = new DescriptionExtractor();
|
||||
|
||||
public RawConfigurationMetadata read(InputStream in, Charset charset)
|
||||
throws IOException {
|
||||
try {
|
||||
JSONObject json = readJson(in, charset);
|
||||
List<ConfigurationMetadataSource> groups = parseAllSources(json);
|
||||
List<ConfigurationMetadataItem> items = parseAllItems(json);
|
||||
List<ConfigurationMetadataHint> hints = parseAllHints(json);
|
||||
return new RawConfigurationMetadata(groups, items, hints);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof IOException) {
|
||||
throw (IOException) ex;
|
||||
}
|
||||
if (ex instanceof RuntimeException) {
|
||||
throw (RuntimeException) ex;
|
||||
}
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ConfigurationMetadataSource> parseAllSources(JSONObject root)
|
||||
throws Exception {
|
||||
List<ConfigurationMetadataSource> result = new ArrayList<>();
|
||||
if (!root.has("groups")) {
|
||||
return result;
|
||||
}
|
||||
JSONArray sources = root.getJSONArray("groups");
|
||||
for (int i = 0; i < sources.length(); i++) {
|
||||
JSONObject source = sources.getJSONObject(i);
|
||||
result.add(parseSource(source));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<ConfigurationMetadataItem> parseAllItems(JSONObject root)
|
||||
throws Exception {
|
||||
List<ConfigurationMetadataItem> result = new ArrayList<>();
|
||||
if (!root.has("properties")) {
|
||||
return result;
|
||||
}
|
||||
JSONArray items = root.getJSONArray("properties");
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject item = items.getJSONObject(i);
|
||||
result.add(parseItem(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<ConfigurationMetadataHint> parseAllHints(JSONObject root)
|
||||
throws Exception {
|
||||
List<ConfigurationMetadataHint> result = new ArrayList<>();
|
||||
if (!root.has("hints")) {
|
||||
return result;
|
||||
}
|
||||
JSONArray items = root.getJSONArray("hints");
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject item = items.getJSONObject(i);
|
||||
result.add(parseHint(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ConfigurationMetadataSource parseSource(JSONObject json) throws Exception {
|
||||
ConfigurationMetadataSource source = new ConfigurationMetadataSource();
|
||||
source.setGroupId(json.getString("name"));
|
||||
source.setType(json.optString("type", null));
|
||||
String description = json.optString("description", null);
|
||||
source.setDescription(description);
|
||||
source.setShortDescription(
|
||||
this.descriptionExtractor.getShortDescription(description));
|
||||
source.setSourceType(json.optString("sourceType", null));
|
||||
source.setSourceMethod(json.optString("sourceMethod", null));
|
||||
return source;
|
||||
}
|
||||
|
||||
private ConfigurationMetadataItem parseItem(JSONObject json) throws Exception {
|
||||
ConfigurationMetadataItem item = new ConfigurationMetadataItem();
|
||||
item.setId(json.getString("name"));
|
||||
item.setType(json.optString("type", null));
|
||||
String description = json.optString("description", null);
|
||||
item.setDescription(description);
|
||||
item.setShortDescription(
|
||||
this.descriptionExtractor.getShortDescription(description));
|
||||
item.setDefaultValue(readItemValue(json.opt("defaultValue")));
|
||||
item.setDeprecation(parseDeprecation(json));
|
||||
item.setSourceType(json.optString("sourceType", null));
|
||||
item.setSourceMethod(json.optString("sourceMethod", null));
|
||||
return item;
|
||||
}
|
||||
|
||||
private ConfigurationMetadataHint parseHint(JSONObject json) throws Exception {
|
||||
ConfigurationMetadataHint hint = new ConfigurationMetadataHint();
|
||||
hint.setId(json.getString("name"));
|
||||
if (json.has("values")) {
|
||||
JSONArray values = json.getJSONArray("values");
|
||||
for (int i = 0; i < values.length(); i++) {
|
||||
JSONObject value = values.getJSONObject(i);
|
||||
ValueHint valueHint = new ValueHint();
|
||||
valueHint.setValue(readItemValue(value.get("value")));
|
||||
String description = value.optString("description", null);
|
||||
valueHint.setDescription(description);
|
||||
valueHint.setShortDescription(
|
||||
this.descriptionExtractor.getShortDescription(description));
|
||||
hint.getValueHints().add(valueHint);
|
||||
}
|
||||
}
|
||||
if (json.has("providers")) {
|
||||
JSONArray providers = json.getJSONArray("providers");
|
||||
for (int i = 0; i < providers.length(); i++) {
|
||||
JSONObject provider = providers.getJSONObject(i);
|
||||
ValueProvider valueProvider = new ValueProvider();
|
||||
valueProvider.setName(provider.getString("name"));
|
||||
if (provider.has("parameters")) {
|
||||
JSONObject parameters = provider.getJSONObject("parameters");
|
||||
Iterator<?> keys = parameters.keys();
|
||||
while (keys.hasNext()) {
|
||||
String key = (String) keys.next();
|
||||
valueProvider.getParameters().put(key,
|
||||
readItemValue(parameters.get(key)));
|
||||
}
|
||||
}
|
||||
hint.getValueProviders().add(valueProvider);
|
||||
}
|
||||
}
|
||||
return hint;
|
||||
}
|
||||
|
||||
private Deprecation parseDeprecation(JSONObject object) throws Exception {
|
||||
if (object.has("deprecation")) {
|
||||
JSONObject deprecationJsonObject = object.getJSONObject("deprecation");
|
||||
Deprecation deprecation = new Deprecation();
|
||||
deprecation.setLevel(parseDeprecationLevel(
|
||||
deprecationJsonObject.optString("level", null)));
|
||||
deprecation.setReason(deprecationJsonObject.optString("reason", null));
|
||||
deprecation
|
||||
.setReplacement(deprecationJsonObject.optString("replacement", null));
|
||||
return deprecation;
|
||||
}
|
||||
return (object.optBoolean("deprecated") ? new Deprecation() : null);
|
||||
}
|
||||
|
||||
private Deprecation.Level parseDeprecationLevel(String value) {
|
||||
if (value != null) {
|
||||
try {
|
||||
return Deprecation.Level.valueOf(value.toUpperCase());
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// let's use the default
|
||||
}
|
||||
}
|
||||
return Deprecation.Level.WARNING;
|
||||
}
|
||||
|
||||
private Object readItemValue(Object value) throws Exception {
|
||||
if (value instanceof JSONArray) {
|
||||
JSONArray array = (JSONArray) value;
|
||||
Object[] content = new Object[array.length()];
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
content[i] = array.get(i);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private JSONObject readJson(InputStream in, Charset charset) throws Exception {
|
||||
try {
|
||||
StringBuilder out = new StringBuilder();
|
||||
InputStreamReader reader = new InputStreamReader(in, charset);
|
||||
char[] buffer = new char[BUFFER_SIZE];
|
||||
int bytesRead = -1;
|
||||
while ((bytesRead = reader.read(buffer)) != -1) {
|
||||
out.append(buffer, 0, bytesRead);
|
||||
}
|
||||
return new JSONObject(out.toString());
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A raw metadata structure. Used to initialize a {@link ConfigurationMetadataRepository}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
class RawConfigurationMetadata {
|
||||
|
||||
private final List<ConfigurationMetadataSource> sources;
|
||||
|
||||
private final List<ConfigurationMetadataItem> items;
|
||||
|
||||
private final List<ConfigurationMetadataHint> hints;
|
||||
|
||||
RawConfigurationMetadata(List<ConfigurationMetadataSource> sources,
|
||||
List<ConfigurationMetadataItem> items,
|
||||
List<ConfigurationMetadataHint> hints) {
|
||||
this.sources = new ArrayList<>(sources);
|
||||
this.items = new ArrayList<>(items);
|
||||
this.hints = new ArrayList<>(hints);
|
||||
for (ConfigurationMetadataItem item : this.items) {
|
||||
resolveName(item);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ConfigurationMetadataSource> getSources() {
|
||||
return this.sources;
|
||||
}
|
||||
|
||||
public ConfigurationMetadataSource getSource(String type) {
|
||||
for (ConfigurationMetadataSource source : this.sources) {
|
||||
if (type.equals(source.getType())) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ConfigurationMetadataItem> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public List<ConfigurationMetadataHint> getHints() {
|
||||
return this.hints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the name of an item against this instance.
|
||||
* @param item the item to resolve
|
||||
* @see ConfigurationMetadataProperty#setName(String)
|
||||
*/
|
||||
private void resolveName(ConfigurationMetadataItem item) {
|
||||
item.setName(item.getId()); // fallback
|
||||
if (item.getSourceType() == null) {
|
||||
return;
|
||||
}
|
||||
ConfigurationMetadataSource source = getSource(item.getSourceType());
|
||||
if (source != null) {
|
||||
String groupId = source.getGroupId();
|
||||
String dottedPrefix = groupId + ".";
|
||||
String id = item.getId();
|
||||
if (hasLength(groupId) && id.startsWith(dottedPrefix)) {
|
||||
String name = id.substring(dottedPrefix.length());
|
||||
item.setName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasLength(String string) {
|
||||
return (string != null && !string.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The default {@link ConfigurationMetadataRepository} implementation.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SimpleConfigurationMetadataRepository
|
||||
implements ConfigurationMetadataRepository, Serializable {
|
||||
|
||||
private final Map<String, ConfigurationMetadataGroup> allGroups = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Map<String, ConfigurationMetadataGroup> getAllGroups() {
|
||||
return Collections.unmodifiableMap(this.allGroups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ConfigurationMetadataProperty> getAllProperties() {
|
||||
Map<String, ConfigurationMetadataProperty> properties = new HashMap<>();
|
||||
for (ConfigurationMetadataGroup group : this.allGroups.values()) {
|
||||
properties.putAll(group.getProperties());
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the specified {@link ConfigurationMetadataSource sources}.
|
||||
* @param sources the sources to add
|
||||
*/
|
||||
public void add(Collection<ConfigurationMetadataSource> sources) {
|
||||
for (ConfigurationMetadataSource source : sources) {
|
||||
String groupId = source.getGroupId();
|
||||
ConfigurationMetadataGroup group = this.allGroups.get(groupId);
|
||||
if (group == null) {
|
||||
group = new ConfigurationMetadataGroup(groupId);
|
||||
this.allGroups.put(groupId, group);
|
||||
}
|
||||
String sourceType = source.getType();
|
||||
if (sourceType != null) {
|
||||
putIfAbsent(group.getSources(), sourceType, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@link ConfigurationMetadataProperty} with the
|
||||
* {@link ConfigurationMetadataSource source} that defines it, if any.
|
||||
* @param property the property to add
|
||||
* @param source the source
|
||||
*/
|
||||
public void add(ConfigurationMetadataProperty property,
|
||||
ConfigurationMetadataSource source) {
|
||||
if (source != null) {
|
||||
putIfAbsent(source.getProperties(), property.getId(), property);
|
||||
}
|
||||
putIfAbsent(getGroup(source).getProperties(), property.getId(), property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the content of the specified repository to this repository.
|
||||
* @param repository the repository to include
|
||||
*/
|
||||
public void include(ConfigurationMetadataRepository repository) {
|
||||
for (ConfigurationMetadataGroup group : repository.getAllGroups().values()) {
|
||||
ConfigurationMetadataGroup existingGroup = this.allGroups.get(group.getId());
|
||||
if (existingGroup == null) {
|
||||
this.allGroups.put(group.getId(), group);
|
||||
}
|
||||
else {
|
||||
// Merge properties
|
||||
for (Map.Entry<String, ConfigurationMetadataProperty> entry : group
|
||||
.getProperties().entrySet()) {
|
||||
putIfAbsent(existingGroup.getProperties(), entry.getKey(),
|
||||
entry.getValue());
|
||||
}
|
||||
// Merge sources
|
||||
for (Map.Entry<String, ConfigurationMetadataSource> entry : group
|
||||
.getSources().entrySet()) {
|
||||
putIfAbsent(existingGroup.getSources(), entry.getKey(),
|
||||
entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ConfigurationMetadataGroup getGroup(ConfigurationMetadataSource source) {
|
||||
if (source == null) {
|
||||
ConfigurationMetadataGroup rootGroup = this.allGroups.get(ROOT_GROUP);
|
||||
if (rootGroup == null) {
|
||||
rootGroup = new ConfigurationMetadataGroup(ROOT_GROUP);
|
||||
this.allGroups.put(ROOT_GROUP, rootGroup);
|
||||
}
|
||||
return rootGroup;
|
||||
}
|
||||
return this.allGroups.get(source.getGroupId());
|
||||
}
|
||||
|
||||
private <V> void putIfAbsent(Map<String, V> map, String key, V value) {
|
||||
if (!map.containsKey(key)) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Hint for a value a given property may have. Provide the value and an optional
|
||||
* description.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ValueHint implements Serializable {
|
||||
|
||||
private Object value;
|
||||
|
||||
private String description;
|
||||
|
||||
private String shortDescription;
|
||||
|
||||
/**
|
||||
* Return the hint value.
|
||||
* @return the value
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* A description of this value, if any. Can be multi-lines.
|
||||
* @return the description
|
||||
* @see #getShortDescription()
|
||||
*/
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* A single-line, single-sentence description of this hint, if any.
|
||||
* @return the short description
|
||||
* @see #getDescription()
|
||||
*/
|
||||
public String getShortDescription() {
|
||||
return this.shortDescription;
|
||||
}
|
||||
|
||||
public void setShortDescription(String shortDescription) {
|
||||
this.shortDescription = shortDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ValueHint{" + "value=" + this.value + ", description='" + this.description
|
||||
+ '\'' + '}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Define a component that is able to provide the values of a property.
|
||||
* <p>
|
||||
* Each provider is defined by a {@code name} and can have an arbitrary number of
|
||||
* {@code parameters}. The available providers are defined in the Spring Boot
|
||||
* documentation.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ValueProvider implements Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private final Map<String, Object> parameters = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Return the name of the provider.
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parameters.
|
||||
* @return the parameters
|
||||
*/
|
||||
public Map<String, Object> getParameters() {
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ValueProvider{" + "name='" + this.name + ", parameters=" + this.parameters
|
||||
+ '}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Spring Boot configuration meta-data parser.
|
||||
*/
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Base for configuration meta-data tests.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractConfigurationMetadataTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
protected void assertSource(ConfigurationMetadataSource actual, String groupId,
|
||||
String type, String sourceType) {
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual.getGroupId()).isEqualTo(groupId);
|
||||
assertThat(actual.getType()).isEqualTo(type);
|
||||
assertThat(actual.getSourceType()).isEqualTo(sourceType);
|
||||
}
|
||||
|
||||
protected void assertProperty(ConfigurationMetadataProperty actual, String id,
|
||||
String name, Class<?> type, Object defaultValue) {
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual.getId()).isEqualTo(id);
|
||||
assertThat(actual.getName()).isEqualTo(name);
|
||||
String typeName = type != null ? type.getName() : null;
|
||||
assertThat(actual.getType()).isEqualTo(typeName);
|
||||
assertThat(actual.getDefaultValue()).isEqualTo(defaultValue);
|
||||
}
|
||||
|
||||
protected void assertItem(ConfigurationMetadataItem actual, String sourceType) {
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual.getSourceType()).isEqualTo(sourceType);
|
||||
}
|
||||
|
||||
protected InputStream getInputStreamFor(String name) throws IOException {
|
||||
Resource r = new ClassPathResource(
|
||||
"metadata/configuration-metadata-" + name + ".json");
|
||||
return r.getInputStream();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConfigurationMetadataRepository}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ConfigurationMetadataRepositoryJsonBuilderTests
|
||||
extends AbstractConfigurationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void nullResource() throws IOException {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
ConfigurationMetadataRepositoryJsonBuilder.create().withJsonResource(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleRepository() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(foo).build();
|
||||
validateFoo(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(1);
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter");
|
||||
assertThat(repo.getAllProperties()).hasSize(3);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hintsOnMaps() throws IOException {
|
||||
try (InputStream map = getInputStreamFor("map")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(map).build();
|
||||
validateMap(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(1);
|
||||
contains(repo.getAllProperties(), "spring.map.first", "spring.map.second",
|
||||
"spring.map.keys", "spring.map.values");
|
||||
assertThat(repo.getAllProperties()).hasSize(4);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalRepositoriesNoConflict() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo");
|
||||
InputStream bar = getInputStreamFor("bar")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(foo, bar).build();
|
||||
validateFoo(repo);
|
||||
validateBar(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(2);
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter", "spring.bar.name", "spring.bar.description",
|
||||
"spring.bar.counter");
|
||||
assertThat(repo.getAllProperties()).hasSize(6);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoryWithRoot() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo");
|
||||
InputStream root = getInputStreamFor("root")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(foo, root).build();
|
||||
validateFoo(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(2);
|
||||
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter", "spring.root.name", "spring.root2.name");
|
||||
assertThat(repo.getAllProperties()).hasSize(5);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalRepositoriesIdenticalGroups() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo");
|
||||
InputStream foo2 = getInputStreamFor("foo2")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(foo, foo2).build();
|
||||
assertThat(repo.getAllGroups()).hasSize(1);
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo");
|
||||
contains(group.getSources(), "org.acme.Foo", "org.acme.Foo2",
|
||||
"org.springframework.boot.FooProperties");
|
||||
assertThat(group.getSources()).hasSize(3);
|
||||
contains(group.getProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter", "spring.foo.enabled", "spring.foo.type");
|
||||
assertThat(group.getProperties()).hasSize(5);
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter", "spring.foo.enabled", "spring.foo.type");
|
||||
assertThat(repo.getAllProperties()).hasSize(5);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyGroups() throws IOException {
|
||||
try (InputStream in = getInputStreamFor("empty-groups")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(in).build();
|
||||
validateEmptyGroup(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(1);
|
||||
contains(repo.getAllProperties(), "name", "title");
|
||||
assertThat(repo.getAllProperties()).hasSize(2);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void builderInstancesAreIsolated() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo");
|
||||
InputStream bar = getInputStreamFor("bar")) {
|
||||
ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create();
|
||||
ConfigurationMetadataRepository firstRepo = builder.withJsonResource(foo)
|
||||
.build();
|
||||
validateFoo(firstRepo);
|
||||
ConfigurationMetadataRepository secondRepo = builder.withJsonResource(bar)
|
||||
.build();
|
||||
validateFoo(secondRepo);
|
||||
validateBar(secondRepo);
|
||||
// first repo not impacted by second build
|
||||
assertThat(secondRepo).isNotEqualTo(firstRepo);
|
||||
assertThat(firstRepo.getAllGroups()).hasSize(1);
|
||||
assertThat(firstRepo.getAllProperties()).hasSize(3);
|
||||
assertThat(secondRepo.getAllGroups()).hasSize(2);
|
||||
assertThat(secondRepo.getAllProperties()).hasSize(6);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateFoo(ConfigurationMetadataRepository repo) {
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo");
|
||||
contains(group.getSources(), "org.acme.Foo",
|
||||
"org.springframework.boot.FooProperties");
|
||||
ConfigurationMetadataSource source = group.getSources().get("org.acme.Foo");
|
||||
contains(source.getProperties(), "spring.foo.name", "spring.foo.description");
|
||||
assertThat(source.getProperties()).hasSize(2);
|
||||
ConfigurationMetadataSource source2 = group.getSources()
|
||||
.get("org.springframework.boot.FooProperties");
|
||||
contains(source2.getProperties(), "spring.foo.name", "spring.foo.counter");
|
||||
assertThat(source2.getProperties()).hasSize(2);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.foo.name"), 0, 0);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.foo.description"), 0,
|
||||
0);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.foo.counter"), 1, 1);
|
||||
}
|
||||
|
||||
private void validateBar(ConfigurationMetadataRepository repo) {
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.bar");
|
||||
contains(group.getSources(), "org.acme.Bar",
|
||||
"org.springframework.boot.BarProperties");
|
||||
ConfigurationMetadataSource source = group.getSources().get("org.acme.Bar");
|
||||
contains(source.getProperties(), "spring.bar.name", "spring.bar.description");
|
||||
assertThat(source.getProperties()).hasSize(2);
|
||||
ConfigurationMetadataSource source2 = group.getSources()
|
||||
.get("org.springframework.boot.BarProperties");
|
||||
contains(source2.getProperties(), "spring.bar.name", "spring.bar.counter");
|
||||
assertThat(source2.getProperties()).hasSize(2);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.bar.name"), 0, 0);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.bar.description"), 2,
|
||||
2);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.bar.counter"), 0, 0);
|
||||
}
|
||||
|
||||
private void validateMap(ConfigurationMetadataRepository repo) {
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.map");
|
||||
ConfigurationMetadataSource source = group.getSources().get("org.acme.Map");
|
||||
contains(source.getProperties(), "spring.map.first", "spring.map.second",
|
||||
"spring.map.keys", "spring.map.values");
|
||||
assertThat(source.getProperties()).hasSize(4);
|
||||
ConfigurationMetadataProperty first = repo.getAllProperties()
|
||||
.get("spring.map.first");
|
||||
assertThat(first.getHints().getKeyHints()).hasSize(2);
|
||||
assertThat(first.getHints().getValueProviders()).hasSize(0);
|
||||
assertThat(first.getHints().getKeyHints().get(0).getValue()).isEqualTo("one");
|
||||
assertThat(first.getHints().getKeyHints().get(0).getDescription())
|
||||
.isEqualTo("First.");
|
||||
assertThat(first.getHints().getKeyHints().get(1).getValue()).isEqualTo("two");
|
||||
assertThat(first.getHints().getKeyHints().get(1).getDescription())
|
||||
.isEqualTo("Second.");
|
||||
ConfigurationMetadataProperty second = repo.getAllProperties()
|
||||
.get("spring.map.second");
|
||||
assertThat(second.getHints().getValueHints()).hasSize(2);
|
||||
assertThat(second.getHints().getValueProviders()).hasSize(0);
|
||||
assertThat(second.getHints().getValueHints().get(0).getValue()).isEqualTo("42");
|
||||
assertThat(second.getHints().getValueHints().get(0).getDescription())
|
||||
.isEqualTo("Choose me.");
|
||||
assertThat(second.getHints().getValueHints().get(1).getValue()).isEqualTo("24");
|
||||
assertThat(second.getHints().getValueHints().get(1).getDescription()).isNull();
|
||||
ConfigurationMetadataProperty keys = repo.getAllProperties()
|
||||
.get("spring.map.keys");
|
||||
assertThat(keys.getHints().getValueHints()).hasSize(0);
|
||||
assertThat(keys.getHints().getValueProviders()).hasSize(1);
|
||||
assertThat(keys.getHints().getValueProviders().get(0).getName()).isEqualTo("any");
|
||||
ConfigurationMetadataProperty values = repo.getAllProperties()
|
||||
.get("spring.map.values");
|
||||
assertThat(values.getHints().getValueHints()).hasSize(0);
|
||||
assertThat(values.getHints().getValueProviders()).hasSize(1);
|
||||
assertThat(values.getHints().getValueProviders().get(0).getName())
|
||||
.isEqualTo("handle-as");
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters())
|
||||
.hasSize(1);
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters()
|
||||
.get("target")).isEqualTo("java.lang.Integer");
|
||||
}
|
||||
|
||||
private void validateEmptyGroup(ConfigurationMetadataRepository repo) {
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("");
|
||||
contains(group.getSources(), "org.acme.Foo", "org.acme.Bar");
|
||||
ConfigurationMetadataSource source = group.getSources().get("org.acme.Foo");
|
||||
contains(source.getProperties(), "name");
|
||||
assertThat(source.getProperties()).hasSize(1);
|
||||
ConfigurationMetadataSource source2 = group.getSources().get("org.acme.Bar");
|
||||
contains(source2.getProperties(), "title");
|
||||
assertThat(source2.getProperties()).hasSize(1);
|
||||
validatePropertyHints(repo.getAllProperties().get("name"), 0, 0);
|
||||
validatePropertyHints(repo.getAllProperties().get("title"), 0, 0);
|
||||
}
|
||||
|
||||
private void validatePropertyHints(ConfigurationMetadataProperty property,
|
||||
int valueHints, int valueProviders) {
|
||||
assertThat(property.getHints().getValueHints().size()).isEqualTo(valueHints);
|
||||
assertThat(property.getHints().getValueProviders().size())
|
||||
.isEqualTo(valueProviders);
|
||||
}
|
||||
|
||||
private void contains(Map<String, ?> source, String... keys) {
|
||||
for (String key : keys) {
|
||||
assertThat(source).containsKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DescriptionExtractor}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class DescriptionExtractorTests {
|
||||
|
||||
private static final String NEW_LINE = System.getProperty("line.separator");
|
||||
|
||||
private DescriptionExtractor extractor = new DescriptionExtractor();
|
||||
|
||||
@Test
|
||||
public void extractShortDescription() {
|
||||
String description = this.extractor
|
||||
.getShortDescription("My short " + "description. More stuff.");
|
||||
assertThat(description).isEqualTo("My short description.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractShortDescriptionNewLineBeforeDot() {
|
||||
String description = this.extractor.getShortDescription(
|
||||
"My short" + NEW_LINE + "description." + NEW_LINE + "More stuff.");
|
||||
assertThat(description).isEqualTo("My short description.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractShortDescriptionNewLineBeforeDotWithSpaces() {
|
||||
String description = this.extractor.getShortDescription(
|
||||
"My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff.");
|
||||
assertThat(description).isEqualTo("My short description.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractShortDescriptionNoDot() {
|
||||
String description = this.extractor.getShortDescription("My short description");
|
||||
assertThat(description).isEqualTo("My short description");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractShortDescriptionNoDotMultipleLines() {
|
||||
String description = this.extractor
|
||||
.getShortDescription("My short description " + NEW_LINE + " More stuff");
|
||||
assertThat(description).isEqualTo("My short description");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractShortDescriptionNull() {
|
||||
assertThat(this.extractor.getShortDescription(null)).isEqualTo(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.configurationmetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.json.JSONException;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JsonReader}
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
|
||||
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
private final JsonReader reader = new JsonReader();
|
||||
|
||||
@Test
|
||||
public void emptyMetadata() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = readFor("empty");
|
||||
assertThat(rawMetadata.getSources()).isEmpty();
|
||||
assertThat(rawMetadata.getItems()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidMetadata() throws IOException {
|
||||
this.thrown.expectCause(CoreMatchers.<Throwable>instanceOf(JSONException.class));
|
||||
readFor("invalid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyGroupName() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = readFor("empty-groups");
|
||||
List<ConfigurationMetadataItem> items = rawMetadata.getItems();
|
||||
assertThat(items).hasSize(2);
|
||||
|
||||
ConfigurationMetadataItem name = items.get(0);
|
||||
assertProperty(name, "name", "name", String.class, null);
|
||||
ConfigurationMetadataItem dotTitle = items.get(1);
|
||||
assertProperty(dotTitle, "title", "title", String.class, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleMetadata() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = readFor("foo");
|
||||
List<ConfigurationMetadataSource> sources = rawMetadata.getSources();
|
||||
assertThat(sources).hasSize(2);
|
||||
List<ConfigurationMetadataItem> items = rawMetadata.getItems();
|
||||
assertThat(items).hasSize(4);
|
||||
List<ConfigurationMetadataHint> hints = rawMetadata.getHints();
|
||||
assertThat(hints).hasSize(1);
|
||||
|
||||
ConfigurationMetadataSource source = sources.get(0);
|
||||
assertSource(source, "spring.foo", "org.acme.Foo", "org.acme.config.FooApp");
|
||||
assertThat(source.getSourceMethod()).isEqualTo("foo()");
|
||||
assertThat(source.getDescription()).isEqualTo("This is Foo.");
|
||||
assertThat(source.getShortDescription()).isEqualTo("This is Foo.");
|
||||
|
||||
ConfigurationMetadataItem item = items.get(0);
|
||||
assertProperty(item, "spring.foo.name", "name", String.class, null);
|
||||
assertItem(item, "org.acme.Foo");
|
||||
ConfigurationMetadataItem item2 = items.get(1);
|
||||
assertProperty(item2, "spring.foo.description", "description", String.class,
|
||||
"FooBar");
|
||||
assertThat(item2.getDescription()).isEqualTo("Foo description.");
|
||||
assertThat(item2.getShortDescription()).isEqualTo("Foo description.");
|
||||
assertThat(item2.getSourceMethod()).isNull();
|
||||
assertItem(item2, "org.acme.Foo");
|
||||
|
||||
ConfigurationMetadataHint hint = hints.get(0);
|
||||
assertThat(hint.getId()).isEqualTo("spring.foo.counter");
|
||||
assertThat(hint.getValueHints()).hasSize(1);
|
||||
ValueHint valueHint = hint.getValueHints().get(0);
|
||||
assertThat(valueHint.getValue()).isEqualTo(42);
|
||||
assertThat(valueHint.getDescription()).isEqualTo(
|
||||
"Because that's the answer to any question, choose it. \nReally.");
|
||||
assertThat(valueHint.getShortDescription())
|
||||
.isEqualTo("Because that's the answer to any question, choose it.");
|
||||
assertThat(hint.getValueProviders()).hasSize(1);
|
||||
ValueProvider valueProvider = hint.getValueProviders().get(0);
|
||||
assertThat(valueProvider.getName()).isEqualTo("handle-as");
|
||||
assertThat(valueProvider.getParameters()).hasSize(1);
|
||||
assertThat(valueProvider.getParameters().get("target"))
|
||||
.isEqualTo(Integer.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metadataHints() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = readFor("bar");
|
||||
List<ConfigurationMetadataHint> hints = rawMetadata.getHints();
|
||||
assertThat(hints).hasSize(1);
|
||||
|
||||
ConfigurationMetadataHint hint = hints.get(0);
|
||||
assertThat(hint.getId()).isEqualTo("spring.bar.description");
|
||||
assertThat(hint.getValueHints()).hasSize(2);
|
||||
ValueHint valueHint = hint.getValueHints().get(0);
|
||||
assertThat(valueHint.getValue()).isEqualTo("one");
|
||||
assertThat(valueHint.getDescription()).isEqualTo("One.");
|
||||
ValueHint valueHint2 = hint.getValueHints().get(1);
|
||||
assertThat(valueHint2.getValue()).isEqualTo("two");
|
||||
assertThat(valueHint2.getDescription()).isEqualTo(null);
|
||||
|
||||
assertThat(hint.getValueProviders()).hasSize(2);
|
||||
ValueProvider valueProvider = hint.getValueProviders().get(0);
|
||||
assertThat(valueProvider.getName()).isEqualTo("handle-as");
|
||||
assertThat(valueProvider.getParameters()).hasSize(1);
|
||||
assertThat(valueProvider.getParameters().get("target"))
|
||||
.isEqualTo(String.class.getName());
|
||||
ValueProvider valueProvider2 = hint.getValueProviders().get(1);
|
||||
assertThat(valueProvider2.getName()).isEqualTo("any");
|
||||
assertThat(valueProvider2.getParameters()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootMetadata() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = readFor("root");
|
||||
List<ConfigurationMetadataSource> sources = rawMetadata.getSources();
|
||||
assertThat(sources).isEmpty();
|
||||
List<ConfigurationMetadataItem> items = rawMetadata.getItems();
|
||||
assertThat(items).hasSize(2);
|
||||
ConfigurationMetadataItem item = items.get(0);
|
||||
assertProperty(item, "spring.root.name", "spring.root.name", String.class, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deprecatedMetadata() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = readFor("deprecated");
|
||||
List<ConfigurationMetadataItem> items = rawMetadata.getItems();
|
||||
assertThat(items).hasSize(5);
|
||||
|
||||
ConfigurationMetadataItem item = items.get(0);
|
||||
assertProperty(item, "server.port", "server.port", Integer.class, null);
|
||||
assertThat(item.isDeprecated()).isTrue();
|
||||
assertThat(item.getDeprecation().getReason())
|
||||
.isEqualTo("Server namespace has moved to spring.server");
|
||||
assertThat(item.getDeprecation().getReplacement())
|
||||
.isEqualTo("server.spring.port");
|
||||
assertThat(item.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.WARNING);
|
||||
|
||||
ConfigurationMetadataItem item2 = items.get(1);
|
||||
assertProperty(item2, "server.cluster-name", "server.cluster-name", String.class,
|
||||
null);
|
||||
assertThat(item2.isDeprecated()).isTrue();
|
||||
assertThat(item2.getDeprecation().getReason()).isNull();
|
||||
assertThat(item2.getDeprecation().getReplacement()).isNull();
|
||||
assertThat(item.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.WARNING);
|
||||
|
||||
ConfigurationMetadataItem item3 = items.get(2);
|
||||
assertProperty(item3, "spring.server.name", "spring.server.name", String.class,
|
||||
null);
|
||||
assertThat(item3.isDeprecated()).isFalse();
|
||||
assertThat(item3.getDeprecation()).isEqualTo(null);
|
||||
|
||||
ConfigurationMetadataItem item4 = items.get(3);
|
||||
assertProperty(item4, "spring.server-name", "spring.server-name", String.class,
|
||||
null);
|
||||
assertThat(item4.isDeprecated()).isTrue();
|
||||
assertThat(item4.getDeprecation().getReason()).isNull();
|
||||
assertThat(item4.getDeprecation().getReplacement())
|
||||
.isEqualTo("spring.server.name");
|
||||
assertThat(item4.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.ERROR);
|
||||
|
||||
ConfigurationMetadataItem item5 = items.get(4);
|
||||
assertProperty(item5, "spring.server-name2", "spring.server-name2", String.class,
|
||||
null);
|
||||
assertThat(item5.isDeprecated()).isTrue();
|
||||
assertThat(item5.getDeprecation().getReason()).isNull();
|
||||
assertThat(item5.getDeprecation().getReplacement())
|
||||
.isEqualTo("spring.server.name");
|
||||
assertThat(item5.getDeprecation().getLevel())
|
||||
.isEqualTo(Deprecation.Level.WARNING);
|
||||
}
|
||||
|
||||
RawConfigurationMetadata readFor(String path) throws IOException {
|
||||
return this.reader.read(getInputStreamFor(path), DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"name": "spring.bar",
|
||||
"type": "org.acme.Bar",
|
||||
"sourceType": "org.acme.config.BarApp",
|
||||
"sourceMethod": "bar()",
|
||||
"description": "This is Bar."
|
||||
},
|
||||
{
|
||||
"name": "spring.bar",
|
||||
"type": "org.springframework.boot.BarProperties"
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.bar.name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Bar"
|
||||
},
|
||||
{
|
||||
"name": "spring.bar.description",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Bar",
|
||||
"description": "Bar description.",
|
||||
"defaultValue": "BarFoo"
|
||||
},
|
||||
{
|
||||
"name": "spring.bar.name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.springframework.boot.BarProperties"
|
||||
},
|
||||
{
|
||||
"name": "spring.bar.counter",
|
||||
"type": "java.lang.Integer",
|
||||
"sourceType": "org.springframework.boot.BarProperties",
|
||||
"defaultValue": 0
|
||||
}
|
||||
],
|
||||
"hints": [
|
||||
{
|
||||
"name": "spring.bar.description",
|
||||
"values": [
|
||||
{
|
||||
"value": "one",
|
||||
"description": "One."
|
||||
},
|
||||
{
|
||||
"value": "two"
|
||||
}
|
||||
],
|
||||
"providers": [
|
||||
{
|
||||
"name": "handle-as",
|
||||
"parameters": {
|
||||
"target": "java.lang.String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "any"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "server.port",
|
||||
"type": "java.lang.Integer",
|
||||
"deprecation": {
|
||||
"reason": "Server namespace has moved to spring.server",
|
||||
"replacement": "server.spring.port"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "server.cluster-name",
|
||||
"type": "java.lang.String",
|
||||
"deprecated": true
|
||||
},
|
||||
{
|
||||
"name": "spring.server.name",
|
||||
"type": "java.lang.String",
|
||||
"deprecated": false
|
||||
},
|
||||
{
|
||||
"name": "spring.server-name",
|
||||
"type": "java.lang.String",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"replacement": "spring.server.name"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.server-name2",
|
||||
"type": "java.lang.String",
|
||||
"deprecation": {
|
||||
"level": "INVALID",
|
||||
"replacement": "spring.server.name"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "org.acme.Foo",
|
||||
"sourceType": "org.acme.config.FooApp",
|
||||
"sourceMethod": "foo()",
|
||||
"description": "This is Foo."
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"type": "org.acme.Bar",
|
||||
"sourceType": "org.acme.config.FooApp",
|
||||
"sourceMethod": "bar()",
|
||||
"description": "This is Bar."
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Foo"
|
||||
},
|
||||
{
|
||||
"name": "title",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Bar"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"foo": "bar"
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"name": "spring.foo",
|
||||
"type": "org.acme.Foo",
|
||||
"sourceType": "org.acme.config.FooApp",
|
||||
"sourceMethod": "foo()",
|
||||
"description": "This is Foo."
|
||||
},
|
||||
{
|
||||
"name": "spring.foo",
|
||||
"type": "org.springframework.boot.FooProperties"
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.foo.name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Foo"
|
||||
},
|
||||
{
|
||||
"name": "spring.foo.description",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Foo",
|
||||
"description": "Foo description.",
|
||||
"defaultValue": "FooBar"
|
||||
},
|
||||
{
|
||||
"name": "spring.foo.name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.springframework.boot.FooProperties"
|
||||
},
|
||||
{
|
||||
"name": "spring.foo.counter",
|
||||
"type": "java.lang.Integer",
|
||||
"sourceType": "org.springframework.boot.FooProperties",
|
||||
"defaultValue": 0
|
||||
}
|
||||
],
|
||||
"hints": [
|
||||
{
|
||||
"name": "spring.foo.counter",
|
||||
"values": [
|
||||
{
|
||||
"value": 42,
|
||||
"description": "Because that's the answer to any question, choose it. \nReally."
|
||||
}
|
||||
],
|
||||
"providers": [
|
||||
{
|
||||
"name": "handle-as",
|
||||
"parameters": {
|
||||
"target": "java.lang.Integer"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"name": "spring.foo",
|
||||
"type": "org.acme.Foo2",
|
||||
"sourceType": "org.acme.config.FooApp",
|
||||
"sourceMethod": "foo2()",
|
||||
"description": "This is Foo2."
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.foo.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "org.acme.Foo2"
|
||||
},
|
||||
{
|
||||
"name": "spring.foo.type",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Foo2"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Invalid"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"name": "spring.map",
|
||||
"type": "org.acme.Map",
|
||||
"sourceType": "org.acme.config.MapApp",
|
||||
"sourceMethod": "map()",
|
||||
"description": "This is Map."
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.map.first",
|
||||
"type": "java.util.Map<String,String>",
|
||||
"sourceType": "org.acme.Map"
|
||||
},
|
||||
{
|
||||
"name": "spring.map.second",
|
||||
"type": "java.util.Map<String,String>",
|
||||
"sourceType": "org.acme.Map"
|
||||
},
|
||||
{
|
||||
"name": "spring.map.keys",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Map"
|
||||
},
|
||||
{
|
||||
"name": "spring.map.values",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Map"
|
||||
}
|
||||
],
|
||||
"hints": [
|
||||
{
|
||||
"name": "spring.map.first.keys",
|
||||
"values": [
|
||||
{
|
||||
"value": "one",
|
||||
"description": "First."
|
||||
},
|
||||
{
|
||||
"value": "two",
|
||||
"description": "Second."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "spring.map.second.values",
|
||||
"values": [
|
||||
{
|
||||
"value": "42",
|
||||
"description": "Choose me."
|
||||
},
|
||||
{
|
||||
"value": "24"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "spring.map.keys",
|
||||
"providers": [
|
||||
{
|
||||
"name": "any"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "spring.map.values",
|
||||
"providers": [
|
||||
{
|
||||
"name": "handle-as",
|
||||
"parameters": {
|
||||
"target": "java.lang.Integer"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.root.name",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"name": "spring.root2.name"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user