Properties Manager Maven Plugin

A container agnostic tool for properties file reading and monitoring

Лицензия

Лицензия

Категории

Категории

Maven Компиляция и сборка
Группа

Группа

io.github.thingersoft
Идентификатор

Идентификатор

properties-manager-maven-plugin
Последняя версия

Последняя версия

1.0.1
Дата

Дата

Тип

Тип

maven-plugin
Описание

Описание

Properties Manager Maven Plugin
A container agnostic tool for properties file reading and monitoring

Скачать properties-manager-maven-plugin

Как подключить последнюю версию

<plugin>
    <groupId>io.github.thingersoft</groupId>
    <artifactId>properties-manager-maven-plugin</artifactId>
    <version>1.0.1</version>
</plugin>

Зависимости

compile (8)

Идентификатор библиотеки Тип Версия
org.apache.maven : maven-plugin-api jar 3.6.0
org.jtwig : jtwig-core jar 5.87.0.RELEASE
org.javassist : javassist jar 3.23.1-GA
io.github.classgraph : classgraph jar 4.8.37
io.github.thingersoft : properties-manager-api jar 1.0.1
org.apache.commons : commons-lang3 jar 3.6
commons-io : commons-io jar 2.6
org.slf4j : slf4j-api jar 1.7.12

provided (3)

Идентификатор библиотеки Тип Версия
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.6.0
org.apache.maven : maven-core jar 3.6.0
org.apache.maven : maven-project jar 2.2.1

test (3)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
org.hamcrest : hamcrest-library jar 1.3
org.slf4j : slf4j-simple jar 1.7.25

Модули Проекта

Данный проект не имеет модулей.

Properties Manager

Maven Central Build Status

A container agnostic tool for application wide configuration through properties files.

Features

  • Hot reloading
  • Multiple source files aggregation
  • Automatic property type conversion
  • Declarative + programmatic API
  • Properties mapping generator

Dependency

<dependency>
    <groupId>io.github.thingersoft</groupId>
    <artifactId>properties-manager-api</artifactId>
    <version>LATEST</version>
</dependency>

Usage

Properties manager offers both declarative and programmatic APIs that can also be mixed together.
For the following examples we'll suppose to deal with this properties file:

sample.string = xxx
sample.integer = 2
sample.date = 01/01/1970

Declarative API

Configure the Properties Manager maven plugin:

<plugin>
    <groupId>io.github.thingersoft</groupId>
    <artifactId>properties-manager-maven-plugin</artifactId>
    <version>LATEST</version>
    <executions>
        <execution>
            <goals>
                <goal>enhance</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Create a mapping class:

@Properties(propertiesLocations = { "{sample.config.dir}/sample.properties" }, datePattern = "dd/MM/yyyy")
public class SampleProperties {

    @Property("sample.string")
    public static String sampleString;
    @Property("sample.integer")
    public static Integer sampleInteger;
    @Property("sample.date")
    public static Date sampleDate;

}

And that's it, the @Property annotated static fields will get injected with up to date properties values.
The @Properties type level annotation attributes can be used for configuration.


Automatic mapping class generation

The Properties Manager maven plugin also features automatic mapping through the "generate" goal:

<plugin>
    <groupId>io.github.thingersoft</groupId>
    <artifactId>properties-manager-maven-plugin</artifactId>
    <version>LATEST</version>
    <executions>
        <execution>
            <id>enhance</id>
            <goals>
                <goal>enhance</goal>
            </goals>
        </execution>
        <execution>
            <id>generate</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <basePackage>com.sample</basePackage>
                <propertiesLocations>
                    <propertiesLocation>{sample.config.dir}/sample.properties</propertiesLocation>
                </propertiesLocations>
                <templateFiles>
                    <templateFile>${project.parent.basedir}/config/sample.properties</templateFile>
                </templateFiles>
            </configuration>
        </execution>    
    </executions>
</plugin>

The above configuration will generate the following class and add it to your sources:

@Properties(
    propertiesLocations = { "{sample.config.dir}/sample.properties" },
    hotReload = true, 
    datePattern = "dd/MM/yy H.mm", 
    locale = "en_US", 
    obfuscatedPropertyPattern = "", 
    obfuscatedPropertyPlaceholder = "******"
)
public class ApplicationProperties {

    @Property("sample.string")
    public static String sampleString;
    @Property("sample.integer")
    public static String sampleInteger;
    @Property("sample.date")
    public static String sampleDate;

}

By default the generator will map properties to String fields, whose name will be inferred by converting property keys into camel case.
You can customize mapping behaviour and overall options through plugin configuration:
<plugin>
    <groupId>io.github.thingersoft</groupId>
    <artifactId>properties-manager-maven-plugin</artifactId>
    <version>LATEST</version>
    <executions>
        <execution>
            <id>generate</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <basePackage>com.sample</basePackage>
                <propertiesLocations>
                    <propertiesLocation>{sample.config.dir}/sample.properties</propertiesLocation>
                </propertiesLocations>
                <templateFiles>
                    <templateFile>${project.parent.basedir}/config/sample.properties</templateFile>
                </templateFiles>
                <options>
                    <datePattern>dd/MM/yyyy</datePattern>
                </options>
                <fieldMappings>
                    <fieldMapping>
                        <fieldName>customDateField</fieldName>
                        <fieldtype>DATE</fieldtype>
                        <propertyKey>sample.date</propertyKey>
                    </fieldMapping>
                </fieldMappings>
            </configuration>
        </execution>
        <execution>
            <id>enhance</id>
            <goals>
                <goal>enhance</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The above configuration will generate:

@Properties(
    propertiesLocations = { "{sample.config.dir}/sample.properties" },
    hotReload = true, 
    datePattern = "dd/MM/yyyy", 
    locale = "en_US", 
    obfuscatedPropertyPattern = "", 
    obfuscatedPropertyPlaceholder = "******"
)
public class SampleProperties {

    @Property("sample.string")
    public static String sampleString;
    @Property("sample.integer")
    public static String sampleInteger;
    @Property("sample.date")
    public static Date customDateField;

}

Programmatic API
PropertiesStore.getOptions().setDatePattern("dd/MM/yyyy");
PropertiesStore.loadProperties("etc/sample.properties");

String stringProperty = PropertiesStore.getProperty("sample.string");
Date dateProperty = PropertiesStore.getDate("sample.date");		

See javadocs for more details and available options.

Версии библиотеки

Версия
1.0.1
1.0.0