Properties Manager

A container agnostic tool for properties file reading and monitoring

Лицензия

Лицензия

Группа

Группа

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

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

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

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

1.0.1
Дата

Дата

Тип

Тип

pom
Описание

Описание

Properties Manager
A container agnostic tool for properties file reading and monitoring
Ссылка на сайт

Ссылка на сайт

https://github.com/thingersoft/properties-manager
Система контроля версий

Система контроля версий

https://github.com/thingersoft/properties-manager

Скачать properties-manager

Имя Файла Размер
properties-manager-1.0.1.pom 4 KB
Обзор

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

<!-- https://jarcasting.com/artifacts/io.github.thingersoft/properties-manager/ -->
<dependency>
    <groupId>io.github.thingersoft</groupId>
    <artifactId>properties-manager</artifactId>
    <version>1.0.1</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/io.github.thingersoft/properties-manager/
implementation 'io.github.thingersoft:properties-manager:1.0.1'
// https://jarcasting.com/artifacts/io.github.thingersoft/properties-manager/
implementation ("io.github.thingersoft:properties-manager:1.0.1")
'io.github.thingersoft:properties-manager:pom:1.0.1'
<dependency org="io.github.thingersoft" name="properties-manager" rev="1.0.1">
  <artifact name="properties-manager" type="pom" />
</dependency>
@Grapes(
@Grab(group='io.github.thingersoft', module='properties-manager', version='1.0.1')
)
libraryDependencies += "io.github.thingersoft" % "properties-manager" % "1.0.1"
[io.github.thingersoft/properties-manager "1.0.1"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
org.apache.commons : commons-lang3 jar 3.6
commons-io : commons-io jar 2.6
org.slf4j : slf4j-api jar 1.7.12

test (3)

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

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

  • commons-test
  • api
  • maven-plugin

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