Java 类org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder 实例源码

项目:building-microservices    文件:MetaDataTests.java   
@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());
    }
}
项目:nb-springboot    文件:SpringBootServiceImpl.java   
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.contains("Map<")) {
                mapProperties.add(key);
            }
            if (type.contains("List<") || type.contains("Set<") || type.contains("Collection<")) {
                collectionProperties.add(key);
            }
        }
    }
}