### Example JSON File Format Source: https://github.com/carmjos/configured/blob/master/providers/gson/README.md This is an example of the JSON file structure used by the configured-JSON library, demonstrating various data types and nested objects. ```json { "version": 1.0, "test-number": 3185496340759645184, "test-enum": "DAYS", "user": { "name": "774b3", "info": { "uuid": "f890b050-d3c5-4a32-a8b0-8a421ec2d4cc" } }, "sub": { "that": { "operators": [] } }, "uuid-value": "a20c2eb2-e36b-40d7-a1ba-57826e3588c2", "users": { "1": "561f5142-8d59-4e50-855d-18638f3cfca8", "2": "629fadab-c625-4678-85d2-cc73cb4aa3b7", "3": "e29d1fb8-d8bd-4c2a-8ac0-4aaee77196dc", "4": "8ff8ab49-7c34-44c0-9edd-203a9d44f309", "5": "3c09dbff-ca37-468a-8c47-e8e52f837a54" }, "inner": { "inner-value": 49.831712577873375 }, "class-value": 1.0, "test": { "user": { "name": "Carm", "info": { "uuid": "c3881d54-3d77-46ca-b031-2962b8b89141" } } } } ``` -------------------------------- ### Demo YAML Configuration Source: https://github.com/carmjos/configured/wiki/Home An example YAML configuration file demonstrating database, server, and logging settings. This file serves as a basis for illustrating Configured library usage. ```yaml # Demo configuration file # Generated by Configured Library # Database configuration database: host: localhost # Database host address port: 3306 # Database port username: root password: password name: my_database pool: max-connections: 10 min-connections: 1 timeout: 3000 server: port: 8080 enable-ssl: false ssl: keystore-path: /path/to/keystore keystore-password: keystore_password logging: level: INFO file: /var/logs/app.log # Thanks for using Configured! # https://github.com/CarmJos/configured ``` -------------------------------- ### Sample YAML Configuration File Source: https://github.com/carmjos/configured/blob/master/README.md An example YAML file corresponding to the `SampleConfig` interface, showing how comments and nested structures are represented. This file is loaded by the Java code. ```yaml # Configurations for sample enabled: true #Enabled? # Server configurations port: # [ UUID >----------------------------------- # A lot of UUIDs uuids: - 00000000-0000-0000-0000-000000000000 - 00000000-0000-0000-0000-000000000001 # [ UUID >----------------------------------- info: # Configure your name! name: Joker how-old-are-you: 24 ``` -------------------------------- ### Example HOCON File Format Source: https://github.com/carmjos/configured/blob/master/providers/hocon/README.md This HOCON snippet demonstrates various data types including strings, numbers, nested objects, arrays, and enums. ```hocon class-value=1.0 # Inner Test inner { inner-value=72.0043567836829 } sub { that { operators=[] } } test { # Section类型数据测试 user { info { uuid="8aba6166-1dc3-476d-8eb6-8957434c05ba" } name=Carm } } test-enum=DAYS test-number=5555780951875134464 # Section类型数据测试 user { info { uuid="9ed3a8f3-ad2a-4a62-a720-5530f5d19b33" } name="9038c" } # [ID - UUID]对照表 # # 用于测试Map类型的解析与序列化保存 users { "1"="4bfe382e-7b9e-4dad-9314-d16ddeb99f34" "2"="6e587a1e-361e-43da-99ba-9de44db198dc" "3"=ce582c1c-d696-43d4-ab58-af40d000d656 "4"="37b7eb1f-86b9-41c7-afa3-9ac9c75fef2c" "5"="2659c33a-3393-404d-960e-850fef3b23fd" } uuid-value="035e89e8-3fe8-45ed-a25d-eef0bbe8f73d" version=1.0 ``` -------------------------------- ### Initialize and Use Configuration in Java Source: https://github.com/carmjos/configured/blob/master/README.md Demonstrates how to load a YAML configuration file, initialize configuration classes, and access/modify configuration values at runtime. Changes made via `set()` are not persisted to the file. ```java public class Sample { public static void main(String[] args) { // 1. Make a configuration provider from a file. ConfigurationHolder holder = YAMLConfigFactory.from("target/config.yml") .resourcePath("configs/sample.yml") .indent(4) // Optional: Set the indentation of the configuration file. .build(); // 2. Initialize the configuration classes or instances. holder.initialize(SampleConfig.class); // 3. Enjoy using the configuration! System.out.println("Enabled? -> " + SampleConfig.ENABLED.resolve()); // true SampleConfig.ENABLED.set(false); System.out.println("And now? -> " + SampleConfig.ENABLED.resolve()); // false // p.s. Changes not save so enable value will still be true in the next run. System.out.println("Your name is " + SampleConfig.INFO.NAME.resolve() + " (age=" + SampleConfig.INFO.AGE.resolve() + ")!"); } } ``` -------------------------------- ### Define Sample Configuration Interface Source: https://github.com/carmjos/configured/blob/master/README.md Defines a configuration interface using annotations for comments, paths, and value types. This is useful for structuring application settings. ```java @ConfigPath(root = true) @HeaderComments("Configurations for sample") public interface SampleConfig extends Configuration { @InlineComment("Enabled?") // Inline comment ConfiguredValue ENABLED = ConfiguredValue.of(true); @HeaderComments("Server configurations") // Header comment ConfiguredValue PORT = ConfiguredValue.of(Integer.class); @HeaderComments({"[ UUID >-----------------------------------", "A lot of UUIDs"}) @FooterComments("[ UUID >-----------------------------------") ConfiguredList UUIDS = ConfiguredList.builderOf(UUID.class).fromString() .parse(UUID::fromString).serialize(UUID::toString) .defaults( UUID.fromString("00000000-0000-0000-0000-000000000000"), UUID.fromString("00000000-0000-0000-0000-000000000001") ).build(); @ConfigPath("info") // Custom path interface INFO extends Configuration { @HeaderComments("Configure your name!") // Header comment ConfiguredValue NAME = ConfiguredValue.of("Joker"); @ConfigPath("how-old-are-you") // Custom path ConfiguredValue AGE = ConfiguredValue.of(24); } } ``` -------------------------------- ### Initialize Configuration Class Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start Initialize the configuration holder with your specific configuration class. This step binds the configuration values to your defined structure. ```java void onAppStart(){ holder.initialize(DemoConfig.class); } ``` -------------------------------- ### Create ConfigurationHolder with YAML Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start Initialize a ConfigurationHolder using a YAML configuration file. The indent method is optional and defaults to 2. ```java void onAppLoad(){ // Use YAML for example. ConfigurationHolder holder = YAMLConfigFactory.from("/path/to/config.yml") .indent(2) // optional, 2 is default // and more... .build(); } ``` -------------------------------- ### Build All Modules Source: https://github.com/carmjos/configured/blob/master/CONTRIBUTING.md Builds all modules in the project. This command cleans previous builds and verifies the project. ```bash mvn -q clean verify ``` -------------------------------- ### Run a Single Module Source: https://github.com/carmjos/configured/blob/master/CONTRIBUTING.md Executes tests for a single module ('core') and its dependencies. ```bash mvn -q -pl core -am test ``` -------------------------------- ### Define Java Configuration Interface Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start This Java code defines a root configuration interface 'DemoConfig' and its nested sections for database, server, and logging settings. It utilizes annotations for comments and path definition, and ConfiguredValue for holding configuration properties with default values. ```java @ConfigPath(root = true) // To define this as the root configuration interface public interface DemoConfig extends Configuration { // "extends Configuration" required @HeaderComments("Database configuration") // header comment(s) interface DATABASE extends Configuration { // as section, "extends Configuration" required /* * field name: "host" * default value: "localhost" * inline comment: "Database host address" * * preview: "host: localhost # Database host address" */ @InlineComment("Database host address") // inline comment ConfiguredValue HOST = ConfiguredValue.of("localhost"); @InlineComment("Database port") ConfiguredValue PORT = ConfiguredValue.of(3306); ConfiguredValue USERNAME = ConfiguredValue.of("root"); ConfiguredValue PASSWORD = ConfiguredValue.of("password"); ConfiguredValue NAME = ConfiguredValue.of("my_database"); interface POOL extends Configuration { ConfiguredValue MAX_COLLECTIONS = ConfiguredValue.of(10); ConfiguredValue MIN_COLLECTIONS = ConfiguredValue.of(1); ConfiguredValue TIMEOUT = ConfiguredValue.of(3000L); } } interface SERVER extends Configuration { ConfiguredValue PORT = ConfiguredValue.of(8080); ConfiguredValue SSL_ENABLED = ConfiguredValue.of(false); interface SSL extends Configuration { ConfiguredValue KEY_PATH = ConfiguredValue.of("/path/to/keystore"); ConfiguredValue KEY_PASSWORD = ConfiguredValue.of("keystore_password"); } } interface LOGGING extends Configuration { ConfiguredValue LEVEL = ConfiguredValue.of("INFO"); ConfiguredValue FILE = ConfiguredValue.of("/var/logs/app.log"); } } ``` -------------------------------- ### Maven Repository Configuration for configured-SQL Source: https://github.com/carmjos/configured/blob/master/providers/sql/README.md Includes Maven Central for stable updates and GitHub Packages for real-time updates of the configured-SQL library. ```xml maven Maven Central https://repo1.maven.org/maven2 configured GitHub Packages https://maven.pkg.github.com/CarmJos/configured ``` -------------------------------- ### Maven Core and Module Dependencies Source: https://github.com/carmjos/configured/blob/master/README.md Add the core configured library and specific implementations (YAML, JSON) as Maven dependencies. Replace '[LATEST RELEASE]' with the actual version. ```xml cc.carm.lib configured-core [LATEST RELEASE] compile cc.carm.lib configured-yaml [LATEST RELEASE] compile cc.carm.lib configured-gson [LATEST RELEASE] compile ``` -------------------------------- ### Generate JavaDoc Source: https://github.com/carmjos/configured/blob/master/CONTRIBUTING.md Generates JavaDoc for the project. This is already bound into the build process. ```bash mvn -q javadoc:javadoc ``` -------------------------------- ### Access Configuration Values Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start Retrieve configuration values. Use .get() for original values, .optional() for optional values (wrapped in Optional), and .resolve() for values with defaults. ```java void foo(){ // get the original value in the config. (with no defaults) String host = DemoConfig.DATABASE.HOST.get(); // get the original value (with Optional<>) in the config. (with no defaults) Optional<@Nullable Integer> optMaxConnections = DemoConfig.DATABASE.POOL.MAX_COLLECTIONS.optional(); // get the resolved value (with defaults if not set in config) in the config. Integer port = DemoConfig.DATABASE.PORT.resolve(); } ``` -------------------------------- ### Gradle Core and Module Dependencies Source: https://github.com/carmjos/configured/blob/master/README.md Declare the core configured library and its implementations (YAML, JSON) as Gradle API dependencies. Replace '[LATEST RELEASE]' with the actual version. ```groovy dependencies { api "cc.carm.lib:configured-core:[LATEST RELEASE]" api "cc.carm.lib:configured-yaml:[LATEST RELEASE]" api "cc.carm.lib:configured-gson:[LATEST RELEASE]" } ``` -------------------------------- ### Run Tests with Maven Source: https://github.com/carmjos/configured/blob/master/CONTRIBUTING.md Execute all tests quietly using Maven. Ensure JUnit 4 is configured for testing. ```bash mvn -q test ``` -------------------------------- ### Build All Modules Skipping Tests Source: https://github.com/carmjos/configured/blob/master/CONTRIBUTING.md Builds all modules while skipping tests. This is not recommended for pull request validation. ```bash mvn -q clean install -DskipTests ``` -------------------------------- ### Reload Configuration Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start Reload the configuration from the source file. This is useful for applying changes made externally to the configuration file. Includes basic error handling. ```java void reload(){ try{ holder.reload(); }catch(Exception e){ throw new RuntimeException(e); } } ``` -------------------------------- ### Gradle Dependency for configured-SQL Source: https://github.com/carmjos/configured/blob/master/providers/sql/README.md Adds the configured-SQL library as an API dependency in Gradle, using a placeholder for the latest release version. ```groovy dependencies { api "cc.carm.lib:configured-sql:[LATEST RELEASE]" } ``` -------------------------------- ### Gradle Kotlin DSL Repositories Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start Configure Gradle with Kotlin DSL to use Maven Central and the GitHub Packages repository for dependencies. ```kotlin 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("https://maven.pkg.github.com/CarmJos/configured") } ``` -------------------------------- ### Maven Dependency for configured-SQL Source: https://github.com/carmjos/configured/blob/master/providers/sql/README.md Specifies the configured-SQL dependency with a placeholder for the latest release version. ```xml cc.carm.lib configured-sql [LATEST RELEASE] compile ``` -------------------------------- ### Maven Dependency for configured-yaml Source: https://github.com/carmjos/configured/blob/master/providers/yaml/README.md Adds the configured-yaml library as a compile-time dependency to a Maven project. Replace '[LATEST RELEASE]' with the actual version. ```xml cc.carm.lib configured-yaml [LATEST RELEASE] compile ``` -------------------------------- ### Gradle Dependency for configured-yaml Source: https://github.com/carmjos/configured/blob/master/providers/yaml/README.md Adds the configured-yaml library as an API dependency in a Gradle project. Replace '[LATEST RELEASE]' with the actual version. ```groovy dependencies { api "cc.carm.lib:configured-yaml:[LATEST RELEASE]" } ``` -------------------------------- ### Maven Dependencies Configuration Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start Add the configured library core, YAML, or JSON implementations as dependencies in your Maven project. Replace '[LATEST RELEASE]' with the desired version. ```xml cc.carm.lib configured-core [LATEST RELEASE] compile cc.carm.lib configured-yaml [LATEST RELEASE] compile cc.carm.lib configured-gson [LATEST RELEASE] compile ``` -------------------------------- ### SQL Table Schema for Configuration Source: https://github.com/carmjos/configured/blob/master/providers/sql/README.md Defines the schema for the 'conf' table, used to store configuration data with fields for namespace, path, type, value, comments, version, and timestamps. Supports MySQL and MariaDB. ```mysql CREATE TABLE IF NOT EXISTS conf ( `namespace` VARCHAR(32) NOT NULL, # 命名空间 (代表其属于谁,类似于单个配置文件地址的概念) `path` VARCHAR(96) NOT NULL, # 配置路径 (ConfigPath) `type` TINYINT UNSIGNED NOT NULL DEFAULT 0, # 数据类型 (Integer/Byte/List/Map/...) `value` MEDIUMTEXT, # 配置项的值 (可能为JSON格式) `inline_comment` TEXT comment 'usage', # 配置项的用法,本质是行内注释 `header_comment` MEDIUMTEXT comment 'description', # 配置项的描述,本质是顶部注释 `footer_comment` MEDIUMTEXT comment 'example', # 配置项的参考,本质是底部注释 `version` MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, # 配置项的版本 `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, # 创建时间 `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, # 更新时间 PRIMARY KEY (`namespace`, `path`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ``` -------------------------------- ### Modify and Save Configuration Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start Modify configuration values programmatically and save the changes back to the configuration source. This allows for dynamic configuration updates. ```java void set(){ DemoConfig.SERVER.PORT.set(8081); try{ holder.save(); }catch(Exception e){ throw new RuntimeException(e); } } ``` -------------------------------- ### Gradle Repositories Configuration Source: https://github.com/carmjos/configured/blob/master/providers/yaml/README.md Configures Gradle to use Maven Central and GitHub Packages repositories for dependency resolution. GitHub dependencies require configuration for real-time updates. ```groovy 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/configured' } } ``` -------------------------------- ### Gradle Kotlin DSL Dependencies Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start Add configured library implementations (core, YAML, or JSON) to your Gradle project using Kotlin DSL. Replace '[LATEST RELEASE]' with the desired version. ```kotlin dependencies { // Basic implementation part, requiring custom implementation of “Provider” and “Wrapper”. implementation("cc.carm.lib:configured-core:[LATEST RELEASE]") // YAML file-based implementation, compatible with all Java environments. implementation("cc.carm.lib:configured-yaml:[LATEST RELEASE]") // JSON file-based implementation, compatible with all Java environments. implementation("cc.carm.lib:configured-gson:[LATEST RELEASE]") } ``` -------------------------------- ### Security Report Template Source: https://github.com/carmjos/configured/blob/master/SECURITY.md Use this template when reporting a security vulnerability. Ensure all fields are completed accurately. ```markdown Subject: [Security Report] Affected Component: (module / class) Version(s) Tested: x.y.z (and earlier if known) Environment: JDK x, OS Summary: Describe the vulnerability and impact. Reproduction Steps: 1. ... 2. ... 3. ... Expected vs Actual: Potential Impact: Workarounds / Mitigations (if any): Credit: (name / handle / anonymous) ``` -------------------------------- ### Maven Remote Repository Configuration Source: https://github.com/carmjos/configured/blob/master/README.md Configure Maven to use Maven Central and GitHub Packages for dependency resolution. Ensure synchronization if using Maven Central extensively. ```xml maven Maven Central https://repo1.maven.org/maven2 configured GitHub Packages https://maven.pkg.github.com/CarmJos/configured ``` -------------------------------- ### Gradle Groovy DSL Dependencies Source: https://github.com/carmjos/configured/wiki/1.-Quick-Start Add configured library implementations (core, YAML, or JSON) to your Gradle project using Groovy DSL. Replace '[LATEST RELEASE]' with the desired version. ```groovy dependencies { // Basic implementation part, requiring custom implementation of “Provider” and “Wrapper”. implementation "cc.carm.lib:configured-core:[LATEST RELEASE]" // YAML file-based implementation, compatible with all Java environments. implementation "cc.carm.lib:configured-yaml:[LATEST RELEASE]" // JSON file-based implementation, compatible with all Java environments. implementation "cc.carm.lib:configured-gson:[LATEST RELEASE]" } ``` -------------------------------- ### Gradle Remote Repository Configuration Source: https://github.com/carmjos/configured/blob/master/README.md Configure Gradle to use Maven Central and GitHub Packages repositories. This allows Gradle to find the necessary dependencies. ```groovy repositories { mavenCentral() maven { url 'https://maven.pkg.github.com/CarmJos/configured' } } ``` -------------------------------- ### Gradle Dependency Declaration Source: https://github.com/carmjos/configured/blob/master/providers/gson/README.md Declare the configured-json artifact as an API dependency in your Gradle project. ```groovy dependencies { api "cc.carm.lib:configured-json:[LATEST RELEASE]" } ``` -------------------------------- ### Maven Central Repository Configuration Source: https://github.com/carmjos/configured/blob/master/providers/yaml/README.md Configures the Maven project to use the Maven Central Repository for dependency resolution. Synchronization might be needed for stable updates. ```xml maven Maven Central https://repo1.maven.org/maven2 configured GitHub Packages https://maven.pkg.github.com/CarmJos/configured ``` -------------------------------- ### Maven Dependency for configured-HOCON Source: https://github.com/carmjos/configured/blob/master/providers/hocon/README.md Add the configured-HOCON library as a compile-time dependency in your Maven project. ```xml cc.carm.lib configured-hocon [LATEST RELEASE] compile ``` -------------------------------- ### Gradle Dependency for configured-HOCON Source: https://github.com/carmjos/configured/blob/master/providers/hocon/README.md Add the configured-HOCON library as an API dependency in your Gradle project. ```groovy dependencies { api "cc.carm.lib:configured-hocon:[LATEST RELEASE]" } ``` -------------------------------- ### Conventional Commits Message Format Source: https://github.com/carmjos/configured/blob/master/CONTRIBUTING.md Standard format for commit messages, including type, optional scope, a short summary, and optional body/footer for breaking changes or issue references. ```markdown (): (optional)