Skip to content

Commit

Permalink
#94: improve documentation and logging (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Mar 12, 2024
1 parent 1cab8d4 commit 4f67c39
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 200 deletions.
10 changes: 10 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.devonfw.tools.ide.io;

import java.nio.file.Path;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

Expand Down Expand Up @@ -213,4 +214,13 @@ default void extract(Path archiveFile, Path targetDir, Consumer<Path> postExtrac
*/
Path findFirst(Path dir, Predicate<Path> filter, boolean recursive);

/**
* @param dir the {@link Path} to the directory where to list the children.
* @param filter the {@link Predicate} used to {@link Predicate#test(Object) decide} which children to include (if
* {@code true} is returned).
* @return all children of the given {@link Path} that match the given {@link Predicate}. Will be the empty list of
* the given {@link Path} is not an existing directory.
*/
List<Path> listChildren(Path dir, Predicate<Path> filter);

}
23 changes: 23 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -763,4 +763,27 @@ private Path findFirstRecursive(Path dir, Predicate<Path> filter, boolean recurs
return null;
}

@Override
public List<Path> listChildren(Path dir, Predicate<Path> filter) {

if (!Files.isDirectory(dir)) {
return List.of();
}
List<Path> children = new ArrayList<>();
try (Stream<Path> childStream = Files.list(dir)) {
Iterator<Path> iterator = childStream.iterator();
while (iterator.hasNext()) {
Path child = iterator.next();
if (filter.test(child)) {
this.context.trace("Accepted file {}", child);
children.add(child);
} else {
this.context.trace("Ignoring file {} according to filter", child);
}
}
} catch (IOException e) {
throw new IllegalStateException("Failed to find children of directory " + dir, e);
}
return children;
}
}
Loading

0 comments on commit 4f67c39

Please sign in to comment.