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


The following commit(s) were added to refs/heads/master by this push:
     new 3b0036a2 Add Executor.getWorkingDirectoryPath()
3b0036a2 is described below

commit 3b0036a2f72c1e750d28f2b279419063778ac061
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Wed Feb 19 09:15:24 2025 -0500

    Add Executor.getWorkingDirectoryPath()
---
 src/changes/changes.xml                                       |  1 +
 src/main/java/org/apache/commons/exec/Executor.java           | 11 +++++++++++
 .../java/org/apache/commons/exec/DefaultExecutorTest.java     | 10 +++++++---
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 83bd6da8..df02759d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -28,6 +28,7 @@
             <!-- ADD -->
             <action type="add" dev="ggregory" due-to="Gary Gregory">Add Maven 
property project.build.outputTimestamp for build reproducibility.</action>
             <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
CommandLine.CommandLine(Path).</action>
+            <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
Executor.getWorkingDirectoryPath().</action>
             <!-- FIX -->
             <action type="fix" dev="ggregory" issue="EXEC-122" 
due-to="Marcono1234">Document PumpStreamHandler stream thread-safety 
requirements.</action>
             <action type="fix" dev="ggregory" due-to="Marcono1234">Fix CI only 
running on Ubuntu and improve OS-specific tests #143.</action>
diff --git a/src/main/java/org/apache/commons/exec/Executor.java 
b/src/main/java/org/apache/commons/exec/Executor.java
index 1ac6a01d..313524b2 100644
--- a/src/main/java/org/apache/commons/exec/Executor.java
+++ b/src/main/java/org/apache/commons/exec/Executor.java
@@ -19,6 +19,7 @@ package org.apache.commons.exec;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Path;
 import java.util.Map;
 
 /**
@@ -119,6 +120,16 @@ public interface Executor {
      */
     File getWorkingDirectory();
 
+    /**
+     * Gets the working directory of the created process.
+     *
+     * @return the working directory.
+     * @since 1.5.0
+     */
+    default Path getWorkingDirectoryPath() {
+        return getWorkingDirectory().toPath();
+    }
+
     /**
      * Tests whether {@code exitValue} signals a failure. If no exit values 
are set than the default conventions of the OS is used. e.g. most OS regard an 
exit
      * code of '0' as successful execution and everything else as failure.
diff --git a/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java 
b/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
index 9d764e89..9988a946 100644
--- a/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
+++ b/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
@@ -35,6 +35,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.time.Duration;
 import java.util.HashMap;
 import java.util.Map;
@@ -220,6 +221,7 @@ public class DefaultExecutorTest {
         assertEquals("FOO..", baos.toString().trim());
         assertFalse(exec.isFailure(exitValue));
         assertEquals(new File("."), exec.getWorkingDirectory());
+        assertEquals(Paths.get("."), exec.getWorkingDirectoryPath());
     }
 
     /**
@@ -717,13 +719,15 @@ public class DefaultExecutorTest {
 
     @Test
     public void testExecuteWithWorkingDirectory() throws Exception {
-        final File workingDir = new File("./target");
+        final Path workingDirPath = Paths.get("./target");
         final CommandLine cl = new CommandLine(testScript);
-        exec.setWorkingDirectory(workingDir);
+        final File workingDirFile = workingDirPath.toFile();
+        exec.setWorkingDirectory(workingDirFile);
         final int exitValue = exec.execute(cl);
         assertEquals("FOO..", baos.toString().trim());
         assertFalse(exec.isFailure(exitValue));
-        assertEquals(exec.getWorkingDirectory(), workingDir);
+        assertEquals(exec.getWorkingDirectory(), workingDirFile);
+        assertEquals(exec.getWorkingDirectoryPath(), workingDirPath);        
     }
 
     /**

Reply via email to