-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support application configuration file by default (#1190)
- Loading branch information
Showing
11 changed files
with
279 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
implementation/src/main/java/io/smallrye/config/PropertiesConfigSourceLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.smallrye.config; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
import org.eclipse.microprofile.config.spi.ConfigSourceProvider; | ||
|
||
public class PropertiesConfigSourceLoader extends AbstractLocationConfigSourceLoader { | ||
protected final String path; | ||
protected final int ordinal; | ||
|
||
PropertiesConfigSourceLoader(final String path, final int ordinal) { | ||
this.path = path; | ||
this.ordinal = ordinal; | ||
} | ||
|
||
@Override | ||
protected String[] getFileExtensions() { | ||
return new String[] { "properties" }; | ||
} | ||
|
||
@Override | ||
protected ConfigSource loadConfigSource(final URL url, final int ordinal) throws IOException { | ||
return new PropertiesConfigSource(url, ordinal); | ||
} | ||
|
||
public static List<ConfigSource> inClassPath(final String path, final int ordinal, final ClassLoader loader) { | ||
return new InClassPath(path, ordinal).getConfigSources(loader); | ||
} | ||
|
||
public static List<ConfigSource> inFileSystem(final String path, final int ordinal, final ClassLoader loader) { | ||
return new InFileSystem(path, ordinal).getConfigSources(loader); | ||
} | ||
|
||
private static class InClassPath extends PropertiesConfigSourceLoader implements ConfigSourceProvider { | ||
public InClassPath(final String path, final int ordinal) { | ||
super(path, ordinal); | ||
} | ||
|
||
@Override | ||
public List<ConfigSource> getConfigSources(final ClassLoader classLoader) { | ||
return loadConfigSources(path, ordinal, classLoader); | ||
} | ||
|
||
@Override | ||
protected List<ConfigSource> tryFileSystem(final URI uri, final int ordinal) { | ||
return emptyList(); | ||
} | ||
} | ||
|
||
private static class InFileSystem extends PropertiesConfigSourceLoader implements ConfigSourceProvider { | ||
public InFileSystem(final String path, final int ordinal) { | ||
super(path, ordinal); | ||
} | ||
|
||
@Override | ||
public List<ConfigSource> getConfigSources(final ClassLoader classLoader) { | ||
return loadConfigSources(path, ordinal, classLoader); | ||
} | ||
|
||
@Override | ||
protected List<ConfigSource> tryClassPath(final URI uri, final int ordinal, final ClassLoader classLoader) { | ||
return emptyList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSourceLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.smallrye.config.source.yaml; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
import org.eclipse.microprofile.config.spi.ConfigSourceProvider; | ||
|
||
import io.smallrye.config.AbstractLocationConfigSourceLoader; | ||
|
||
public class YamlConfigSourceLoader extends AbstractLocationConfigSourceLoader { | ||
@Override | ||
protected String[] getFileExtensions() { | ||
return new String[] { | ||
"yaml", | ||
"yml" | ||
}; | ||
} | ||
|
||
@Override | ||
protected ConfigSource loadConfigSource(final URL url, final int ordinal) throws IOException { | ||
return new YamlConfigSource(url, ordinal); | ||
} | ||
|
||
public static class InClassPath extends YamlConfigSourceLoader implements ConfigSourceProvider { | ||
@Override | ||
public List<ConfigSource> getConfigSources(final ClassLoader classLoader) { | ||
List<ConfigSource> configSources = new ArrayList<>(); | ||
configSources.addAll(loadConfigSources("application.yaml", 255, classLoader)); | ||
configSources.addAll(loadConfigSources("application.yml", 255, classLoader)); | ||
configSources.addAll(loadConfigSources("META-INF/microprofile-config.yaml", 110, classLoader)); | ||
configSources.addAll(loadConfigSources("META-INF/microprofile-config.yml", 110, classLoader)); | ||
return configSources; | ||
} | ||
|
||
@Override | ||
protected List<ConfigSource> tryFileSystem(final URI uri, final int ordinal) { | ||
return emptyList(); | ||
} | ||
} | ||
|
||
public static class InFileSystem extends YamlConfigSourceLoader implements ConfigSourceProvider { | ||
@Override | ||
public List<ConfigSource> getConfigSources(final ClassLoader classLoader) { | ||
List<ConfigSource> configSources = new ArrayList<>(); | ||
configSources.addAll(loadConfigSources( | ||
Paths.get(System.getProperty("user.dir"), "config", "application.yaml").toUri().toString(), 265, | ||
classLoader)); | ||
configSources.addAll( | ||
loadConfigSources(Paths.get(System.getProperty("user.dir"), "config", "application.yml").toUri().toString(), | ||
265, classLoader)); | ||
return configSources; | ||
} | ||
|
||
@Override | ||
protected List<ConfigSource> tryClassPath(final URI uri, final int ordinal, final ClassLoader classLoader) { | ||
return emptyList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSourceProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
io.smallrye.config.source.yaml.YamlConfigSourceProvider | ||
io.smallrye.config.source.yaml.YamlConfigSourceLoader$InClassPath | ||
io.smallrye.config.source.yaml.YamlConfigSourceLoader$InFileSystem |
Oops, something went wrong.