[jboss-cvs] JBossAS SVN: r102424 - in projects/vfs/trunk/src: test/java/org/jboss/test/vfs and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 15 14:04:37 EDT 2010


Author: johnbailey
Date: 2010-03-15 14:04:36 -0400 (Mon, 15 Mar 2010)
New Revision: 102424

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java
   projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
   projects/vfs/trunk/src/test/java/org/jboss/test/vfs/MountHandleTestCase.java
Log:
[JBVFS-152] - Fallback to returning Closeables for VFS.mount* calls

Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java	2010-03-15 18:02:28 UTC (rev 102423)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java	2010-03-15 18:04:36 UTC (rev 102424)
@@ -398,7 +398,7 @@
      *
      * @throws IOException if an error occurs
      */
-    public static MountHandle mountZip(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
+    public static Closeable mountZip(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
         boolean ok = false;
         final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName());
         try {
@@ -425,7 +425,7 @@
      *
      * @throws IOException if an error occurs
      */
-    public static MountHandle mountZip(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
+    public static Closeable mountZip(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
         boolean ok = false;
         try {
             final TempDir tempDir = tempFileProvider.createTempDir(zipName);
@@ -455,7 +455,7 @@
      *
      * @throws IOException if an error occurs
      */
-    public static MountHandle mountZip(VirtualFile zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
+    public static Closeable mountZip(VirtualFile zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
         return mountZip(zipFile.openStream(), zipFile.getName(), mountPoint, tempFileProvider);
     }
 
@@ -470,7 +470,7 @@
      *
      * @throws IOException if an error occurs
      */
-    public static MountHandle mountReal(File realRoot, VirtualFile mountPoint) throws IOException {
+    public static Closeable mountReal(File realRoot, VirtualFile mountPoint) throws IOException {
         return doMount(new RealFileSystem(realRoot), mountPoint);
     }
 
@@ -485,7 +485,7 @@
      *
      * @throws IOException if an error occurs
      */
-    public static MountHandle mountTemp(VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
+    public static Closeable mountTemp(VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
         boolean ok = false;
         final TempDir tempDir = tempFileProvider.createTempDir("tmpfs");
         try {
@@ -511,7 +511,7 @@
      *
      * @throws IOException if an error occurs
      */
-    public static MountHandle mountZipExpanded(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
+    public static Closeable mountZipExpanded(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
         boolean ok = false;
         final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName());
         try {
@@ -540,7 +540,7 @@
      *
      * @throws IOException if an error occurs
      */
-    public static MountHandle mountZipExpanded(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
+    public static Closeable mountZipExpanded(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
         try {
             boolean ok = false;
             final TempDir tempDir = tempFileProvider.createTempDir(zipName);
@@ -587,7 +587,7 @@
      *
      * @throws IOException if an error occurs
      */
-    public static MountHandle mountZipExpanded(VirtualFile zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
+    public static Closeable mountZipExpanded(VirtualFile zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
         return mountZipExpanded(zipFile.openStream(), zipFile.getName(), mountPoint, tempFileProvider);
     }
     
@@ -601,7 +601,7 @@
      * 
      * @throws IOException if an error occurs
      */
-    public static MountHandle mountAssembly(VirtualFileAssembly assembly, VirtualFile mountPoint) throws IOException {
+    public static Closeable mountAssembly(VirtualFileAssembly assembly, VirtualFile mountPoint) throws IOException {
        return doMount(new AssemblyFileSystem(assembly), mountPoint);
     }
 

Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java	2010-03-15 18:02:28 UTC (rev 102423)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java	2010-03-15 18:04:36 UTC (rev 102424)
@@ -53,6 +53,7 @@
 
 import org.jboss.logging.Logger;
 import org.jboss.util.collection.CollectionsFactory;
+import org.jboss.vfs.spi.MountHandle;
 import org.jboss.vfs.util.PathTokenizer;
 import org.jboss.vfs.util.automount.Automounter;
 
@@ -812,6 +813,17 @@
         }
     }
 
+   /**
+    * Return the mount source File for a given mount handle.
+    * @param handle The handle to get the source for
+    * @return The mount source file or null if the handle does not have a source, or is not a MountHandle
+    */
+    public static File getMountSource(Closeable handle) {
+       if(handle instanceof MountHandle)
+         return MountHandle.class.cast(handle).getMountSource();
+       return null;
+    }
+
     private static final Pattern GLOB_PATTERN = Pattern.compile("(\\*\\*?)|(\\?)|(\\\\.)|(/+)|([^*?]+)");
 
     /**

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/MountHandleTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/MountHandleTestCase.java	2010-03-15 18:02:28 UTC (rev 102423)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/MountHandleTestCase.java	2010-03-15 18:04:36 UTC (rev 102424)
@@ -24,8 +24,8 @@
 import org.jboss.vfs.VFS;
 import org.jboss.vfs.VFSUtils;
 import org.jboss.vfs.VirtualFile;
-import org.jboss.vfs.spi.MountHandle;
 
+import java.io.Closeable;
 import java.io.File;
 
 /**
@@ -42,11 +42,11 @@
    public void testZipGetMountSource() throws Exception {
       VirtualFile jar  = getVirtualFile("/vfs/test/jar1.jar");
       File origin = jar.getPhysicalFile();
-      MountHandle mountHandle = VFS.mountZip(jar, jar, provider);
+      Closeable mountHandle = VFS.mountZip(jar, jar, provider);
       try
       {
          File mounted = jar.getPhysicalFile();
-         File source = mountHandle.getMountSource();
+         File source = VFSUtils.getMountSource(mountHandle);
 
          assertNotNull(origin);
          assertNotNull(mounted);




More information about the jboss-cvs-commits mailing list