1 package org.apache.maven.surefire.api.booter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.annotation.Nonnull;
23 import java.util.Map;
24 import java.util.concurrent.ConcurrentHashMap;
25
26 import static java.util.Collections.unmodifiableMap;
27
28
29
30
31
32
33
34 public enum ForkedProcessEventType
35 {
36 BOOTERCODE_SYSPROPS( "sys-prop" ),
37
38 BOOTERCODE_TESTSET_STARTING( "testset-starting" ),
39 BOOTERCODE_TESTSET_COMPLETED( "testset-completed" ),
40 BOOTERCODE_TEST_STARTING( "test-starting" ),
41 BOOTERCODE_TEST_SUCCEEDED( "test-succeeded" ),
42 BOOTERCODE_TEST_FAILED( "test-failed" ),
43 BOOTERCODE_TEST_SKIPPED( "test-skipped" ),
44 BOOTERCODE_TEST_ERROR( "test-error" ),
45 BOOTERCODE_TEST_ASSUMPTIONFAILURE( "test-assumption-failure" ),
46
47 BOOTERCODE_STDOUT( "std-out-stream" ),
48 BOOTERCODE_STDOUT_NEW_LINE( "std-out-stream-new-line" ),
49 BOOTERCODE_STDERR( "std-err-stream" ),
50 BOOTERCODE_STDERR_NEW_LINE( "std-err-stream-new-line" ),
51
52 BOOTERCODE_CONSOLE_INFO( "console-info-log" ),
53 BOOTERCODE_CONSOLE_DEBUG( "console-debug-log" ),
54 BOOTERCODE_CONSOLE_WARNING( "console-warning-log" ),
55 BOOTERCODE_CONSOLE_ERROR( "console-error-log" ),
56
57 BOOTERCODE_BYE( "bye" ),
58 BOOTERCODE_STOP_ON_NEXT_TEST( "stop-on-next-test" ),
59 BOOTERCODE_NEXT_TEST( "next-test" ),
60
61 BOOTERCODE_JVM_EXIT_ERROR( "jvm-exit-error" );
62
63 public static final String MAGIC_NUMBER = "maven-surefire-event";
64
65 private static final Map<String, ForkedProcessEventType> EVENTS = events();
66
67 private static Map<String, ForkedProcessEventType> events()
68 {
69 Map<String, ForkedProcessEventType> events = new ConcurrentHashMap<>();
70 for ( ForkedProcessEventType event : values() )
71 {
72 events.put( event.getOpcode(), event );
73 }
74 return unmodifiableMap( events );
75 }
76
77 private final String opcode;
78
79 ForkedProcessEventType( String opcode )
80 {
81 this.opcode = opcode;
82 }
83
84 public String getOpcode()
85 {
86 return opcode;
87 }
88
89 public boolean isSysPropCategory()
90 {
91 return this == BOOTERCODE_SYSPROPS;
92 }
93
94 public boolean isTestCategory()
95 {
96 return this == BOOTERCODE_TESTSET_STARTING
97 || this == BOOTERCODE_TESTSET_COMPLETED
98 || this == BOOTERCODE_TEST_STARTING
99 || this == BOOTERCODE_TEST_SUCCEEDED
100 || this == BOOTERCODE_TEST_FAILED
101 || this == BOOTERCODE_TEST_SKIPPED
102 || this == BOOTERCODE_TEST_ERROR
103 || this == BOOTERCODE_TEST_ASSUMPTIONFAILURE;
104 }
105
106 public boolean isStandardStreamCategory()
107 {
108 return this == BOOTERCODE_STDOUT || this == BOOTERCODE_STDOUT_NEW_LINE
109 || this == BOOTERCODE_STDERR || this == BOOTERCODE_STDERR_NEW_LINE;
110 }
111
112 public boolean isConsoleCategory()
113 {
114 return this == BOOTERCODE_CONSOLE_INFO
115 || this == BOOTERCODE_CONSOLE_DEBUG
116 || this == BOOTERCODE_CONSOLE_WARNING;
117 }
118
119 public boolean isConsoleErrorCategory()
120 {
121 return this == BOOTERCODE_CONSOLE_ERROR;
122 }
123
124 public boolean isControlCategory()
125 {
126 return this == BOOTERCODE_BYE || this == BOOTERCODE_STOP_ON_NEXT_TEST || this == BOOTERCODE_NEXT_TEST;
127 }
128
129 public boolean isJvmExitError()
130 {
131 return this == BOOTERCODE_JVM_EXIT_ERROR;
132 }
133
134 public static ForkedProcessEventType byOpcode( @Nonnull String opcode )
135 {
136 return EVENTS.get( opcode );
137 }
138 }