mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 494491cf94 | |||
| 00e88b50ff | |||
| 033236c89b | |||
| 791fa6e5b4 | |||
| 51c287a0a7 | |||
| ab2f898164 | |||
| 4f4b203240 | |||
| c94fef893f | |||
| c2a08c6c72 | |||
| dd7a6c819f | |||
| e9c010981e | |||
| 78d52e1aae |
@@ -0,0 +1,3 @@
|
|||||||
|
# 欢迎使用 EasyConfiguration !
|
||||||
|
|
||||||
|
这个项目刚刚创建,详细的Javadoc与开发指南还在补充,请给我一点时间~
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||||
|
|
||||||
name: "Project Deploy"
|
name: "Deploy & Publish"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
# 支持手动触发构建
|
# 支持手动触发构建
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||||
|
|
||||||
name: Project Build & Tests
|
name: Build & Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
# 支持手动触发构建
|
# 支持手动触发构建
|
||||||
|
|||||||
@@ -1,21 +1,165 @@
|
|||||||
MIT License
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
Copyright (c) 2022 Carm
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
This version of the GNU Lesser General Public License incorporates
|
||||||
copies or substantial portions of the Software.
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
0. Additional Definitions.
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
General Public License.
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
"The Library" refers to a covered work governed by this License,
|
||||||
|
other than an Application or a Combined Work as defined below.
|
||||||
|
|
||||||
|
An "Application" is any work that makes use of an interface provided
|
||||||
|
by the Library, but which is not otherwise based on the Library.
|
||||||
|
Defining a subclass of a class defined by the Library is deemed a mode
|
||||||
|
of using an interface provided by the Library.
|
||||||
|
|
||||||
|
A "Combined Work" is a work produced by combining or linking an
|
||||||
|
Application with the Library. The particular version of the Library
|
||||||
|
with which the Combined Work was made is also called the "Linked
|
||||||
|
Version".
|
||||||
|
|
||||||
|
The "Minimal Corresponding Source" for a Combined Work means the
|
||||||
|
Corresponding Source for the Combined Work, excluding any source code
|
||||||
|
for portions of the Combined Work that, considered in isolation, are
|
||||||
|
based on the Application, and not on the Linked Version.
|
||||||
|
|
||||||
|
The "Corresponding Application Code" for a Combined Work means the
|
||||||
|
object code and/or source code for the Application, including any data
|
||||||
|
and utility programs needed for reproducing the Combined Work from the
|
||||||
|
Application, but excluding the System Libraries of the Combined Work.
|
||||||
|
|
||||||
|
1. Exception to Section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
You may convey a covered work under sections 3 and 4 of this License
|
||||||
|
without being bound by section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
2. Conveying Modified Versions.
|
||||||
|
|
||||||
|
If you modify a copy of the Library, and, in your modifications, a
|
||||||
|
facility refers to a function or data to be supplied by an Application
|
||||||
|
that uses the facility (other than as an argument passed when the
|
||||||
|
facility is invoked), then you may convey a copy of the modified
|
||||||
|
version:
|
||||||
|
|
||||||
|
a) under this License, provided that you make a good faith effort to
|
||||||
|
ensure that, in the event an Application does not supply the
|
||||||
|
function or data, the facility still operates, and performs
|
||||||
|
whatever part of its purpose remains meaningful, or
|
||||||
|
|
||||||
|
b) under the GNU GPL, with none of the additional permissions of
|
||||||
|
this License applicable to that copy.
|
||||||
|
|
||||||
|
3. Object Code Incorporating Material from Library Header Files.
|
||||||
|
|
||||||
|
The object code form of an Application may incorporate material from
|
||||||
|
a header file that is part of the Library. You may convey such object
|
||||||
|
code under terms of your choice, provided that, if the incorporated
|
||||||
|
material is not limited to numerical parameters, data structure
|
||||||
|
layouts and accessors, or small macros, inline functions and templates
|
||||||
|
(ten or fewer lines in length), you do both of the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the object code that the
|
||||||
|
Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
4. Combined Works.
|
||||||
|
|
||||||
|
You may convey a Combined Work under terms of your choice that,
|
||||||
|
taken together, effectively do not restrict modification of the
|
||||||
|
portions of the Library contained in the Combined Work and reverse
|
||||||
|
engineering for debugging such modifications, if you also do each of
|
||||||
|
the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the Combined Work that
|
||||||
|
the Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
c) For a Combined Work that displays copyright notices during
|
||||||
|
execution, include the copyright notice for the Library among
|
||||||
|
these notices, as well as a reference directing the user to the
|
||||||
|
copies of the GNU GPL and this license document.
|
||||||
|
|
||||||
|
d) Do one of the following:
|
||||||
|
|
||||||
|
0) Convey the Minimal Corresponding Source under the terms of this
|
||||||
|
License, and the Corresponding Application Code in a form
|
||||||
|
suitable for, and under terms that permit, the user to
|
||||||
|
recombine or relink the Application with a modified version of
|
||||||
|
the Linked Version to produce a modified Combined Work, in the
|
||||||
|
manner specified by section 6 of the GNU GPL for conveying
|
||||||
|
Corresponding Source.
|
||||||
|
|
||||||
|
1) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (a) uses at run time
|
||||||
|
a copy of the Library already present on the user's computer
|
||||||
|
system, and (b) will operate properly with a modified version
|
||||||
|
of the Library that is interface-compatible with the Linked
|
||||||
|
Version.
|
||||||
|
|
||||||
|
e) Provide Installation Information, but only if you would otherwise
|
||||||
|
be required to provide such information under section 6 of the
|
||||||
|
GNU GPL, and only to the extent that such information is
|
||||||
|
necessary to install and execute a modified version of the
|
||||||
|
Combined Work produced by recombining or relinking the
|
||||||
|
Application with a modified version of the Linked Version. (If
|
||||||
|
you use option 4d0, the Installation Information must accompany
|
||||||
|
the Minimal Corresponding Source and Corresponding Application
|
||||||
|
Code. If you use option 4d1, you must provide the Installation
|
||||||
|
Information in the manner specified by section 6 of the GNU GPL
|
||||||
|
for conveying Corresponding Source.)
|
||||||
|
|
||||||
|
5. Combined Libraries.
|
||||||
|
|
||||||
|
You may place library facilities that are a work based on the
|
||||||
|
Library side by side in a single library together with other library
|
||||||
|
facilities that are not Applications and are not covered by this
|
||||||
|
License, and convey such a combined library under terms of your
|
||||||
|
choice, if you do both of the following:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work based
|
||||||
|
on the Library, uncombined with any other library facilities,
|
||||||
|
conveyed under the terms of this License.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library that part of it
|
||||||
|
is a work based on the Library, and explaining where to find the
|
||||||
|
accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
6. Revised Versions of the GNU Lesser General Public License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU Lesser General Public License from time to time. Such new
|
||||||
|
versions will be similar in spirit to the present version, but may
|
||||||
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Library as you received it specifies that a certain numbered version
|
||||||
|
of the GNU Lesser General Public License "or any later version"
|
||||||
|
applies to it, you have the option of following the terms and
|
||||||
|
conditions either of that published version or of any later version
|
||||||
|
published by the Free Software Foundation. If the Library as you
|
||||||
|
received it does not specify a version number of the GNU Lesser
|
||||||
|
General Public License, you may choose any version of the GNU Lesser
|
||||||
|
General Public License ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Library as you received it specifies that a proxy can decide
|
||||||
|
whether future versions of the GNU Lesser General Public License shall
|
||||||
|
apply, that proxy's public statement of acceptance of any version is
|
||||||
|
permanent authorization for you to choose that version for the
|
||||||
|
Library.
|
||||||
@@ -23,11 +23,11 @@
|
|||||||
|
|
||||||
## 开发
|
## 开发
|
||||||
|
|
||||||
详细开发介绍请 [点击这里](.documentation/README.md) , JavaDoc(最新Release) 请 [点击这里](https://carmjos.github.io/EasyConfiguration) 。
|
详细开发介绍请 [点击这里](.documentation/README.md) , JavaDoc(最新Release) 请 [点击这里](https://CarmJos.github.io/EasyConfiguration) 。
|
||||||
|
|
||||||
### 示例代码
|
### 示例代码
|
||||||
|
|
||||||
您可以 [点击这里](impl/yaml/src/test/java/config/source/TestConfiguration.java) 查看部分代码演示,更多演示详见 [开发介绍](.documentation/README.md) 。
|
您可以 [点击这里](impl/yaml/src/test/java/config/source/DemoConfiguration.java) 查看部分代码演示,更多演示详见 [开发介绍](.documentation/README.md) 。
|
||||||
|
|
||||||
### 依赖方式
|
### 依赖方式
|
||||||
|
|
||||||
@@ -145,7 +145,6 @@ EasyConfiguration for MineCraft!
|
|||||||
|
|
||||||
目前支持 BungeeCord, Bukkit(Spigot) 服务端,后续将支持更多平台。
|
目前支持 BungeeCord, Bukkit(Spigot) 服务端,后续将支持更多平台。
|
||||||
|
|
||||||
|
|
||||||
## 支持与捐赠
|
## 支持与捐赠
|
||||||
|
|
||||||
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyconfiguration-parent</artifactId>
|
<artifactId>easyconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>2.0.0</version>
|
<version>2.2.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置文件类初始化方法
|
||||||
|
* 用于初始化 {@link ConfigurationRoot} 中的每个 {@link ConfigValue} 对象
|
||||||
|
*
|
||||||
|
* @param <T> {@link ConfigurationProvider} 配置文件的数据来源
|
||||||
|
* @author CarmJos
|
||||||
|
*/
|
||||||
public class ConfigInitializer<T extends ConfigurationProvider<?>> {
|
public class ConfigInitializer<T extends ConfigurationProvider<?>> {
|
||||||
|
|
||||||
protected final @NotNull T provider;
|
protected final @NotNull T provider;
|
||||||
@@ -17,19 +24,59 @@ public class ConfigInitializer<T extends ConfigurationProvider<?>> {
|
|||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化指定类以及其子类的所有 {@link ConfigValue} 对象。
|
||||||
|
*
|
||||||
|
* @param clazz 配置文件类,须继承于 {@link ConfigurationRoot} 。
|
||||||
|
* @param saveDefaults 是否写入默认值(默认为 true)。
|
||||||
|
*/
|
||||||
public void initialize(@NotNull Class<? extends ConfigurationRoot> clazz, boolean saveDefaults) {
|
public void initialize(@NotNull Class<? extends ConfigurationRoot> clazz, boolean saveDefaults) {
|
||||||
initializeClass(clazz, null, null, null, null, saveDefaults);
|
initialize(clazz, saveDefaults, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化指定类的所有 {@link ConfigValue} 对象。
|
||||||
|
*
|
||||||
|
* @param clazz 配置文件类,须继承于 {@link ConfigurationRoot} 。
|
||||||
|
* @param saveDefaults 是否写入默认值(默认为 true)。
|
||||||
|
* @param loadSubClasses 是否加载内部子类(默认为 true)。
|
||||||
|
*/
|
||||||
|
public void initialize(@NotNull Class<? extends ConfigurationRoot> clazz,
|
||||||
|
boolean saveDefaults, boolean loadSubClasses) {
|
||||||
|
initializeClass(
|
||||||
|
clazz, null,
|
||||||
|
null, null, null,
|
||||||
|
saveDefaults, loadSubClasses
|
||||||
|
);
|
||||||
|
if (saveDefaults) {
|
||||||
|
try {
|
||||||
|
provider.save();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initializeClass(@NotNull Class<?> clazz,
|
protected void initializeClass(@NotNull Class<?> clazz,
|
||||||
@Nullable String parentPath, @Nullable String fieldName,
|
@Nullable String parentPath, @Nullable String fieldName,
|
||||||
@Nullable ConfigPath fieldPath, @Nullable ConfigComment filedComments,
|
@Nullable ConfigPath fieldPath, @Nullable ConfigComment filedComments,
|
||||||
boolean saveDefaults) {
|
boolean saveDefaults, boolean loadSubClasses) {
|
||||||
if (!ConfigurationRoot.class.isAssignableFrom(clazz)) return;
|
|
||||||
String path = getClassPath(clazz, parentPath, fieldName, fieldPath);
|
String path = getClassPath(clazz, parentPath, fieldName, fieldPath);
|
||||||
if (path != null) setComments(path, getClassComments(clazz, filedComments));
|
if (path != null) setComments(path, getClassComments(clazz, filedComments));
|
||||||
for (Field field : clazz.getDeclaredFields()) {
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
initializeField(clazz, field, path, saveDefaults);
|
initializeField(clazz, field, path, saveDefaults, loadSubClasses);
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?>[] classes = clazz.getDeclaredClasses();
|
||||||
|
if (loadSubClasses && classes.length > 0) {
|
||||||
|
// 逆向加载,保持顺序。
|
||||||
|
for (int i = classes.length - 1; i >= 0; i--) {
|
||||||
|
initializeClass(
|
||||||
|
classes[i], path, classes[i].getSimpleName(),
|
||||||
|
null, null,
|
||||||
|
saveDefaults, true
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,8 +86,8 @@ public class ConfigInitializer<T extends ConfigurationProvider<?>> {
|
|||||||
value.initialize(provider, saveDefaults, path, comments);
|
value.initialize(provider, saveDefaults, path, comments);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeField(@NotNull Class<?> source, @NotNull Field field,
|
private void initializeField(@NotNull Class<?> source, @NotNull Field field, @Nullable String parent,
|
||||||
@Nullable String parent, boolean saveDefaults) {
|
boolean saveDefaults, boolean loadSubClasses) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
@@ -55,7 +102,7 @@ public class ConfigInitializer<T extends ConfigurationProvider<?>> {
|
|||||||
(Class<?>) object, parent, field.getName(),
|
(Class<?>) object, parent, field.getName(),
|
||||||
field.getAnnotation(ConfigPath.class),
|
field.getAnnotation(ConfigPath.class),
|
||||||
field.getAnnotation(ConfigComment.class),
|
field.getAnnotation(ConfigComment.class),
|
||||||
saveDefaults
|
saveDefaults, loadSubClasses
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException ignored) {
|
} catch (IllegalAccessException ignored) {
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
package cc.carm.lib.configuration.core;
|
package cc.carm.lib.configuration.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置文件类的根节点,用于标注该类用于记录配置文件中的配置信息。
|
||||||
|
*/
|
||||||
public abstract class ConfigurationRoot {
|
public abstract class ConfigurationRoot {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
|||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SourceListBuilder<S, V> extends CommonConfigBuilder<List<V>, SourceListBuilder<S, V>> {
|
public class SourceListBuilder<S, V> extends CommonConfigBuilder<List<V>, SourceListBuilder<S, V>> {
|
||||||
@@ -30,6 +32,11 @@ public class SourceListBuilder<S, V> extends CommonConfigBuilder<List<V>, Source
|
|||||||
this.valueSerializer = valueSerializer;
|
this.valueSerializer = valueSerializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public final @NotNull SourceListBuilder<S, V> defaults(@NotNull V... values) {
|
||||||
|
return defaults(new ArrayList<>(Arrays.asList(values)));
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull SourceListBuilder<S, V> parseSource(ConfigDataFunction<Object, S> sourceParser) {
|
public @NotNull SourceListBuilder<S, V> parseSource(ConfigDataFunction<Object, S> sourceParser) {
|
||||||
this.sourceParser = sourceParser;
|
this.sourceParser = sourceParser;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -41,4 +41,8 @@ public abstract class ConfigurationProvider<W extends ConfigurationWrapper> {
|
|||||||
getInitializer().initialize(configClazz, saveDefaults);
|
getInitializer().initialize(configClazz, saveDefaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initialize(Class<? extends ConfigurationRoot> configClazz, boolean saveDefaults, boolean loadSubClasses) {
|
||||||
|
getInitializer().initialize(configClazz, saveDefaults, loadSubClasses);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,12 +45,29 @@ public abstract class ConfigValue<T> {
|
|||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到该配置的设定值(即读取到的值)。
|
||||||
|
* <br> 若初始化时未写入默认值,则可以通过 {@link #getOrDefault()} 方法在该设定值为空时获取默认值。
|
||||||
|
*
|
||||||
|
* @return 设定值
|
||||||
|
*/
|
||||||
public abstract @Nullable T get();
|
public abstract @Nullable T get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到该配置的设定值,若不存在,则返回默认值。
|
||||||
|
*
|
||||||
|
* @return 设定值或默认值
|
||||||
|
*/
|
||||||
public @Nullable T getOrDefault() {
|
public @Nullable T getOrDefault() {
|
||||||
return Optional.ofNullable(get()).orElse(getDefaultValue());
|
return getOptional().orElse(getDefaultValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到该配置的非空值。
|
||||||
|
*
|
||||||
|
* @return 非空值
|
||||||
|
* @throws NullPointerException 对应数据为空时抛出
|
||||||
|
*/
|
||||||
public @NotNull T getNotNull() {
|
public @NotNull T getNotNull() {
|
||||||
return Objects.requireNonNull(getOrDefault(), "Value(" + configPath + ") is null.");
|
return Objects.requireNonNull(getOrDefault(), "Value(" + configPath + ") is null.");
|
||||||
}
|
}
|
||||||
@@ -59,12 +76,28 @@ public abstract class ConfigValue<T> {
|
|||||||
return Optional.ofNullable(get());
|
return Optional.ofNullable(get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设定该配置的值。
|
||||||
|
* <br> 设定后,不会自动保存配置文件;若需要保存,请调用 {@link ConfigurationProvider#save()} 方法。
|
||||||
|
*
|
||||||
|
* @param value 配置的值
|
||||||
|
*/
|
||||||
public abstract void set(@Nullable T value);
|
public abstract void set(@Nullable T value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化该配置的默认值。
|
||||||
|
* <br> 设定后,不会自动保存配置文件;若需要保存,请调用 {@link ConfigurationProvider#save()} 方法。
|
||||||
|
*/
|
||||||
public void setDefault() {
|
public void setDefault() {
|
||||||
setDefault(false);
|
setDefault(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将该配置的值设置为默认值。
|
||||||
|
* <br> 设定后,不会自动保存配置文件;若需要保存,请调用 {@link ConfigurationProvider#save()} 方法。
|
||||||
|
*
|
||||||
|
* @param override 是否覆盖已设定的值
|
||||||
|
*/
|
||||||
public void setDefault(boolean override) {
|
public void setDefault(boolean override) {
|
||||||
if (!override && getConfiguration().contains(getConfigPath())) return;
|
if (!override && getConfiguration().contains(getConfigPath())) return;
|
||||||
Optional.ofNullable(getDefaultValue()).ifPresent(this::set);
|
Optional.ofNullable(getDefaultValue()).ifPresent(this::set);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class ConfiguredValue<V> extends CachedConfigValue<V> {
|
|||||||
@Override
|
@Override
|
||||||
public V get() {
|
public V get() {
|
||||||
if (isExpired()) { // 已过时的数据,需要重新解析一次。
|
if (isExpired()) { // 已过时的数据,需要重新解析一次。
|
||||||
Object value = getConfiguration().get(getConfigPath());
|
Object value = getValue();
|
||||||
if (value == null) return useDefault(); // 获取的值不存在,直接使用默认值。
|
if (value == null) return useDefault(); // 获取的值不存在,直接使用默认值。
|
||||||
try {
|
try {
|
||||||
// 若未出现错误,则直接更新缓存并返回。
|
// 若未出现错误,则直接更新缓存并返回。
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>easyconfiguration-parent</artifactId>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<artifactId>easyconfiguration-json</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyconfiguration-core</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package cc.carm.lib.configuration;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.json.JSONConfigProvider;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class EasyConfiguration {
|
||||||
|
|
||||||
|
public static JSONConfigProvider from(File file, String source) {
|
||||||
|
JSONConfigProvider provider = new JSONConfigProvider(file);
|
||||||
|
try {
|
||||||
|
provider.initializeFile(source);
|
||||||
|
provider.initializeConfig();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONConfigProvider from(File file) {
|
||||||
|
return from(file, file.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONConfigProvider from(String fileName) {
|
||||||
|
return from(fileName, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONConfigProvider from(String fileName, String source) {
|
||||||
|
return from(new File(fileName), source);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package cc.carm.lib.configuration.json;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some code comes from BungeeCord's implementation of the JsonConfiguration.
|
||||||
|
*
|
||||||
|
* @author md_5, CarmJos
|
||||||
|
*/
|
||||||
|
public class JSONConfigProvider extends FileConfigProvider<JSONConfigWrapper> {
|
||||||
|
|
||||||
|
protected final Gson gson = new GsonBuilder()
|
||||||
|
.serializeNulls().disableHtmlEscaping().setPrettyPrinting()
|
||||||
|
.registerTypeAdapter(
|
||||||
|
JSONConfigWrapper.class,
|
||||||
|
(JsonSerializer<JSONConfigWrapper>) (src, typeOfSrc, context) -> context.serialize(src.data)
|
||||||
|
).create();
|
||||||
|
|
||||||
|
protected JSONConfigWrapper configuration;
|
||||||
|
protected ConfigInitializer<JSONConfigProvider> initializer;
|
||||||
|
|
||||||
|
public JSONConfigProvider(@NotNull File file) {
|
||||||
|
super(file);
|
||||||
|
this.initializer = new ConfigInitializer<>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeConfig() {
|
||||||
|
LinkedHashMap<?, ?> map = null;
|
||||||
|
|
||||||
|
try (FileInputStream is = new FileInputStream(file)) {
|
||||||
|
map = gson.fromJson(new InputStreamReader(is, StandardCharsets.UTF_8), LinkedHashMap.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map == null) map = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
this.configuration = new JSONConfigWrapper(map);
|
||||||
|
this.initializer = new ConfigInitializer<>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull JSONConfigWrapper getConfiguration() {
|
||||||
|
return this.configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
initializeConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() throws Exception {
|
||||||
|
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
|
||||||
|
gson.toJson(configuration.data, writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setComments(@NotNull String path, @NotNull String... comments) {
|
||||||
|
// JSON doesn't support comments.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String[] getComments(@NotNull String path) {
|
||||||
|
return new String[0]; // JSON doesn't support comments.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfigInitializer<? extends ConfigurationProvider<JSONConfigWrapper>> getInitializer() {
|
||||||
|
return this.initializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package cc.carm.lib.configuration.json;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some code comes from BungeeCord's implementation of the JsonConfiguration.
|
||||||
|
*
|
||||||
|
* @author md_5, CarmJos
|
||||||
|
*/
|
||||||
|
public class JSONConfigWrapper implements ConfigurationWrapper {
|
||||||
|
|
||||||
|
private static final char SEPARATOR = '.';
|
||||||
|
protected final Map<String, Object> data;
|
||||||
|
|
||||||
|
JSONConfigWrapper(Map<?, ?> map) {
|
||||||
|
this.data = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||||
|
String key = (entry.getKey() == null) ? "null" : entry.getKey().toString();
|
||||||
|
|
||||||
|
if (entry.getValue() instanceof Map) {
|
||||||
|
this.data.put(key, new JSONConfigWrapper((Map<?, ?>) entry.getValue()));
|
||||||
|
} else {
|
||||||
|
this.data.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Set<String> getKeys(boolean deep) {
|
||||||
|
return new LinkedHashSet<>(this.data.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||||
|
return new LinkedHashMap<>(this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(@NotNull String path, @Nullable Object value) {
|
||||||
|
if (value instanceof Map) {
|
||||||
|
value = new JSONConfigWrapper((Map<?, ?>) value);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONConfigWrapper section = getSectionFor(path);
|
||||||
|
if (section == this) {
|
||||||
|
if (value == null) {
|
||||||
|
this.data.remove(path);
|
||||||
|
} else {
|
||||||
|
this.data.put(path, value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
section.set(getChild(path), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(@NotNull String path) {
|
||||||
|
return get(path) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Object get(@NotNull String path) {
|
||||||
|
JSONConfigWrapper section = getSectionFor(path);
|
||||||
|
return section == this ? data.get(path) : section.get(getChild(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isList(@NotNull String path) {
|
||||||
|
return get(path) instanceof List<?>;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<?> getList(@NotNull String path) {
|
||||||
|
Object val = get(path);
|
||||||
|
return (val instanceof List<?>) ? (List<?>) val : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConfigurationSection(@NotNull String path) {
|
||||||
|
return get(path) instanceof JSONConfigWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
||||||
|
Object val = get(path);
|
||||||
|
return (val instanceof JSONConfigWrapper) ? (JSONConfigWrapper) val : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JSONConfigWrapper getSectionFor(String path) {
|
||||||
|
int index = path.indexOf(SEPARATOR);
|
||||||
|
if (index == -1) return this;
|
||||||
|
|
||||||
|
String root = path.substring(0, index);
|
||||||
|
Object section = this.data.get(root);
|
||||||
|
if (section == null) {
|
||||||
|
section = new JSONConfigWrapper(new LinkedHashMap<>());
|
||||||
|
this.data.put(root, section);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (JSONConfigWrapper) section;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getChild(String path) {
|
||||||
|
int index = path.indexOf(SEPARATOR);
|
||||||
|
return (index == -1) ? path : path.substring(index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package cc.carm.lib.configuration.json;
|
||||||
|
|
||||||
|
public abstract class JSONValue {
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package config;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.EasyConfiguration;
|
||||||
|
import cc.carm.lib.configuration.json.JSONConfigProvider;
|
||||||
|
import config.model.TestModel;
|
||||||
|
import config.source.DemoConfiguration;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
public class JSONConfigTest {
|
||||||
|
|
||||||
|
protected final JSONConfigProvider provider = EasyConfiguration.from("target/config.yml", "config.yml");
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onTest() {
|
||||||
|
|
||||||
|
provider.initialize(DemoConfiguration.class);
|
||||||
|
|
||||||
|
testDemo();
|
||||||
|
|
||||||
|
try {
|
||||||
|
provider.save();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void testDemo() {
|
||||||
|
System.out.println("----------------------------------------------------");
|
||||||
|
|
||||||
|
System.out.println("> Test Value:");
|
||||||
|
System.out.println("before: " + DemoConfiguration.Sub.UUID_CONFIG_VALUE.get());
|
||||||
|
DemoConfiguration.Sub.UUID_CONFIG_VALUE.set(UUID.randomUUID());
|
||||||
|
System.out.println("after: " + DemoConfiguration.Sub.UUID_CONFIG_VALUE.get());
|
||||||
|
|
||||||
|
System.out.println("> Test List:");
|
||||||
|
DemoConfiguration.Sub.That.OPERATORS.getNotNull().forEach(System.out::println);
|
||||||
|
List<UUID> operators = IntStream.range(0, 5).mapToObj(i -> UUID.randomUUID()).collect(Collectors.toList());
|
||||||
|
DemoConfiguration.Sub.That.OPERATORS.set(operators);
|
||||||
|
|
||||||
|
System.out.println("> Test Section:");
|
||||||
|
System.out.println(DemoConfiguration.MODEL_TEST.get());
|
||||||
|
DemoConfiguration.MODEL_TEST.set(TestModel.random());
|
||||||
|
|
||||||
|
System.out.println("> Test Maps:");
|
||||||
|
DemoConfiguration.USERS.getNotNull().forEach((k, v) -> System.out.println(k + ": " + v));
|
||||||
|
LinkedHashMap<Integer, UUID> data = new LinkedHashMap<>();
|
||||||
|
for (int i = 1; i <= 5; i++) {
|
||||||
|
data.put(i, UUID.randomUUID());
|
||||||
|
}
|
||||||
|
DemoConfiguration.USERS.set(data);
|
||||||
|
System.out.println("----------------------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package config.model;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public abstract class AbstractModel {
|
||||||
|
|
||||||
|
protected final @NotNull String name;
|
||||||
|
|
||||||
|
public AbstractModel(@NotNull String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package config.model;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.TestOnly;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SomeModel extends AbstractModel {
|
||||||
|
|
||||||
|
int num;
|
||||||
|
|
||||||
|
public SomeModel(@NotNull String name, int num) {
|
||||||
|
super(name);
|
||||||
|
this.num = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "SomeModel{" +
|
||||||
|
"name='" + name + '\'' +
|
||||||
|
", num=" + num +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("name", name);
|
||||||
|
map.put("num", num);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestOnly
|
||||||
|
public static SomeModel deserialize(Map<String, ?> args) {
|
||||||
|
return new SomeModel((String) args.get("name"), (Integer) args.get("num"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package config.model;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class TestModel extends AbstractModel {
|
||||||
|
|
||||||
|
public UUID uuid;
|
||||||
|
|
||||||
|
public TestModel(String name, UUID uuid) {
|
||||||
|
super(name);
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUuid(UUID uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("name", name);
|
||||||
|
Map<String, Object> map2 = new HashMap<>();
|
||||||
|
map2.put("uuid", uuid.toString());
|
||||||
|
map.put("info", map2);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TestModel deserialize(ConfigurationWrapper section) {
|
||||||
|
String name = section.getString("name");
|
||||||
|
if (name == null) throw new NullPointerException("name is null");
|
||||||
|
String uuidString = section.getString("info.uuid");
|
||||||
|
if (uuidString == null) throw new NullPointerException("uuid is null");
|
||||||
|
return new TestModel(name, UUID.fromString(uuidString));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TestModel random() {
|
||||||
|
return new TestModel(UUID.randomUUID().toString().substring(0, 5), UUID.randomUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TestUser{" +
|
||||||
|
"name='" + name + '\'' +
|
||||||
|
", uuid=" + uuid +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package config.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||||
|
import cc.carm.lib.configuration.core.annotation.ConfigComment;
|
||||||
|
import cc.carm.lib.configuration.core.annotation.ConfigPath;
|
||||||
|
import cc.carm.lib.configuration.core.value.ConfigValue;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||||
|
|
||||||
|
@ConfigComment({"数据库配置", " 用于提供数据库连接,进行数据库操作。"})
|
||||||
|
public class DatabaseConfiguration extends ConfigurationRoot {
|
||||||
|
|
||||||
|
@ConfigPath("driver")
|
||||||
|
protected static final ConfigValue<String> DRIVER_NAME = ConfiguredValue.of(
|
||||||
|
String.class, "com.mysql.cj.jdbc.Driver"
|
||||||
|
);
|
||||||
|
|
||||||
|
protected static final ConfigValue<String> HOST = ConfiguredValue.of(String.class, "127.0.0.1");
|
||||||
|
protected static final ConfigValue<Integer> PORT = ConfiguredValue.of(Integer.class, 3306);
|
||||||
|
|
||||||
|
protected static final ConfigValue<String> DATABASE = ConfiguredValue.of(String.class, "minecraft");
|
||||||
|
protected static final ConfigValue<String> USERNAME = ConfiguredValue.of(String.class, "root");
|
||||||
|
protected static final ConfigValue<String> PASSWORD = ConfiguredValue.of(String.class, "password");
|
||||||
|
|
||||||
|
protected static final ConfigValue<String> EXTRA = ConfiguredValue.of(String.class, "?useSSL=false");
|
||||||
|
|
||||||
|
protected static String buildJDBC() {
|
||||||
|
return String.format("jdbc:mysql://%s:%s/%s%s", HOST.get(), PORT.get(), DATABASE.get(), EXTRA.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package config.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||||
|
import cc.carm.lib.configuration.core.annotation.ConfigPath;
|
||||||
|
import cc.carm.lib.configuration.core.value.ConfigValue;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredMap;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||||
|
import config.model.TestModel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DemoConfiguration extends ConfigurationRoot {
|
||||||
|
|
||||||
|
@ConfigPath(root = true)
|
||||||
|
protected static final ConfigValue<Double> VERSION = ConfiguredValue.of(Double.class, 1.0D);
|
||||||
|
|
||||||
|
// 可以直接写静态内部类,并通过 Class<?> 声明。
|
||||||
|
public static final Class<?> SUB_TEST = Sub.class;
|
||||||
|
|
||||||
|
@ConfigPath("user") // 通过注解规定配置文件中的路径,若不进行注解则以变量名自动生成。
|
||||||
|
public static final ConfigValue<TestModel> MODEL_TEST = ConfiguredSection
|
||||||
|
.builder(TestModel.class)
|
||||||
|
.defaults(new TestModel("Carm", UUID.randomUUID()))
|
||||||
|
.parseValue((section, defaultValue) -> TestModel.deserialize(section))
|
||||||
|
.serializeValue(TestModel::serialize).build();
|
||||||
|
|
||||||
|
// 子配置文件
|
||||||
|
@ConfigPath("database")
|
||||||
|
public static final Class<?> DB_CONFIG = DatabaseConfiguration.class;
|
||||||
|
|
||||||
|
public static final ConfigValue<Map<Integer, UUID>> USERS = ConfiguredMap
|
||||||
|
.builder(Integer.class, UUID.class).fromString()
|
||||||
|
.parseKey(Integer::parseInt)
|
||||||
|
.parseValue(v -> Objects.requireNonNull(UUID.fromString(v)))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
public static class Sub extends ConfigurationRoot {
|
||||||
|
|
||||||
|
@ConfigPath(value = "uuid-value", root = true)
|
||||||
|
public static final ConfigValue<UUID> UUID_CONFIG_VALUE = ConfiguredValue
|
||||||
|
.builder(UUID.class).fromString()
|
||||||
|
.parseValue((data, defaultValue) -> UUID.fromString(data))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public static final Class<?> NOTHING = That.class;
|
||||||
|
|
||||||
|
public static class That extends ConfigurationRoot {
|
||||||
|
|
||||||
|
public static final ConfigValue<List<UUID>> OPERATORS = ConfiguredList
|
||||||
|
.builder(UUID.class).fromString()
|
||||||
|
.parseValue(s -> Objects.requireNonNull(UUID.fromString(s)))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyconfiguration-parent</artifactId>
|
<artifactId>easyconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>2.0.0</version>
|
<version>2.2.0</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package cc.carm.lib.configuration;
|
package cc.carm.lib.configuration;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.yaml.YamlConfigProvider;
|
import cc.carm.lib.configuration.yaml.YAMLConfigProvider;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class EasyConfiguration {
|
public class EasyConfiguration {
|
||||||
|
|
||||||
public static YamlConfigProvider from(File file, String source) {
|
public static YAMLConfigProvider from(File file, String source) {
|
||||||
YamlConfigProvider provider = new YamlConfigProvider(file);
|
YAMLConfigProvider provider = new YAMLConfigProvider(file);
|
||||||
try {
|
try {
|
||||||
provider.initializeFile(source);
|
provider.initializeFile(source);
|
||||||
provider.initializeConfig();
|
provider.initializeConfig();
|
||||||
@@ -18,15 +18,15 @@ public class EasyConfiguration {
|
|||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static YamlConfigProvider from(File file) {
|
public static YAMLConfigProvider from(File file) {
|
||||||
return from(file, file.getName());
|
return from(file, file.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static YamlConfigProvider from(String fileName) {
|
public static YAMLConfigProvider from(String fileName) {
|
||||||
return from(fileName, fileName);
|
return from(fileName, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static YamlConfigProvider from(String fileName, String source) {
|
public static YAMLConfigProvider from(String fileName, String source) {
|
||||||
return from(new File(fileName), source);
|
return from(new File(fileName), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class YamlComments implements CommentsProvider {
|
public class YAMLComments implements CommentsProvider {
|
||||||
|
|
||||||
Map<String, String[]> comments = new HashMap<>();
|
Map<String, String[]> comments = new HashMap<>();
|
||||||
|
|
||||||
+7
-7
@@ -8,13 +8,13 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class YamlConfigProvider extends FileConfigProvider<YamlSectionWrapper> {
|
public class YAMLConfigProvider extends FileConfigProvider<YAMLSectionWrapper> {
|
||||||
|
|
||||||
protected final @NotNull YamlComments comments = new YamlComments();
|
protected final @NotNull YAMLComments comments = new YAMLComments();
|
||||||
protected CommentedYamlConfiguration configuration;
|
protected CommentedYamlConfiguration configuration;
|
||||||
protected ConfigInitializer<YamlConfigProvider> initializer;
|
protected ConfigInitializer<YAMLConfigProvider> initializer;
|
||||||
|
|
||||||
public YamlConfigProvider(@NotNull File file) {
|
public YAMLConfigProvider(@NotNull File file) {
|
||||||
super(file);
|
super(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ public class YamlConfigProvider extends FileConfigProvider<YamlSectionWrapper> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull YamlSectionWrapper getConfiguration() {
|
public @NotNull YAMLSectionWrapper getConfiguration() {
|
||||||
return YamlSectionWrapper.of(configuration);
|
return YAMLSectionWrapper.of(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -49,7 +49,7 @@ public class YamlConfigProvider extends FileConfigProvider<YamlSectionWrapper> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ConfigInitializer<YamlConfigProvider> getInitializer() {
|
public @NotNull ConfigInitializer<YAMLConfigProvider> getInitializer() {
|
||||||
return this.initializer;
|
return this.initializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
+4
-4
@@ -12,17 +12,17 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class YamlSectionWrapper implements ConfigurationWrapper {
|
public class YAMLSectionWrapper implements ConfigurationWrapper {
|
||||||
|
|
||||||
private final ConfigurationSection section;
|
private final ConfigurationSection section;
|
||||||
|
|
||||||
private YamlSectionWrapper(ConfigurationSection section) {
|
private YAMLSectionWrapper(ConfigurationSection section) {
|
||||||
this.section = section;
|
this.section = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract("!null->!null")
|
@Contract("!null->!null")
|
||||||
public static @Nullable YamlSectionWrapper of(@Nullable ConfigurationSection section) {
|
public static @Nullable YAMLSectionWrapper of(@Nullable ConfigurationSection section) {
|
||||||
return section == null ? null : new YamlSectionWrapper(section);
|
return section == null ? null : new YAMLSectionWrapper(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2,30 +2,28 @@ package cc.carm.lib.configuration.yaml;
|
|||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||||
import cc.carm.lib.configuration.yaml.YamlConfigProvider;
|
import cc.carm.lib.configuration.yaml.builder.YAMLConfigBuilder;
|
||||||
import cc.carm.lib.configuration.yaml.YamlSectionWrapper;
|
|
||||||
import cc.carm.lib.configuration.yaml.builder.YamlConfigBuilder;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public abstract class YAMLValue<T> extends CachedConfigValue<T> {
|
public abstract class YAMLValue<T> extends CachedConfigValue<T> {
|
||||||
|
|
||||||
public static @NotNull YamlConfigBuilder builder() {
|
public static @NotNull YAMLConfigBuilder builder() {
|
||||||
return new YamlConfigBuilder();
|
return new YAMLConfigBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public YAMLValue(@Nullable YamlConfigProvider provider,
|
public YAMLValue(@Nullable YAMLConfigProvider provider,
|
||||||
@Nullable String configPath, @NotNull String[] comments, @Nullable T defaultValue) {
|
@Nullable String configPath, @NotNull String[] comments, @Nullable T defaultValue) {
|
||||||
super(provider, configPath, comments, defaultValue);
|
super(provider, configPath, comments, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public YamlConfigProvider getYAMLProvider() {
|
public YAMLConfigProvider getYAMLProvider() {
|
||||||
ConfigurationProvider<?> provider = getProvider();
|
ConfigurationProvider<?> provider = getProvider();
|
||||||
if (provider instanceof YamlConfigProvider) return (YamlConfigProvider) getProvider();
|
if (provider instanceof YAMLConfigProvider) return (YAMLConfigProvider) getProvider();
|
||||||
else throw new IllegalStateException("Provider is not a SpigotConfigProvider");
|
else throw new IllegalStateException("Provider is not a YamlConfigProvider");
|
||||||
}
|
}
|
||||||
|
|
||||||
public YamlSectionWrapper getYAMLConfig() {
|
public YAMLSectionWrapper getYAMLConfig() {
|
||||||
return getYAMLProvider().getConfiguration();
|
return getYAMLProvider().getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,13 +1,13 @@
|
|||||||
package cc.carm.lib.configuration.yaml.builder;
|
package cc.carm.lib.configuration.yaml.builder;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
||||||
import cc.carm.lib.configuration.yaml.YamlConfigProvider;
|
import cc.carm.lib.configuration.yaml.YAMLConfigProvider;
|
||||||
|
|
||||||
public abstract class AbstractYAMLBuilder<T, B extends AbstractYAMLBuilder<T, B>>
|
public abstract class AbstractYAMLBuilder<T, B extends AbstractYAMLBuilder<T, B>>
|
||||||
extends AbstractConfigBuilder<T, B, YamlConfigProvider> {
|
extends AbstractConfigBuilder<T, B, YAMLConfigProvider> {
|
||||||
|
|
||||||
public AbstractYAMLBuilder() {
|
public AbstractYAMLBuilder() {
|
||||||
super(YamlConfigProvider.class);
|
super(YAMLConfigProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import cc.carm.lib.configuration.yaml.builder.serializable.SerializableBuilder;
|
|||||||
import org.bspfsystems.yamlconfiguration.serialization.ConfigurationSerializable;
|
import org.bspfsystems.yamlconfiguration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class YamlConfigBuilder extends ConfigBuilder {
|
public class YAMLConfigBuilder extends ConfigBuilder {
|
||||||
|
|
||||||
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
||||||
return new SerializableBuilder<>(valueClass);
|
return new SerializableBuilder<>(valueClass);
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
package cc.carm.lib.configuration.yaml.value;
|
package cc.carm.lib.configuration.yaml.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.yaml.YAMLValue;
|
import cc.carm.lib.configuration.yaml.YAMLValue;
|
||||||
import cc.carm.lib.configuration.yaml.YamlConfigProvider;
|
import cc.carm.lib.configuration.yaml.YAMLConfigProvider;
|
||||||
import org.bspfsystems.yamlconfiguration.serialization.ConfigurationSerializable;
|
import org.bspfsystems.yamlconfiguration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -21,7 +21,7 @@ public class ConfiguredSerializable<T extends ConfigurationSerializable> extends
|
|||||||
|
|
||||||
protected final @NotNull Class<T> valueClass;
|
protected final @NotNull Class<T> valueClass;
|
||||||
|
|
||||||
public ConfiguredSerializable(@Nullable YamlConfigProvider provider,
|
public ConfiguredSerializable(@Nullable YAMLConfigProvider provider,
|
||||||
@Nullable String configPath, @NotNull String[] comments,
|
@Nullable String configPath, @NotNull String[] comments,
|
||||||
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
||||||
super(provider, configPath, comments, defaultValue);
|
super(provider, configPath, comments, defaultValue);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package config;
|
package config;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.EasyConfiguration;
|
import cc.carm.lib.configuration.EasyConfiguration;
|
||||||
import cc.carm.lib.configuration.yaml.YamlConfigProvider;
|
import cc.carm.lib.configuration.yaml.YAMLConfigProvider;
|
||||||
import config.model.AbstractModel;
|
import config.model.AbstractModel;
|
||||||
import config.model.SomeModel;
|
import config.model.SomeModel;
|
||||||
import config.model.TestModel;
|
import config.model.TestModel;
|
||||||
@@ -23,7 +23,7 @@ public class ConfigTester {
|
|||||||
ConfigurationSerialization.registerClass(SomeModel.class);
|
ConfigurationSerialization.registerClass(SomeModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final YamlConfigProvider provider = EasyConfiguration.from("target/config.yml", "config.yml");
|
protected final YAMLConfigProvider provider = EasyConfiguration.from("target/config.yml", "config.yml");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onTest() {
|
public void onTest() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package config.source;
|
package config.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||||
import cc.carm.lib.configuration.core.annotation.ConfigComment;
|
import cc.carm.lib.configuration.core.annotation.ConfigComment;
|
||||||
import cc.carm.lib.configuration.core.annotation.ConfigPath;
|
import cc.carm.lib.configuration.core.annotation.ConfigPath;
|
||||||
@@ -26,13 +27,15 @@ public class DemoConfiguration extends ConfigurationRoot {
|
|||||||
protected static final ConfigValue<Double> VERSION = ConfiguredValue.of(Double.class, 1.0D);
|
protected static final ConfigValue<Double> VERSION = ConfiguredValue.of(Double.class, 1.0D);
|
||||||
|
|
||||||
|
|
||||||
|
// 支持通过 Class<?> 变量标注子配置,一并注册。
|
||||||
// 注意: 若对应类也有注解,则优先使用类的注解。
|
// 注意: 若对应类也有注解,则优先使用类的注解。
|
||||||
@ConfigPath("impl-test") //支持通过注解修改子配置的主路径,若不修改则以变量名自动生成。
|
@ConfigPath("impl-test") //支持通过注解修改子配置的主路径,若不修改则以变量名自动生成。
|
||||||
@ConfigComment("Something...") // 支持给子路径直接打注释
|
@ConfigComment("Something...") // 支持给子路径直接打注释
|
||||||
public static final Class<?> IMPL = ImplConfiguration.class;
|
public static final Class<?> IMPL = ImplConfiguration.class;
|
||||||
|
|
||||||
// 可以直接写静态内部类,并通过 Class<?> 声明。
|
// 子配置文件
|
||||||
public static final Class<?> SUB_TEST = Sub.class;
|
@ConfigPath("database")
|
||||||
|
public static final Class<?> DB_CONFIG = DatabaseConfiguration.class;
|
||||||
|
|
||||||
@ConfigPath("user") // 通过注解规定配置文件中的路径,若不进行注解则以变量名自动生成。
|
@ConfigPath("user") // 通过注解规定配置文件中的路径,若不进行注解则以变量名自动生成。
|
||||||
@ConfigComment({"Section类型数据测试"}) // 通过注解给配置添加注释。
|
@ConfigComment({"Section类型数据测试"}) // 通过注解给配置添加注释。
|
||||||
@@ -42,10 +45,6 @@ public class DemoConfiguration extends ConfigurationRoot {
|
|||||||
.parseValue((section, defaultValue) -> TestModel.deserialize(section))
|
.parseValue((section, defaultValue) -> TestModel.deserialize(section))
|
||||||
.serializeValue(TestModel::serialize).build();
|
.serializeValue(TestModel::serialize).build();
|
||||||
|
|
||||||
// 子配置文件
|
|
||||||
@ConfigPath("database")
|
|
||||||
public static final Class<?> DB_CONFIG = DatabaseConfiguration.class;
|
|
||||||
|
|
||||||
@ConfigComment({"[ID-UUID] 对照表", "", "用于测试Map类型的解析与序列化保存"})
|
@ConfigComment({"[ID-UUID] 对照表", "", "用于测试Map类型的解析与序列化保存"})
|
||||||
public static final ConfigValue<Map<Integer, UUID>> USERS = ConfiguredMap
|
public static final ConfigValue<Map<Integer, UUID>> USERS = ConfiguredMap
|
||||||
.builder(Integer.class, UUID.class).fromString()
|
.builder(Integer.class, UUID.class).fromString()
|
||||||
@@ -54,6 +53,10 @@ public class DemoConfiguration extends ConfigurationRoot {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支持内部类的直接注册。
|
||||||
|
* 注意,需要使用 {@link ConfigInitializer#initialize(Class, boolean, boolean)} 方法,并设定第三个参数为 true。
|
||||||
|
*/
|
||||||
public static class Sub extends ConfigurationRoot {
|
public static class Sub extends ConfigurationRoot {
|
||||||
|
|
||||||
@ConfigPath(value = "uuid-value", root = true)
|
@ConfigPath(value = "uuid-value", root = true)
|
||||||
@@ -62,8 +65,6 @@ public class DemoConfiguration extends ConfigurationRoot {
|
|||||||
.parseValue((data, defaultValue) -> UUID.fromString(data))
|
.parseValue((data, defaultValue) -> UUID.fromString(data))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final Class<?> NOTHING = Sub.That.class;
|
|
||||||
|
|
||||||
public static class That extends ConfigurationRoot {
|
public static class That extends ConfigurationRoot {
|
||||||
|
|
||||||
public static final ConfigValue<List<UUID>> OPERATORS = ConfiguredList
|
public static final ConfigValue<List<UUID>> OPERATORS = ConfiguredList
|
||||||
|
|||||||
@@ -15,10 +15,11 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyconfiguration-parent</artifactId>
|
<artifactId>easyconfiguration-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>2.0.0</version>
|
<version>2.2.0</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>core</module>
|
<module>core</module>
|
||||||
<module>impl/yaml</module>
|
<module>impl/yaml</module>
|
||||||
|
<module>impl/json</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<name>EasyConfiguration</name>
|
<name>EasyConfiguration</name>
|
||||||
@@ -44,8 +45,8 @@
|
|||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>The MIT License</name>
|
<name>GNU LESSER GENERAL PUBLIC LICENSE</name>
|
||||||
<url>https://opensource.org/licenses/MIT</url>
|
<url>https://www.gnu.org/licenses/lgpl-3.0.html</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
@@ -163,7 +164,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.4.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<classifier>javadoc</classifier>
|
<classifier>javadoc</classifier>
|
||||||
<detectJavaApiLink>false</detectJavaApiLink>
|
<detectJavaApiLink>false</detectJavaApiLink>
|
||||||
|
|||||||
Reference in New Issue
Block a user