[logback-dev] svn commit: r2417 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling/helper

noreply.ceki at qos.ch noreply.ceki at qos.ch
Thu Aug 6 23:52:03 CEST 2009


Author: ceki
Date: Thu Aug  6 23:52:03 2009
New Revision: 2417

Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java

Log:
- all logback-core tests pass

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileFilterUtil.java	Thu Aug  6 23:52:03 2009
@@ -52,17 +52,20 @@
    * Return the set of files matching the stemRegex as found in 'directory'. A
    * stemRegex does not contain any slash characters or any folder seperators.
    * 
-   * @param directory
+   * @param file
    * @param stemRegex
    * @return
    */
-  public static File[] filesInFolderMatchingStemRegex(File directory,
+  public static File[] filesInFolderMatchingStemRegex(File file,
       final String stemRegex) {
-    if (directory == null || directory.isDirectory()) {
-      throw new IllegalArgumentException("[" + directory
-          + " cannot be null or a non-directory");
+
+    if (file == null) {
+      return new File[0];
+    }
+    if (!file.exists() || !file.isDirectory()) {
+      return new File[0];
     }
-    File[] matchingFileArray = directory.listFiles(new FilenameFilter() {
+    File[] matchingFileArray = file.listFiles(new FilenameFilter() {
       public boolean accept(File dir, String name) {
         return name.matches(stemRegex);
       }
@@ -71,9 +74,9 @@
   }
 
   static public int extractCounter(File file, final String stemRegex) {
-     Pattern p = Pattern.compile(stemRegex);
+    Pattern p = Pattern.compile(stemRegex);
     String lastFileName = file.getName();
-  
+
     Matcher m = p.matcher(lastFileName);
     if (!m.matches()) {
       throw new IllegalStateException("The regex [" + stemRegex

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java	Thu Aug  6 23:52:03 2009
@@ -154,7 +154,7 @@
       } else if (p instanceof IntegerTokenConverter) {
         buf.append("(\\d{1,2})");
       } else if (p instanceof DateTokenConverter) {
-        buf.append(p.convert(date));
+        buf.append(FileFilterUtil.slashify(p.convert(date)));
       }
       p = p.getNext();
     }

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java	Thu Aug  6 23:52:03 2009
@@ -117,13 +117,13 @@
       FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt",
           context);
       String regex = fnp.toSRegex(cal.getTime());
-      assertEquals("foo-2003.05.20-\\d{1,2}.txt", regex);
+      assertEquals("foo-2003.05.20-(\\d{1,2}).txt", regex);
     }
     {
       FileNamePattern fnp = new FileNamePattern("\\toto\\foo-%d{yyyy\\MM\\dd}-%i.txt",
           context);
       String regex = fnp.toSRegex(cal.getTime());
-      assertEquals("/toto/foo-2003/05/20-\\d{1,2}.txt", regex);
+      assertEquals("/toto/foo-2003/05/20-(\\d{1,2}).txt", regex);
     }
   }
 


More information about the logback-dev mailing list