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 2021/09/11 14:23:45 UTC

[commons-io] 01/04: Add FileUtils.current().

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-io.git

commit d990ec36a4d3b570dba499834bbdb8bb22dd659d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Sep 11 07:07:56 2021 -0700

    Add FileUtils.current().
---
 src/changes/changes.xml                                  |  3 +++
 src/main/java/org/apache/commons/io/FileUtils.java       | 12 ++++++++++++
 .../org/apache/commons/io/FileUtilsWaitForTestCase.java  | 16 +++++++---------
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a4450a2..6f3c71b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -172,6 +172,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="add" due-to="Gary Gregory">
         Add org.apache.commons.io.input.Tailer.getDelayDuration().
       </action>
+      <action dev="ggregory" type="add" due-to="Gary Gregory">
+        Add FileUtils.current().
+      </action>
       <!-- UPDATE -->
       <action dev="ggregory" type="add" due-to="Gary Gregory">
         Update FileEntry to use FileTime instead of long for file time stamps.
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java
index fd5438d..227c994 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -1116,6 +1116,17 @@ public class FileUtils {
     }
 
     /**
+     * Gets the current directory.
+     *
+     * @return the current directory.
+     *
+     * @since 2.12.0
+     */
+    public static File current() {
+        return PathUtils.current().toFile();
+    }
+
+    /**
      * Decodes the specified URL as per RFC 3986, i.e. transforms
      * percent-encoded octets to characters by decoding with the UTF-8 character
      * set. This function is primarily intended for usage with
@@ -3601,4 +3612,5 @@ public class FileUtils {
     public FileUtils() { //NOSONAR
 
     }
+
 }
diff --git a/src/test/java/org/apache/commons/io/FileUtilsWaitForTestCase.java b/src/test/java/org/apache/commons/io/FileUtilsWaitForTestCase.java
index 1068f24..eea7bf7 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsWaitForTestCase.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsWaitForTestCase.java
@@ -18,7 +18,6 @@ package org.apache.commons.io;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.io.File;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -35,25 +34,24 @@ public class FileUtilsWaitForTestCase {
 
     @Test
     public void testWaitFor() {
-        FileUtils.waitFor(new File(""), -1);
-        FileUtils.waitFor(new File(""), 2);
+        FileUtils.waitFor(FileUtils.current(), -1);
+        FileUtils.waitFor(FileUtils.current(), 2);
     }
 
     @Test
     public void testWaitForInterrupted() throws InterruptedException {
         final AtomicBoolean wasInterrupted = new AtomicBoolean(false);
         final CountDownLatch started = new CountDownLatch(1);
-        final Runnable thread = () -> {
+        final Thread thread1 = new Thread(() -> {
             started.countDown();
-            FileUtils.waitFor(new File(""), 2);
-            wasInterrupted.set( Thread.currentThread().isInterrupted());
-        };
-        final Thread thread1 = new Thread(thread);
+            FileUtils.waitFor(FileUtils.current(), 2);
+            wasInterrupted.set(Thread.currentThread().isInterrupted());
+        });
         thread1.start();
         started.await();
         thread1.interrupt();
         thread1.join();
-        assertTrue( wasInterrupted.get() );
+        assertTrue(wasInterrupted.get());
     }
 
 }