smallrye / smallrye-config

SmallRye Config - A Java Configuration library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `classpath:` scheme support (similar to Spring)

magicprinc opened this issue · comments

In Spring, one can (or rather have to) add classpath: scheme-prefix to a resource name to specify search of the resource in the ClassPath.

In SmallRyeConfig, "no prefix" means a ClassPath search.

Could you add additional/optional classpath: scheme-prefix support
(AbstractLocationConfigSourceLoader#loadConfigSources):

  • it makes using of SmallRyeConfig with Spring more pleasant and
  • it allows disabling search in the file system, if only the class path search is required.

See also: #1101

~

protected List<ConfigSource> loadConfigSources(final String[] locations, final int ordinal, final ClassLoader classLoader) {
  if (locations == null || locations.length == 0) {
    return Collections.emptyList();
  }

  final List<ConfigSource> configSources = new ArrayList<>();
  for (String location : locations) {
    final URI uri = URI_CONVERTER.convert(location);
    if (uri.getScheme() == null) {
      configSources.addAll(tryFileSystem(uri, ordinal));
      configSources.addAll(tryClassPath(uri, ordinal, classLoader));
    } else if ("classpath".equals(uri.getScheme())) {
      uri = new URI(uri.toString().substring(10));
      configSources.addAll(tryClassPath(uri, ordinal, classLoader));
    } else if (uri.getScheme().equals("file")) {
      configSources.addAll(tryFileSystem(uri, ordinal));
    } else if (uri.getScheme().equals("jar")) {
      configSources.addAll(tryJar(uri, ordinal));
    } else if (uri.getScheme().startsWith("http")) {
      configSources.addAll(tryHttpResource(uri, ordinal));
    } else {
      throw ConfigMessages.msg.schemeNotSupported(uri.getScheme());
    }
  }
  return configSources;
}```