Skip to content
This repository has been archived by the owner on Oct 20, 2019. It is now read-only.
/ confy Public archive

Configuration library

License

Notifications You must be signed in to change notification settings

pitcer/confy

Repository files navigation

Build Status Download

Confy

Configuration library.

Add to project

Gradle

repositories {
    maven {
        url 'https://jcenter.bintray.com'
    }
}

dependencies {
    implementation 'pl.pitcer:confy:1.0.0'
}

Gradle Kotlin DSL

repositories {
    jcenter()
}

dependencies {
    implementation("pl.pitcer:confy:1.0.0")
}

Usage example

Create config POJO class. You can use annotations to change config and properties names:

import pl.pitcer.confy.annotation.Config;
import pl.pitcer.confy.annotation.Property;

@Config("database")
public class DatabaseConfig {

    @Property("host")
    private String hostname;
    private Integer port;
    private String user;
    private String password;

    public DatabaseConfig(String hostname, Integer port, String user, String password) {
        this.hostname = hostname;
        this.port = port;
        this.user = user;
        this.password = password;
    }

    public String getHostname() {
        return this.hostname;
    }

    public Integer getPort() {
        return this.port;
    }

    public String getUser() {
        return this.user;
    }

    public String getPassword() {
        return this.password;
    }
}

Initialize the config POJO with default values:

DatabaseConfig databaseConfig = new DatabaseConfig("localhost", 3306, "admin", "password");

Save the config to file:

DatabaseConfig databaseConfig = ...
File configFile = new File("database.conf");
Config<DatabaseConfig> config = new Config<>(DatabaseConfig.class, configFile);
config.save(databaseConfig);

Result:

database {
    host=localhost
    password=password
    port=3306
    user=admin
}

Now you can edit config file and read properties from it. They will be stored in config POJO:

database {
    host=1.1.1.1
    ...
}
Config<DatabaseConfig> config = ...
DatabaseConfig databaseConfig = config.load();
String hostname = databaseConfig.getHostname(); //1.1.1.1

Releases

No releases published

Packages

No packages published