From 3a0a8e79b98a61f63452bb3045886dcfd501fddc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=86=AC=E8=8A=B1ice?=
<67498111+flowerinsnowdh@users.noreply.github.com>
Date: Wed, 21 Jun 2023 19:54:30 +0800
Subject: [PATCH] =?UTF-8?q?feat(hocon):=20=E5=AE=8C=E6=88=90=E5=AF=B9=20HO?=
=?UTF-8?q?CON=20=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=94=AF=E6=8C=81=20(#36)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
impl/hocon/pom.xml | 66 ++++++++++
.../lib/configuration/EasyConfiguration.java | 31 +++++
.../configuration/hocon/CommentedHOCON.java | 26 ++++
.../hocon/HOCONConfigWrapper.java | 117 ++++++++++++++++++
.../hocon/HOCONFileConfigProvider.java | 103 +++++++++++++++
.../exception/HOCONGetValueException.java | 19 +++
.../hocon/source/StringConfigProvider.java | 23 ++++
.../configuration/hocon/util/HOCONUtils.java | 105 ++++++++++++++++
.../test/easyconfiguration/HOCONTest.java | 23 ++++
.../test/easyconfiguration/config/Config.java | 20 +++
pom.xml | 1 +
11 files changed, 534 insertions(+)
create mode 100644 impl/hocon/pom.xml
create mode 100644 impl/hocon/src/main/java/cc/carm/lib/configuration/EasyConfiguration.java
create mode 100644 impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/CommentedHOCON.java
create mode 100644 impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/HOCONConfigWrapper.java
create mode 100644 impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/HOCONFileConfigProvider.java
create mode 100644 impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/exception/HOCONGetValueException.java
create mode 100644 impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/source/StringConfigProvider.java
create mode 100644 impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/util/HOCONUtils.java
create mode 100644 impl/hocon/src/test/java/online/flowerinsnow/test/easyconfiguration/HOCONTest.java
create mode 100644 impl/hocon/src/test/java/online/flowerinsnow/test/easyconfiguration/config/Config.java
diff --git a/impl/hocon/pom.xml b/impl/hocon/pom.xml
new file mode 100644
index 0000000..2257f20
--- /dev/null
+++ b/impl/hocon/pom.xml
@@ -0,0 +1,66 @@
+
+
+ 4.0.0
+
+ cc.carm.lib
+ easyconfiguration-parent
+ 3.6.0
+ ../../pom.xml
+
+
+ easyconfiguration-hocon
+ jar
+
+
+ ${project.jdk.version}
+ ${project.jdk.version}
+ UTF-8
+ UTF-8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+
+
+
+
+
+ ${project.parent.groupId}
+ easyconfiguration-core
+ ${project.parent.version}
+ compile
+
+
+
+ ${project.parent.groupId}
+ easyconfiguration-demo
+ ${project.parent.version}
+ test
+
+
+
+ com.typesafe
+ config
+ 1.4.2
+ compile
+
+
+
\ No newline at end of file
diff --git a/impl/hocon/src/main/java/cc/carm/lib/configuration/EasyConfiguration.java b/impl/hocon/src/main/java/cc/carm/lib/configuration/EasyConfiguration.java
new file mode 100644
index 0000000..f0e63ca
--- /dev/null
+++ b/impl/hocon/src/main/java/cc/carm/lib/configuration/EasyConfiguration.java
@@ -0,0 +1,31 @@
+package cc.carm.lib.configuration;
+
+import cc.carm.lib.configuration.hocon.HOCONFileConfigProvider;
+
+import java.io.File;
+import java.io.IOException;
+
+public class EasyConfiguration {
+ public static HOCONFileConfigProvider from(File file, String source) {
+ HOCONFileConfigProvider provider = new HOCONFileConfigProvider(file);
+ try {
+ provider.initializeFile(source);
+ provider.initializeConfig();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return provider;
+ }
+
+ public static HOCONFileConfigProvider from(File file) {
+ return from(file, file.getName());
+ }
+
+ public static HOCONFileConfigProvider from(String fileName) {
+ return from(fileName, fileName);
+ }
+
+ public static HOCONFileConfigProvider from(String fileName, String source) {
+ return from(new File(fileName), source);
+ }
+}
diff --git a/impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/CommentedHOCON.java b/impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/CommentedHOCON.java
new file mode 100644
index 0000000..202bb1f
--- /dev/null
+++ b/impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/CommentedHOCON.java
@@ -0,0 +1,26 @@
+package cc.carm.lib.configuration.hocon;
+
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+import java.util.Set;
+
+public interface CommentedHOCON {
+ default @NotNull Set getKeys() {
+ return getKeys(null, true);
+ }
+
+ String serializeValue(@NotNull String key, @NotNull Object value);
+
+ @Contract("null,_ -> !null;!null,_ -> _")
+ @Nullable Set getKeys(@Nullable String sectionKey, boolean deep);
+
+ @Nullable Object getValue(@NotNull String key);
+
+ @Nullable String getInlineComment(@NotNull String key);
+
+ @Nullable
+ List getHeaderComments(@Nullable String key);
+}
diff --git a/impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/HOCONConfigWrapper.java b/impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/HOCONConfigWrapper.java
new file mode 100644
index 0000000..5465e23
--- /dev/null
+++ b/impl/hocon/src/main/java/cc/carm/lib/configuration/hocon/HOCONConfigWrapper.java
@@ -0,0 +1,117 @@
+package cc.carm.lib.configuration.hocon;
+
+import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
+import cc.carm.lib.configuration.hocon.util.HOCONUtils;
+import com.typesafe.config.*;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.*;
+
+public class HOCONConfigWrapper implements ConfigurationWrapper