99import java .nio .file .attribute .FileTime ;
1010import java .util .List ;
1111import lombok .extern .slf4j .Slf4j ;
12+ import me .itzg .helpers .errors .ExceptionDetailer ;
13+ import me .itzg .helpers .errors .InvalidParameterException ;
1214
1315@ Slf4j
1416class SynchronizingFileVisitor implements FileVisitor <Path > {
@@ -24,9 +26,21 @@ public SynchronizingFileVisitor(Path src, Path dest, boolean skipNewerInDestinat
2426 this .fileProcessor = fileProcessor ;
2527 }
2628
29+ /**
30+ * Convenience method that processes each source path into the destination path by applying a {@link SynchronizingFileVisitor}
31+ * to each source.
32+ * @param srcDest source... dest
33+ * @param skipNewerInDestination provided to {@link SynchronizingFileVisitor}
34+ * @param fileProcessor provided to {@link SynchronizingFileVisitor}
35+ * @return exit code style of 1 for failure, 0 for success
36+ */
2737 static int walkDirectories (List <Path > srcDest , boolean skipNewerInDestination ,
2838 FileProcessor fileProcessor
2939 ) {
40+ if (srcDest .size () < 2 ) {
41+ throw new InvalidParameterException ("At least one source and destination path is required" );
42+ }
43+
3044 // TODO can use getLast() with java 21
3145 final Path dest = srcDest .get (srcDest .size () - 1 );
3246
@@ -35,7 +49,7 @@ static int walkDirectories(List<Path> srcDest, boolean skipNewerInDestination,
3549 try {
3650 Files .walkFileTree (src , new SynchronizingFileVisitor (src , dest , skipNewerInDestination , fileProcessor ));
3751 } catch (IOException e ) {
38- log .error ("Failed to sync and interpolate {} into {} : {}" , src , dest , e . getMessage ( ));
52+ log .error ("Failed to sync and interpolate {} into {}: {}" , src , dest , ExceptionDetailer . buildCausalMessages ( e ));
3953 log .debug ("Details" , e );
4054 return 1 ;
4155 }
@@ -104,7 +118,7 @@ private boolean shouldProcessFile(Path srcFile, Path destFile) throws IOExceptio
104118
105119 @ Override
106120 public FileVisitResult visitFileFailed (Path file , IOException e ) {
107- log .warn ("Failed to visit file {} due to {}:{} " , file , e . getClass (), e . getMessage ( ));
121+ log .warn ("Failed to visit file {} due to {}" , file , ExceptionDetailer . buildCausalMessages ( e ));
108122 log .debug ("Details" , e );
109123 return FileVisitResult .CONTINUE ;
110124 }
0 commit comments