This is an automated email from the ASF dual-hosted git repository.

zhangliang 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 1e35d073942 Refactor : refactor the agent packging structure (#23392) 
(#23393)
1e35d073942 is described below

commit 1e35d07394265bd21a98f0dc0eaa62e962f0bbdc
Author: 孙念君 Nianjun Sun <[email protected]>
AuthorDate: Mon Jan 9 12:21:31 2023 +0800

    Refactor : refactor the agent packging structure (#23392) (#23393)
    
    * Refactor : refactor the agent packging structure (#23392)
    
    * Add : add sneaky throw to getJarFiles (#23392)
---
 .../agent/core/plugin/jar/PluginJarLoader.java     | 31 +++++++++++++++++-----
 .../shardingsphere-agent-binary-distribution.xml   |  6 ++---
 2 files changed, 27 insertions(+), 10 deletions(-)

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 10ee97fbdeb..57a7f9b76c8 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
@@ -19,14 +19,18 @@ package org.apache.shardingsphere.agent.core.plugin.jar;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import lombok.SneakyThrows;
 import org.apache.shardingsphere.agent.core.log.LoggerFactory;
 import org.apache.shardingsphere.agent.core.log.LoggerFactory.Logger;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Arrays;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.jar.JarFile;
@@ -48,8 +52,8 @@ public final class PluginJarLoader {
      */
     public static Collection<PluginJar> load(final File agentRootPath) throws 
IOException {
         List<File> jarFiles = new LinkedList<>();
-        jarFiles.addAll(getJarFiles(new File(String.join("/", 
agentRootPath.getPath(), "lib"))));
-        jarFiles.addAll(getJarFiles(new File(String.join("/", 
agentRootPath.getPath(), "plugins"))));
+        getJarFiles(new File(String.join("/", agentRootPath.getPath(), 
"lib")), jarFiles);
+        getJarFiles(new File(String.join("/", agentRootPath.getPath(), 
"plugins")), jarFiles);
         Collection<PluginJar> result = new LinkedList<>();
         for (File each : jarFiles) {
             result.add(new PluginJar(new JarFile(each, true), each));
@@ -58,8 +62,21 @@ public final class PluginJarLoader {
         return result;
     }
     
-    private static List<File> getJarFiles(final File path) {
-        File[] jarFiles = path.listFiles(each -> 
each.getName().endsWith(".jar"));
-        return (null == jarFiles || jarFiles.length == 0) ? 
Collections.emptyList() : Arrays.asList(jarFiles);
+    @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")) {
+                    jarFiles.add(path.toFile());
+                }
+                if (path.toFile().isDirectory()) {
+                    getJarFiles(path.toFile(), jarFiles);
+                }
+                return FileVisitResult.CONTINUE;
+            }
+        });
     }
 }
diff --git 
a/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
 
b/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
index 6309cae0e4c..ba21b55cd71 100644
--- 
a/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
+++ 
b/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
@@ -56,21 +56,21 @@
         
         <fileSet>
             <directory>../plugins/logging/type/target/plugins</directory>
-            <outputDirectory>./plugins</outputDirectory>
+            <outputDirectory>./plugins/logging</outputDirectory>
             <includes>
                 <include>**.jar</include>
             </includes>
         </fileSet>
         <fileSet>
             <directory>../plugins/tracing/type/target/plugins</directory>
-            <outputDirectory>./plugins</outputDirectory>
+            <outputDirectory>./plugins/tracing</outputDirectory>
             <includes>
                 <include>**.jar</include>
             </includes>
         </fileSet>
         <fileSet>
             <directory>../plugins/metrics/type/target/plugins</directory>
-            <outputDirectory>./plugins</outputDirectory>
+            <outputDirectory>./plugins/metrics</outputDirectory>
             <includes>
                 <include>**.jar</include>
             </includes>

Reply via email to