Skip to content

Commit

Permalink
chore: improve debug logging
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Jan 11, 2023
1 parent 783a50d commit 2aa0472
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.PathMatcher;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
Expand All @@ -36,8 +37,10 @@
import java.util.stream.Stream;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Getter
@Slf4j
public final class Selection {

private final File basedir;
Expand All @@ -59,9 +62,17 @@ public Selection(File basedir, String[] included, String[] excluded, boolean use
@SneakyThrows
public String[] getSelectedFiles() {
if (selectedFiles.isDone()) {
return selectedFiles.get(0, TimeUnit.SECONDS);
final String[] files = selectedFiles.get(0, TimeUnit.SECONDS);
log.debug("Got previous selected files: {} (count: {})", Arrays.toString(files), files.length);
return files;
}

log.debug(
"Selecting files with baseDir: {}, included: {}, excluded: {}",
basedir,
Arrays.toString(included),
Arrays.toString(excluded));

final Path basePath = basedir.toPath();

final List<String> excludesList = new ArrayList<>();
Expand All @@ -86,7 +97,7 @@ public String[] getSelectedFiles() {
final Set<FileVisitOption> followLinksOption = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
Files.walkFileTree(basePath, followLinksOption, Integer.MAX_VALUE, new FileVisitor<>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
final Path path = basePath.relativize(dir);
final boolean isExcluded = folderExcludes.stream().anyMatch(m -> m.matches(path));
final boolean isInvertExcluded = folderInvertExcludes.stream().anyMatch(m -> m.matches(path));
Expand Down Expand Up @@ -117,7 +128,10 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
});

this.selectedFiles.complete(results.toArray(String[]::new));
return selectedFiles.get(0, TimeUnit.SECONDS);
final String[] files = selectedFiles.get(0, TimeUnit.SECONDS);
log.debug("Selected files: {} (count: {})", Arrays.toString(files), files.length);

return files;
}

private List<PathMatcher> buildFolderPathMaters(String[] patterns) {
Expand Down

0 comments on commit 2aa0472

Please sign in to comment.