zhuzhurk commented on a change in pull request #9950: [FLINK-14464][runtime] 
Introduce the AbstractUserClassPathJobGraphRetriever
URL: https://github.com/apache/flink/pull/9950#discussion_r339283412
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/FileUtils.java
 ##########
 @@ -525,6 +540,102 @@ public static Path expandDirectory(Path file, Path 
targetDirectory) throws IOExc
                return new Path(targetDirectory, rootDir);
        }
 
+       /**
+        * List the directory {@code directory} recursively and return the 
files that satisfies the {@code fileFilter}.
+        *
+        * @param directory the directory to be listed
+        * @param fileFilter a file filter
+        * @return a collection of {@code File}s
+        *
+        * @throws IOException if an I/O error occurs while listing the files 
in the given directory
+        */
+       public static Collection<File> listFilesInPath(@Nonnull final File 
directory, @Nonnull final Predicate<File> fileFilter) throws IOException {
+               if (!Files.exists(directory.toPath())) {
+                       throw new IllegalArgumentException(String.format("The 
directory %s dose not exist.", directory));
+               }
+               if (!Files.isDirectory(directory.toPath())) {
+                       throw new IllegalArgumentException(String.format("The 
%s is not a directory.", directory));
+               }
+
+               final FilterFileVisitor filterFileVisitor = new 
FilterFileVisitor(fileFilter);
+
+               Files.walkFileTree(
+                       directory.toPath(),
+                       EnumSet.of(FileVisitOption.FOLLOW_LINKS),
+                       Integer.MAX_VALUE,
+                       filterFileVisitor
+               );
+               return filterFileVisitor.getFiles().isEmpty() ? 
Collections.emptyList() : filterFileVisitor.getFiles();
+       }
+
+       /**
+        * Convert a collection of {@code File}s to a collection of relative 
path to the working dir.
+        *
+        * @param files a collection of files needed to be relatived
+        * @return a collection of relative {@code File}s
+        */
+       public static Collection<File> relativizeToWorkingDir(@Nonnull final 
Collection<File> files) {
+               final java.nio.file.Path workingDirPath = 
Paths.get(System.getProperty("user.dir"));
+
+               final List<File> relativeFiles = new LinkedList<>();
+
+               for (File file : files) {
+                       if (file.isAbsolute()) {
+                               
relativeFiles.add(workingDirPath.relativize(file.toPath()).toFile());
+                       } else {
+                               relativeFiles.add(file);
+                       }
+               }
+               return relativeFiles.isEmpty() ? Collections.emptyList() : 
relativeFiles;
 
 Review comment:
   ```suggestion
                return relativeFiles;
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to