From bb25cfa96d074e9943da8eb7a82b339ca11a6429 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 26 Apr 2021 19:53:41 +0200 Subject: [PATCH] Improved not exist file case. --- src/fr/devinsy/logar/app/Logar.java | 59 ++++++++++++++++++------ src/org/april/logar/util/FilesUtils.java | 58 +++++++++++------------ 2 files changed, 75 insertions(+), 42 deletions(-) diff --git a/src/fr/devinsy/logar/app/Logar.java b/src/fr/devinsy/logar/app/Logar.java index b9b9d1b..8539e81 100644 --- a/src/fr/devinsy/logar/app/Logar.java +++ b/src/fr/devinsy/logar/app/Logar.java @@ -393,11 +393,22 @@ public final class Logar */ public static void checkLogFiles(final File source) { - Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName(); - - for (File file : files) + if (source == null) { - checkLogFile(file); + System.out.println("Undefined source."); + } + else if (source.exists()) + { + System.out.println("Missing source to check."); + } + else + { + Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName(); + + for (File file : files) + { + checkLogFile(file); + } } } @@ -410,11 +421,22 @@ public final class Logar */ public static void checkSort(final File source) throws IOException { - Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName(); - - for (File file : files) + if (source == null) { - checkSortFile(file); + System.out.println("Undefined source."); + } + else if (source.exists()) + { + System.out.println("Missing source to check."); + } + else + { + Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName(); + + for (File file : files) + { + checkSortFile(file); + } } } @@ -483,12 +505,23 @@ public final class Logar */ public static void sort(final File source) throws IOException { - Files files = FilesUtils.searchEndingWith(source, LOGFILE_PATTERN).removeHidden().sortByName(); - - for (File file : files) + if (source == null) { - System.out.println("== Sort for [" + file.getName() + "]"); - LogFile.sortLogFile(file); + System.out.println("Undefined source."); + } + else if (source.exists()) + { + System.out.println("Missing source to sort."); + } + else + { + Files files = FilesUtils.searchEndingWith(source, LOGFILE_PATTERN).removeHidden().sortByName(); + + for (File file : files) + { + System.out.println("== Sort for [" + file.getName() + "]"); + LogFile.sortLogFile(file); + } } } diff --git a/src/org/april/logar/util/FilesUtils.java b/src/org/april/logar/util/FilesUtils.java index 6d416fc..6b40d2f 100644 --- a/src/org/april/logar/util/FilesUtils.java +++ b/src/org/april/logar/util/FilesUtils.java @@ -48,7 +48,7 @@ public class FilesUtils Files result; result = new Files(); - if (source != null) + if ((source != null) && (source.exists())) { if (source.isFile()) { @@ -74,34 +74,6 @@ public class FilesUtils return result; } - /** - * List recursively. - * - * @param source - * the source - * @param extensions - * the extensions - * @return the files - */ - public static Files searchEndingWith(final File source, final String... extensions) - { - Files result; - - result = new Files(); - - Files full = listRecursively(source); - for (File file : full) - { - if (StringUtils.endsWithAny(file.getName(), extensions)) - { - result.add(file); - } - } - - // - return result; - } - /** * Search recursively. * @@ -131,4 +103,32 @@ public class FilesUtils // return result; } + + /** + * List recursively. + * + * @param source + * the source + * @param extensions + * the extensions + * @return the files + */ + public static Files searchEndingWith(final File source, final String... extensions) + { + Files result; + + result = new Files(); + + Files full = listRecursively(source); + for (File file : full) + { + if (StringUtils.endsWithAny(file.getName(), extensions)) + { + result.add(file); + } + } + + // + return result; + } }