Skip to content

Commit 4ced57c

Browse files
committed
Revert "Replace runing external process and parsing output with simple Proces…"
This reverts commit 0b19014.
1 parent 8496d9a commit 4ced57c

13 files changed

Lines changed: 452 additions & 851 deletions

File tree

maven-surefire-common/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
<dependency>
173173
<groupId>commons-io</groupId>
174174
<artifactId>commons-io</artifactId>
175+
<version>2.21.0</version>
175176
<scope>test</scope>
176177
</dependency>
177178
</dependencies>

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/Platform.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/**
3131
* Loads platform specifics.
32-
* TODO simplify or remove when Java 8 support is dropped
32+
*
3333
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
3434
* @since 2.20.1
3535
*/
@@ -80,6 +80,11 @@ public Platform withJdkExecAttributesForTests(JdkAttributes jdk) {
8080
}
8181

8282
private static Callable<Long> pidJob() {
83-
return SystemUtils::pid;
83+
return new Callable<Long>() {
84+
@Override
85+
public Long call() throws Exception {
86+
return SystemUtils.pid();
87+
}
88+
};
8489
}
8590
}

maven-surefire-plugin/src/site/apt/examples/shutdown.apt.vm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,9 @@ Shutdown of Forked JVM
5555

5656
[]
5757

58-
If Java9 is available, the start time of the process is determined by <<< ProcessHandle.current().info().startInstant() >>>.
59-
6058
On Unix like systems the process' uptime is determined by native command <<< (/usr)/bin/ps -o etime= -p [PID] >>>.
6159

62-
On Windows the start time is determined using <<< powershell -command "... Get-CimInstance Win32_Process ..." >>>.
63-
64-
[]
60+
On Windows the start time is determined using <<< wmic process where (ProcessId=[PID]) get CreationDate >>>
6561
in the forked JVM.
6662

6763

surefire-booter/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@
9191
<artifactId>powermock-api-mockito2</artifactId>
9292
<scope>test</scope>
9393
</dependency>
94-
<dependency>
95-
<groupId>commons-io</groupId>
96-
<artifactId>commons-io</artifactId>
97-
<scope>test</scope>
98-
</dependency>
9994
</dependencies>
10095

10196
<build>

surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private void closeForkChannel() {
215215
}
216216

217217
private PingScheduler listenToShutdownCommands(String ppid) {
218-
ProcessChecker ppidChecker = ProcessChecker.of(ppid);
218+
PpidChecker ppidChecker = ppid == null ? null : new PpidChecker(ppid);
219219
commandReader.addShutdownListener(createExitHandler(ppidChecker));
220220
AtomicBoolean pingDone = new AtomicBoolean(true);
221221
commandReader.addNoopListener(createPingHandler(pingDone));
@@ -280,7 +280,7 @@ public void update(Command command) {
280280
};
281281
}
282282

283-
private CommandListener createExitHandler(final ProcessChecker ppidChecker) {
283+
private CommandListener createExitHandler(final PpidChecker ppidChecker) {
284284
return new CommandListener() {
285285
@Override
286286
public void update(Command command) {
@@ -325,7 +325,7 @@ public void update(Command command) {
325325
};
326326
}
327327

328-
private Runnable createPingJob(final AtomicBoolean pingDone, final ProcessChecker pluginProcessChecker) {
328+
private Runnable createPingJob(final AtomicBoolean pingDone, final PpidChecker pluginProcessChecker) {
329329
return new Runnable() {
330330
@Override
331331
public void run() {
@@ -515,7 +515,7 @@ private static void run(ForkedBooter booter, String[] args) {
515515
}
516516
}
517517

518-
private static boolean canUseNewPingMechanism(ProcessChecker pluginProcessChecker) {
518+
private static boolean canUseNewPingMechanism(PpidChecker pluginProcessChecker) {
519519
return pluginProcessChecker != null && pluginProcessChecker.canUse();
520520
}
521521

@@ -553,12 +553,12 @@ private static boolean isDebugging() {
553553
private static class PingScheduler {
554554
private final ScheduledExecutorService pingScheduler;
555555
private final ScheduledExecutorService processCheckerScheduler;
556-
private final ProcessChecker processChecker;
556+
private final PpidChecker processChecker;
557557

558558
PingScheduler(
559559
ScheduledExecutorService pingScheduler,
560560
ScheduledExecutorService processCheckerScheduler,
561-
ProcessChecker processChecker) {
561+
PpidChecker processChecker) {
562562
this.pingScheduler = pingScheduler;
563563
this.processCheckerScheduler = processCheckerScheduler;
564564
this.processChecker = processChecker;

surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,11 @@
5757

5858
/**
5959
* Recognizes PID of Plugin process and determines lifetime.
60-
* <p>
61-
* This implementation uses native commands ({@code ps} on Unix, {@code powershell} on Windows)
62-
* to check the parent process status. On Java 9+, consider using {@code ProcessHandleChecker}
63-
* instead, which uses the Java {@code ProcessHandle} API and doesn't require spawning external processes.
6460
*
6561
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
6662
* @since 2.20.1
67-
* @see ProcessChecker
68-
* @deprecated Use {@code ProcessHandleChecker} via {@link ProcessChecker#of(String)} instead
6963
*/
70-
@Deprecated
71-
final class PpidChecker implements ProcessChecker {
64+
final class PpidChecker {
7265
private static final long MINUTES_TO_MILLIS = 60L * 1000L;
7366
// 25 chars https://superuser.com/questions/937380/get-creation-time-of-file-in-milliseconds/937401#937401
7467
private static final int WMIC_CREATION_DATE_VALUE_LENGTH = 25;
@@ -102,8 +95,7 @@ final class PpidChecker implements ProcessChecker {
10295
this.ppid = ppid;
10396
}
10497

105-
@Override
106-
public boolean canUse() {
98+
boolean canUse() {
10799
if (isStopped()) {
108100
return false;
109101
}
@@ -119,8 +111,7 @@ public boolean canUse() {
119111
* or this object has been {@link #destroyActiveCommands() destroyed}
120112
* @throws NullPointerException if extracted e-time is null
121113
*/
122-
@Override
123-
public boolean isProcessAlive() {
114+
boolean isProcessAlive() {
124115
if (!canUse()) {
125116
throw new IllegalStateException("irrelevant to call isProcessAlive()");
126117
}
@@ -235,16 +226,14 @@ ProcessInfo consumeLine(String line, ProcessInfo previousProcessInfo) throws Exc
235226
return reader.execute(psPath + "powershell", "-NoProfile", "-NonInteractive", "-Command", psCommand);
236227
}
237228

238-
@Override
239-
public void destroyActiveCommands() {
229+
void destroyActiveCommands() {
240230
stopped = true;
241231
for (Process p = destroyableCommands.poll(); p != null; p = destroyableCommands.poll()) {
242232
p.destroy();
243233
}
244234
}
245235

246-
@Override
247-
public boolean isStopped() {
236+
boolean isStopped() {
248237
return stopped;
249238
}
250239

@@ -336,16 +325,10 @@ private static SimpleDateFormat createWindowsCreationDateFormat() {
336325
return formatter;
337326
}
338327

339-
@Override
340328
public void stop() {
341329
stopped = true;
342330
}
343331

344-
@Override
345-
public ProcessInfo processInfo() {
346-
return parentProcessInfo;
347-
}
348-
349332
/**
350333
* Reads standard output from {@link Process}.
351334
* <br>

surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProcessChecker.java

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)