-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
368 additions
and
65 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
18 changes: 18 additions & 0 deletions
18
platform-library/src/main/java/platform/contracts/ConfigurationReader.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,18 @@ | ||
package platform.contracts; | ||
|
||
/** | ||
* Defines common expectation for the functionality which reads properties from configuration. | ||
* | ||
* <p>The exact details about how the configuration is read are irrelevant. | ||
*/ | ||
public interface ConfigurationReader { | ||
/** | ||
* Get a config for a path and a given class. | ||
* | ||
* @param path path to get the config for | ||
* @param clazz class to get the class for | ||
* @param <T> type of class to get | ||
* @return the configuration as a specified type | ||
*/ | ||
<T> T read(String path, Class<T> clazz); | ||
} |
2 changes: 2 additions & 0 deletions
2
platform-library/src/main/java/platform/contracts/package-info.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,2 @@ | ||
/** Defines contracts to help decouple library-specific code from the rest of the components. */ | ||
package platform.contracts; |
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
53 changes: 53 additions & 0 deletions
53
platform-library/src/main/java/platform/dependencies/ConfigurationReaderProvider.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,53 @@ | ||
package platform.dependencies; | ||
|
||
import io.github.suppierk.inject.Provides; | ||
import jakarta.inject.Singleton; | ||
import org.github.gestalt.config.builder.GestaltBuilder; | ||
import org.github.gestalt.config.exceptions.GestaltException; | ||
import org.github.gestalt.config.source.ClassPathConfigSourceBuilder; | ||
import platform.contracts.ConfigurationReader; | ||
|
||
/** | ||
* Factory to create an instance of {@link ConfigurationReader}. | ||
* | ||
* <p>Here we are using {@link org.github.gestalt.config.Gestalt} and this can be replaced as | ||
* needed. | ||
* | ||
* <p>This class is <b>NOT</b> {@code final} to allow its replacement in the {@link | ||
* io.github.suppierk.inject.Injector}, for example, during tests to be able to leverage | ||
* TestContainers as can be seen in {@link platform.test.AbstractApplicationTest}. | ||
*/ | ||
@Singleton | ||
public class ConfigurationReaderProvider { | ||
protected static final String CONFIGURATION_FILE = "application.yml"; | ||
|
||
/** | ||
* Initialize new {@link ConfigurationReader} instance. | ||
* | ||
* @return {@link org.github.gestalt.config.Gestalt} as {@link ConfigurationReader} | ||
* @throws Exception if {@link org.github.gestalt.config.Gestalt} cannot be instantiated | ||
*/ | ||
@Provides | ||
@Singleton | ||
@SuppressWarnings("unused") | ||
public ConfigurationReader configurationReader() throws Exception { | ||
final var gestalt = | ||
new GestaltBuilder() | ||
.addSource( | ||
ClassPathConfigSourceBuilder.builder().setResource(CONFIGURATION_FILE).build()) | ||
.build(); | ||
|
||
gestalt.loadConfigs(); | ||
|
||
return new ConfigurationReader() { | ||
@Override | ||
public <T> T read(String path, Class<T> clazz) { | ||
try { | ||
return gestalt.getConfig(path, clazz); | ||
} catch (GestaltException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
}; | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
platform-library/src/main/java/platform/dependencies/GestaltProvider.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.