EnumGen Maven Plugin

Generate Java Enums based on resources

Лицензия

Лицензия

Категории

Категории

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

Группа

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

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

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

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

0.1.0
Дата

Дата

Тип

Тип

maven-plugin
Описание

Описание

EnumGen Maven Plugin
Generate Java Enums based on resources
Ссылка на сайт

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

http://maven.apache.org

Скачать enumgen-maven-plugin

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

<plugin>
    <groupId>io.github.jkrauze.enumgen</groupId>
    <artifactId>enumgen-maven-plugin</artifactId>
    <version>0.1.0</version>
</plugin>

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
io.github.jkrauze.enumgen : enumgen-core jar 0.1.0
org.apache.maven : maven-compat jar 3.6.1
org.apache.maven : maven-core jar 3.6.1

provided (2)

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

test (2)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.13
org.apache.maven.plugin-testing : maven-plugin-testing-harness jar 3.3.0

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

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

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.

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

Версия
0.1.0