org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder Java Examples
The following examples show how to use
org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeployerConfigurationMetadataResolver.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
/** * 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; }
Example #2
Source File: PropertyDocumentation.java From joinfaces with Apache License 2.0 | 5 votes |
@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("----"); } }
Example #3
Source File: DeployerConfigurationMetadataResolver.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * 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; }
Example #4
Source File: MetaDataTests.java From building-microservices with Apache License 2.0 | 5 votes |
@Test public void writeMetadataInfo() throws Exception { InputStream inputStream = new FileInputStream( "target/classes/META-INF/spring-configuration-metadata.json"); ConfigurationMetadataRepository repository = ConfigurationMetadataRepositoryJsonBuilder .create(UTF_8).withJsonResource(inputStream).build(); for (Map.Entry<String, ConfigurationMetadataProperty> entry : repository .getAllProperties().entrySet()) { System.out.println( entry.getKey() + " = " + entry.getValue().getShortDescription()); } }
Example #5
Source File: SpringBootServiceImpl.java From nb-springboot with Apache License 2.0 | 4 votes |
private void updateConfigRepo() { logger.fine("Updating config metadata repo"); repo = new SimpleConfigurationMetadataRepository(); final List<FileObject> cfgMetaFiles = cpExec.findAllResources(METADATA_JSON); for (FileObject fo : cfgMetaFiles) { try { ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create(); ConfigurationMetadataRepository currRepo; FileObject archiveFo = FileUtil.getArchiveFile(fo); if (archiveFo != null) { // parse and cache configuration metadata from JSON file in jar String archivePath = archiveFo.getPath(); if (!reposInJars.containsKey(archivePath)) { logger.log(INFO, "Unmarshalling configuration metadata from {0}", FileUtil.getFileDisplayName(fo)); ConfigurationMetadataRepository jarRepo = builder.withJsonResource(fo.getInputStream()).build(); reposInJars.put(archivePath, jarRepo); } currRepo = reposInJars.get(archivePath); } else { // parse configuration metadata from standalone JSON file (usually produced by spring configuration processor) logger.log(INFO, "Unmarshalling configuration metadata from {0}", FileUtil.getFileDisplayName(fo)); currRepo = builder.withJsonResource(fo.getInputStream()).build(); } repo.include(currRepo); } catch (Exception ex) { Exceptions.printStackTrace(ex); } } // update cached values cachedProperties = repo.getAllProperties(); // extract collection/map properties names based on heuristics for (Map.Entry<String, ConfigurationMetadataProperty> entry : cachedProperties.entrySet()) { final String type = entry.getValue().getType(); if (type != null) { final String key = entry.getKey(); if (type.startsWith("java.util.Map<")) { mapProperties.add(key); } if (type.startsWith("java.util.List<") || type.startsWith("java.util.Set<") || type.startsWith("java.util.Collection<")) { collectionProperties.add(key); } } } }