EnumGen Core

Generate Java Enums based on resources

License

License

GroupId

GroupId

io.github.jkrauze.enumgen
ArtifactId

ArtifactId

enumgen-core
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

EnumGen Core
Generate Java Enums based on resources

Download enumgen-core

How to add to project

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

Dependencies

compile (5)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.6.1
org.reflections : reflections jar 0.9.12
commons-io : commons-io jar 2.6
org.freemarker : freemarker jar 2.3.30
org.jetbrains : annotations jar 13.0

provided (1)

Group / Artifact Type Version
org.immutables : value jar 2.8.2

test (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.6.2

Project Modules

There are no modules declared in this project.

EnumGen

Generate Java Enums based on resources.

Replace your manually built properties key enum or string constants with compile-time generated enum.

Example

Convert .properties file (TODO: .json and .yaml support)

application.properties

sample.key=Sample value
other.sample.key=Other sample value!

to Java enum

ApplicationKeys

public enum ApplicationKeys {

    OTHER_SAMPLE_KEY("other.sample.key", "Other sample value!"),
    SAMPLE_KEY("sample.key", "Sample value");

    private String key;
    private String defaultValue;

    ApplicationKeys(String key, String defaultValue) {
        this.key = key;
        this.defaultValue = defaultValue;
    }

    public String getKey() {
        return key;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

}

on the compile time.

You'll be able to use the enum to ensure your string keys.

Instead of

System.getProperty("sample.key")
// or
System.getProperty("sample.key", "Sample value")

you could do

System.getProperty(ApplicationKeys.SAMPLE_KEY.getKey());
// or
System.getProperty(ApplicationKeys.SAMPLE_KEY.getKey(), ApplicationKeys.SAMPLE_KEY.getDefaultValue());

what would help you find out if you're using wrong key at the compile time!

How to run?

Add the build plugin to your Maven project.

    <build>
        <plugins>
            <plugin>
                <groupId>io.github.jkrauze.enumgen</groupId>
                <artifactId>enumgen-maven-plugin</artifactId>
                <version>0.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-enum</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Configuration

TODO

            <plugin>
                ...
                <configuration>
                    <basePackageName>${project.groupId}.${project.artifactId}.resources</basePackageName>
                    <baseDir>src/main/resources</baseDir>
                    <recursive>true</recursive>
                    <outputBaseDir>target/generated-sources/enumgen</outputBaseDir>
                    <allowedExtensions>
                        <extension>properties</extension>
                        <!--TODO <extension>json</extension>-->
                        <!--TODO <extension>yaml</extension>-->
                    </allowedExtensions>
                    <enumClassNamePrefix></enumClassNamePrefix>
                    <enumClassNameSuffix>Keys</enumClassNameSuffix>
                </configuration>
            </plugin>

License

Licensed under the MIT License.

Versions

Version
0.1.0