Coder Social home page Coder Social logo

configme's Introduction

ConfigMe

Build Status Coverage Status Javadocs Code Climate

A simple configuration management library with YAML support out of the box.

  • Lightweight
  • Flexible
  • Out of the box support for YAML
  • Allows migrations / config file checks
  • Null-safe
  • Unit testing friendly

How it works

  • Each configurable value is a Property in ConfigMe. Properties are declared as public static final fields in classes which implement the SettingsHolder interface.
  • Configurations are read from a PropertyResource (e.g. the provided YamlFileResource), which abstracts reading and writing.
  • The property resource may be checked for completeness with the MigrationService, which allows you also to rename properties or to remove obsolete ones.
  • The SettingsManager unifies the members above. On creation, it calls the migration service and allows you to get and change property values.

Integration

Start using ConfigMe by adding this to your pom.xml:

<dependencies>
    <dependency>
        <groupId>ch.jalu</groupId>
        <artifactId>configme</artifactId>
        <version>1.4.1</version>
    </dependency>
</dependencies>

Example

config.yml

title:
    text: 'Hello'
    size: 12

TitleConfig.java

public class TitleConfig implements SettingsHolder {

    public static final Property<String> TITLE_TEXT =
        newProperty("title.text", "-Default-");

    public static final Property<Integer> TITLE_SIZE =
        newProperty("title.size", 10);

    private TitleConfig() {
        // prevent instantiation
    }
}

WelcomeWriter.java

public class WelcomeWriter {
    public String generateWelcomeMessage() {
        SettingsManager settings = SettingsManagerBuilder
            .withYamlFile(Path.of("config.yml"))
            .configurationData(TitleConfig.class)
            .useDefaultMigrationService()
            .create();

        // Get properties from the settings manager
        return "<font size=\""
            + settings.getProperty(TitleConfig.TITLE_SIZE) + "\">"
            + settings.getProperty(TitleConfig.TITLE_TEXT) + "</font>";
    }
}

๐Ÿ“ Read the full documentation in the ConfigMe Wiki.

๐Ÿ“ See a full working example based on this here.

๐Ÿ“ See how to use custom classes as property types in the bean properties demo.

configme's People

Contributors

ljacqu avatar sgdc3 avatar sxtanna avatar zenegix avatar gamerover98 avatar dependabot-support avatar yagahut avatar sharief007 avatar dependabot[bot] avatar zrdzn avatar dependabot-preview[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.