Hello All,
In trying to build Jetspeed-2 from cvs this morning I noticed that one of the test-cases was failing:


org.apache.jetspeed.page.TestCastorXmlPageManager.testFolders(..)

The problem is that the setUp() method is copying a test-data directory structure and is including the CVS directory. The test-case expects N folders to exists in a particular case, but there end up being N+1.

I've implemented one possible solution, which is to add file-filtering into the DirectoryHelper. There is a new method on that class, which looks like:

public void setFileFilter(final FileFilter fileFilter);

The test-case changed in that it sets a FileFilter that declines "CVS" directories.

Please let me know if this sounds like a reasonable solution, and whether I should make any changes.


Cheers, Enrique

_________________________________________________________________
�Cu�nto vale tu auto? Tips para mantener tu carro. �De todo en MSN Latino Autos! http://latino.msn.com/autos/
Index: commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java
===================================================================
RCS file: /home/cvspublic/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java,v
retrieving revision 1.1
diff -u -r1.1 commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java
--- commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java 14 Jul 2004 21:08:05 -0000 1.1
+++ commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java 15 Jul 2004 18:15:30 -0000
@@ -16,6 +16,7 @@
package org.apache.jetspeed.util;


import java.io.File;
+import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -32,6 +33,7 @@
{

    protected File directory;
+    protected FileFilter fileFilter;

/**
*
@@ -49,6 +51,13 @@
throw new IllegalArgumentException("DirectoryHelper(File) requires directory not a file.");
}
this.directory = directory;
+
+ this.fileFilter = new FileFilter() {
+ public boolean accept(File pathname)
+ {
+ return true;
+ }
+ };
}


/**
@@ -88,21 +97,26 @@
for(int i=0; i<children.length; i++)
{
File child = children[i];
- if(child.isFile())
+ if(fileFilter.accept(child))
{
- File toFile = new File(dstDir, child.getName());
- toFile.createNewFile();
- FileChannel srcChannel = new FileInputStream(child).getChannel();
- FileChannel dstChannel = new FileOutputStream(toFile).getChannel();
- dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
- srcChannel.close();
- dstChannel.close();
- }
- else
- {
- File newSubDir = new File(dstDir, child.getName());
- newSubDir.mkdir();
- copyFiles(child, newSubDir);
+ if(child.isFile())
+ {
+ File toFile = new File(dstDir, child.getName());
+ toFile.createNewFile();
+ FileChannel srcChannel = new FileInputStream(child).getChannel();
+ FileChannel dstChannel = new FileOutputStream(toFile).getChannel();
+ dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
+ srcChannel.close();
+ dstChannel.close();
+ }
+ else
+ {
+ File newSubDir = new File(dstDir, child.getName());
+ newSubDir.mkdir();
+ copyFiles(child, newSubDir);
+ }
+ } else {
+ //XXX log?
}
}
}
@@ -186,5 +200,17 @@
public String getSourcePath()
{
return getRootDirectory().getAbsolutePath();
+ }
+
+ /**
+ * <p>
+ * setFileFilter(fileFilter)
+ * </p>
+ *
+ * @see java.io.FileFilter
+ */
+ public void setFileFilter(final FileFilter fileFilter)
+ {
+ this.fileFilter = fileFilter;
}
}




Index: components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java
===================================================================
RCS file: /home/cvspublic/jakarta-jetspeed-2/components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java,v
retrieving revision 1.3
diff -u -r1.3 components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java
--- components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java 14 Jul 2004 21:09:24 -0000 1.3
+++ components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java 15 Jul 2004 18:18:57 -0000
@@ -17,6 +17,7 @@


// Java imports
import java.io.File;
+import java.io.FileFilter;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -55,6 +56,18 @@
    {
        super.setUp();
        dirHelper = new DirectoryHelper(new File("target/testdata/pages"));
+        dirHelper.setFileFilter(new FileFilter() {
+            public boolean accept(File pathname)
+            {
+               boolean result = true;
+               if(pathname.isDirectory())
+               {
+                   String dirName = pathname.getName();
+                   result = !dirName.equals("CVS");
+               }
+               return result;
+            }
+        });
        dirHelper.copyFrom(new File("testdata/pages"));
        IdGenerator idGen = new JetspeedIdGenerator(65536,"P-","");
        FileCache cache = new FileCache(10, 12);


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to