Repository: maven-surefire Updated Branches: refs/heads/master 5aed84309 -> 1c707717f
[SUREFIRE-1422] Forking fails on Linux if /bin/ps isn't available Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/1c707717 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/1c707717 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/1c707717 Branch: refs/heads/master Commit: 1c707717f87c2179fb7a2f650217f70b0edd13e7 Parents: 5aed843 Author: Tibor17 <[email protected]> Authored: Sun Oct 1 23:16:04 2017 +0200 Committer: Tibor17 <[email protected]> Committed: Tue Oct 3 08:25:37 2017 +0200 ---------------------------------------------------------------------- .../maven/surefire/booter/PpidChecker.java | 20 ++++++++++++++++++-- .../maven/surefire/booter/PpidCheckerTest.java | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1c707717/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java index 7c27584..c78fd43 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java @@ -65,12 +65,13 @@ final class PpidChecker PpidChecker( long pluginPid ) { this.pluginPid = pluginPid; + //todo WARN logger (after new logger is finished) that (IS_OS_UNIX && canExecuteUnixPs()) is false } boolean canUse() { return pluginProcessInfo == null - ? IS_OS_WINDOWS || IS_OS_UNIX + ? IS_OS_WINDOWS || IS_OS_UNIX && canExecuteUnixPs() : pluginProcessInfo.isValid() && !pluginProcessInfo.isError(); } @@ -203,7 +204,22 @@ final class PpidChecker static String unixPathToPS() { - return new File( "/usr/bin/ps" ).canExecute() ? "/usr/bin/ps" : "/bin/ps"; + return canExecuteLocalUnixPs() ? "/usr/bin/ps" : "/bin/ps"; + } + + static boolean canExecuteUnixPs() + { + return canExecuteLocalUnixPs() || canExecuteStandardUnixPs(); + } + + private static boolean canExecuteLocalUnixPs() + { + return new File( "/usr/bin/ps" ).canExecute(); + } + + private static boolean canExecuteStandardUnixPs() + { + return new File( "/bin/ps" ).canExecute(); } static long fromDays( Matcher matcher ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1c707717/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java index b0153ac..103f841 100644 --- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java +++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java @@ -68,6 +68,10 @@ public class PpidCheckerTest { assumeTrue( IS_OS_UNIX ); + assertThat( PpidChecker.canExecuteUnixPs() ) + .as( "Surefire should be tested on real box OS, e.g. Ubuntu or FreeBSD." ) + .isTrue(); + long expectedPid = Long.parseLong( ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim() ); PpidChecker checker = new PpidChecker( expectedPid );
