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/08/20 08:10:50 UTC
cvs commit: jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test AbstractFileSystemTestCase.java
adammurdoch 2002/08/19 23:10:50
Modified: vfs project.xml
vfs/src/java/org/apache/commons/vfs/impl
DefaultFileReplicator.java
DefaultFileSystemManager.java
vfs/src/java/org/apache/commons/vfs/provider
AbstractFileProvider.java AbstractFileSystem.java
AbstractFileSystemProvider.java FileProvider.java
FileReplicator.java FileSystem.java
vfs/src/java/org/apache/commons/vfs/provider/ftp
FtpFileSystem.java
vfs/src/java/org/apache/commons/vfs/provider/zip
ZipFileSystem.java
vfs/src/test/org/apache/commons AbstractVfsTestCase.java
vfs/src/test/org/apache/commons/vfs/test
AbstractFileSystemTestCase.java
Log:
Migrated from Avalon framework, to commons equivalent:
- Use commons logging instead of Avalon Logger.
- Replaced use of Disposable with explicit close() method.
Revision Changes Path
1.5 +5 -5 jakarta-commons-sandbox/vfs/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/project.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- project.xml 20 Aug 2002 02:57:01 -0000 1.4
+++ project.xml 20 Aug 2002 06:10:49 -0000 1.5
@@ -80,15 +80,15 @@
</dependency>
<dependency>
- <id>excalibur-i18n</id>
+ <id>commons-logging</id>
<version>1.0</version>
</dependency>
-
+
<dependency>
- <id>avalon-framework</id>
- <version>4.0</version>
+ <id>excalibur-i18n</id>
+ <version>1.0</version>
</dependency>
-
+
<dependency>
<id>jcifs</id>
<version>0.6.5</version>
1.3 +9 -13 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultFileReplicator.java 20 Aug 2002 02:57:02 -0000 1.2
+++ DefaultFileReplicator.java 20 Aug 2002 06:10:49 -0000 1.3
@@ -8,21 +8,18 @@
package org.apache.commons.vfs.impl;
import java.io.File;
-import java.util.ArrayList;
-import java.util.Random;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
-import org.apache.commons.vfs.FileConstants;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Random;
+import org.apache.avalon.excalibur.i18n.ResourceManager;
+import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.provider.FileReplicator;
-import org.apache.avalon.excalibur.i18n.ResourceManager;
-import org.apache.avalon.excalibur.i18n.Resources;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
/**
* A simple file replicator.
@@ -31,8 +28,7 @@
* @version $Revision$ $Date$
*/
public final class DefaultFileReplicator
- extends AbstractLogEnabled
- implements FileReplicator, Disposable
+ implements FileReplicator
{
private static final Resources REZ =
ResourceManager.getPackageResources( DefaultFileReplicator.class );
@@ -49,15 +45,15 @@
m_tempDir = (File) AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
- return new File( "ant_vfs_cache" ).getAbsoluteFile();
+ return new File( "vfs_cache" ).getAbsoluteFile();
}
} );
}
/**
- * Deletes the temporary files.
+ * Closes the replicator, deleting the temporary files.
*/
- public void dispose()
+ public void close()
{
/*
AccessController.doPrivileged(
1.2 +7 -25 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultFileSystemManager.java 16 Jul 2002 17:18:59 -0000 1.1
+++ DefaultFileSystemManager.java 20 Aug 2002 06:10:49 -0000 1.2
@@ -15,6 +15,8 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import org.apache.avalon.excalibur.i18n.ResourceManager;
+import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
@@ -23,11 +25,6 @@
import org.apache.commons.vfs.provider.FileReplicator;
import org.apache.commons.vfs.provider.LocalFileProvider;
import org.apache.commons.vfs.provider.UriParser;
-import org.apache.avalon.excalibur.i18n.ResourceManager;
-import org.apache.avalon.excalibur.i18n.Resources;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.logger.Logger;
/**
* A default file system manager implementation.
@@ -38,8 +35,7 @@
* @version $Revision$ $Date$
*/
public class DefaultFileSystemManager
- extends AbstractLogEnabled
- implements FileSystemManager, Disposable
+ implements FileSystemManager
{
private static final Resources REZ
= ResourceManager.getPackageResources( DefaultFileSystemManager.class );
@@ -88,7 +84,6 @@
}
// Contextualise
- setupLogger( provider );
provider.setContext( m_context );
// Add to map
@@ -116,19 +111,10 @@
}
/**
- * Enable logging.
- */
- public void enableLogging( final Logger logger )
- {
- super.enableLogging( logger );
- setupLogger( m_fileReplicator );
- }
-
- /**
* Closes all files created by this manager, and cleans up any temporary
* files.
*/
- public void dispose()
+ public void close()
{
// Dispose the providers (making sure we only dispose each provider
// once
@@ -136,16 +122,12 @@
providers.addAll( m_providers.values() );
for( Iterator iterator = providers.iterator(); iterator.hasNext(); )
{
- Object provider = iterator.next();
- if( provider instanceof Disposable )
- {
- Disposable disposable = (Disposable)provider;
- disposable.dispose();
- }
+ FileProvider provider = (FileProvider)iterator.next();
+ provider.close();
}
m_providers.clear();
- m_fileReplicator.dispose();
+ m_fileReplicator.close();
}
/**
1.2 +0 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileProvider.java
Index: AbstractFileProvider.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileProvider.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractFileProvider.java 16 Jul 2002 17:18:57 -0000 1.1
+++ AbstractFileProvider.java 20 Aug 2002 06:10:50 -0000 1.2
@@ -7,7 +7,6 @@
*/
package org.apache.commons.vfs.provider;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
/**
* A partial FileProvider implementation.
@@ -16,7 +15,6 @@
* @version $Revision$ $Date$
*/
public abstract class AbstractFileProvider
- extends AbstractLogEnabled
implements FileProvider
{
private FileSystemProviderContext m_context;
1.2 +12 -5 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractFileSystem.java 16 Jul 2002 17:18:57 -0000 1.1
+++ AbstractFileSystem.java 20 Aug 2002 06:10:50 -0000 1.2
@@ -12,8 +12,8 @@
import org.apache.commons.vfs.FileName;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* A partial file system implementation.
@@ -22,8 +22,7 @@
* @version $Revision$ $Date$
*/
public abstract class AbstractFileSystem
- extends AbstractLogEnabled
- implements FileSystem, Disposable
+ implements FileSystem
{
private FileObject m_root;
private final FileName m_rootName;
@@ -39,7 +38,7 @@
m_context = context;
}
- public void dispose()
+ public void close()
{
// Clean-up
m_files.clear();
@@ -110,5 +109,13 @@
m_files.put( name, file );
}
return file;
+ }
+
+ /**
+ * Returns the logger for this file system to use.
+ */
+ protected Log getLogger()
+ {
+ return LogFactory.getLog( getClass() );
}
}
1.2 +2 -9 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystemProvider.java
Index: AbstractFileSystemProvider.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystemProvider.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractFileSystemProvider.java 16 Jul 2002 17:18:57 -0000 1.1
+++ AbstractFileSystemProvider.java 20 Aug 2002 06:10:50 -0000 1.2
@@ -14,7 +14,6 @@
import org.apache.commons.vfs.FileSystemException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
-import org.apache.avalon.framework.activity.Disposable;
/**
* A partial file system provider implementation.
@@ -24,7 +23,6 @@
*/
public abstract class AbstractFileSystemProvider
extends AbstractFileProvider
- implements Disposable
{
private static final Resources REZ =
ResourceManager.getPackageResources( AbstractFileSystemProvider.class );
@@ -38,16 +36,12 @@
/**
* Closes the file systems created by this provider.
*/
- public void dispose()
+ public void close()
{
for( Iterator iterator = m_fileSystems.values().iterator(); iterator.hasNext(); )
{
FileSystem fileSystem = (FileSystem)iterator.next();
- if( fileSystem instanceof Disposable )
- {
- Disposable disposable = (Disposable)fileSystem;
- disposable.dispose();
- }
+ fileSystem.close();
}
m_fileSystems.clear();
}
@@ -90,7 +84,6 @@
{
// Need to create the file system, and cache it
fs = createFileSystem( parsedUri );
- setupLogger( fs );
m_fileSystems.put( rootUri, fs );
}
1.2 +5 -0 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileProvider.java
Index: FileProvider.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileProvider.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileProvider.java 16 Jul 2002 17:18:57 -0000 1.1
+++ FileProvider.java 20 Aug 2002 06:10:50 -0000 1.2
@@ -57,4 +57,9 @@
*/
FileObject createFileSystem( String scheme, FileObject file )
throws FileSystemException;
+
+ /**
+ * Closes the provider.
+ */
+ void close();
}
1.2 +5 -0 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileReplicator.java
Index: FileReplicator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileReplicator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileReplicator.java 16 Jul 2002 17:18:57 -0000 1.1
+++ FileReplicator.java 20 Aug 2002 06:10:50 -0000 1.2
@@ -33,4 +33,9 @@
*/
File replicateFile( FileObject srcFile, FileSelector selector )
throws FileSystemException;
+
+ /**
+ * Closes the replicator.
+ */
+ void close();
}
1.2 +5 -0 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileSystem.java
Index: FileSystem.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileSystem.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileSystem.java 16 Jul 2002 17:18:57 -0000 1.1
+++ FileSystem.java 20 Aug 2002 06:10:50 -0000 1.2
@@ -39,4 +39,9 @@
* The name of the file. This must be an absolute path.
*/
FileObject findFile( String name ) throws FileSystemException;
+
+ /**
+ * Closes this file system.
+ */
+ void close();
}
1.3 +3 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java
Index: FtpFileSystem.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FtpFileSystem.java 17 Jul 2002 10:23:44 -0000 1.2
+++ FtpFileSystem.java 20 Aug 2002 06:10:50 -0000 1.3
@@ -75,11 +75,12 @@
}
}
- public void dispose()
+ public void close()
{
// Clean up the connection
- super.dispose();
closeConnection();
+
+ super.close();
}
/**
1.2 +3 -3 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ZipFileSystem.java 16 Jul 2002 17:18:58 -0000 1.1
+++ ZipFileSystem.java 20 Aug 2002 06:10:50 -0000 1.2
@@ -109,10 +109,8 @@
}
}
- public void dispose()
+ public void close()
{
- super.dispose();
-
// Release the zip file
try
{
@@ -126,6 +124,8 @@
final String message = REZ.getString( "close-zip-file.error", m_file );
getLogger().warn( message, e );
}
+
+ super.close();
}
/**
1.3 +18 -17 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/AbstractVfsTestCase.java
Index: AbstractVfsTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/AbstractVfsTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractVfsTestCase.java 20 Aug 2002 02:57:02 -0000 1.2
+++ AbstractVfsTestCase.java 20 Aug 2002 06:10:50 -0000 1.3
@@ -9,12 +9,10 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
-import org.apache.avalon.framework.ExceptionUtil;
-import org.apache.avalon.framework.logger.ConsoleLogger;
-import org.apache.avalon.framework.logger.Logger;
/**
* A base class for VFS tests. Provides utility methods for locating
@@ -28,7 +26,6 @@
{
private final File m_testBaseDir;
private final File m_baseDir;
- private Logger m_logger;
public AbstractVfsTestCase( final String name )
{
@@ -148,18 +145,6 @@
}
/**
- * Creates a logger.
- */
- protected Logger getLogger()
- {
- if( m_logger == null )
- {
- m_logger = new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG );
- }
- return m_logger;
- }
-
- /**
* Asserts that an exception chain contains the expected messages.
*
* @param messages The messages, in order. A null entry in this array
@@ -178,7 +163,23 @@
}
// Get the next exception in the chain
- current = ExceptionUtil.getCause( current, true );
+ current = getCause( current );
+ }
+ }
+
+ /**
+ * Returns the cause of an exception.
+ */
+ private Throwable getCause( Throwable throwable )
+ {
+ try
+ {
+ Method method = throwable.getClass().getMethod( "getCause", null );
+ return (Throwable)method.invoke( throwable, null );
+ }
+ catch ( Exception e )
+ {
+ return null;
}
}
1.3 +1 -2 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractFileSystemTestCase.java 20 Aug 2002 02:57:02 -0000 1.2
+++ AbstractFileSystemTestCase.java 20 Aug 2002 06:10:50 -0000 1.3
@@ -113,7 +113,6 @@
{
// Create the file system manager
m_manager = new DefaultFileSystemManager();
- m_manager.enableLogging( getLogger() );
m_manager.addProvider( "file", new DefaultLocalFileSystemProvider() );
// Locate the base folder
@@ -132,7 +131,7 @@
*/
protected void tearDown() throws Exception
{
- m_manager.dispose();
+ m_manager.close();
}
/**
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>