Properties Manager Commons Test Artifacts

A container agnostic tool for properties file reading and monitoring

License

License

GroupId

GroupId

io.github.thingersoft
ArtifactId

ArtifactId

properties-manager-commons-test
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Properties Manager Commons Test Artifacts
A container agnostic tool for properties file reading and monitoring

Download properties-manager-commons-test

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
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)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-library jar 1.3
org.slf4j : slf4j-simple jar 1.7.25

Project Modules

There are no modules declared in this project.

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.

Versions

Version
1.0.1
1.0.0