1 package org.apache.maven.surefire.booter;
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.surefire.providerapi.SurefireProvider;
23 import org.apache.maven.surefire.report.ReporterConfiguration;
24
25 import java.util.Timer;
26 import java.util.TimerTask;
27
28
29
30
31
32
33
34 class ForkTimeout
35 {
36
37 private final Timer timer;
38
39
40 ForkTimeout( int timeOutInMs, ReporterConfiguration reporterConfiguration, SurefireProvider surefireProvider )
41 {
42 SurefireTimeoutMonitor timeoutTask = new SurefireTimeoutMonitor( reporterConfiguration, surefireProvider );
43 timer = new Timer( "Surefire fork timeout timer" );
44 timer.schedule( timeoutTask, timeOutInMs );
45 }
46
47 public void close()
48 {
49 timer.cancel();
50 }
51
52 private static class SurefireTimeoutMonitor
53 extends TimerTask
54 {
55 private final ReporterConfiguration reporterConfiguration;
56 private final SurefireProvider surefireProvider;
57
58
59 public SurefireTimeoutMonitor( ReporterConfiguration reporterConfiguration, SurefireProvider surefireProvider )
60 {
61 this.reporterConfiguration = reporterConfiguration;
62 this.surefireProvider = surefireProvider;
63 }
64
65 public void run()
66 {
67 reporterConfiguration.setTimedOut( true );
68 surefireProvider.cancel();
69 }
70 }
71
72 }