Adding readme and build
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@ target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
|
||||
89
README.md
Normal file
89
README.md
Normal file
@@ -0,0 +1,89 @@
|
||||
|
||||
# ConfigurationUtilities
|
||||
|
||||
A java library to load config from cli-args, .env, toml-config and default values.
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
||||
|
||||
|
||||
## Acknowledgements
|
||||
This project depends on the following libraries:
|
||||
|
||||
- org.slf4j:slf4f-api
|
||||
- com.electronwill.night-config:toml
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Install ConfigurationUtilities with Maven
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>space.b00tload.utils</groupId>
|
||||
<artifactId>ConfigurationUtilities</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
## Usage/Examples
|
||||
Create an enum implementing the interface `space.b00tload.utils.configuration.ConfigValues` (e.g. as shown below).
|
||||
```java
|
||||
public enum ConfigurationValues implements ConfigValues {
|
||||
|
||||
DISCORD_TOKEN("discord-token", "db", "DISCORD_BOT_TOKEN", "discord.token.bot", null),
|
||||
DISCORD_APP_ID("discord-app-id", "da", "DISCORD_APPLICATION_ID", "discord.token.applicationid", null),
|
||||
DISCORD_PUB_KEY("discord-public-key", "dp", "DISCORD_PUBLIC_KEY", "discord.token.publickey", null),
|
||||
W2G_TOKEN("w2g-token", "w", "W2G_API_TOKEN", "w2g.token", null),
|
||||
ENDPOINT_PORT("webserver-port", "p", "WEBSERVER_PORT", "webserver.port", "86542"),
|
||||
;
|
||||
|
||||
private final String flag, flagAlias, env, toml, defaultValue;
|
||||
|
||||
ConfigValues(String flag, String flagAlias, String env, String toml, String defaultValue) {
|
||||
this.flag = flag;
|
||||
this.flagAlias = flagAlias;
|
||||
this.env = env;
|
||||
this.toml = toml;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
[... implement override methods]
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConfigValues{" +
|
||||
", defaultValue='" + defaultValue + '\'' +
|
||||
"tomlPath='" + toml + '\'' +
|
||||
", environmentVarName='" + env + '\'' +
|
||||
", flagAlias='" + flagAlias + '\'' +
|
||||
", flag='" + flag + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Afterwards initialize the Configuration using `Configuration.init(args, SOFTWARE_VERSION, APPLICATION_BASE, ConfigurationValues.values());`.
|
||||
- args = args passed to main-methods
|
||||
- SOFTWARE_VERSION = the version of your software
|
||||
- APPLICATION_BASE = the base directory for app data (config.toml will be saved in APPLICATION_BASE/config/)
|
||||
- ConfigurationValues.values() = values() method of the enum
|
||||
|
||||
## License
|
||||
|
||||
[GNU GPL v3](https://github.com/B00tLoad/ConfigurationUtilities/blob/master/LICENSE)
|
||||
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [@B00tLoad](https://www.github.com/B00tLoad)
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
For support, open an issue or contact me at alix (at) ja-lol-ey (dot) de.
|
||||
|
||||
93
pom.xml
93
pom.xml
@@ -13,6 +13,13 @@
|
||||
<inceptionYear>2024</inceptionYear>
|
||||
<url>https://github.com/B00tLoad/ConfigurationUtilities</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU GPL v3.0</name>
|
||||
<url>https://github.com/B00tLoad/ConfigurationUtilities/blob/master/LICENSE</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>B00tLoad_</id>
|
||||
@@ -32,9 +39,16 @@
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/B00tLoad/ConfigurationUtilities/.git</connection>
|
||||
<developerConnection>scm:git:ssh://github.com:B00tLoad/ConfigurationUtilities.git</developerConnection>
|
||||
<url>https://github.com/B00tLoad/ConfigurationUtilities/tree/master</url>
|
||||
</scm>
|
||||
|
||||
|
||||
<issueManagement>
|
||||
<system>GitHub</system>
|
||||
<url>https://github.com/B00tLoad/SnowflakeService/issues</url>
|
||||
<url>https://github.com/B00tLoad/ConfigurationUtilities/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<properties>
|
||||
@@ -47,12 +61,12 @@
|
||||
<dependencies>
|
||||
<!-- logging-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.13</version>
|
||||
</dependency>
|
||||
|
||||
<!-- config-->
|
||||
<!-- config file-->
|
||||
<dependency>
|
||||
<groupId>com.electronwill.night-config</groupId>
|
||||
<artifactId>toml</artifactId>
|
||||
@@ -60,4 +74,73 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>0.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<tokenAuth>true</tokenAuth>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<configuration>
|
||||
<tags>
|
||||
<tag>
|
||||
<name>example</name>
|
||||
<placement>a</placement>
|
||||
<head>Usage example:</head>
|
||||
</tag>
|
||||
</tags>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<keyname>${gpg.keyname}</keyname>
|
||||
<passphraseServerId>${gpg.keyname}</passphraseServerId>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -7,4 +7,79 @@ package space.b00tload.utils.configuration.exceptions;
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class ConfigException extends RuntimeException {}
|
||||
public class ConfigException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a new config exception with {@code null} as its
|
||||
* detail message. The cause is not initialized, and may subsequently be
|
||||
* initialized by a call to {@link #initCause}.
|
||||
*/
|
||||
public ConfigException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new config exception with the specified detail message.
|
||||
* The cause is not initialized, and may subsequently be initialized by a
|
||||
* call to {@link #initCause}.
|
||||
*
|
||||
* @param message the detail message. The detail message is saved for
|
||||
* later retrieval by the {@link #getMessage()} method.
|
||||
*/
|
||||
public ConfigException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new config exception with the specified detail message and
|
||||
* cause. <p>Note that the detail message associated with
|
||||
* {@code cause} is <i>not</i> automatically incorporated in
|
||||
* this config exception's detail message.
|
||||
*
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
* by the {@link #getMessage()} method).
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A {@code null} value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
*/
|
||||
public ConfigException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new config exception with the specified cause and a
|
||||
* detail message of {@code (cause==null ? null : cause.toString())}
|
||||
* (which typically contains the class and detail message of
|
||||
* {@code cause}). This constructor is useful for config exceptions
|
||||
* that are little more than wrappers for other throwables.
|
||||
*
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A {@code null} value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
*/
|
||||
public ConfigException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new config exception with the specified detail
|
||||
* message, cause, suppression enabled or disabled, and writable
|
||||
* stack trace enabled or disabled.
|
||||
*
|
||||
* @param message the detail message.
|
||||
* @param cause the cause. (A {@code null} value is permitted,
|
||||
* and indicates that the cause is nonexistent or unknown.)
|
||||
* @param enableSuppression whether or not suppression is enabled
|
||||
* or disabled
|
||||
* @param writableStackTrace whether or not the stack trace should
|
||||
* be writable
|
||||
* @since 1.7
|
||||
*/
|
||||
protected ConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class ConfigIncompleteException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* A {@code java.util.List} of {@code space.b00tload.utils.configuration.ConfigValues} for storing missing values.
|
||||
*/
|
||||
private final List<ConfigValues> missingValues;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user