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.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 volatile JdkAttributes jdk;
42
43 public Platform()
44 {
45
46 this( new FutureTask<>( pidJob() ), null );
47 newDaemonThread( pluginPidJob ).start();
48 }
49
50 private Platform( RunnableFuture<Long> pluginPidJob, JdkAttributes jdk )
51 {
52 this.pluginPidJob = pluginPidJob;
53 this.jdk = jdk;
54 }
55
56 public Long getPluginPid()
57 {
58 try
59 {
60 return pluginPidJob.get();
61 }
62 catch ( Exception e )
63 {
64 return null;
65 }
66 }
67
68 public JdkAttributes getJdkExecAttributesForTests()
69 {
70 return jdk;
71 }
72
73 public Platform withJdkExecAttributesForTests( JdkAttributes jdk )
74 {
75 return new Platform( pluginPidJob, jdk );
76 }
77
78 private static Callable<Long> pidJob()
79 {
80 return new Callable<Long>()
81 {
82 @Override
83 public Long call() throws Exception
84 {
85 return SystemUtils.pid();
86 }
87 };
88 }
89 }