You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/10/05 22:32:31 UTC

[commons-vfs] branch master updated: [VFS-735] Add org.apache.commons.vfs2.FileSystemManager.close() via AutoCloseable.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new eed9b13  [VFS-735] Add org.apache.commons.vfs2.FileSystemManager.close() via AutoCloseable.
eed9b13 is described below

commit eed9b13580630503caec418f06f576459eb35928
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 5 18:32:27 2019 -0400

    [VFS-735] Add org.apache.commons.vfs2.FileSystemManager.close() via
    AutoCloseable.
---
 .../org/apache/commons/vfs2/FileSystemManager.java | 12 +++++-
 .../vfs2/impl/DefaultFileSystemManager.java        |  4 +-
 .../vfs2/impl/DefaultFileSystemManagerTest.java    | 50 ++++++++++++++++++++++
 .../vfs2/impl/StandardFileSystemManagerTest.java   | 50 ++++++++++++++++++++++
 src/changes/changes.xml                            |  5 ++-
 5 files changed, 118 insertions(+), 3 deletions(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemManager.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemManager.java
index ce10c5d..a55bf77 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemManager.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemManager.java
@@ -50,7 +50,7 @@ import org.apache.commons.vfs2.operations.FileOperationProvider;
  * elements. See {@link FileObject#resolveFile} for more details.</li>
  * </ul>
  */
-public interface FileSystemManager {
+public interface FileSystemManager extends AutoCloseable {
 
     /**
      * Adds the specified FileOperationProvider for the specified scheme.
@@ -84,6 +84,16 @@ public interface FileSystemManager {
     boolean canCreateFileSystem(FileObject file) throws FileSystemException;
 
     /**
+     * Closes this file system manager.
+     *
+     * @since 2.5.0
+     */
+    @Override
+    default void close() {
+        // noop
+    }
+
+    /**
      * Closes the given file system.
      * <p>
      * If you use VFS as singleton it is VERY dangerous to call this method.
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
index 31318a0..5c95ed8 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
@@ -60,7 +60,7 @@ import org.apache.commons.vfs2.provider.VfsComponent;
 /**
  * The default file system manager implementation.
  */
-public class DefaultFileSystemManager implements FileSystemManager, AutoCloseable {
+public class DefaultFileSystemManager implements FileSystemManager {
     /**
      * Mapping from URI scheme to FileProvider.
      */
@@ -512,6 +512,7 @@ public class DefaultFileSystemManager implements FileSystemManager, AutoCloseabl
      * <p>
      * The manager is in uninitialized state after this method.
      */
+    @Override
     public void close() {
         if (!init) {
             return;
@@ -1164,4 +1165,5 @@ public class DefaultFileSystemManager implements FileSystemManager, AutoCloseabl
             throw new FileSystemException(e);
         }
     }
+
 }
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/DefaultFileSystemManagerTest.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/DefaultFileSystemManagerTest.java
new file mode 100644
index 0000000..d195518
--- /dev/null
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/DefaultFileSystemManagerTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.vfs2.impl;
+
+import java.nio.file.Paths;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.VFS;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests {@link DefaultFileSystemManager}.
+ *
+ * @since 2.5.0
+ */
+public class DefaultFileSystemManagerTest {
+
+    /**
+     * Tests {@link DefaultFileSystemManager#close()}.
+     *
+     * @throws FileSystemException
+     */
+    @Test
+    public void test_close() throws FileSystemException {
+        try (FileSystemManager fileSystemManager = new DefaultFileSystemManager()) {
+            VFS.setManager(fileSystemManager);
+            VFS.setManager(null);
+        }
+        Assert.assertNotNull(VFS.getManager());
+        Assert.assertFalse(VFS.getManager().resolveFile(Paths.get("DoesNotExist.not").toUri()).exists());
+    }
+
+}
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/StandardFileSystemManagerTest.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/StandardFileSystemManagerTest.java
new file mode 100644
index 0000000..1f1ca8a
--- /dev/null
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/StandardFileSystemManagerTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.vfs2.impl;
+
+import java.nio.file.Paths;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.VFS;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests {@link StandardFileSystemManager}.
+ *
+ * @since 2.5.0
+ */
+public class StandardFileSystemManagerTest {
+
+    /**
+     * Tests {@link StandardFileSystemManager#close()}.
+     *
+     * @throws FileSystemException
+     */
+    @Test
+    public void test_close() throws FileSystemException {
+        try (FileSystemManager fileSystemManager = new StandardFileSystemManager()) {
+            VFS.setManager(fileSystemManager);
+            VFS.setManager(null);
+        }
+        Assert.assertNotNull(VFS.getManager());
+        Assert.assertFalse(VFS.getManager().resolveFile(Paths.get("DoesNotExist.not").toUri()).exists());
+    }
+
+}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cefecec..e35bfa0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -77,9 +77,12 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="update" due-to="Gary Gregory">
         Update tests using org.mockito:mockito-core from 3.0.0 to 3.1.0.
       </action>
-      <action issue="VFS-734" dev="ggregory" type="update" due-to="Gary Gregory">
+      <action issue="VFS-734" dev="ggregory" type="add" due-to="Gary Gregory">
         Add functional interface org.apache.commons.vfs2.function.VfsConsumer.
       </action>
+      <action issue="VFS-735" dev="ggregory" type="add" due-to="Gary Gregory">
+        Add org.apache.commons.vfs2.FileSystemManager.close() via AutoCloseable.
+      </action>
     </release>
     <release version="2.4.1" date="2019-08-10" description="Bug fix release.">
       <action issue="VFS-725" dev="ggregory" type="fix" due-to="Gary Gregory">