Example usage for org.springframework.boot.configurationmetadata SimpleConfigurationMetadataRepository SimpleConfigurationMetadataRepository

List of usage examples for org.springframework.boot.configurationmetadata SimpleConfigurationMetadataRepository SimpleConfigurationMetadataRepository

Introduction

In this page you can find the example usage for org.springframework.boot.configurationmetadata SimpleConfigurationMetadataRepository SimpleConfigurationMetadataRepository.

Prototype

SimpleConfigurationMetadataRepository

Source Link

Usage

From source file:com.github.alexfalappa.nbspringboot.projects.service.spi.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 {// w w w.j  av  a2s . c  o m
            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);
            }
        }
    }
    System.out.printf("Collections: %s%n", collectionProperties);
    System.out.printf("       Maps: %s%n", mapProperties);
}