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 2022/08/24 15:15:00 UTC

[commons-exec] branch master updated (4e19da2 -> ecf1ea9)

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 4e19da2  Add pmd:cpd-check to Maven default goal
     new aff02be  Use method instead of property
     new 3202a88  Use method reference
     new 344f620  Use lambda
     new ba5b69e  Remove extra parens
     new ad68e0e  No need to nest, format
     new b1dca4c  Use compact array
     new ecf1ea9  Add PMD check to default Maven goal

The 7 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:
 pom.xml                                            |  2 +-
 .../org/apache/commons/exec/DefaultExecutor.java   | 27 +++----
 src/main/java/org/apache/commons/exec/OS.java      |  7 +-
 .../java/org/apache/commons/exec/StreamPumper.java |  2 +-
 .../environment/DefaultProcessingEnvironment.java  |  8 +-
 .../org/apache/commons/exec/util/StringUtils.java  | 90 +++++++++++-----------
 .../apache/commons/exec/DefaultExecutorTest.java   | 16 ++--
 .../exec/environment/EnvironmentUtilsTest.java     |  2 +-
 8 files changed, 67 insertions(+), 87 deletions(-)


[commons-exec] 06/07: Use compact array

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 b1dca4c214d249af7c5a4979a957524c35d98b09
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 24 11:12:20 2022 -0400

    Use compact array
---
 .../java/org/apache/commons/exec/environment/EnvironmentUtilsTest.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilsTest.java b/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilsTest.java
