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 2025/05/24 14:33:40 UTC

(commons-exec) branch master updated (83653f40 -> 008804a9)

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

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


    from 83653f40 Failing Checkstyle now fails the build (the default behavior)
     new a3ce9400 Migrate internal type declaration from class Vector to interface List
     new afa90ed7 Remove some extra vertical whitespace
     new 008804a9 Fix Checkstyle JavadocVariable

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/conf/checkstyle-suppressions.xml               |  1 +
 src/conf/checkstyle.xml                            |  4 +---
 .../java/org/apache/commons/exec/CommandLine.java  | 27 ++++++++--------------
 .../org/apache/commons/exec/DefaultExecutor.java   | 11 +++++++++
 .../org/apache/commons/exec/ExecuteWatchdog.java   |  3 +++
 .../org/apache/commons/exec/LogOutputStream.java   |  9 ++++++++
 src/main/java/org/apache/commons/exec/OS.java      | 20 +++++++++++++---
 .../org/apache/commons/exec/PumpStreamHandler.java | 12 ++++++++++
 .../commons/exec/ShutdownHookProcessDestroyer.java | 10 +++++---
 .../java/org/apache/commons/exec/Watchdog.java     | 22 ++++++++++++++----
 .../commons/exec/environment/EnvironmentUtils.java |  3 +++
 .../org/apache/commons/exec/util/StringUtils.java  |  9 ++++++++
 12 files changed, 100 insertions(+), 31 deletions(-)


(commons-exec) 03/03: Fix Checkstyle JavadocVariable

Posted by gg...@apache.org.
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

commit 008804a997fb6dc25b392f9fc5a5495674cf125a
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat May 24 10:33:35 2025 -0400

    Fix Checkstyle JavadocVariable
    
    - inline redundant constant
---
 src/conf/checkstyle-suppressions.xml                 |  1 +
 src/conf/checkstyle.xml                              |  4 +---
 .../java/org/apache/commons/exec/CommandLine.java    |  7 +++++++
 .../org/apache/commons/exec/DefaultExecutor.java     | 11 +++++++++++
 .../org/apache/commons/exec/ExecuteWatchdog.java     |  3 +++
 .../org/apache/commons/exec/LogOutputStream.java     |  9 +++++++++
 src/main/java/org/apache/commons/exec/OS.java        | 20 +++++++++++++++++---
 .../org/apache/commons/exec/PumpStreamHandler.java   | 12 ++++++++++++
 .../commons/exec/ShutdownHookProcessDestroyer.java   |  3 +++
 src/main/java/org/apache/commons/exec/Watchdog.java  | 14 ++++++++++++++
 .../commons/exec/environment/EnvironmentUtils.java   |  3 +++
 .../org/apache/commons/exec/util/StringUtils.java    |  9 +++++++++
 12 files changed, 90 insertions(+), 6 deletions(-)

diff --git a/src/conf/checkstyle-suppressions.xml b/src/conf/checkstyle-suppressions.xml
index 0f6721d6..102cb60d 100644
--- a/src/conf/checkstyle-suppressions.xml
+++ b/src/conf/checkstyle-suppressions.xml
@@ -21,6 +21,7 @@ limitations under the License.
 <!-- SEE: http://checkstyle.sourceforge.net/config.html#Examples -->
 <suppressions>
   <suppress checks="JavadocPackage" files="src[/\\]test[/\\]java[/\\]" />
+  <suppress checks="JavadocVariable" files="src[/\\]test[/\\]java[/\\]" />
   <!--  EnvironmentUtils can be final when we break BC. -->
   <suppress checks="FinalClass" files="src[/\\]main[/\\]java[/\\]org[/\\]apache[/\\]commons[/\\]exec[/\\]environment[/\\]EnvironmentUtils.java" />
   <!--  StringUtils can have a private default constructor when we break BC. -->
diff --git a/src/conf/checkstyle.xml b/src/conf/checkstyle.xml
index 2559dab4..affff048 100644
--- a/src/conf/checkstyle.xml
+++ b/src/conf/checkstyle.xml
@@ -63,9 +63,7 @@
     <!-- See https://checkstyle.sf.net/config_javadoc.html -->
     <module name="JavadocType">
     </module>
-    <module name="JavadocVariable">
-      <property name="accessModifiers" value="public, protected"/>
-    </module>
+    <module name="JavadocVariable" />
     <!-- Checks for Naming Conventions. -->
     <!-- See https://checkstyle.sf.net/config_naming.html -->
     <module name="ConstantName" />
