Repository: maven-surefire Updated Branches: refs/heads/master 3ddcd1f67 -> aee2bb45f
[SUREFIRE-1475] PpidChecker.windows() assumes wmic is on the path Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/aee2bb45 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/aee2bb45 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/aee2bb45 Branch: refs/heads/master Commit: aee2bb45f312d5f1a130bc668e92b342022f101d Parents: 3ddcd1f Author: Tibor17 <tibordig...@apache.org> Authored: Sat Mar 3 06:55:12 2018 +0100 Committer: Tibor17 <tibordig...@apache.org> Committed: Sat Mar 3 06:55:12 2018 +0100 ---------------------------------------------------------------------- .../apache/maven/surefire/booter/PpidChecker.java | 14 +++++++++++++- .../maven/surefire/booter/PpidCheckerTest.java | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/aee2bb45/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 e5d39eb..462eacc 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 @@ -35,6 +35,7 @@ import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.regex.Pattern.compile; import static org.apache.commons.io.IOUtils.closeQuietly; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.SystemUtils.IS_OS_UNIX; import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS; import static org.apache.maven.surefire.booter.ProcessInfo.ERR_PROCESS_INFO; @@ -49,6 +50,10 @@ import static org.apache.maven.surefire.booter.ProcessInfo.INVALID_PROCESS_INFO; final class PpidChecker { private static final String WMIC_CREATION_DATE = "CreationDate"; + private static final String WINDOWS_SYSTEM_ROOT_ENV = "SystemRoot"; + private static final String RELATIVE_PATH_TO_WMIC = "System32\\Wbem"; + private static final String SYSTEM_PATH_TO_WMIC = + "%" + WINDOWS_SYSTEM_ROOT_ENV + "%\\" + RELATIVE_PATH_TO_WMIC + "\\"; private final Queue<Process> destroyableCommands = new ConcurrentLinkedQueue<Process>(); @@ -184,8 +189,9 @@ final class PpidChecker } }; String pid = String.valueOf( pluginPid ); + String wmicPath = hasWmicStandardSystemPath() ? SYSTEM_PATH_TO_WMIC : ""; return reader.execute( "CMD", "/A", "/X", "/C", - "wmic process where (ProcessId=" + pid + ") get " + WMIC_CREATION_DATE + wmicPath + "wmic process where (ProcessId=" + pid + ") get " + WMIC_CREATION_DATE ); } @@ -223,6 +229,12 @@ final class PpidChecker return new File( "/bin/ps" ).canExecute(); } + private static boolean hasWmicStandardSystemPath() + { + String systemRoot = System.getenv( WINDOWS_SYSTEM_ROOT_ENV ); + return isNotBlank( systemRoot ) && new File( systemRoot, RELATIVE_PATH_TO_WMIC + "\\wmic.exe" ).isFile(); + } + static long fromDays( Matcher matcher ) { String s = matcher.group( 3 ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/aee2bb45/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 a58614d..84f0837 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 @@ -21,13 +21,19 @@ package org.apache.maven.surefire.booter; import org.junit.Test; +import java.io.File; import java.lang.management.ManagementFactory; import java.util.regex.Matcher; import static org.apache.commons.lang3.SystemUtils.IS_OS_UNIX; import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS; import static org.fest.assertions.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assume.assumeThat; import static org.junit.Assume.assumeTrue; +import static org.powermock.reflect.Whitebox.invokeMethod; /** * Testing {@link PpidChecker} on a platform. @@ -153,4 +159,16 @@ public class PpidCheckerTest assertThat( PpidChecker.fromMinutes( m ) ).isEqualTo( 300L ); assertThat( PpidChecker.fromSeconds( m ) ).isEqualTo( 3L ); } + + @Test + public void shouldHaveSystemPathToWmicOnWindows() throws Exception + { + assumeTrue( IS_OS_WINDOWS ); + assumeThat( System.getenv( "SystemRoot" ), is( notNullValue() ) ); + assumeThat( System.getenv( "SystemRoot" ), is( not( "" ) ) ); + assumeTrue( new File( System.getenv( "SystemRoot" ), "System32\\Wbem" ).isDirectory() ); + assumeTrue( new File( System.getenv( "SystemRoot" ), "System32\\Wbem\\wmic.exe" ).isFile() ); + assertThat( (Boolean) invokeMethod( PpidChecker.class, "hasWmicStandardSystemPath" ) ).isTrue(); + assertThat( new File( System.getenv( "SystemRoot" ), "System32\\Wbem\\wmic.exe" ) ).isFile(); + } }