2727import org .jetbrains .annotations .Blocking ;
2828import org .reactivestreams .Publisher ;
2929import org .slf4j .event .Level ;
30+ import org .slf4j .spi .LoggingEventBuilder ;
3031import picocli .CommandLine .Command ;
3132import picocli .CommandLine .ExitCode ;
3233import picocli .CommandLine .Option ;
3940 + "Supports auto-detected sourcing from file list, directories, and URLs" )
4041@ Slf4j
4142public class MulitCopyCommand implements Callable <Integer > {
43+ @ SuppressWarnings ("unused" )
4244 @ Option (names = {"--help" , "-h" }, usageHelp = true )
4345 boolean showHelp ;
4446
@@ -154,7 +156,7 @@ private Publisher<Path> processSource(String source, boolean fileIsListing, Path
154156 } else {
155157 final Path path = Paths .get (resolvedSource );
156158 if (!Files .exists (path )) {
157- return Mono .error (new GenericException (String .format ("Source file '%s' does not exist" , resolvedSource )));
159+ return Mono .error (new InvalidParameterException (String .format ("Source file '%s' does not exist" , resolvedSource )));
158160 }
159161
160162 if (Files .isDirectory (path )) {
@@ -209,27 +211,23 @@ private Path processFileImmediate(Path source, Path scopedDest) {
209211 try {
210212 if (Files .size (source ) != Files .size (destFile )) {
211213 if (Files .getLastModifiedTime (source ).compareTo (Files .getLastModifiedTime (destFile )) > 0 ) {
212- log .debug ("Copying over existing={} file since source={} file is newer" ,
214+ log .info ("Copying over existing file {} since {} is newer" ,
213215 destFile , source
214216 );
215217
216218 Files .copy (source , destFile , StandardCopyOption .REPLACE_EXISTING );
217219 } else {
218- log .debug ("Skipping existing={} since it is newer than source={}" ,
219- destFile , source
220- );
220+ forSkipped ().log ("Skipping existing={} since it is newer than source={}" , destFile , source );
221221 }
222222 } else {
223- log .debug ("Skipping existing={} since it has same size as source={}" ,
224- destFile , source
225- );
223+ forSkipped ().log ("Skipping existing={} since it has same size as source={}" , destFile , source );
226224 }
227225 } catch (IOException e ) {
228226 throw new GenericException ("Failed to evaluate/copy existing file" , e );
229227 }
230228 } else {
231229 try {
232- log .debug ("Copying new file from= {} to= {}" , source , destFile );
230+ log .info ("Copying new file from {} to {}" , source , destFile );
233231
234232 Files .copy (source , destFile );
235233 } catch (IOException e ) {
@@ -279,17 +277,15 @@ private Mono<Path> processRemoteSource(String source, Path destination) {
279277 .handleStatus ((status , uri , file ) -> {
280278 switch (status ) {
281279 case DOWNLOADING :
282- log .info ("Downloading {} from {}" , file , uri );
283280 break ;
284281 case SKIP_FILE_UP_TO_DATE :
285- log .atLevel (quietWhenSkipped ? Level .DEBUG : Level .INFO )
286- .log ("The file {} is already up to date" , file );
282+ forSkipped ().log ("The file {} is already up to date" , file );
287283 break ;
288284 case SKIP_FILE_EXISTS :
289- log .atLevel (quietWhenSkipped ? Level .DEBUG : Level .INFO )
290- .log ("The file {} already exists" , file );
285+ forSkipped ().log ("The file {} already exists" , file );
291286 break ;
292287 case DOWNLOADED :
288+ log .info ("Downloaded {} from {}" , file , uri );
293289 break ;
294290 }
295291 })
@@ -300,6 +296,10 @@ private Mono<Path> processRemoteSource(String source, Path destination) {
300296 .checkpoint ("Retrieving " + source , true );
301297 }
302298
299+ private LoggingEventBuilder forSkipped () {
300+ return log .atLevel (quietWhenSkipped ? Level .DEBUG : Level .INFO );
301+ }
302+
303303 private Flux <Path > processRemoteListingFile (String source , Path destination ) {
304304 @ SuppressWarnings ("resource" ) // closed on terminate
305305 SharedFetch sharedFetch = Fetch .sharedFetch ("mcopy" , SharedFetch .Options .builder ().build ());
0 commit comments