mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21f0ca8256 | |||
| f54ee83938 | |||
| f5316eb320 | |||
| 500eebefde | |||
| d9cb95b2e9 | |||
| ce6554c3f1 | |||
| 7dcd690a05 | |||
| f376f22ad0 | |||
| ab586c4b00 | |||
| 64cbfaa974 | |||
| 3cab343919 | |||
| 1ad8c1f407 | |||
| 4e6db50049 | |||
| e62cef5644 | |||
| d6a56003aa | |||
| 8a5870300d | |||
| 42885b2a12 | |||
| 96216d5126 | |||
| d890ce1b94 | |||
| d1ff4f7014 | |||
| 9f3089566c | |||
| 79105bf400 | |||
| 2b0b74af92 | |||
| c65d164167 | |||
| 74bde0c7ea | |||
| 7fba61cb64 | |||
| b609e1d174 | |||
| bdbd484690 | |||
| cc5383b0f2 | |||
| 35d2653f56 | |||
| d6fa7710dc | |||
| fdb6d81bf0 |
@@ -1,70 +1,34 @@
|
||||
---
|
||||
name:
|
||||
问题提交
|
||||
about:
|
||||
描述问题并提交,帮助我们对其进行检查与修复。
|
||||
title: ''
|
||||
labels:
|
||||
bug
|
||||
name: Submit bugs&issues
|
||||
about: Describe the problem and submit it to help us review and fix it.
|
||||
title: 'fix: '
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
###
|
||||
*
|
||||
*问题简述
|
||||
**
|
||||
### **Description**
|
||||
|
||||
用简短的话语描述一下大概问题。
|
||||
<!-- Describe the general problem in short words.-->
|
||||
|
||||
###
|
||||
*
|
||||
*问题来源
|
||||
**
|
||||
### **Operations**
|
||||
|
||||
描述一下通过哪些操作才发现的问题,如:
|
||||
<!--
|
||||
Describe the problem discovered through what operations, such as:
|
||||
|
||||
1.
|
||||
使用了 '...'
|
||||
2.
|
||||
输入了 '....'
|
||||
3.
|
||||
出现了报错 '....'
|
||||
1. Clicked '...'
|
||||
2. Typed '....'
|
||||
3. Error says '....'
|
||||
-->
|
||||
|
||||
###
|
||||
*
|
||||
*预期结果
|
||||
** (可选)
|
||||
### **Expected result** _(Optional)_
|
||||
|
||||
如果问题不发生,应该是什么情况
|
||||
### **Screenshots & Error Logs**
|
||||
|
||||
###
|
||||
*
|
||||
*问题截图/问题报错
|
||||
**
|
||||
### **Environment**
|
||||
|
||||
如果有报错或输出,请提供截图。
|
||||
- System: `Windows 10` / `Ubuntu` / `...`
|
||||
- Java version: `JDK11` / `OPENJDK8` / `JRE8` / `...`
|
||||
|
||||
###
|
||||
*
|
||||
*操作环境
|
||||
**
|
||||
### **Anything else...**
|
||||
|
||||
-
|
||||
系统环境:
|
||||
`Windows 10` /
|
||||
`Ubuntu` /
|
||||
`...`
|
||||
-
|
||||
Java版本:
|
||||
`JDK11` /
|
||||
`OPENJDK8` /
|
||||
`JRE8` /
|
||||
`...`
|
||||
|
||||
###
|
||||
*
|
||||
*其他补充
|
||||
**
|
||||
|
||||
如有其他补充,可以在这里描述。
|
||||
<!-- If there are other supplements, they can be described here. -->
|
||||
|
||||
@@ -1,38 +1,23 @@
|
||||
---
|
||||
name:
|
||||
功能需求
|
||||
about:
|
||||
希望我们提供更多的功能。
|
||||
title: ''
|
||||
labels:
|
||||
enhancement
|
||||
name: Features
|
||||
about: Ask for new features.
|
||||
title: 'feat: '
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
###
|
||||
*
|
||||
*功能简述
|
||||
**
|
||||
### **Description**
|
||||
|
||||
简单的描述一下你想要的功能
|
||||
<!-- Describe the features in short words.-->
|
||||
|
||||
###
|
||||
*
|
||||
*需求来源
|
||||
**
|
||||
### **Source**
|
||||
|
||||
简单的描述一下为什么需要这个功能。
|
||||
<!-- Describe the reason that you need this feature in short words.-->
|
||||
|
||||
###
|
||||
*
|
||||
*功能参考
|
||||
**(可选)
|
||||
### **Examples** _(Optional)_
|
||||
|
||||
如果有相关功能的参考,如文本、截图,请提供给我们。
|
||||
<!--Any screenshots or example codes please.-->
|
||||
|
||||
###
|
||||
*
|
||||
*附加内容
|
||||
**
|
||||
### **Additional details**
|
||||
|
||||
如果有什么小细节需要重点注意,请在这里告诉我们。
|
||||
<!--If there are any small details that need to be highlighted, please let us know here.-->
|
||||
|
||||
@@ -38,11 +38,11 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@v6
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -53,7 +53,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
uses: github/codeql-action/autobuild@v4
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -67,4 +67,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
uses: github/codeql-action/analyze@v4
|
||||
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
@@ -87,7 +87,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
|
||||
@@ -15,7 +15,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
@@ -26,7 +26,7 @@ jobs:
|
||||
- name: "Target Stage"
|
||||
run: mkdir staging && cp */target/*.jar staging
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: Artifact
|
||||
path: staging
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
@@ -17,7 +17,7 @@
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
|
||||
<deps.mysql-driver.version>8.0.33</deps.mysql-driver.version>
|
||||
<log4j.version>2.25.2</log4j.version>
|
||||
<log4j.version>2.25.3</log4j.version>
|
||||
</properties>
|
||||
<artifactId>configured-demo</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
@@ -14,7 +14,7 @@
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<kotlin.version>2.2.20</kotlin.version>
|
||||
<kotlin.version>2.3.10</kotlin.version>
|
||||
</properties>
|
||||
|
||||
<artifactId>configured-feature-kotlin</artifactId>
|
||||
@@ -86,7 +86,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.dokka</groupId>
|
||||
<artifactId>dokka-maven-plugin</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>pre-site</phase>
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<kotlin.version>2.3.10</kotlin.version>
|
||||
</properties>
|
||||
<artifactId>configured-feature-multi</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Configured - Record Feature</name>
|
||||
<url>https://github.com/CarmJos/configured</url>
|
||||
<description>Provides Java record type support for the Configured framework.</description>
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-feature-file</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-yaml</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</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,135 @@
|
||||
package cc.carm.lib.configuration.multi;
|
||||
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class MultiConfiguration<K, T> {
|
||||
|
||||
protected final ConcurrentHashMap<K, T> valuesCache = new ConcurrentHashMap<>();
|
||||
|
||||
public MultiConfiguration() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the value of the key from the holder, and return the value.
|
||||
*
|
||||
* @param key The key of the value to read.
|
||||
* @param holder The holder of the value to read.
|
||||
* @return The value of the key, or null if the value is not exist.
|
||||
*/
|
||||
public abstract T read(@NotNull K key, @NotNull ConfigurationHolder<?> holder);
|
||||
|
||||
/**
|
||||
* Write (and save) the value of the key to the holder, then update the cache.
|
||||
*
|
||||
* @param holder The holder of the value to write.
|
||||
* @param value The value to write, which should not be null.
|
||||
*/
|
||||
public abstract void write(@NotNull ConfigurationHolder<?> holder, @NotNull T value);
|
||||
|
||||
/**
|
||||
* Get all holders of the configuration, which should be a concurrent map to support concurrent access.
|
||||
*
|
||||
* @return All holders of the configuration.
|
||||
*/
|
||||
public abstract @NotNull Map<K, ConfigurationHolder<?>> holders();
|
||||
|
||||
/**
|
||||
* Get the holder of the key.
|
||||
* If the holder of the key is not exist,
|
||||
* it should be created then return the created holder.
|
||||
*
|
||||
* @param key The key of the holder to get.
|
||||
* @return The holder of the key.
|
||||
*/
|
||||
public abstract @NotNull ConfigurationHolder<?> holder(@NotNull K key);
|
||||
|
||||
/**
|
||||
* Remove the holder of the key, and remove the value of the key from the cache.
|
||||
* Also delete the configuration file if necessary.
|
||||
*
|
||||
* @param key The key of the holder to remove.
|
||||
*/
|
||||
public abstract void removeHolder(@NotNull K key);
|
||||
|
||||
public void loadAll() {
|
||||
for (Map.Entry<K, ConfigurationHolder<?>> entry : holders().entrySet()) {
|
||||
K key = entry.getKey();
|
||||
ConfigurationHolder<?> holder = entry.getValue();
|
||||
try {
|
||||
T loaded = read(key, holder);
|
||||
if (loaded != null) {
|
||||
valuesCache.put(key, loaded);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAll() {
|
||||
for (Map.Entry<K, T> entry : valuesCache.entrySet()) {
|
||||
K key = entry.getKey();
|
||||
T value = entry.getValue();
|
||||
ConfigurationHolder<?> holder = holder(key);
|
||||
try {
|
||||
write(holder, value);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all keys in the cache.
|
||||
*
|
||||
* @return All keys in the cache.
|
||||
*/
|
||||
public @NotNull Set<K> keys() {
|
||||
return valuesCache.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all values in the cache.
|
||||
*
|
||||
* @return All values in the cache.
|
||||
*/
|
||||
public @NotNull Map<K, T> values() {
|
||||
return this.valuesCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the key, or null if the value is not exist.
|
||||
*
|
||||
* @param key The key of the value to get.
|
||||
* @return The value of the key, or null if the value is not exist.
|
||||
*/
|
||||
public @Nullable T get(@NotNull K key) {
|
||||
return valuesCache.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the value of the key, and return the old value.
|
||||
*
|
||||
* @param key The key of the value to update.
|
||||
* @param value The new value, or null to remove the value.
|
||||
* @return The old value, or null if the value is not exist.
|
||||
*/
|
||||
public @Nullable T update(@NotNull K key, @Nullable T value) {
|
||||
if (value == null) {
|
||||
T current = valuesCache.remove(key);
|
||||
removeHolder(key);
|
||||
return current;
|
||||
}
|
||||
ConfigurationHolder<?> holder = holder(key);
|
||||
write(holder, value);
|
||||
return valuesCache.put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package cc.carm.lib.configuration.multi;
|
||||
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class MultiFileConfiguration<K, T> extends MultiConfiguration<K, T> {
|
||||
|
||||
protected final @NotNull File dataFolder;
|
||||
protected final @NotNull String extensionSuffix; // e.g. ".yml"
|
||||
|
||||
protected final ConcurrentHashMap<K, ConfigurationHolder<?>> holders = new ConcurrentHashMap<>();
|
||||
|
||||
public MultiFileConfiguration(@NotNull File dataFolder, @NotNull String extensionSuffix) {
|
||||
this.dataFolder = dataFolder;
|
||||
this.extensionSuffix = extensionSuffix;
|
||||
|
||||
// Load existing configuration files
|
||||
if (dataFolder.exists() && dataFolder.isDirectory()) {
|
||||
File[] files = dataFolder.listFiles((dir, name) -> name.endsWith(extensionSuffix));
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
String fileName = file.getName();
|
||||
String keyStr = fileName.substring(0, fileName.length() - extensionSuffix.length()); // Remove extension suffix
|
||||
try {
|
||||
holders.put(extractKeyFromFilename(keyStr), loadHolder(file));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadAll();
|
||||
}
|
||||
|
||||
public abstract K extractKeyFromFilename(@NotNull String fileName);
|
||||
|
||||
public String keyToFilename(@NotNull K key) {
|
||||
return key.toString();
|
||||
}
|
||||
|
||||
public abstract ConfigurationHolder<?> loadHolder(@NotNull File file);
|
||||
|
||||
@Override
|
||||
public @NotNull Map<K, ConfigurationHolder<?>> holders() {
|
||||
return this.holders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigurationHolder<?> holder(@NotNull K key) {
|
||||
ConfigurationHolder<?> loaded = holders.get(key);
|
||||
if (loaded != null) return loaded;
|
||||
|
||||
File file = new File(dataFolder, keyToFilename(key) + this.extensionSuffix);
|
||||
ConfigurationHolder<?> created = loadHolder(file);
|
||||
holders.put(key, created);
|
||||
return created;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHolder(@NotNull K key) {
|
||||
ConfigurationHolder<?> loaded = holders.remove(key);
|
||||
if (loaded == null) return;
|
||||
|
||||
File file = new File(dataFolder, key + ".yml");
|
||||
if (file.exists()) file.delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package cc.carm.lib.configuration.tests;
|
||||
|
||||
import cc.carm.lib.configuration.multi.MultiFileConfiguration;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.section.ConfigureSection;
|
||||
import cc.carm.lib.configuration.source.yaml.YAMLConfigFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MultiFileTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ProfileStorage storage = new ProfileStorage(new File(new File("target"), "test-profiles"));
|
||||
|
||||
// Add (or create) a new entry to file.
|
||||
UserProfile profile = new UserProfile(UUID.randomUUID(), "John Doe", "john@google.com", "123123123");
|
||||
storage.update(profile.getUniqueId(), profile);
|
||||
|
||||
// Read files.
|
||||
System.out.println("Current users: ");
|
||||
storage.values().forEach((k, v) -> {
|
||||
System.out.println("# " + k);
|
||||
System.out.println("- " + v.getName() + " (" + v.getEmail() + ", " + v.getPhone() + ")");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static class ProfileStorage extends MultiFileConfiguration<UUID, UserProfile> {
|
||||
|
||||
|
||||
public ProfileStorage(@NotNull File dataFolder) {
|
||||
super(dataFolder, ".yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfile read(@NotNull UUID key, @NotNull ConfigurationHolder<?> holder) {
|
||||
ConfigureSection conf = holder.config();
|
||||
return new UserProfile(
|
||||
key,
|
||||
conf.getString("name", "Unknown"),
|
||||
conf.getString("email", "unset"),
|
||||
conf.getString("phone", "123123123")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull ConfigurationHolder<?> holder, @NotNull UserProfile value) {
|
||||
ConfigureSection conf = holder.config();
|
||||
conf.set("name", value.getName());
|
||||
conf.set("email", value.getEmail());
|
||||
conf.set("phone", value.getPhone());
|
||||
try {
|
||||
holder.save();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID extractKeyFromFilename(@NotNull String fileName) {
|
||||
return UUID.fromString(fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationHolder<?> loadHolder(@NotNull File file) {
|
||||
return YAMLConfigFactory.from(file).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package cc.carm.lib.configuration.tests;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserProfile {
|
||||
|
||||
protected final @NotNull UUID uuid;
|
||||
protected final @NotNull String name;
|
||||
protected final @NotNull String email;
|
||||
protected final @NotNull String phone;
|
||||
|
||||
public UserProfile(@NotNull UUID uuid, @NotNull String name, @NotNull String email, @NotNull String phone) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public @NotNull UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public @NotNull String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public @NotNull String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public @NotNull String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof UserProfile)) return false;
|
||||
UserProfile that = (UserProfile) o;
|
||||
return Objects.equals(name, that.name) && Objects.equals(email, that.email) && Objects.equals(phone, that.phone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, email, phone);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
+2
-1
@@ -39,7 +39,8 @@ public abstract class ContentInserter<RECEIVER> implements Comparable<ContentIns
|
||||
@NotNull Insertable<RECEIVER, ?> insertions) {
|
||||
Matcher matcher = matcher(line);
|
||||
if (!matcher.matches()) return null;
|
||||
if (!insertions.inserting(extractID(matcher))) return Collections.emptyList();
|
||||
String id = extractID(matcher);
|
||||
if (id == null || !insertions.inserting(id)) return Collections.emptyList();
|
||||
return get(receiver, matcher, insertions);
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -47,8 +47,13 @@ public abstract class ContentReplacer<RECEIVER> implements Comparable<ContentRep
|
||||
Matcher matcher = matcher(text);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String replaced = get(receiver, matcher);
|
||||
matcher.appendReplacement(sb, replaced == null ? "" : replaced);
|
||||
try {
|
||||
String replaced = get(receiver, matcher);
|
||||
matcher.appendReplacement(sb, replaced == null ? "" : replaced);
|
||||
} catch (Exception ex) {
|
||||
// Do nothing if exception occurred.
|
||||
ex.printStackTrace(); // for debug
|
||||
}
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
return sb.toString();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<kotlin.version>2.2.20</kotlin.version>
|
||||
<kotlin.version>2.3.10</kotlin.version>
|
||||
</properties>
|
||||
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<modules>
|
||||
<module>core</module>
|
||||
<module>features/section</module>
|
||||
@@ -37,6 +37,7 @@
|
||||
<module>providers/mongodb</module>
|
||||
|
||||
<module>demo</module>
|
||||
<module>features/multi</module>
|
||||
</modules>
|
||||
|
||||
<name>configured</name>
|
||||
@@ -121,7 +122,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>26.0.2-1</version>
|
||||
<version>26.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -134,7 +135,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.4</version>
|
||||
<version>3.5.5</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
@@ -162,7 +163,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.1</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<useReleaseProfile>false</useReleaseProfile>
|
||||
@@ -204,7 +205,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.1</version>
|
||||
<version>3.15.0</version>
|
||||
<configuration>
|
||||
<source>${project.jdk.version}</source>
|
||||
<target>${project.jdk.version}</target>
|
||||
@@ -216,13 +217,13 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.4.2</version>
|
||||
<version>3.5.0</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<version>3.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -236,7 +237,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<version>3.6.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -283,7 +284,7 @@
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<version>0.10.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
@@ -50,7 +50,7 @@
|
||||
<dependency>
|
||||
<groupId>com.typesafe</groupId>
|
||||
<artifactId>config</artifactId>
|
||||
<version>1.4.5</version>
|
||||
<version>1.4.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -14,7 +14,7 @@
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<deps.mongodb.version>5.6.0</deps.mongodb.version>
|
||||
<deps.mongodb.version>5.6.4</deps.mongodb.version>
|
||||
</properties>
|
||||
<artifactId>configured-mongodb</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>configured-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>4.2.0</version>
|
||||
<version>4.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
@@ -63,7 +63,7 @@
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.5</version>
|
||||
<version>2.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user