Package org.sosy_lab.common.configuration


@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:

  • Class
    Description
    Immutable container that stores a value and an optional string.
    This is an optional annotation for all configuration options (i.e., elements that are annotated with Option) whose type is Class.
    Immutable wrapper around a map with properties, providing useful access helper methods.
    Interface for constructing Configuration instances.
    This is an annotation providing more features for options of types File and Path.
     
    This is an optional annotation for all configuration options (i.e., elements that are annotated with Option) whose type is an integer number (i.e., int, long, Integer and Long):
    Exception class to signal that something is wrong in the user-specified configuration.
    An annotation to mark fields or methods which should get configuration values injected.
    Annotation processor for checking constraints on Option and Options annotations.
    This class collects all Options of a program.
    This is a meta annotation that marks other annotation which may be used in conjunction with Option to provide more information for a specific option type.
    Annotation for a class which has fields or methods with an Option annotation.
    This is an annotation for all integer options that specify some sort of time duration (e.g., a timeout).