1
mirror of https://github.com/CarmJos/EasyConfiguration.git synced 2024-09-16 18:55:50 +00:00
轻松(做)配置,简单便捷的通用配置文件加载、读取与更新工具,可自定义配置格式。
Go to file
dependabot[bot] 9626ed8f49 chore(deps): Bump org.apache.maven.plugins:maven-gpg-plugin
Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.4 to 3.2.5.
- [Release notes](https://github.com/apache/maven-gpg-plugin/releases)
- [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.4...maven-gpg-plugin-3.2.5)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-gpg-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-14 22:50:32 +08:00
.doc docs(readme): Add English version of README files. 2023-12-23 21:15:15 +08:00
.github docs(readme): Add English version of README files. 2023-12-23 21:15:15 +08:00
core chore(map): Optimize Map builders. 2024-01-05 01:26:50 +08:00
demo build(plugin): Fixed build plugins missing. 2023-12-24 20:59:50 +08:00
impl chore(deps-dev): Bump log4j.version from 2.23.1 to 2.24.0 2024-09-14 22:49:11 +08:00
.gitignore 初始版本完成 2022-04-17 00:32:33 +08:00
LICENSE [skip-ci] 修改开源协议 2022-04-22 17:44:21 +08:00
pom.xml chore(deps): Bump org.apache.maven.plugins:maven-gpg-plugin 2024-09-14 22:50:32 +08:00
README_CN.md docs(url): Fixed url 2024-01-14 01:44:05 +08:00
README.md docs(url): Fixed url 2024-01-14 01:44:05 +08:00

   ____                _____          ____                    __  _
  / __/__ ____ __ __  / ___/__  ___  / _(_)__ ___ _________ _/ /_(_)__  ___
 / _// _ `(_-</ // / / /__/ _ \/ _ \/ _/ / _ `/ // / __/ _ `/ __/ / _ \/ _ \
/___/\_,_/___/\_, /  \___/\___/_//_/_//_/\_, /\_,_/_/  \_,_/\__/_/\___/_//_/
             /___/                      /___/

README LANGUAGES [ English | 中文 ]

EasyConfiguration

version License workflow CodeFactor CodeSize

Easy (to make) Configurations!

A simple, easy-to-use and universal solution for managing configuration files. Enjoy the ease of use with customizable formats for loading, reading, and updating your configuration files.

Features & Advantages

Supported YAML, JSON, HOCON and SQL based configuration files format.

  • Class-based mechanism for initializing, loading, retrieving, and updating configuration files, ensuring convenience and efficiency.
  • Supports manual serialization and deserialization of complex configurations.
  • Offers multiple builder forms for rapid construction of ConfigValue<?> objects.
  • Enables specification of configuration paths, comments, and more via annotations.

Development

For the latest JavaDoc release, CLICK HERE.

For a detailed development guide, CLICK HERE.

Code Samples

To quickly demonstrate the applicability of the project, here are a few practical demonstrations:

Check out all code demonstrations HERE. For more examples, see the Development Guide.

@HeaderComment("Configurations for sample")
interface SampleConfig extends Configuration {

    @InlineComment("Enabled?") // Inline comment
    ConfiguredValue<Boolean> ENABLED = ConfiguredValue.of(true);

    ConfiguredList<UUID> UUIDS = ConfiguredList.builderOf(UUID.class).fromString()
            .parseValue(UUID::fromString).serializeValue(UUID::toString)
            .defaults(
                    UUID.fromString("00000000-0000-0000-0000-000000000000"),
                    UUID.fromString("00000000-0000-0000-0000-000000000001")
            ).build();

    interface INFO extends Configuration {
        
        @HeaderComment("Configure your name!") // Header comment
        ConfiguredValue<String> NAME = ConfiguredValue.of("Joker");

        @ConfigPath("year") // Custom path
        ConfiguredValue<Integer> AGE = ConfiguredValue.of(24);
    
    }
}
public class Sample {
  public static void main(String[] args) {
    // 1. Make a configuration provider from a file.
    ConfigurationProvider<?> provider = EasyConfiguration.from("config.yml");
    // 2. Initialize the configuration classes or instances.
    provider.initialize(SampleConfig.class);
    // 3. Enjoy using the configuration!
    SampleConfig.ENABLED.set(false);
    System.out.println("Your name is " + SampleConfig.INFO.NAME.getNotNull() + " !");
  }
}

# Configurations for sample

enabled: true # Enabled?

uuids:
  - 00000000-0000-0000-0000-000000000000
  - 00000000-0000-0000-0000-000000000001

info:
  # Configure your name!
  name: Joker
  year: 24

Dependencies

Maven Dependency

Remote Repository Configuration

<project>
    <repositories>

        <repository>
            <!-- Using Maven Central Repository for secure and stable updates, though synchronization might be needed. -->
            <id>maven</id>
            <name>Maven Central</name>
            <url>https://repo1.maven.org/maven2</url>
        </repository>

        <repository>
            <!-- Using GitHub dependencies for real-time updates, configuration required (recommended). -->
            <id>EasyConfiguration</id>
            <name>GitHub Packages</name>
            <url>https://maven.pkg.github.com/CarmJos/EasyConfiguration</url>
        </repository>

    </repositories>
</project>
Generic Native Dependency

<project>
    <dependencies>
        <!-- Basic implementation part, requiring custom implementation of “Provider” and “Wrapper”. -->
        <dependency>
            <groupId>cc.carm.lib</groupId>
            <artifactId>easyconfiguration-core</artifactId>
            <version>[LATEST RELEASE]</version>
            <scope>compile</scope>
        </dependency>

        <!-- YAML file-based implementation, compatible with all Java environments. -->
        <dependency>
            <groupId>cc.carm.lib</groupId>
            <artifactId>easyconfiguration-yaml</artifactId>
            <version>[LATEST RELEASE]</version>
            <scope>compile</scope>
        </dependency>

        <!-- JSON file-based implementation, compatible with all Java environments. Note: JSON does not support file comments. -->
        <dependency>
            <groupId>cc.carm.lib</groupId>
            <artifactId>easyconfiguration-json</artifactId>
            <version>[LATEST RELEASE]</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>
</project>

Gradle Dependency

Remote Repository Configuration
repositories {

    // Using Maven Central Repository for secure and stable updates, though synchronization might be needed.
    mavenCentral()

    // Using GitHub dependencies for real-time updates, configuration required (recommended).
    maven { url 'https://maven.pkg.github.com/CarmJos/EasyConfiguration' }

}
Generic Native Dependency

dependencies {

    // Basic implementation part, requiring custom implementation of “Provider” and “Wrapper”.
    api "cc.carm.lib:easyconfiguration-core:[LATEST RELEASE]"

    // YAML file-based implementation, compatible with all Java environments.
    api "cc.carm.lib:easyconfiguration-yaml:[LATEST RELEASE]"

    // JSON file-based implementation, compatible with all Java environments. Note: JSON does not support file comments.
    api "cc.carm.lib:easyconfiguration-json:[LATEST RELEASE]"

}

Derived Projects

MineConfiguration (by @CarmJos)

EasyConfiguration for MineCraft! Easily manage configurations on MineCraft-related server platforms.

Currently supports BungeeCord, Bukkit (Spigot) servers, with more platforms to be supported soon.

Support and Donation

If you appreciate this plugin, consider supporting me with a donation!

Thank you for supporting open-source projects!

Many thanks to Jetbrains for kindly providing a license for us to work on this and other open-source projects.

Open Source License

This project's source code is licensed under the GNU LESSER GENERAL PUBLIC LICENSE.