Browse Source

Improved not exist file case.

master
Christian P. MOMON 7 months ago
parent
commit
bb25cfa96d
  1. 59
      src/fr/devinsy/logar/app/Logar.java
  2. 26
      src/org/april/logar/util/FilesUtils.java

59
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)
{
System.out.println("Undefined source.");
}
else if (source.exists())
{
checkLogFile(file);
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)
{
System.out.println("Undefined source.");
}
else if (source.exists())
{
System.out.println("Missing source to check.");
}
else
{
checkSortFile(file);
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);
}
}
}

26
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())
{
@ -75,24 +75,26 @@ public class FilesUtils
}
/**
* List recursively.
* Search recursively.
*
* @param source
* the source
* @param extensions
* the extensions
* @param regex
* the regex
* @return the files
*/
public static Files searchEndingWith(final File source, final String... extensions)
public static Files search(final File source, final String regex)
{
Files result;
result = new Files();
Pattern pattern = Pattern.compile(regex);
Files full = listRecursively(source);
for (File file : full)
{
if (StringUtils.endsWithAny(file.getName(), extensions))
if (pattern.matcher(file.getName()).matches())
{
result.add(file);
}
@ -103,26 +105,24 @@ public class FilesUtils
}
/**
* Search recursively.
* List recursively.
*
* @param source
* the source
* @param regex
* the regex
* @param extensions
* the extensions
* @return the files
*/
public static Files search(final File source, final String regex)
public static Files searchEndingWith(final File source, final String... extensions)
{
Files result;
result = new Files();
Pattern pattern = Pattern.compile(regex);
Files full = listRecursively(source);
for (File file : full)
{
if (pattern.matcher(file.getName()).matches())
if (StringUtils.endsWithAny(file.getName(), extensions))
{
result.add(file);
}

Loading…
Cancel
Save