Code Monkey home page Code Monkey logo

runtimegoodies's Introduction

RuntimeGoodies Logo

A Java library for representing, reading, validating and fixing externally stored files/configs.



Description

RuntimeGoodies is a Java 8+ library that aims to solve a fundamental problem: reading & maintaining program configurations. It attemps to load external config files into declared POJOs with its custom annotations and validators. It even fixes the config when necessary (e.g an empty field is replaced by the default value and saved)

It comes with a few modules to support following formats:

  • JSON (module: com.github.iGoodie.RuntimeGoodies:json:<version-here>)
  • TOML 0.4.0 (module: com.github.iGoodie.RuntimeGoodies:toml:<version-here>)

Out of the box, it comes with a built-in way to universally represent entities during runtime called Goodies. Goodies are serializable in any format desired. They have a very similar structure to JSON elements. Goodies do not exist outside the runtime, they are in-memory only.

How to Use?

This library uses JitPack to serve artifacts that can be depended on. If your project is a Gradle project, use following steps:

  1. Add JitPack repository to your build.gradle file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Depend on desired release. (Replace <version-here> with the version of choice)
dependencies {
    implementation 'com.github.iGoodie.RuntimeGoodies:core:<version-here>'
    implementation 'com.github.iGoodie.RuntimeGoodies:json:<version-here>' // Format of choice, see supported formats above
}

List of all available the versions can be found under GitHub Releases section. Alternatively, master-SNAPSHOT can be used to depend on the nightly version (at your own risk).

Getting Started

  1. Create a POJO (ConfiGoodie) to represent the external config file. (In this example, external file is in JSON format)
public class ServerConfig extends JsonConfiGoodie {

    @Goodie // <-- Annotate the fields you want to be exposed with @Goodie
    String username, password;

    @Goodie
    Date launchDate; // Some values are converted from string!

    @Goodie
    int port = 3000; // You can declare default values!

    @Goodie
    DBConnection mongodbConnection; // Other ConfiGoodies/POJOs can be nested too!

    @Goodie
    DBConnection mysqlConnection = defaultValue(() -> {
        DBConnection connection = new DBConnection();
        connection.ports = Arrays.asList(3000, 3001, 3002);
        return connection;
    }); // You can declare default values via your own supplier!

    public static class DBConnection {

        @Goodie
        String uri = "localhost:3000";

        @Goodie
        List<Integer> ports; // You can have Lists as well!

        @Goodie
        Map<String, String> aliases; // Guess what, Maps too!

    }

}
  1. Instance that POJO and let RuntimeGoodie read (and fix if necessary) for you!
public class Test {

    public static void main(String[] args) {
        File configFile = new File("path/to/config.json");

        // Tadaaa! Your config object is now read, validated and fixed accordingly.
        ServerConfig config = new ServerConfig().readConfig(configFile);

        // Note that, the call above will override the file if changes are made during fixing phase.
        // Check out the Wiki, if you want to customize that behavior.
    }

}

In order to learn more about what else you can do, check the Wiki out!

Facing an Issue?

License

© 2021 Taha Anılcan Metinyurt (iGoodie)

For any part of this work for which the license is applicable, this work is licensed under the Attribution-NonCommercial-NoDerivatives 4.0 International license. (See LICENSE).

Creative Commons License

runtimegoodies's People

Contributors

igoodie avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.