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