You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ad...@apache.org on 2002/10/23 12:56:33 UTC
cvs commit: jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test FileInfo.java VerifyingFileSelector.java AbstractFileSystemTestCase.java AbstractWritableFileSystemTestCase.java FileSystemManagerFactoryTestCase.java
adammurdoch 2002/10/23 03:56:33
Modified: vfs/src/java/org/apache/commons/vfs AllFileSelector.java
FileDepthSelector.java FileObject.java
FileSelectInfo.java FileSelector.java
FileSystem.java FileSystemManager.java
Resources.properties
vfs/src/java/org/apache/commons/vfs/impl
DefaultFileReplicator.java
DefaultFileSystemManager.java
DefaultProviderContext.java
vfs/src/java/org/apache/commons/vfs/provider
AbstractFileObject.java AbstractFileSystem.java
AbstractOriginatingFileProvider.java
DefaultFileContent.java
vfs/src/java/org/apache/commons/vfs/provider/zip
ZipFileSystem.java
vfs/src/test/org/apache/commons/vfs/provider/local/test
LocalFileSystemTestCase.java
vfs/src/test/org/apache/commons/vfs/test
AbstractFileSystemTestCase.java
AbstractWritableFileSystemTestCase.java
FileSystemManagerFactoryTestCase.java
Added: vfs/src/java/org/apache/commons/vfs FileTypeSelector.java
Selectors.java
vfs/src/test/org/apache/commons/vfs/test FileInfo.java
VerifyingFileSelector.java
Removed: vfs/src/java/org/apache/commons/vfs FileConstants.java
Log:
- FileObject:
- Added getChild() and findFiles().
- Fixed problem when isReadable() or isWriteable() is the first method
called on a FileObject.
- Changes to FileSelector:
- Methods now throw Exception, rather than FileSystemException.
- Specify the order that methods are called.
- Added FileTypeSelector to select on file type.
- Renamed FileConstants to Selectors.
- Renamed FileSystemManager.convert() to toFileObject().
- Renamed FileSystem.findFile() to resolveFile().
- More javadoc.
Revision Changes Path
1.2 +0 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/AllFileSelector.java
Index: AllFileSelector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/AllFileSelector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AllFileSelector.java 16 Jul 2002 17:18:58 -0000 1.1
+++ AllFileSelector.java 23 Oct 2002 10:56:32 -0000 1.2
@@ -20,7 +20,6 @@
* Determines if a file or folder should be selected.
*/
public boolean includeFile( final FileSelectInfo fileInfo )
- throws FileSystemException
{
return true;
}
@@ -29,7 +28,6 @@
* Determines whether a folder should be traversed.
*/
public boolean traverseDescendents( final FileSelectInfo fileInfo )
- throws FileSystemException
{
return true;
}
1.3 +2 -4 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileDepthSelector.java
Index: FileDepthSelector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileDepthSelector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FileDepthSelector.java 21 Aug 2002 07:00:10 -0000 1.2
+++ FileDepthSelector.java 23 Oct 2002 10:56:32 -0000 1.3
@@ -29,18 +29,16 @@
* Determines if a file or folder should be selected.
*/
public boolean includeFile( final FileSelectInfo fileInfo )
- throws FileSystemException
{
final int depth = fileInfo.getDepth();
- return minDepth <= depth && depth <= maxDepth;
+ return ( minDepth <= depth && depth <= maxDepth );
}
/**
* Determines whether a folder should be traversed.
*/
public boolean traverseDescendents( final FileSelectInfo fileInfo )
- throws FileSystemException
{
- return fileInfo.getDepth() < maxDepth;
+ return ( fileInfo.getDepth() < maxDepth );
}
}
1.6 +30 -1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileObject.java
Index: FileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileObject.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FileObject.java 21 Oct 2002 01:40:37 -0000 1.5
+++ FileObject.java 23 Oct 2002 10:56:32 -0000 1.6
@@ -10,6 +10,7 @@
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.List;
/**
* This interface represents a file, and is used to access the content and
@@ -69,7 +70,7 @@
FileName getName();
/**
- * Returns a URL representing the file.
+ * Returns a URL representing this file.
*/
URL getURL() throws MalformedURLException;
@@ -152,6 +153,23 @@
FileObject[] getChildren() throws FileSystemException;
/**
+ * Returns a child of this file. Note that this method returns <code>null</code>
+ * when the child does not exist. This differs from
+ * {@link #resolveFile( String, NameScope)} which never returns null.
+ *
+ * @param name
+ * The name of the child.
+ *
+ * @return
+ * The child, or null if there is no such child.
+ *
+ * @throws FileSystemException
+ * If this file does not exist, or is not a folder, or on error
+ * determining this file's children.
+ */
+ FileObject getChild( String name ) throws FileSystemException;
+
+ /**
* Finds a file, relative to this file. Refer to {@link NameScope}
* for a description of how names are resolved in the different scopes.
*
@@ -182,6 +200,17 @@
* On error parsing the path, or on error finding the file.
*/
FileObject resolveFile( String path ) throws FileSystemException;
+
+ /**
+ * Finds the set of matching descendents of this file, in depthwise order.
+ *
+ * @param selector The selector to use to select matching files.
+ *
+ * @return A list of matching {@link FileObject} files. The files are
+ * returned in depthwise order (that is, a child appears in the
+ * list before its parent).
+ */
+ List findFiles( FileSelector selector ) throws FileSystemException;
/**
* Deletes this file, and all descendents. Does nothing if the file
1.2 +2 -0 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSelectInfo.java
Index: FileSelectInfo.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSelectInfo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileSelectInfo.java 16 Jul 2002 17:18:58 -0000 1.1
+++ FileSelectInfo.java 23 Oct 2002 10:56:32 -0000 1.2
@@ -13,6 +13,8 @@
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
+ *
+ * @todo Rename this interface, as it is used by both FileSelector and FileVisitor.
*/
public interface FileSelectInfo
{
1.2 +8 -3 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSelector.java
Index: FileSelector.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSelector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileSelector.java 16 Jul 2002 17:18:58 -0000 1.1
+++ FileSelector.java 23 Oct 2002 10:56:32 -0000 1.2
@@ -16,23 +16,28 @@
public interface FileSelector
{
/**
- * Determines if a file or folder should be selected.
+ * Determines if a file or folder should be selected. This method is
+ * called in depthwise order (that is, it is called for the children
+ * of a folder before it is called for the folder itself).
*
* @param fileInfo the file or folder to select.
* @return true if the file should be selected.
*/
boolean includeFile( FileSelectInfo fileInfo )
- throws FileSystemException;
+ throws Exception;
/**
* Determines whether a folder should be traversed. If this method returns
* true, {@link #includeFile} is called for each of the children of
* the folder, and each of the child folders is recursively traversed.
*
+ * <p>This method is called on a folder before {@link #includeFile}
+ * is called.
+ *
* @param fileInfo the file or folder to select.
*
* @return true if the folder should be traversed.
*/
boolean traverseDescendents( FileSelectInfo fileInfo )
- throws FileSystemException;
+ throws Exception;
}
1.3 +10 -6 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystem.java
Index: FileSystem.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystem.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FileSystem.java 21 Oct 2002 02:52:40 -0000 1.2
+++ FileSystem.java 23 Oct 2002 10:56:32 -0000 1.3
@@ -23,7 +23,7 @@
FileObject getRoot() throws FileSystemException;
/**
- * Returns the parent layerer if this is a layered file system.
+ * Returns the parent layer if this is a layered file system.
* This returns null if this is not a layered file system.
*/
FileObject getParentLayer() throws FileSystemException;
@@ -54,7 +54,7 @@
* Sets the value of an attribute of the file's content. Creates the
* file if it does not exist.
*
- * @see org.apache.commons.vfs.FileContent#setAttribute
+ * @see FileContent#setAttribute
*
* @param attrName
* The name of the attribute.
@@ -62,7 +62,7 @@
* @param value
* The value of the attribute.
*
- * @throws org.apache.commons.vfs.FileSystemException
+ * @throws FileSystemException
* If the file is read-only, or is being read, or if the attribute
* is not supported, or on error setting the attribute.
*/
@@ -74,14 +74,18 @@
*
* @param name
* The name of the file.
+ *
+ * @return The file. Never returns null.
*/
- FileObject findFile( FileName name ) throws FileSystemException;
+ FileObject resolveFile( FileName name ) throws FileSystemException;
/**
* Finds a file in this file system.
*
* @param name
* The name of the file. This must be an absolute path.
+ *
+ * @return The file. Never returns null.
*/
- FileObject findFile( String name ) throws FileSystemException;
+ FileObject resolveFile( String name ) throws FileSystemException;
}
1.4 +11 -4 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystemManager.java
Index: FileSystemManager.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystemManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FileSystemManager.java 21 Aug 2002 07:00:10 -0000 1.3
+++ FileSystemManager.java 23 Oct 2002 10:56:32 -0000 1.4
@@ -68,6 +68,8 @@
* @param name
* The name of the file.
*
+ * @return The file. Never returns null.
+ *
* @throws FileSystemException
* On error parsing the file name.
*/
@@ -86,7 +88,9 @@
* The name of the file.
*
* @param baseFile
- * The base file to use to resolve relative paths.
+ * The base file to use to resolve relative paths. May be null.
+ *
+ * @return The file. Never returns null.
*
* @throws FileSystemException
* On error parsing the file name.
@@ -99,11 +103,13 @@
* for details.
*
* @param baseFile
- * The base file to use to resolve relative paths.
+ * The base file to use to resolve relative paths. May be null.
*
* @param name
* The name of the file.
*
+ * @return The file. Never returns null.
+ *
* @throws FileSystemException
* On error parsing the file name.
*
@@ -118,12 +124,13 @@
* The file to convert.
*
* @return
- * The {@link FileObject} that represents the local file.
+ * The {@link FileObject} that represents the local file. Never
+ * returns null.
*
* @throws FileSystemException
* On error converting the file.
*/
- FileObject convert( File file )
+ FileObject toFileObject( File file )
throws FileSystemException;
/**
1.4 +3 -1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Resources.properties 22 Oct 2002 13:01:56 -0000 1.3
+++ Resources.properties 23 Oct 2002 10:56:32 -0000 1.4
@@ -23,6 +23,7 @@
vfs.provider/copy-file.error=Could not copy "{0}" to "{1}".
vfs.provider/copy-read-only.error=Could not copy {0} "{1}" to "{2}" because the destination file is read-only.
vfs.provider/copy-missing-file.error=Could not copy "{0}" because it does not exist.
+vfs.provider/find-files.error=Could not find files in "{0}".
# DefaultFileContent
vfs.provider/get-size-folder.error=Could not determine the size of "{0}" because it is a folder.
@@ -109,4 +110,5 @@
vfs.tasks/sync.no-source-file.error=No source file specified.
vfs.tasks/sync.too-many-source-files.error=Too many source files specified.
vfs.tasks/sync.source-not-file.error=Source file "{0}" is not a file, or does not exist.
-vfs.tasks/sync.src-file-no-exist.error=Source file "{0}" does not exist.
\ No newline at end of file
+vfs.tasks/sync.src-file-no-exist.error=Source file "{0}" does not exist.
+vfs.tasks/delete.no-source-files.error=No files to delete specified.
1.1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileTypeSelector.java
Index: FileTypeSelector.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.vfs;
/**
* A {@link FileSelector} that selects files of a particular type.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/10/23 10:56:32 $
*/
public class FileTypeSelector
implements FileSelector
{
private final FileType type;
public FileTypeSelector( final FileType type )
{
this.type = type;
}
/**
* Determines if a file or folder should be selected.
*/
public boolean includeFile( final FileSelectInfo fileInfo )
throws FileSystemException
{
return ( fileInfo.getFile().getType() == type );
}
/**
* Determines whether a folder should be traversed.
*/
public boolean traverseDescendents( final FileSelectInfo fileInfo )
{
return true;
}
}
1.1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Selectors.java
Index: Selectors.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.vfs;
/**
* Several standard file selectors.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/10/23 10:56:32 $
*/
public interface Selectors
{
/**
* A {@link FileSelector} that selects only the base file/folder.
*/
FileSelector SELECT_SELF = new FileDepthSelector( 0, 0 );
/**
* A {@link FileSelector} that selects the base file/folder and its
* direct children.
*/
FileSelector SELECT_SELF_AND_CHILDREN = new FileDepthSelector( 0, 1 );
/**
* A {@link FileSelector} that selects only the direct children
* of the base folder.
*/
FileSelector SELECT_CHILDREN = new FileDepthSelector( 1, 1 );
/**
* A {@link FileSelector} that selects all the descendents of the
* base folder, but does not select the base folder itself.
*/
FileSelector EXCLUDE_SELF = new FileDepthSelector( 1, Integer.MAX_VALUE );
/**
* A {@link FileSelector} that only files (not folders).
*/
FileSelector SELECT_FILES = new FileTypeSelector( FileType.FILE );
/**
* A {@link FileSelector} that only folders (not files).
*/
FileSelector SELECT_FOLDERS = new FileTypeSelector( FileType.FOLDER );
/**
* A {@link FileSelector} that selects the base file/folder, plus all
* its descendents.
*/
FileSelector SELECT_ALL = new AllFileSelector();
}
1.9 +2 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileReplicator.java
Index: DefaultFileReplicator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileReplicator.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DefaultFileReplicator.java 22 Oct 2002 11:41:49 -0000 1.8
+++ DefaultFileReplicator.java 23 Oct 2002 10:56:32 -0000 1.9
@@ -10,7 +10,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Random;
-import org.apache.commons.vfs.FileConstants;
+import org.apache.commons.vfs.Selectors;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystemException;
@@ -53,7 +53,7 @@
final FileObject file = (FileObject)copies.remove( 0 );
try
{
- file.delete( FileConstants.SELECT_ALL );
+ file.delete( Selectors.SELECT_ALL );
}
catch ( final FileSystemException e )
{
1.9 +16 -4 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
Index: DefaultFileSystemManager.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DefaultFileSystemManager.java 21 Oct 2002 01:40:38 -0000 1.8
+++ DefaultFileSystemManager.java 23 Oct 2002 10:56:32 -0000 1.9
@@ -26,7 +26,19 @@
import org.apache.commons.vfs.provider.VfsComponent;
/**
- * A default file system manager implementation.
+ * A default file system manager implementation. To use this class:
+ * <ul>
+ * <li>Create an instance of this class.
+ * <li>Call {@link #setLogger} to set the logger that the manager, and its
+ * components, should use.
+ * <li>Add one or more file providers using {@link #addProvider}.
+ * <li>Set the default provider using {@link #setDefaultProvider} (optional).
+ * <li>Set the file replicator using {@link #setReplicator} (optional).
+ * <li>Set the base file using {@link #setBaseFile} (optional).
+ * </ul>
+ *
+ * <p>When finished with the manager, call its {@link #close} method to clean
+ * up any resources it is using.
*
* @todo - Extract an AbstractFileSystemManager super-class from this class.
*
@@ -91,7 +103,7 @@
}
}
- // Contextualise
+ // Contextualise the component (if not already)
setupComponent( provider );
// Add to map
@@ -186,7 +198,7 @@
/**
* Closes all files created by this manager, and cleans up any temporary
- * files.
+ * files. Also closes all providers and the replicator.
*/
public void close()
{
@@ -308,7 +320,7 @@
/**
* Converts a local file into a {@link FileObject}.
*/
- public FileObject convert( final File file )
+ public FileObject toFileObject( final File file )
throws FileSystemException
{
return getLocalFileProvider().findLocalFile( file );
1.4 +1 -1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultProviderContext.java
Index: DefaultProviderContext.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultProviderContext.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultProviderContext.java 21 Aug 2002 07:00:11 -0000 1.3
+++ DefaultProviderContext.java 23 Oct 2002 10:56:32 -0000 1.4
@@ -53,7 +53,7 @@
public FileObject getFile( File file )
throws FileSystemException
{
- return manager.convert( file );
+ return manager.toFileObject( file );
}
/**
1.12 +73 -31 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
Index: AbstractFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AbstractFileObject.java 22 Oct 2002 11:51:30 -0000 1.11
+++ AbstractFileObject.java 23 Oct 2002 10:56:33 -0000 1.12
@@ -18,7 +18,7 @@
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.vfs.FileConstants;
+import org.apache.commons.vfs.Selectors;
import org.apache.commons.vfs.FileContent;
import org.apache.commons.vfs.FileName;
import org.apache.commons.vfs.FileObject;
@@ -337,7 +337,7 @@
{
try
{
- doAttach();
+ attach();
if ( exists() )
{
return doIsReadable();
@@ -360,6 +360,7 @@
{
try
{
+ attach();
if ( exists() )
{
return doIsWriteable();
@@ -396,7 +397,7 @@
// Locate the parent of this file
if ( parent == null )
{
- parent = (AbstractFileObject)fs.findFile( name.getParent() );
+ parent = (AbstractFileObject)fs.resolveFile( name.getParent() );
}
return parent;
}
@@ -449,7 +450,7 @@
for ( int i = 0; i < files.length; i++ )
{
String file = files[ i ];
- children[ i ] = fs.findFile( name.resolveName( file, NameScope.CHILD ) );
+ children[ i ] = fs.resolveFile( name.resolveName( file, NameScope.CHILD ) );
}
}
@@ -457,12 +458,32 @@
}
/**
+ * Returns a child of this file.
+ */
+ public FileObject getChild( final String name ) throws FileSystemException
+ {
+ // TODO - use a hashtable when there are a large number of children
+ getChildren();
+ for ( int i = 0; i < children.length; i++ )
+ {
+ final FileObject child = children[ i ];
+ // TODO - use a comparator to compare names
+ if ( child.getName().getBaseName().equals( name ) )
+ {
+ return child;
+ }
+ }
+ return null;
+ }
+
+ /**
* Returns a child by name.
*/
- public FileObject resolveFile( String name, NameScope scope ) throws FileSystemException
+ public FileObject resolveFile( final String name, final NameScope scope )
+ throws FileSystemException
{
// TODO - cache children (only if they exist)
- return fs.findFile( this.name.resolveName( name, scope ) );
+ return fs.resolveFile( this.name.resolveName( name, scope ) );
}
/**
@@ -477,7 +498,7 @@
public FileObject resolveFile( final String path ) throws FileSystemException
{
final FileName otherName = name.resolveName( path );
- return fs.findFile( otherName );
+ return fs.resolveFile( otherName );
}
/**
@@ -634,7 +655,7 @@
// The destination file exists, and is not of the same type,
// so delete it
// TODO - add a pluggable policy for deleting and overwriting existing files
- destFile.delete( FileConstants.SELECT_ALL );
+ destFile.delete( Selectors.SELECT_ALL );
}
// Copy across
@@ -650,6 +671,17 @@
}
/**
+ * Finds the set of matching descendents of this file, in depthwise
+ * order.
+ */
+ public List findFiles( final FileSelector selector ) throws FileSystemException
+ {
+ final ArrayList list = new ArrayList();
+ findFiles( selector, true, list );
+ return list;
+ }
+
+ /**
* Creates a temporary local copy of this file, and its descendents.
*/
public File replicateFile( final FileSelector selector )
@@ -725,7 +757,7 @@
*/
boolean isFolder()
{
- return type == FileType.FOLDER;
+ return ( type == FileType.FOLDER );
}
/**
@@ -909,18 +941,25 @@
* Traverses the descendents of this file, and builds a list of selected
* files.
*/
- void findFiles( final FileSelector selector,
- final boolean depthwise,
- final List selected ) throws FileSystemException
- {
- if ( exists() )
- {
- // Traverse starting at this file
- final DefaultFileSelectorInfo info = new DefaultFileSelectorInfo();
- info.setBaseFolder( this );
- info.setDepth( 0 );
- info.setFile( this );
- traverse( info, selector, depthwise, selected );
+ private void findFiles( final FileSelector selector,
+ final boolean depthwise,
+ final List selected ) throws FileSystemException
+ {
+ try
+ {
+ if ( exists() )
+ {
+ // Traverse starting at this file
+ final DefaultFileSelectorInfo info = new DefaultFileSelectorInfo();
+ info.setBaseFolder( this );
+ info.setDepth( 0 );
+ info.setFile( this );
+ traverse( info, selector, depthwise, selected );
+ }
+ }
+ catch ( final Exception e )
+ {
+ throw new FileSystemException( "vfs.provider/find-files.error", name, e );
}
}
@@ -931,17 +970,11 @@
final FileSelector selector,
final boolean depthwise,
final List selected )
- throws FileSystemException
+ throws Exception
{
// Check the file itself
- final boolean includeFile = selector.includeFile( fileInfo );
final FileObject file = fileInfo.getFile();
-
- // Add the file if not doing depthwise traversal
- if ( !depthwise && includeFile )
- {
- selected.add( file );
- }
+ final int index = selected.size();
// If the file is a folder, traverse it
if ( file.getType() == FileType.FOLDER && selector.traverseDescendents( fileInfo ) )
@@ -963,9 +996,18 @@
}
// Add the file if doing depthwise traversal
- if ( depthwise && includeFile )
+ if ( selector.includeFile( fileInfo ) )
{
- selected.add( file );
+ if ( depthwise )
+ {
+ // Add this file after its descendents
+ selected.add( file );
+ }
+ else
+ {
+ // Add this file before its descendents
+ selected.add( index, file );
+ }
}
}
1.9 +4 -4 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java
Index: AbstractFileSystem.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractFileSystem.java 22 Oct 2002 11:51:30 -0000 1.8
+++ AbstractFileSystem.java 23 Oct 2002 10:56:33 -0000 1.9
@@ -101,7 +101,7 @@
{
if ( root == null )
{
- root = findFile( rootName );
+ root = resolveFile( rootName );
}
return root;
}
@@ -109,17 +109,17 @@
/**
* Finds a file in this file system.
*/
- public FileObject findFile( final String nameStr ) throws FileSystemException
+ public FileObject resolveFile( final String nameStr ) throws FileSystemException
{
// Resolve the name, and create the file
final FileName name = rootName.resolveName( nameStr );
- return findFile( name );
+ return resolveFile( name );
}
/**
* Finds a file in this file system.
*/
- public FileObject findFile( final FileName name ) throws FileSystemException
+ public FileObject resolveFile( final FileName name ) throws FileSystemException
{
// TODO - assert that name is from this file system
FileObject file = (FileObject)files.get( name );
1.3 +2 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractOriginatingFileProvider.java
Index: AbstractOriginatingFileProvider.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractOriginatingFileProvider.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractOriginatingFileProvider.java 21 Oct 2002 01:40:38 -0000 1.2
+++ AbstractOriginatingFileProvider.java 23 Oct 2002 10:56:33 -0000 1.3
@@ -73,7 +73,7 @@
}
// Locate the file
- return fs.findFile( parsedUri.getPath() );
+ return fs.resolveFile( parsedUri.getPath() );
}
/**
1.6 +0 -1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java
Index: DefaultFileContent.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultFileContent.java 21 Oct 2002 02:52:40 -0000 1.5
+++ DefaultFileContent.java 23 Oct 2002 10:56:33 -0000 1.6
@@ -196,7 +196,6 @@
*/
public void close() throws FileSystemException
{
-
try
{
// Close the input stream
1.12 +2 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java
Index: ZipFileSystem.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ZipFileSystem.java 21 Oct 2002 02:52:40 -0000 1.11
+++ ZipFileSystem.java 23 Oct 2002 10:56:33 -0000 1.12
@@ -12,7 +12,7 @@
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-import org.apache.commons.vfs.FileConstants;
+import org.apache.commons.vfs.Selectors;
import org.apache.commons.vfs.FileName;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
@@ -40,7 +40,7 @@
super( rootName, parentLayer );
// Make a local copy of the file
- final File file = parentLayer.replicateFile( FileConstants.SELECT_SELF );
+ final File file = parentLayer.replicateFile( Selectors.SELECT_SELF );
this.file = file;
1.4 +2 -2 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/local/test/LocalFileSystemTestCase.java
Index: LocalFileSystemTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/local/test/LocalFileSystemTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LocalFileSystemTestCase.java 21 Oct 2002 02:52:41 -0000 1.3
+++ LocalFileSystemTestCase.java 23 Oct 2002 10:56:33 -0000 1.4
@@ -32,7 +32,7 @@
final File testDir = getTestResource( "basedir" );
final File emptyDir = new File( testDir, "emptydir" );
emptyDir.mkdirs();
- return getManager().convert( testDir );
+ return getManager().toFileObject( testDir );
}
/**
@@ -41,7 +41,7 @@
protected FileObject getWriteFolder() throws Exception
{
final File testDir = getTestDirectory( "write-tests" );
- return getManager().convert( testDir );
+ return getManager().toFileObject( testDir );
}
/**
1.14 +19 -36 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractFileSystemTestCase.java
Index: AbstractFileSystemTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractFileSystemTestCase.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- AbstractFileSystemTestCase.java 22 Oct 2002 11:48:13 -0000 1.13
+++ AbstractFileSystemTestCase.java 23 Oct 2002 10:56:33 -0000 1.14
@@ -14,9 +14,7 @@
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.apache.commons.AbstractVfsTestCase;
import org.apache.commons.vfs.FileContent;
import org.apache.commons.vfs.FileName;
@@ -102,7 +100,7 @@
private FileInfo buildExpectedStructure()
{
// Build the expected structure
- final FileInfo base = new FileInfo( "test", FileType.FOLDER );
+ final FileInfo base = new FileInfo( baseFolder.getName().getBaseName(), FileType.FOLDER );
base.addChild( "file1.txt", FileType.FILE );
base.addChild( "empty.txt", FileType.FILE );
base.addChild( "emptydir", FileType.FOLDER );
@@ -609,9 +607,9 @@
final FileInfo info = (FileInfo)queueExpected.remove( 0 );
// Check the type is correct
- assertSame( file.getType(), info.m_type );
+ assertSame( file.getType(), info.type );
- if( info.m_type == FileType.FILE )
+ if( info.type == FileType.FILE )
{
continue;
}
@@ -621,13 +619,13 @@
// Make sure all children were found
assertNotNull( children );
- assertEquals( "count children of \"" + file.getName() + "\"", info.m_children.size(), children.length );
+ assertEquals( "count children of \"" + file.getName() + "\"", info.children.size(), children.length );
// Recursively check each child
for( int i = 0; i < children.length; i++ )
{
final FileObject child = children[ i ];
- final FileInfo childInfo = (FileInfo)info.m_children.get( child.getName().getBaseName() );
+ final FileInfo childInfo = (FileInfo)info.children.get( child.getName().getBaseName() );
// Make sure the child is expected
assertNotNull( childInfo );
@@ -1031,40 +1029,25 @@
}
/**
- * Info about a file.
+ * Tests that findFiles() works.
*/
- protected static final class FileInfo
+ public void testFindFiles() throws Exception
{
- String m_baseName;
- FileType m_type;
- Map m_children = new HashMap();
+ final FileInfo fileInfo = buildExpectedStructure();
+ final VerifyingFileSelector selector = new VerifyingFileSelector( fileInfo );
- public FileInfo( final String name, final FileType type )
- {
- m_baseName = name;
- m_type = type;
- }
-
- /** Adds a child. */
- public void addChild( final FileInfo child )
- {
- m_children.put( child.m_baseName, child );
- }
+ // Find the files
+ final List actualFiles = baseFolder.findFiles( selector );
- /** Adds a child. */
- public void addChild( final String baseName, final FileType type )
+ // Compare actual and expected list of files
+ final List expectedFiles = selector.finish();
+ assertEquals( expectedFiles.size(), actualFiles.size() );
+ final int count = expectedFiles.size();
+ for ( int i = 0; i < count; i++ )
{
- addChild( new FileInfo( baseName, type ) );
- }
-
- /** Adds a bunch of children. */
- public void addChildren( final String[] baseNames, final FileType type )
- {
- for( int i = 0; i < baseNames.length; i++ )
- {
- String baseName = baseNames[ i ];
- addChild( new FileInfo( baseName, type ) );
- }
+ final FileObject expected = (FileObject)expectedFiles.get( i );
+ final FileObject actual = (FileObject)actualFiles.get( i );
+ assertEquals( expected, actual );
}
}
}
1.2 +9 -9 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractWritableFileSystemTestCase.java
Index: AbstractWritableFileSystemTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractWritableFileSystemTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractWritableFileSystemTestCase.java 16 Jul 2002 17:18:58 -0000 1.1
+++ AbstractWritableFileSystemTestCase.java 23 Oct 2002 10:56:33 -0000 1.2
@@ -10,7 +10,7 @@
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
-import org.apache.commons.vfs.FileConstants;
+import org.apache.commons.vfs.Selectors;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileType;
@@ -41,7 +41,7 @@
FileObject scratchFolder = getWriteFolder();
// Make sure the test folder is empty
- scratchFolder.delete( FileConstants.EXCLUDE_SELF );
+ scratchFolder.delete( Selectors.EXCLUDE_SELF );
scratchFolder.create( FileType.FOLDER );
return scratchFolder;
@@ -174,13 +174,13 @@
// Delete a file
FileObject file = folder.resolveFile( "file1.txt" );
assertTrue( file.exists() );
- file.delete( FileConstants.SELECT_ALL );
+ file.delete( Selectors.SELECT_ALL );
assertTrue( !file.exists() );
// Delete an empty folder
file = folder.resolveFile( "emptydir" );
assertTrue( file.exists() );
- file.delete( FileConstants.SELECT_ALL );
+ file.delete( Selectors.SELECT_ALL );
assertTrue( !file.exists() );
// Recursive delete
@@ -188,14 +188,14 @@
FileObject file2 = file.resolveFile( "dir2/file2.txt" );
assertTrue( file.exists() );
assertTrue( file2.exists() );
- file.delete( FileConstants.SELECT_ALL );
+ file.delete( Selectors.SELECT_ALL );
assertTrue( !file.exists() );
assertTrue( !file2.exists() );
// Delete a file that does not exist
file = folder.resolveFile( "some-folder/some-file" );
assertTrue( !file.exists() );
- file.delete( FileConstants.SELECT_ALL );
+ file.delete( Selectors.SELECT_ALL );
assertTrue( !file.exists() );
}
@@ -232,17 +232,17 @@
assertSameFileSet( names, folder.getChildren() );
// Delete a child folder
- folder.resolveFile( "dir1" ).delete( FileConstants.SELECT_ALL );
+ folder.resolveFile( "dir1" ).delete( Selectors.SELECT_ALL );
names.remove( "dir1" );
assertSameFileSet( names, folder.getChildren() );
// Delete a child file
- folder.resolveFile( "file1.html" ).delete( FileConstants.SELECT_ALL );
+ folder.resolveFile( "file1.html" ).delete( Selectors.SELECT_ALL );
names.remove( "file1.html" );
assertSameFileSet( names, folder.getChildren() );
// Recreate the folder
- folder.delete( FileConstants.SELECT_ALL );
+ folder.delete( Selectors.SELECT_ALL );
folder.create( FileType.FOLDER );
assertEquals( 0, folder.getChildren().length );
}
1.2 +2 -2 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java
Index: FileSystemManagerFactoryTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileSystemManagerFactoryTestCase.java 21 Aug 2002 01:44:56 -0000 1.1
+++ FileSystemManagerFactoryTestCase.java 23 Oct 2002 10:56:33 -0000 1.2
@@ -37,7 +37,7 @@
// Lookup a test file
final File testDir = getTestResource( "basedir" );
- final FileObject file = manager.convert( testDir );
+ final FileObject file = manager.toFileObject( testDir );
assertNotNull( file );
assertTrue( file.exists() );
}
1.1 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/FileInfo.java
Index: FileInfo.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.vfs.test;
import org.apache.commons.vfs.FileType;
import java.util.Map;
import java.util.HashMap;
/**
* Info about a file.
*/
class FileInfo
{
String baseName;
FileType type;
Map children = new HashMap();
FileInfo parent;
public FileInfo( final String name, final FileType type )
{
baseName = name;
this.type = type;
}
public FileInfo getParent()
{
return parent;
}
/** Adds a child. */
public void addChild( final FileInfo child )
{
children.put( child.baseName, child );
child.parent = this;
}
/** Adds a child. */
public void addChild( final String baseName, final FileType type )
{
addChild( new FileInfo( baseName, type ) );
}
/** Adds a bunch of children. */
public void addChildren( final String[] baseNames, final FileType type )
{
for( int i = 0; i < baseNames.length; i++ )
{
String baseName = baseNames[ i ];
addChild( new FileInfo( baseName, type ) );
}
}
}
1.1 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/VerifyingFileSelector.java
Index: VerifyingFileSelector.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.vfs.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import junit.framework.Assert;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelectInfo;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileType;
/**
* A file selector that asserts that all files are visited, in the correct
* order.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/10/23 10:56:33 $
*/
public class VerifyingFileSelector
extends Assert
implements FileSelector
{
private final FileInfo rootFile;
private final List files = new ArrayList();
private FileInfo currentFolderInfo;
private FileObject currentFolder;
private Set children;
private List stack = new ArrayList();
public VerifyingFileSelector( final FileInfo fileInfo )
{
this.rootFile = fileInfo;
children = new HashSet();
children.add( rootFile.baseName );
}
/**
* Determines if a file or folder should be selected.
*/
public boolean includeFile( final FileSelectInfo fileInfo )
throws FileSystemException
{
final FileObject file = fileInfo.getFile();
if ( file == currentFolder )
{
// Pop current folder
assertEquals( 0, children.size() );
currentFolder = currentFolder.getParent();
currentFolderInfo = currentFolderInfo.getParent();
children = (Set)stack.remove( 0 );
}
final String baseName = file.getName().getBaseName();
final FileInfo childInfo = getChild( baseName );
assertSame( childInfo.type, file.getType() );
final boolean isChild = children.remove( baseName );
assertTrue( isChild );
files.add( file );
return true;
}
/**
* Determines whether a folder should be traversed.
*/
public boolean traverseDescendents( final FileSelectInfo fileInfo )
throws FileSystemException
{
// Check that the given file is a folder
final FileObject folder = fileInfo.getFile();
assertSame( FileType.FOLDER, folder.getType() );
// Locate the info for the folder
final String baseName = folder.getName().getBaseName();
if ( currentFolder == null )
{
assertEquals( rootFile.baseName, baseName );
currentFolderInfo = rootFile;
}
else
{
assertSame( currentFolder, folder.getParent() );
// Locate the info for the child, and make sure it is folder
currentFolderInfo = getChild( baseName );
assertSame( FileType.FOLDER, currentFolderInfo.type );
}
// Push the folder
stack.add( 0, children );
children = new HashSet( currentFolderInfo.children.keySet() );
currentFolder = folder;
return true;
}
/**
* Finds a child of the current folder.
*/
private FileInfo getChild( final String baseName )
{
if ( currentFolderInfo == null )
{
assertEquals( rootFile.baseName, baseName );
return rootFile;
}
else
{
final FileInfo child = (FileInfo)currentFolderInfo.children.get( baseName );
assertNotNull( child );
return child;
}
}
/**
* Asserts that the selector has seen all the files.
* @return The files in the order they where visited.
*/
public List finish()
{
assertEquals( 0, children.size() );
return files;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>