diff --git a/src/main/java/org/apache/commons/exec/CommandLine.java b/src/main/java/org/apache/commons/exec/CommandLine.java
index 1a7cbf3d..c526a782 100644
--- a/src/main/java/org/apache/commons/exec/CommandLine.java
+++ b/src/main/java/org/apache/commons/exec/CommandLine.java
@@ -41,7 +41,14 @@ public class CommandLine {
      */
     static final class Argument {
 
+        /**
+         * Argument value.
+         */
         private final String value;
+
+        /**
+         * Whether to quote arguments.
+         */
         private final boolean handleQuoting;
 
         private Argument(final String value, final boolean handleQuoting) {
diff --git a/src/main/java/org/apache/commons/exec/DefaultExecutor.java b/src/main/java/org/apache/commons/exec/DefaultExecutor.java
index f9ceae74..e970c983 100644
--- a/src/main/java/org/apache/commons/exec/DefaultExecutor.java
+++ b/src/main/java/org/apache/commons/exec/DefaultExecutor.java
@@ -62,8 +62,19 @@ public class DefaultExecutor implements Executor {
      */
     public static class Builder<T extends Builder<T>> implements Supplier<DefaultExecutor> {
 
+        /**
+         * Error stream handler.
+         */
         private ExecuteStreamHandler executeStreamHandler;
+
+        /**
+         * Thread factory.
+         */
         private ThreadFactory threadFactory;
+
+        /**
+         * Working directory path.
+         */
         private Path workingDirectory;
 
         /**
diff --git a/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java b/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java
index 4130ea5f..f11f72e5 100644
--- a/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java
+++ b/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java
@@ -60,7 +60,10 @@ public class ExecuteWatchdog implements TimeoutObserver {
      */
     public static final class Builder implements Supplier<ExecuteWatchdog> {
 
+        /** Thread factory. */
         private ThreadFactory threadFactory;
+
+        /** Timeout duration. */
         private Duration timeout;
 
         /**
diff --git a/src/main/java/org/apache/commons/exec/LogOutputStream.java b/src/main/java/org/apache/commons/exec/LogOutputStream.java
index ad2edf85..0026578a 100644
--- a/src/main/java/org/apache/commons/exec/LogOutputStream.java
+++ b/src/main/java/org/apache/commons/exec/LogOutputStream.java
@@ -52,10 +52,19 @@ public abstract class LogOutputStream extends OutputStream {
     /** The internal buffer. */
     private final ByteArrayOutputStreamX buffer = new ByteArrayOutputStreamX(INTIAL_SIZE);
 
+    /**
+     * Last written char was a CR.
+     */
     private boolean skip;
 
+    /**
+     * Level used to log data written to this stream.
+     */
     private final int level;
 
+    /**
+     * Character Set to use when processing lines.
+     */
     private final Charset charset;
 
     /**
diff --git a/src/main/java/org/apache/commons/exec/OS.java b/src/main/java/org/apache/commons/exec/OS.java
index 9d6a803b..bb158eaf 100644
--- a/src/main/java/org/apache/commons/exec/OS.java
+++ b/src/main/java/org/apache/commons/exec/OS.java
@@ -89,12 +89,25 @@ public final class OS {
      */
     public static final String FAMILY_ZOS = "z/os";
 
+    /**
+     * Apple Darwin string: {@value}
+     */
     private static final String DARWIN = "darwin";
 
+    /**
+     * The OS name.
+     */
     private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ROOT);
+
+    /**
+     * The OS architecture.
+     */
     private static final String OS_ARCH = System.getProperty("os.arch").toLowerCase(Locale.ROOT);
+
+    /**
+     * The OS version.
+     */
     private static final String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.ROOT);
-    private static final String PATH_SEP = File.pathSeparator;
 
     /**
      * Tests whether the OS on which commons-exec is executing matches the given OS architecture.
@@ -280,7 +293,7 @@ public final class OS {
                     isFamily = OS_NAME.contains(FAMILY_NETWARE);
                     break;
                 case FAMILY_DOS:
-                    isFamily = PATH_SEP.equals(";") && !isFamily(FAMILY_NETWARE);
+                    isFamily = File.pathSeparator.equals(";") && !isFamily(FAMILY_NETWARE);
                     break;
                 case FAMILY_MAC:
                     isFamily = OS_NAME.contains(FAMILY_MAC) || OS_NAME.contains(DARWIN);
@@ -289,7 +302,8 @@ public final class OS {
                     isFamily = OS_NAME.contains("nonstop_kernel");
                     break;
                 case FAMILY_UNIX:
-                    isFamily = PATH_SEP.equals(":") && !isFamily(FAMILY_VMS) && (!isFamily(FAMILY_MAC) || OS_NAME.endsWith("x") || OS_NAME.contains(DARWIN));
+                    isFamily = File.pathSeparator.equals(":") && !isFamily(FAMILY_VMS)
+                            && (!isFamily(FAMILY_MAC) || OS_NAME.endsWith("x") || OS_NAME.contains(DARWIN));
                     break;
                 case FAMILY_ZOS:
                     isFamily = OS_NAME.contains(FAMILY_ZOS) || OS_NAME.contains("os/390");
diff --git a/src/main/java/org/apache/commons/exec/PumpStreamHandler.java b/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
index 3bb23dbc..51c2cb86 100644
--- a/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
+++ b/src/main/java/org/apache/commons/exec/PumpStreamHandler.java
@@ -36,20 +36,32 @@ import org.apache.commons.exec.util.DebugUtils;
  */
 public class PumpStreamHandler implements ExecuteStreamHandler {
 
+    /** Three seconds timeout. */
     private static final Duration STOP_TIMEOUT_ADDITION = Duration.ofSeconds(2);
 
+    /**
+     * Output thread.
+     */
     private Thread outputThread;
 
+    /**
+     * Error thread.
+     */
     private Thread errorThread;
 
+    /** Input thread. */
     private Thread inputThread;
 
+    /** Output stream. */
     private final OutputStream outputStream;
 
+    /** Error output stream. */
     private final OutputStream errorOutputStream;
 
+    /** Error input stream. */
     private final InputStream inputStream;
 
+    /** Pumper input stream. */
     private InputStreamPumper inputStreamPumper;
 
     /** The timeout Duration the implementation waits when stopping the pumper threads. */
diff --git a/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java b/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
index ec823e5e..63fd00c1 100644
--- a/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
+++ b/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
@@ -30,6 +30,9 @@ public class ShutdownHookProcessDestroyer implements ProcessDestroyer, Runnable
 
     private final class ProcessDestroyerThread extends Thread {
 
+        /**
+         * Whether to run the ShutdownHookProcessDestroyer.
+         */
         private AtomicBoolean shouldDestroy = new AtomicBoolean(true);
 
         private ProcessDestroyerThread() {
diff --git a/src/main/java/org/apache/commons/exec/Watchdog.java b/src/main/java/org/apache/commons/exec/Watchdog.java
index 9c36f2ae..60ef82b7 100644
--- a/src/main/java/org/apache/commons/exec/Watchdog.java
+++ b/src/main/java/org/apache/commons/exec/Watchdog.java
@@ -39,7 +39,12 @@ public class Watchdog implements Runnable {
      */
     public static final class Builder implements Supplier<Watchdog> {
 
+        /** Thread factory. */
         private ThreadFactory threadFactory;
+
+        /**
+         * Timeout duration.
+         */
         private Duration timeout;
 
         /**
@@ -93,10 +98,19 @@ public class Watchdog implements Runnable {
         return new Builder();
     }
 
+    /**
+     * Observers.
+     */
     private final List<TimeoutObserver> observers = new Vector<>(1);
 
+    /**
+     * Timeout duration.
+     */
     private final long timeoutMillis;
 
+    /**
+     * Whether this is stopped.
+     */
     private boolean stopped;
 
     /**
diff --git a/src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java b/src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java
index 9c297869..8f5e6e20 100644
--- a/src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java
+++ b/src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java
@@ -28,6 +28,9 @@ import java.util.Objects;
  */
 public class EnvironmentUtils {
 
+    /**
+     * Default environment.
+     */
     private static final DefaultProcessingEnvironment ENVIRONMENT;
 
     static {
diff --git a/src/main/java/org/apache/commons/exec/util/StringUtils.java b/src/main/java/org/apache/commons/exec/util/StringUtils.java
index 1016b5ac..90322eca 100644
--- a/src/main/java/org/apache/commons/exec/util/StringUtils.java
+++ b/src/main/java/org/apache/commons/exec/util/StringUtils.java
@@ -33,10 +33,19 @@ import java.util.StringTokenizer;
  */
 public class StringUtils {
 
+    /** Empty array. */
     private static final String[] EMPTY_STRING_ARRAY = {};
+
+    /** Single quote. */
     private static final String SINGLE_QUOTE = "\'";
+
+    /** Double quote. */
     private static final String DOUBLE_QUOTE = "\"";
+
+    /** Forward lash character. */
     private static final char SLASH_CHAR = '/';
+
+    /** Backlash character. */
     private static final char BACKSLASH_CHAR = '\\';
 
     /**


(commons-exec) 01/03: Migrate internal type declaration from class Vector to interface List

Posted by gg...@apache.org.
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

commit a3ce9400df261985398f70c08a4e3501cdd94076
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat May 24 10:03:48 2025 -0400

    Migrate internal type declaration from class Vector to interface List
    
    - Actual type is still Vector for now
---
 src/main/java/org/apache/commons/exec/CommandLine.java             | 4 ++--
 .../java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java | 7 ++++---
 src/main/java/org/apache/commons/exec/Watchdog.java                | 7 ++++---
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/exec/CommandLine.java b/src/main/java/org/apache/commons/exec/CommandLine.java
index 528f03df..9c20e946 100644
--- a/src/main/java/org/apache/commons/exec/CommandLine.java
+++ b/src/main/java/org/apache/commons/exec/CommandLine.java
@@ -23,6 +23,7 @@ import java.io.File;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.StringTokenizer;
@@ -175,7 +176,7 @@ public class CommandLine {
     /**
      * The arguments of the command.
      */
-    private final Vector<Argument> arguments = new Vector<>();
+    private final List<Argument> arguments = new Vector<>();
 
     /**
      * The program to execute.
@@ -201,7 +202,6 @@ public class CommandLine {
         this.executable = other.getExecutable();
         this.isFile = other.isFile();
         this.arguments.addAll(other.arguments);
-
         if (other.getSubstitutionMap() != null) {
             this.substitutionMap = new HashMap<>(other.getSubstitutionMap());
         }
diff --git a/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java b/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
index cc22ed73..ec823e5e 100644
--- a/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
+++ b/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
@@ -19,6 +19,7 @@
 
 package org.apache.commons.exec;
 
+import java.util.List;
 import java.util.Vector;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -48,7 +49,7 @@ public class ShutdownHookProcessDestroyer implements ProcessDestroyer, Runnable
     }
 
     /** The list of currently running processes. */
-    private final Vector<Process> processes = new Vector<>();
+    private final List<Process> processes = new Vector<>();
 
     /** The thread registered at the JVM to execute the shutdown handler. */
     private ProcessDestroyerThread destroyProcessThread;
@@ -83,7 +84,7 @@ public class ShutdownHookProcessDestroyer implements ProcessDestroyer, Runnable
             if (processes.isEmpty()) {
                 addShutdownHook();
             }
-            processes.addElement(process);
+            processes.add(process);
             return processes.contains(process);
         }
     }
@@ -127,7 +128,7 @@ public class ShutdownHookProcessDestroyer implements ProcessDestroyer, Runnable
     @Override
     public boolean remove(final Process process) {
         synchronized (processes) {
-            final boolean processRemoved = processes.removeElement(process);
+            final boolean processRemoved = processes.remove(process);
             if (processRemoved && processes.isEmpty()) {
                 removeShutdownHook();
             }
diff --git a/src/main/java/org/apache/commons/exec/Watchdog.java b/src/main/java/org/apache/commons/exec/Watchdog.java
index af650d41..ac245677 100644
--- a/src/main/java/org/apache/commons/exec/Watchdog.java
+++ b/src/main/java/org/apache/commons/exec/Watchdog.java
@@ -20,6 +20,7 @@
 package org.apache.commons.exec;
 
 import java.time.Duration;
+import java.util.List;
 import java.util.Vector;
 import java.util.concurrent.ThreadFactory;
 import java.util.function.Supplier;
@@ -92,7 +93,7 @@ public class Watchdog implements Runnable {
         return new Builder();
     }
 
-    private final Vector<TimeoutObserver> observers = new Vector<>(1);
+    private final List<TimeoutObserver> observers = new Vector<>(1);
 
     private final long timeoutMillis;
 
@@ -134,7 +135,7 @@ public class Watchdog implements Runnable {
      * @param to a TimeoutObserver to add.
      */
     public void addTimeoutObserver(final TimeoutObserver to) {
-        observers.addElement(to);
+        observers.add(to);
     }
 
     /**
@@ -150,7 +151,7 @@ public class Watchdog implements Runnable {
      * @param to a TimeoutObserver to remove.
      */
     public void removeTimeoutObserver(final TimeoutObserver to) {
-        observers.removeElement(to);
+        observers.remove(to);
     }
 
     @Override


(commons-exec) 02/03: Remove some extra vertical whitespace

Posted by gg...@apache.org.
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

commit afa90ed7acc1b79d6fd160622a4347e1bf754dca
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat May 24 10:05:08 2025 -0400

    Remove some extra vertical whitespace
---
 src/main/java/org/apache/commons/exec/CommandLine.java | 16 ----------------
 src/main/java/org/apache/commons/exec/Watchdog.java    |  1 -
 2 files changed, 17 deletions(-)

diff --git a/src/main/java/org/apache/commons/exec/CommandLine.java b/src/main/java/org/apache/commons/exec/CommandLine.java
index 9c20e946..1a7cbf3d 100644
--- a/src/main/java/org/apache/commons/exec/CommandLine.java
+++ b/src/main/java/org/apache/commons/exec/CommandLine.java
@@ -78,7 +78,6 @@ public class CommandLine {
      * @throws IllegalArgumentException If line is null or all whitespace.
      */
     public static CommandLine parse(final String line, final Map<String, ?> substitutionMap) {
-
         if (line == null) {
             throw new IllegalArgumentException("Command line cannot be null");
         }
@@ -86,13 +85,11 @@ public class CommandLine {
             throw new IllegalArgumentException("Command line cannot be empty");
         }
         final String[] tmp = translateCommandline(line);
-
         final CommandLine cl = new CommandLine(tmp[0]);
         cl.setSubstitutionMap(substitutionMap);
         for (int i = 1; i < tmp.length; i++) {
             cl.addArgument(tmp[i]);
         }
-
         return cl;
     }
 
@@ -107,9 +104,7 @@ public class CommandLine {
             // no command? no string
             return new String[0];
         }
-
         // parse with a simple finite state machine.
-
         final int normal = 0;
         final int inQuote = 1;
         final int inDoubleQuote = 2;
@@ -118,7 +113,6 @@ public class CommandLine {
         final ArrayList<String> list = new ArrayList<>();
         StringBuilder current = new StringBuilder();
         boolean lastTokenHasBeenQuoted = false;
-
         while (tok.hasMoreTokens()) {
             final String nextTok = tok.nextToken();
             switch (state) {
@@ -160,15 +154,12 @@ public class CommandLine {
                 break;
             }
         }
-
         if (lastTokenHasBeenQuoted || current.length() != 0) {
             list.add(current.toString());
         }
-
         if (state == inQuote || state == inDoubleQuote) {
             throw new IllegalArgumentException("Unbalanced quotes in " + toProcess);
         }
-
         final String[] args = new String[list.size()];
         return list.toArray(args);
     }
@@ -259,17 +250,14 @@ public class CommandLine {
      * @return The command line itself.
      */
     public CommandLine addArgument(final String argument, final boolean handleQuoting) {
-
         if (argument == null) {
             return this;
         }
-
         // check if we can really quote the argument - if not throw an
         // IllegalArgumentException
         if (handleQuoting) {
             StringUtils.quoteArgument(argument);
         }
-
         arguments.add(new Argument(argument, handleQuoting));
         return this;
     }
@@ -298,7 +286,6 @@ public class CommandLine {
             final String[] argumentsArray = translateCommandline(addArguments);
             addArguments(argumentsArray, handleQuoting);
         }
-
         return this;
     }
 
@@ -345,17 +332,14 @@ public class CommandLine {
      * @return The quoted arguments.
      */
     public String[] getArguments() {
-
         Argument currArgument;
         String expandedArgument;
         final String[] result = new String[arguments.size()];
-
         for (int i = 0; i < result.length; i++) {
             currArgument = arguments.get(i);
             expandedArgument = expandArgument(currArgument.getValue());
             result[i] = currArgument.isHandleQuoting() ? StringUtils.quoteArgument(expandedArgument) : expandedArgument;
         }
-
         return result;
     }
 
diff --git a/src/main/java/org/apache/commons/exec/Watchdog.java b/src/main/java/org/apache/commons/exec/Watchdog.java
index ac245677..9c36f2ae 100644
--- a/src/main/java/org/apache/commons/exec/Watchdog.java
+++ b/src/main/java/org/apache/commons/exec/Watchdog.java
@@ -171,7 +171,6 @@ public class Watchdog implements Runnable {
                 isWaiting = timeLeftMillis > 0;
             }
         }
-
         // notify the listeners outside of the synchronized block (see EXEC-60)
         if (!isWaiting) {
             fireTimeoutOccured();