Skip to content

Teragrep Configuration Library for Java

License

AGPL-3.0, Unknown licenses found

Licenses found

AGPL-3.0
LICENSE
Unknown
license-header
Notifications You must be signed in to change notification settings

teragrep/cnf_01

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Teragrep Configuration Library for Java

CNF-01 is a library that provides immutable configuration for Java projects. Immutability is achieved by converting the configuration source into an immutable Map. The resulting configuration Map can’t be altered even with modifying the underlying source.

Features

  • Provides immutable configurations for:

    1. configuration files / path properties (PathConfiguration)

    2. System Properties (PropertiesConfiguration)

    3. environment variables (EnvironmentConfiguration)

  • Default configurations in case the provided configurations from a source are not found or are otherwise broken (DefaultConfiguration)

Limitations

All planned configuration sources are not yet supported.

How to use

Configuration

All sources of configuration can be used with the Configuration interface. It provides the method asMap() which returns the immutable configurations.

An example with PathConfiguration:

Configuration configuration = new PathConfiguration("file/path");
Map<String, String> configurationMap = configuration.asMap();

Default configuration

You might want to specify default configurations in case something brakes. For example, the file path in the code block above might not be found. In the following example, notice how the Map with default configurations are given through the ImmutabilitySupportedMap object to ensure type safety. DefaultConfiguration only takes an ImmutableMap (provided in CNF-01) as a parameter for the defaults.

Map<String, String> map = new HashMap<>();
ImmutableMap<String, String> defaults = new ImmutabilitySupportedMap<>(map).toImmutableMap();

DefaultConfiguration defaultConfiguration = new DefaultConfiguration(
        new PathConfiguration("file/path"),
        defaults
);
Map<String, String> configurationMap = defaultConfiguration.asMap();

Configuration objects in your project

The configuration Map from CNF-01 shouldn’t be used directly in regular objects. It should only be passed to objects that are responsible for providing configured versions of other objects, in other words, Factories.

Small example with an Example object:

ExampleFactory exampleFactory = new ExampleFactory(configurationMap);
Example example = exampleFactory.example();

Here, the logic for instantiating an Example is in the ExampleFactory object, which receives the configuration map from CNF-01 as a parameter. This ensures that the main object Example is as clear as it can be.

Contributing

You can involve yourself with our project by opening an issue or submitting a pull request.

Contribution requirements:

  1. All changes must be accompanied by a new or changed test. If you think testing is not required in your pull request, include a sufficient explanation as why you think so.

  2. Security checks must pass

  3. Pull requests must align with the principles and values of extreme programming.

  4. Pull requests must follow the principles of Object Thinking and Elegant Objects (EO).

Read more in our Contributing Guideline.

Contributor License Agreement

Contributors must sign Teragrep Contributor License Agreement before a pull request is accepted to organization’s repositories.

You need to submit the CLA only once. After submitting the CLA you can contribute to all Teragrep’s repositories.