index f666bf5..b0beaa8 100644
--- a/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilsTest.java
+++ b/src/test/java/org/apache/commons/exec/environment/EnvironmentUtilsTest.java
@@ -52,7 +52,7 @@ public class EnvironmentUtilsTest {
         env.put("foo2", "bar2");
         env.put("foo", "bar");
         final String[] envStrings = EnvironmentUtils.toStrings(env);
-        final String[] expected = new String[]{"foo2=bar2", "foo=bar"};
+        final String[] expected = {"foo2=bar2", "foo=bar"};
         // ensure the result does not depend on the hash ordering
         Arrays.sort(expected);
         Arrays.sort(envStrings);


[commons-exec] 03/07: Use lambda

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 344f620b8f04eb8d0aed872095717e4495b453c1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 24 11:00:35 2022 -0400

    Use lambda
---
 .../org/apache/commons/exec/DefaultExecutor.java   | 27 ++++++++--------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/src/main/java/org/apache/commons/exec/DefaultExecutor.java b/src/main/java/org/apache/commons/exec/DefaultExecutor.java
index c55ea03..88c02fd 100644
--- a/src/main/java/org/apache/commons/exec/DefaultExecutor.java
+++ b/src/main/java/org/apache/commons/exec/DefaultExecutor.java
@@ -202,24 +202,17 @@ public class DefaultExecutor implements Executor {
             watchdog.setProcessNotStarted();
         }
 
-        final Runnable runnable = new Runnable()
-        {
-            @Override
-            public void run()
-            {
-                int exitValue = Executor.INVALID_EXITVALUE;
-                try {
-                    exitValue = executeInternal(command, environment, workingDirectory, streamHandler);
-                    handler.onProcessComplete(exitValue);
-                } catch (final ExecuteException e) {
-                    handler.onProcessFailed(e);
-                } catch (final Exception e) {
-                    handler.onProcessFailed(new ExecuteException("Execution failed", exitValue, e));
-                }
+        this.executorThread = createThread(() -> {
+            int exitValue = Executor.INVALID_EXITVALUE;
+            try {
+                exitValue = executeInternal(command, environment, workingDirectory, streamHandler);
+                handler.onProcessComplete(exitValue);
+            } catch (final ExecuteException e) {
+                handler.onProcessFailed(e);
+            } catch (final Exception e) {
+                handler.onProcessFailed(new ExecuteException("Execution failed", exitValue, e));
             }
-        };
-
-        this.executorThread = createThread(runnable, "Exec Default Executor");
+        }, "Exec Default Executor");
         getExecutorThread().start();
     }
 


[commons-exec] 04/07: Remove extra parens

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 ba5b69ebee3f8615e0b73b13166e41a5bbe0a50d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 24 11:07:59 2022 -0400

    Remove extra parens
    
    No need to nest, format
---
 .../org/apache/commons/exec/util/StringUtils.java  | 90 +++++++++++-----------
 1 file changed, 43 insertions(+), 47 deletions(-)

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 46e78e7..9f2afe8 100644
--- a/src/main/java/org/apache/commons/exec/util/StringUtils.java
+++ b/src/main/java/org/apache/commons/exec/util/StringUtils.java
@@ -87,65 +87,61 @@ public class StringUtils {
 
             switch (ch) {
 
-                case '$':
-                    final StringBuilder nameBuf = new StringBuilder();
-                    del = argStr.charAt(cIdx + 1);
-                    if (del == '{') {
-                        cIdx++;
-
-                        for (++cIdx; cIdx < argStr.length(); ++cIdx) {
-                            ch = argStr.charAt(cIdx);
-                            if ((ch != '_') && (ch != '.') && (ch != '-') && (ch != '+') && !Character.isLetterOrDigit(ch)) {
-                                break;
-                            }
-                            nameBuf.append(ch);
+            case '$':
+                final StringBuilder nameBuf = new StringBuilder();
+                del = argStr.charAt(cIdx + 1);
+                if (del == '{') {
+                    cIdx++;
+
+                    for (++cIdx; cIdx < argStr.length(); ++cIdx) {
+                        ch = argStr.charAt(cIdx);
+                        if (ch != '_' && ch != '.' && ch != '-' && ch != '+' && !Character.isLetterOrDigit(ch)) {
+                            break;
                         }
+                        nameBuf.append(ch);
+                    }
 
-                        if (nameBuf.length() >= 0) {
+                    if (nameBuf.length() >= 0) {
 
-                            String value;
-                            final Object temp = vars.get(nameBuf.toString());
+                        String value;
+                        final Object temp = vars.get(nameBuf.toString());
 
-                            if (temp instanceof File) {
-                                // for a file we have to fix the separator chars to allow
-                                // cross-platform compatibility
-                                value = fixFileSeparatorChar(((File) temp).getAbsolutePath());
-                            }
-                            else {
-                                value = temp != null ? temp.toString() : null;
-                            }
+                        if (temp instanceof File) {
+                            // for a file we have to fix the separator chars to allow
+                            // cross-platform compatibility
+                            value = fixFileSeparatorChar(((File) temp).getAbsolutePath());
+                        } else {
+                            value = temp != null ? temp.toString() : null;
+                        }
 
-                            if (value != null) {
-                                argBuf.append(value);
-                            } else {
-                                if (!isLenient) {
-                                    // complain that no variable was found
-                                    throw new RuntimeException("No value found for : " + nameBuf);
-                                }
-                                // just append the unresolved variable declaration
-                                argBuf.append("${").append(nameBuf.toString()).append("}");
+                        if (value != null) {
+                            argBuf.append(value);
+                        } else {
+                            if (!isLenient) {
+                                // complain that no variable was found
+                                throw new RuntimeException("No value found for : " + nameBuf);
                             }
+                            // just append the unresolved variable declaration
+                            argBuf.append("${").append(nameBuf.toString()).append("}");
+                        }
 
-                            del = argStr.charAt(cIdx);
+                        del = argStr.charAt(cIdx);
 
-                            if (del != '}') {
-                                throw new RuntimeException("Delimiter not found for : " + nameBuf);
-                            }
+                        if (del != '}') {
+                            throw new RuntimeException("Delimiter not found for : " + nameBuf);
                         }
-
-                        cIdx++;
-                    }
-                    else {
-                        argBuf.append(ch);
-                        ++cIdx;
                     }
+                } else {
+                    argBuf.append(ch);
+                }
+                cIdx++;
 
-                    break;
+                break;
 
-                default:
-                    argBuf.append(ch);
-                    ++cIdx;
-                    break;
+            default:
+                argBuf.append(ch);
+                ++cIdx;
+                break;
             }
         }
 


[commons-exec] 05/07: No need to nest, format

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 ad68e0e72767469873b94eae3a9edc3389559c14
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 24 11:12:05 2022 -0400

    No need to nest, format
---
 .../org/apache/commons/exec/DefaultExecutorTest.java     | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java b/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
index 5d0402f..b1d581d 100644
--- a/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
+++ b/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
@@ -561,12 +561,11 @@ public class DefaultExecutorTest {
             final String result = baos.toString().trim();
             assertTrue(result, result.indexOf("Finished reading from stdin") > 0);
             assertFalse("exitValue=" + exitValue, exec.isFailure(exitValue));
-        } else if (OS.isFamilyWindows()) {
-            System.err
-                    .println("The code samples to do that in windows look like a joke ... :-( .., no way I'm doing that");
-            System.err.println("The test 'testExecuteWithRedirectedStreams' does not support the following OS : "
-                    + System.getProperty("os.name"));
         } else {
+            if (OS.isFamilyWindows()) {
+                System.err
+                        .println("The code samples to do that in windows look like a joke ... :-( .., no way I'm doing that");
+            }
             System.err.println("The test 'testExecuteWithRedirectedStreams' does not support the following OS : "
                     + System.getProperty("os.name"));
         }
@@ -759,11 +758,8 @@ public class DefaultExecutorTest {
         final StringBuilder contents = new StringBuilder();
         final BufferedReader reader = new BufferedReader(new FileReader(file));
 
-        while ((text = reader.readLine()) != null)
-        {
-            contents.append(text)
-                .append(System.getProperty(
-                    "line.separator"));
+        while ((text = reader.readLine()) != null) {
+            contents.append(text).append(System.getProperty("line.separator"));
         }
         reader.close();
         return contents.toString();


[commons-exec] 01/07: Use method instead of property

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 aff02be38ab2b320d460cde64b3656e4baf0c7e3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 24 10:54:28 2022 -0400

    Use method instead of property
    
    Remove extra parens
---
 src/main/java/org/apache/commons/exec/OS.java | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/exec/OS.java b/src/main/java/org/apache/commons/exec/OS.java
index 466df33..620639d 100644
--- a/src/main/java/org/apache/commons/exec/OS.java
+++ b/src/main/java/org/apache/commons/exec/OS.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.exec;
 
+import java.io.File;
 import java.util.Locale;
 
 /**
@@ -79,7 +80,7 @@ public final class OS {
     private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
     private static final String OS_ARCH = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
     private static final String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.ENGLISH);
-    private static final String PATH_SEP = System.getProperty("path.separator");
+    private static final String PATH_SEP = File.pathSeparator;
 
     /**
      * Default constructor
@@ -208,12 +209,12 @@ public final class OS {
                 boolean isNT = false;
                 if (isWindows) {
                     //there are only four 9x platforms that we look for
-                    is9x = (OS_NAME.contains("95")
+                    is9x = OS_NAME.contains("95")
                             || OS_NAME.contains("98")
                             || OS_NAME.contains("me")
                             //wince isn't really 9x, but crippled enough to
                             //be a muchness. Ant doesn't run on CE, anyway.
-                            || OS_NAME.contains("ce"));
+                            || OS_NAME.contains("ce");
                     isNT = !is9x;
                 }
                 if (family.equals(FAMILY_WINDOWS)) {


[commons-exec] 07/07: Add PMD check to default Maven goal

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 ecf1ea9d58cc9b70bcf20af3d4bf544e1fe67586
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 24 11:14:55 2022 -0400

    Add PMD check to default Maven goal
    
    Use PMD convention to call exception variable "ignored"
---
 pom.xml                                                 | 2 +-
 src/main/java/org/apache/commons/exec/StreamPumper.java | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 456a5f0..a6a5b61 100644
--- a/pom.xml
+++ b/pom.xml
@@ -120,7 +120,7 @@
 
     <build>
         <!-- TODO Add checkstyle:check -->
-        <defaultGoal>clean verify apache-rat:check japicmp:cmp pmd:cpd-check javadoc:javadoc</defaultGoal>     
+        <defaultGoal>clean verify apache-rat:check japicmp:cmp pmd:cpd-check pmd:check javadoc:javadoc</defaultGoal>     
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
diff --git a/src/main/java/org/apache/commons/exec/StreamPumper.java b/src/main/java/org/apache/commons/exec/StreamPumper.java
index 33621cb..ae7e52b 100644
--- a/src/main/java/org/apache/commons/exec/StreamPumper.java
+++ b/src/main/java/org/apache/commons/exec/StreamPumper.java
@@ -107,7 +107,7 @@ public class StreamPumper implements Runnable {
             while ((length = is.read(buf)) > 0) {
                 os.write(buf, 0, length);
             }
-        } catch (final Exception e) {
+        } catch (final Exception ignored) {
             // nothing to do - happens quite often with watchdog
         } finally {
             if (closeWhenExhausted) {


[commons-exec] 02/07: Use method reference

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 3202a8816ae96a21d4840036c39340e6ab00dee8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 24 10:57:13 2022 -0400

    Use method reference
---
 .../commons/exec/environment/DefaultProcessingEnvironment.java    | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java b/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java
index f673112..e718dd6 100644
--- a/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java
+++ b/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java
@@ -19,7 +19,6 @@ package org.apache.commons.exec.environment;
 
 import java.io.BufferedReader;
 import java.io.IOException;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeMap;
@@ -216,12 +215,7 @@ public class DefaultProcessingEnvironment {
      */
     private Map<String, String> createEnvironmentMap() {
         if (OS.isFamilyWindows()) {
-            return new TreeMap<>(new Comparator<String>() {
-                @Override
-                public int compare(final String key0, final String key1) {
-                    return key0.compareToIgnoreCase(key1);
-                }
-            });
+            return new TreeMap<>(String::compareToIgnoreCase);
         }
         return new HashMap<>();
     }