1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.surefire.booterclient;
20
21 import java.util.concurrent.Callable;
22 import java.util.concurrent.FutureTask;
23 import java.util.concurrent.RunnableFuture;
24
25 import org.apache.maven.plugin.surefire.JdkAttributes;
26 import org.apache.maven.surefire.booter.SystemUtils;
27
28 import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThread;
29
30
31
32
33
34
35
36 public final class Platform {
37 private final RunnableFuture<Long> pluginPidJob;
38
39 private final JdkAttributes jdk;
40
41 private volatile boolean shutdown;
42
43 public Platform() {
44
45 this(new FutureTask<>(pidJob()), null);
46 newDaemonThread(pluginPidJob).start();
47 }
48
49 private Platform(RunnableFuture<Long> pluginPidJob, JdkAttributes jdk) {
50 this.pluginPidJob = pluginPidJob;
51 this.jdk = jdk;
52 }
53
54 public boolean isShutdown() {
55 return shutdown;
56 }
57
58 public void setShutdownState() {
59 this.shutdown = true;
60 }
61
62 public void clearShutdownState() {
63 this.shutdown = false;
64 }
65
66 public Long getPluginPid() {
67 try {
68 return pluginPidJob.get();
69 } catch (Exception e) {
70 return null;
71 }
72 }
73
74 public JdkAttributes getJdkExecAttributesForTests() {
75 return jdk;
76 }
77
78 public Platform withJdkExecAttributesForTests(JdkAttributes jdk) {
79 return new Platform(pluginPidJob, jdk);
80 }
81
82 private static Callable<Long> pidJob() {
83 return new Callable<Long>() {
84 @Override
85 public Long call() throws Exception {
86 return SystemUtils.pid();
87 }
88 };
89 }
90 }