This is an automated email from the ASF dual-hosted git repository.
totalo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 6457e379a87 Split PluginConfigurationLoader and
YamlPluginConfigurationLoader (#23426)
6457e379a87 is described below
commit 6457e379a875270ede16d7c72378151eed7ffc4d
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 9 13:16:47 2023 +0800
Split PluginConfigurationLoader and YamlPluginConfigurationLoader (#23426)
* Code format for PluginJarLoader
* Split PluginConfigurationLoader and YamlPluginConfigurationLoader
---
.../agent/core/ShardingSphereAgent.java | 4 ++--
.../{loader => }/AdvisorConfigurationLoader.java | 2 +-
.../{yaml/loader => }/PluginConfigurationLoader.java | 19 +++----------------
.../agent/core/plugin/jar/PluginJarLoader.java | 3 +--
...Loader.java => YamlPluginConfigurationLoader.java} | 16 +++-------------
.../loader => }/PluginConfigurationLoaderTest.java | 2 +-
6 files changed, 11 insertions(+), 35 deletions(-)
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
index feac810b366..488b9ea9ef6 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
@@ -24,9 +24,9 @@ import
org.apache.shardingsphere.agent.core.builder.AgentBuilderFactory;
import org.apache.shardingsphere.agent.core.path.AgentPath;
import org.apache.shardingsphere.agent.core.plugin.jar.PluginJar;
import
org.apache.shardingsphere.agent.core.advisor.config.AdvisorConfiguration;
-import
org.apache.shardingsphere.agent.core.advisor.loader.AdvisorConfigurationLoader;
+import org.apache.shardingsphere.agent.core.advisor.AdvisorConfigurationLoader;
import org.apache.shardingsphere.agent.core.plugin.jar.PluginJarLoader;
-import
org.apache.shardingsphere.agent.core.plugin.yaml.loader.PluginConfigurationLoader;
+import org.apache.shardingsphere.agent.core.plugin.PluginConfigurationLoader;
import java.io.File;
import java.io.IOException;
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/loader/AdvisorConfigurationLoader.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/AdvisorConfigurationLoader.java
similarity index 98%
rename from
agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/loader/AdvisorConfigurationLoader.java
rename to
agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/AdvisorConfigurationLoader.java
index 496be1debc0..a825707faf7 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/loader/AdvisorConfigurationLoader.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/AdvisorConfigurationLoader.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.advisor.loader;
+package org.apache.shardingsphere.agent.core.advisor;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/PluginConfigurationLoader.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginConfigurationLoader.java
similarity index 63%
copy from
agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/PluginConfigurationLoader.java
copy to
agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginConfigurationLoader.java
index 311958ab9b5..2fb834ba456 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/PluginConfigurationLoader.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginConfigurationLoader.java
@@ -15,22 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.yaml.loader;
+package org.apache.shardingsphere.agent.core.plugin;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.api.PluginConfiguration;
-import
org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlAgentConfiguration;
+import
org.apache.shardingsphere.agent.core.plugin.yaml.loader.YamlPluginConfigurationLoader;
import
org.apache.shardingsphere.agent.core.plugin.yaml.swapper.YamlPluginsConfigurationSwapper;
-import org.yaml.snakeyaml.Yaml;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Map;
-import java.util.Optional;
/**
* Plugin configuration loader.
@@ -48,15 +44,6 @@ public final class PluginConfigurationLoader {
* @throws IOException IO exception
*/
public static Map<String, PluginConfiguration> load(final File
agentRootPath) throws IOException {
- return loadYAML(new File(agentRootPath,
CONFIG_PATH)).map(YamlPluginsConfigurationSwapper::swap).orElse(Collections.emptyMap());
- }
-
- private static Optional<YamlAgentConfiguration> loadYAML(final File
yamlFile) throws IOException {
- try (
- FileInputStream fileInputStream = new
FileInputStream(yamlFile);
- InputStreamReader inputStreamReader = new
InputStreamReader(fileInputStream)) {
- YamlAgentConfiguration result = new
Yaml().loadAs(inputStreamReader, YamlAgentConfiguration.class);
- return null == result ? Optional.empty() : Optional.of(result);
- }
+ return YamlPluginConfigurationLoader.load(new File(agentRootPath,
CONFIG_PATH)).map(YamlPluginsConfigurationSwapper::swap).orElse(Collections.emptyMap());
}
}
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoader.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoader.java
index 57a7f9b76c8..1238fb77a11 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoader.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoader.java
@@ -64,9 +64,8 @@ public final class PluginJarLoader {
@SneakyThrows(IOException.class)
private static void getJarFiles(final File file, final List<File>
jarFiles) {
-
Files.walkFileTree(file.toPath(), new SimpleFileVisitor<Path>() {
-
+
@Override
public FileVisitResult visitFile(final Path path, final
BasicFileAttributes attributes) {
if (path.toFile().isFile() &&
path.toFile().getName().endsWith(".jar")) {
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/PluginConfigurationLoader.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/YamlPluginConfigurationLoader.java
similarity index 71%
rename from
agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/PluginConfigurationLoader.java
rename to
agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/YamlPluginConfigurationLoader.java
index 311958ab9b5..6f0f4c0d8a3 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/PluginConfigurationLoader.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/YamlPluginConfigurationLoader.java
@@ -19,39 +19,29 @@ package
org.apache.shardingsphere.agent.core.plugin.yaml.loader;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.agent.api.PluginConfiguration;
import
org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlAgentConfiguration;
-import
org.apache.shardingsphere.agent.core.plugin.yaml.swapper.YamlPluginsConfigurationSwapper;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.util.Collections;
-import java.util.Map;
import java.util.Optional;
/**
* Plugin configuration loader.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PluginConfigurationLoader {
-
- private static final String CONFIG_PATH = "/conf/agent.yaml";
+public final class YamlPluginConfigurationLoader {
/**
* Load plugin configurations.
*
- * @param agentRootPath agent root path
+ * @param yamlFile yaml file
* @return plugin configurations
* @throws IOException IO exception
*/
- public static Map<String, PluginConfiguration> load(final File
agentRootPath) throws IOException {
- return loadYAML(new File(agentRootPath,
CONFIG_PATH)).map(YamlPluginsConfigurationSwapper::swap).orElse(Collections.emptyMap());
- }
-
- private static Optional<YamlAgentConfiguration> loadYAML(final File
yamlFile) throws IOException {
+ public static Optional<YamlAgentConfiguration> load(final File yamlFile)
throws IOException {
try (
FileInputStream fileInputStream = new
FileInputStream(yamlFile);
InputStreamReader inputStreamReader = new
InputStreamReader(fileInputStream)) {
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/PluginConfigurationLoaderTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/PluginConfigurationLoaderTest.java
similarity index 97%
rename from
agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/PluginConfigurationLoaderTest.java
rename to
agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/PluginConfigurationLoaderTest.java
index 49b0d7a18f2..2d49645e715 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/loader/PluginConfigurationLoaderTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/PluginConfigurationLoaderTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.yaml.loader;
+package org.apache.shardingsphere.agent.core.plugin;
import org.apache.shardingsphere.agent.api.PluginConfiguration;
import org.junit.Test;