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

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/FileUtils.java
 ##########
 @@ -525,6 +540,123 @@ public static Path expandDirectory(Path file, Path 
targetDirectory) throws IOExc
                return new Path(targetDirectory, rootDir);
        }
 
+       /**
+        * List the {@code directory} recursively and return the files that 
satisfy 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(final File directory, 
final Predicate<File> fileFilter) throws IOException {
+               checkNotNull(directory, "directory");
+               checkNotNull(fileFilter, "fileFilter");
+
+               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();
+       }
+
+       /**
+        * 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(final 
Collection<File> files) {
+               checkNotNull(files, "files");
+
+               if (files.isEmpty()) {
+                       return Collections.emptyList();
+               }
+
+               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 Collections.unmodifiableCollection(relativeFiles);
+       }
+
+       /**
+        * Convert a collection of relative {@code File}s to a collection of 
relative {@code URL}s.
 
 Review comment:
   ```suggestion
         * Convert a collection of relative {@link File Files} to a collection 
of relative {@link URL URLs}.
   ```

----------------------------------------------------------------
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