@CheckReturnValue @ParametersAreNonnullByDefault @ReturnValuesAreNonnullByDefault @FieldsAreNonnullByDefault

Package org.sosy_lab.common.configuration

Java-Config is a library for injecting configuration options in a decentralized way.

Configuration objects can be generated either from .properties configuration files, or from command line options. The usability is geared towards configuration files, but command line generation is also supported.

The library is conceptually similar to GFlags and allows arbitrary option injection throughout used classes.

Annotating classes with options

The example below demonstrates defining options for a class:

 
 @Options(prefix="grep")
 public class Grep {
   @Option(description="Ignore case of the query", secure=true)
   private boolean ignoreCase = false;

   @Option(description="File to search", secure=true)
   @FileOption(Type.REQUIRED_INPUT_FILE)
   private PathCounterTemplate haystack = null;

   public Grep(Configuration c) {
     c.inject(this);
   }

   public boolean search(String needle) {
      // ... search for a needle in a haystack.
   }
 
 

Note the following features:

  • @Option annotations are used to define various options associated with a class. Options are decentralized, the only requirement is that the Configuration object is injected (preferably in the constructor).
  • The fields defining options can be private. The injector contains reflection calls to set them to the arbitrary file.
  • Normally, the type of the option is defined by the type of the field. For complex cases (e.g. files) additional decorators are used.
  • Option name is either derived from the field name (prefixed with a base prefix), or set explicitly in the Option annotation.

Configuration options instance can be constructed in three different ways: