From 8cfabc8cca3fca0bc6f7e16fe944bac346ea75e5 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Mon, 25 May 2020 14:02:50 +0200 Subject: [PATCH] Log warning if a known configuration file exists and we have no parser for it. (#1853) Signed-off-by: Tomas Langer --- .../io/helidon/config/MetaConfigFinder.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/config/config/src/main/java/io/helidon/config/MetaConfigFinder.java b/config/config/src/main/java/io/helidon/config/MetaConfigFinder.java index 7a71bc4aefe..392feff3515 100644 --- a/config/config/src/main/java/io/helidon/config/MetaConfigFinder.java +++ b/config/config/src/main/java/io/helidon/config/MetaConfigFinder.java @@ -19,8 +19,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.function.Function; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -41,6 +43,10 @@ final class MetaConfigFinder { private static final List CONFIG_SUFFIXES = List.of("yaml", "conf", "json", "properties"); private static final String META_CONFIG_PREFIX = "meta-config."; private static final String CONFIG_PREFIX = "application."; + // set of files/classpath resources that were found yet we have no parser configured for them + // limit logging to once per file + private static final Set FILES_LOGGED = new HashSet<>(); + private static final Set CLASSPATH_LOGGED = new HashSet<>(); private MetaConfigFinder() { } @@ -85,10 +91,13 @@ private static Optional findSource(Function suppo String type) { Optional source; + Set invalidSuffixes = new HashSet<>(CONFIG_SUFFIXES); List validSuffixes = CONFIG_SUFFIXES.stream() .filter(suffix -> supportedMediaType.apply(MediaTypes.detectExtensionType(suffix).orElse("unknown/unknown"))) .collect(Collectors.toList()); + validSuffixes.forEach(invalidSuffixes::remove); + // look into the file system - in current user directory source = validSuffixes.stream() .map(suf -> configPrefix + suf) @@ -101,11 +110,39 @@ private static Optional findSource(Function suppo } // and finally try to find meta configuration on classpath - return validSuffixes.stream() + source = validSuffixes.stream() .map(suf -> configPrefix + suf) .map(resource -> MetaConfigFinder.findClasspath(cl, resource, type)) .flatMap(Optional::stream) .findFirst(); + + if (source.isPresent()) { + return source; + } + + // now let's see if we have one of the invalid suffixes available + invalidSuffixes.stream() + .map(suf -> configPrefix + suf) + .forEach(it -> { + Optional found = findFile(it, type); + if (found.isPresent()) { + if (FILES_LOGGED.add(it)) { + LOGGER.warning("Configuration file " + + it + + " is on file system, yet there is no parser configured for it"); + } + } + found = MetaConfigFinder.findClasspath(cl, it, type); + if (found.isPresent()) { + if (CLASSPATH_LOGGED.add(it)) { + LOGGER.warning("Configuration file " + + it + + " is on classpath, yet there is no parser configured for it"); + } + } + }); + + return Optional.empty(); } private static Optional findFile(String name, String type) {