类org.springframework.boot.configurationmetadata.ConfigurationMetadataGroup源码实例Demo

下面列出了怎么用org.springframework.boot.configurationmetadata.ConfigurationMetadataGroup的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * Resolve all configuration metadata properties prefixed with {@code spring.cloud.deployer.}
 *
 * @return the list
 */
public List<ConfigurationMetadataProperty> resolve() {
	List<ConfigurationMetadataProperty> metadataProperties = new ArrayList<>();
	ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
	try {
		Resource[] resources = applicationContext.getResources(CONFIGURATION_METADATA_PATTERN);
		for (Resource resource : resources) {
			builder.withJsonResource(resource.getInputStream());
		}
	}
	catch (IOException e) {
		throw new SkipperException("Unable to read configuration metadata", e);
	}
	ConfigurationMetadataRepository metadataRepository = builder.build();
	Map<String, ConfigurationMetadataGroup> groups = metadataRepository.getAllGroups();
	// 1. go through all groups and their properties
	// 2. filter 'spring.cloud.deployer.' properties
	// 3. pass in only group includes, empty passes through all
	// 4. pass in group excludes
	// 5. same logic for properties for includes and excludes
	// 6. what's left is white/black listed props
	groups.values().stream()
		.filter(g -> g.getId().startsWith(KEY_PREFIX))
		.filter(groupEmptyOrAnyMatch(deployerProperties.getGroupIncludes()))
		.filter(groupNoneMatch(deployerProperties.getGroupExcludes()))
		.forEach(g -> {
			g.getProperties().values().stream()
				.filter(propertyEmptyOrAnyMatch(deployerProperties.getPropertyIncludes()))
				.filter(propertyNoneMatch(deployerProperties.getPropertyExcludes()))
				.forEach(p -> {
					metadataProperties.add(p);
				});
		});
	return metadataProperties;
}
 
源代码2 项目: joinfaces   文件: PropertyDocumentation.java
@TaskAction
public void generatePropertyDocumentation() throws IOException {
	ConfigurationMetadataRepository configurationMetadataRepository;

	configurationMetadataRepository = ConfigurationMetadataRepositoryJsonBuilder.create()
			.withJsonResource(new FileInputStream(getInputFile().getAsFile().get()))
			.build();

	try (PrintWriter writer = ResourceGroovyMethods.newPrintWriter(getOutputFile().getAsFile().get(), "UTF-8")) {

		writer.println("[source,properties,indent=0,subs=\"verbatim,attributes,macros\"]");
		writer.println("----");

		configurationMetadataRepository.getAllGroups().values().stream()
				.sorted(Comparator.comparing(ConfigurationMetadataGroup::getId))
				.forEach(group -> {
					writer.printf("## %s\n", group.getId());

					group.getSources().values()
							.stream()
							.map(ConfigurationMetadataSource::getShortDescription)
							.filter(s -> s != null && !s.isEmpty())
							.forEach(d -> writer.printf("# %s\n", d));

					group.getProperties().values().stream()
							.sorted(Comparator.comparing(ConfigurationMetadataProperty::getId))
							.forEach(property -> printProperty(writer, property));
					writer.println();
					writer.flush();
				});

		writer.println("----");
	}
}
 
/**
 * Resolve all configuration metadata properties prefixed with {@code spring.cloud.deployer.}
 *
 * @return the list
 */
public List<ConfigurationMetadataProperty> resolve() {
	List<ConfigurationMetadataProperty> metadataProperties = new ArrayList<>();
	ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
	try {
		Resource[] resources = applicationContext.getResources(CONFIGURATION_METADATA_PATTERN);
		for (Resource resource : resources) {
			builder.withJsonResource(resource.getInputStream());
		}
	}
	catch (IOException e) {
		throw new SkipperException("Unable to read configuration metadata", e);
	}
	ConfigurationMetadataRepository metadataRepository = builder.build();
	Map<String, ConfigurationMetadataGroup> groups = metadataRepository.getAllGroups();
	// 1. go through all groups and their properties
	// 2. filter 'spring.cloud.deployer.' properties
	// 3. pass in only group includes, empty passes through all
	// 4. pass in group excludes
	// 5. same logic for properties for includes and excludes
	// 6. what's left is white/black listed props
	groups.values().stream()
		.filter(g -> g.getId().startsWith(KEY_PREFIX))
		.filter(groupEmptyOrAnyMatch(deployerProperties.getGroupIncludes()))
		.filter(groupNoneMatch(deployerProperties.getGroupExcludes()))
		.forEach(g -> {
			g.getProperties().values().stream()
				.filter(propertyEmptyOrAnyMatch(deployerProperties.getPropertyIncludes()))
				.filter(propertyNoneMatch(deployerProperties.getPropertyExcludes()))
				.forEach(p -> {
					metadataProperties.add(p);
				});
		});
	return metadataProperties;
}
 
private Predicate<ConfigurationMetadataGroup> groupEmptyOrAnyMatch(String[] matches) {
	if (ObjectUtils.isEmpty(matches)) {
		return g -> true;
	}
	return g -> Arrays.stream(matches).anyMatch(g.getId()::equals);
}
 
private Predicate<ConfigurationMetadataGroup> groupNoneMatch(String[] matches) {
	return g -> Arrays.stream(matches).noneMatch(g.getId()::equals);
}
 
/**
 * Return whether a configuration property group (class) has been white listed as being a "main" group.
 */
private boolean isWhiteListed(ConfigurationMetadataGroup group, Collection<String> classes) {
	Set<String> sourceTypes = group.getSources().keySet();
	return !sourceTypes.isEmpty() && classes.containsAll(sourceTypes);
}
 
/**
 * Return whether a configuration property group (class) has been white listed as
 * being a "main" group.
 */
private boolean isWhiteListed(ConfigurationMetadataGroup group, Collection<String> classes) {
	Set<String> sourceTypes = group.getSources().keySet();
	return !sourceTypes.isEmpty() && classes.containsAll(sourceTypes);
}
 
private Predicate<ConfigurationMetadataGroup> groupEmptyOrAnyMatch(String[] matches) {
	if (ObjectUtils.isEmpty(matches)) {
		return g -> true;
	}
	return g -> Arrays.stream(matches).anyMatch(g.getId()::equals);
}
 
private Predicate<ConfigurationMetadataGroup> groupNoneMatch(String[] matches) {
	return g -> Arrays.stream(matches).noneMatch(g.getId()::equals);
}
 
 类所在包
 同包方法