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/25 13:10:40 UTC
cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks VfsTask.java
adammurdoch 2002/10/25 04:10:40
Modified: vfs/src/java/org/apache/commons/vfs/tasks VfsTask.java
Log:
VfsTask:
- Creates the FileSystemManager for the tasks to use.
- Attaches VFS logging to Ant logging.
- Cleans up the VFS when the build finishes.
Revision Changes Path
1.5 +143 -6 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/VfsTask.java
Index: VfsTask.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/VfsTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- VfsTask.java 24 Oct 2002 02:11:03 -0000 1.4
+++ VfsTask.java 25 Oct 2002 11:10:40 -0000 1.5
@@ -55,11 +55,14 @@
*/
package org.apache.commons.vfs.tasks;
-import org.apache.tools.ant.Task;
+import org.apache.commons.logging.Log;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
-import org.apache.commons.vfs.VFS;
-import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.impl.StandardFileSystemManager;
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
/**
* Base class for the VFS Ant tasks. Provides some utility methods.
@@ -70,7 +73,7 @@
public class VfsTask
extends Task
{
- private FileSystemManager manager;
+ private static StandardFileSystemManager manager;
/**
* Resolves a URI to a file, relative to the project's base directory.
@@ -82,8 +85,142 @@
{
if ( manager == null )
{
- manager = VFS.getManager();
+ manager = new StandardFileSystemManager();
+ manager.setLogger( new AntLogger() );
+ manager.init();
+ getProject().addBuildListener( new CloseListener() );
}
return manager.resolveFile( getProject().getBaseDir(), uri );
+ }
+
+ /** Closes the VFS manager when the project finishes. */
+ private class CloseListener
+ implements BuildListener
+ {
+ public void buildFinished( BuildEvent event )
+ {
+ if ( manager != null )
+ {
+ manager.close();
+ manager = null;
+ }
+ }
+
+ public void buildStarted( BuildEvent event )
+ {
+ }
+
+ public void messageLogged( BuildEvent event )
+ {
+ }
+
+ public void targetFinished( BuildEvent event )
+ {
+ }
+
+ public void targetStarted( BuildEvent event )
+ {
+ }
+
+ public void taskFinished( BuildEvent event )
+ {
+ }
+
+ public void taskStarted( BuildEvent event )
+ {
+ }
+ }
+
+ /** A commons-logging wrapper for Ant logging. */
+ private class AntLogger
+ implements Log
+ {
+ public void debug( final Object o )
+ {
+ log( String.valueOf( o ), Project.MSG_DEBUG );
+ }
+
+ public void debug( Object o, Throwable throwable )
+ {
+ debug( o );
+ }
+
+ public void error( Object o )
+ {
+ log( String.valueOf( o ), Project.MSG_ERR );
+ }
+
+ public void error( Object o, Throwable throwable )
+ {
+ error( o );
+ }
+
+ public void fatal( Object o )
+ {
+ log( String.valueOf( o ), Project.MSG_ERR );
+ }
+
+ public void fatal( Object o, Throwable throwable )
+ {
+ fatal( o );
+ }
+
+ public void info( Object o )
+ {
+ log( String.valueOf( o ), Project.MSG_INFO );
+ }
+
+ public void info( Object o, Throwable throwable )
+ {
+ info( o );
+ }
+
+ public void trace( Object o )
+ {
+ }
+
+ public void trace( Object o, Throwable throwable )
+ {
+ }
+
+ public void warn( Object o )
+ {
+ log( String.valueOf( o ), Project.MSG_WARN );
+ }
+
+ public void warn( Object o, Throwable throwable )
+ {
+ warn( o );
+ }
+
+ public boolean isDebugEnabled()
+ {
+ return true;
+ }
+
+ public boolean isErrorEnabled()
+ {
+ return true;
+ }
+
+ public boolean isFatalEnabled()
+ {
+ return true;
+ }
+
+ public boolean isInfoEnabled()
+ {
+ return true;
+ }
+
+ public boolean isTraceEnabled()
+ {
+ return false;
+ }
+
+ public boolean isWarnEnabled()
+ {
+ return true;
+ }
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>