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

duanzhengqiang 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 a3d6aa6596b Fixes ClasspathResourceDirectoryReaderTest to fail on 
Windows. (#30382)
a3d6aa6596b is described below

commit a3d6aa6596b9803d507d015c8d8581d9ffc2218f
Author: Cong Hu <[email protected]>
AuthorDate: Mon Mar 4 16:24:40 2024 +0800

    Fixes ClasspathResourceDirectoryReaderTest to fail on Windows. (#30382)
---
 .../util/directory/ClasspathResourceDirectoryReader.java    | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java
index 5f7306f4a27..eab4a8165a4 100644
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java
+++ 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.infra.util.directory;
 import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
 
-import java.io.File;
 import java.io.IOException;
 import java.net.JarURLConnection;
 import java.net.URISyntaxException;
@@ -86,6 +85,7 @@ public class ClasspathResourceDirectoryReader {
     
     /**
      * Return a lazily populated Stream that contains the names of resources 
in the provided directory. The Stream is recursive, meaning it includes 
resources from all subdirectories as well.
+     * <p>The name of a resource directory is a /-separated path name</p>
      * <p>When the {@code directory} parameter is a file, the method can still 
work.</p>
      *
      * @param directory directory
@@ -100,6 +100,7 @@ public class ClasspathResourceDirectoryReader {
     
     /**
      * Return a lazily populated Stream that contains the names of resources 
in the provided directory. The Stream is recursive, meaning it includes 
resources from all subdirectories as well.
+     * <p>The name of a resource directory is a /-separated path name</p>
      * <p>When the {@code directory} parameter is a file, the method can still 
work.</p>
      *
      * @param classLoader class loader
@@ -178,6 +179,14 @@ public class ClasspathResourceDirectoryReader {
         Path directoryPath = Paths.get(directoryUrl.toURI());
         // noinspection resource
         Stream<Path> walkStream = Files.find(directoryPath, Integer.MAX_VALUE, 
(path, basicFileAttributes) -> !basicFileAttributes.isDirectory(), 
FileVisitOption.FOLLOW_LINKS);
-        return walkStream.map(path -> directory + File.separator + 
path.subpath(directoryPath.getNameCount(), path.getNameCount()));
+        return walkStream.map(path -> {
+            StringBuilder stringBuilder = new StringBuilder();
+            stringBuilder.append(directory);
+            for (Path each : path.subpath(directoryPath.getNameCount(), 
path.getNameCount())) {
+                stringBuilder.append("/");
+                stringBuilder.append(each);
+            }
+            return stringBuilder.toString();
+        });
     }
 }

Reply via email to