View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.api.booter;
20  
21  import static java.nio.charset.StandardCharsets.US_ASCII;
22  
23  /**
24   * Events sent back to the plugin process.
25   *
26   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
27   * @since 3.0.0-M4
28   */
29  @SuppressWarnings("checkstyle:linelength")
30  public enum ForkedProcessEventType {
31      /**
32       * This is the opcode "sys-prop". The frame is composed of segments and the separator characters ':'
33       * <pre>
34       * :maven-surefire-event:sys-prop:RunMode:0x0000000100000000:5:UTF-8:0xFFFFFFFF:key:0xFFFFFFFF:value:
35       * </pre>
36       * The constructor with one argument:
37       * <ul>
38       *     <li>the opcode is "sys-prop"
39       * </ul>
40       */
41      BOOTERCODE_SYSPROPS("sys-prop"),
42  
43      /**
44       * This is the opcode "testset-starting". The frame is composed of segments and the separator characters ':'
45       * <pre>
46       * :maven-surefire-event:testset-starting:RunMode:0x0000000100000000:5:UTF-8:0xFFFFFFFF:SourceName:0xFFFFFFFF:SourceText:0xFFFFFFFF:Name:0xFFFFFFFF:NameText:0xFFFFFFFF:Group:0xFFFFFFFF:Message:ElapsedTime (binary int):0xFFFFFFFF:LocalizedMessage:0xFFFFFFFF:SmartTrimmedStackTrace:0xFFFFFFFF:toStackTrace( stw, trimStackTraces ):
47       * </pre>
48       * The constructor with one argument:
49       * <ul>
50       *     <li>the opcode is "testset-starting"
51       * </ul>
52       */
53      BOOTERCODE_TESTSET_STARTING("testset-starting"),
54  
55      /**
56       * This is the opcode "testset-completed". The frame is composed of segments and the separator characters ':'
57       * <pre>
58       * :maven-surefire-event:testset-completed:RunMode:0x0000000100000000:5:UTF-8:0xFFFFFFFF:SourceName:0xFFFFFFFF:SourceText:0xFFFFFFFF:Name:0xFFFFFFFF:NameText:0xFFFFFFFF:Group:0xFFFFFFFF:Message:ElapsedTime (binary int):0xFFFFFFFF:LocalizedMessage:0xFFFFFFFF:SmartTrimmedStackTrace:0xFFFFFFFF:toStackTrace( stw, trimStackTraces ):
59       * </pre>
60       * The constructor with one argument:
61       * <ul>
62       *     <li>the opcode is "testset-completed"
63       * </ul>
64       */
65      BOOTERCODE_TESTSET_COMPLETED("testset-completed"),
66  
67      /**
68       * This is the opcode "test-starting". The frame is composed of segments and the separator characters ':'
69       * <pre>
70       * :maven-surefire-event:test-starting:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:SourceName:0xFFFFFFFF:SourceText:0xFFFFFFFF:Name:0xFFFFFFFF:NameText:0xFFFFFFFF:Group:0xFFFFFFFF:Message:ElapsedTime (binary int):0xFFFFFFFF:LocalizedMessage:0xFFFFFFFF:SmartTrimmedStackTrace:0xFFFFFFFF:toStackTrace( stw, trimStackTraces ):
71       * </pre>
72       * The constructor with one argument:
73       * <ul>
74       *     <li>the opcode is "test-starting"
75       * </ul>
76       */
77      BOOTERCODE_TEST_STARTING("test-starting"),
78  
79      /**
80       * This is the opcode "test-succeeded". The frame is composed of segments and the separator characters ':'
81       * <pre>
82       * :maven-surefire-event:test-succeeded:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:SourceName:0xFFFFFFFF:SourceText:0xFFFFFFFF:Name:0xFFFFFFFF:NameText:0xFFFFFFFF:Group:0xFFFFFFFF:Message:ElapsedTime (binary int):0xFFFFFFFF:LocalizedMessage:0xFFFFFFFF:SmartTrimmedStackTrace:0xFFFFFFFF:toStackTrace( stw, trimStackTraces ):
83       * </pre>
84       * The constructor with one argument:
85       * <ul>
86       *     <li>the opcode is "test-succeeded"
87       * </ul>
88       */
89      BOOTERCODE_TEST_SUCCEEDED("test-succeeded"),
90  
91      /**
92       * This is the opcode "test-failed". The frame is composed of segments and the separator characters ':'
93       * <pre>
94       * :maven-surefire-event:test-failed:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:SourceName:0xFFFFFFFF:SourceText:0xFFFFFFFF:Name:0xFFFFFFFF:NameText:0xFFFFFFFF:Group:0xFFFFFFFF:Message:ElapsedTime (binary int):0xFFFFFFFF:LocalizedMessage:0xFFFFFFFF:SmartTrimmedStackTrace:0xFFFFFFFF:toStackTrace( stw, trimStackTraces ):
95       * </pre>
96       * The constructor with one argument:
97       * <ul>
98       *     <li>the opcode is "test-failed"
99       * </ul>
100      */
101     BOOTERCODE_TEST_FAILED("test-failed"),
102 
103     /**
104      * This is the opcode "test-skipped". The frame is composed of segments and the separator characters ':'
105      * <pre>
106      * :maven-surefire-event:test-skipped:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:SourceName:0xFFFFFFFF:SourceText:0xFFFFFFFF:Name:0xFFFFFFFF:NameText:0xFFFFFFFF:Group:0xFFFFFFFF:Message:ElapsedTime (binary int):0xFFFFFFFF:LocalizedMessage:0xFFFFFFFF:SmartTrimmedStackTrace:0xFFFFFFFF:toStackTrace( stw, trimStackTraces ):
107      * </pre>
108      * The constructor with one argument:
109      * <ul>
110      *     <li>the opcode is "test-skipped"
111      * </ul>
112      */
113     BOOTERCODE_TEST_SKIPPED("test-skipped"),
114 
115     /**
116      * This is the opcode "test-error". The frame is composed of segments and the separator characters ':'
117      * <pre>
118      * :maven-surefire-event:test-error:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:SourceName:0xFFFFFFFF:SourceText:0xFFFFFFFF:Name:0xFFFFFFFF:NameText:0xFFFFFFFF:Group:0xFFFFFFFF:Message:ElapsedTime (binary int):0xFFFFFFFF:LocalizedMessage:0xFFFFFFFF:SmartTrimmedStackTrace:0xFFFFFFFF:toStackTrace( stw, trimStackTraces ):
119      * </pre>
120      * The constructor with one argument:
121      * <ul>
122      *     <li>the opcode is "test-error"
123      * </ul>
124      */
125     BOOTERCODE_TEST_ERROR("test-error"),
126 
127     /**
128      * This is the opcode "test-assumption-failure". The frame is composed of segments and the separator characters ':'
129      * <pre>
130      * :maven-surefire-event:test-assumption-failure:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:SourceName:0xFFFFFFFF:SourceText:0xFFFFFFFF:Name:0xFFFFFFFF:NameText:0xFFFFFFFF:Group:0xFFFFFFFF:Message:ElapsedTime (binary int):0xFFFFFFFF:LocalizedMessage:0xFFFFFFFF:SmartTrimmedStackTrace:0xFFFFFFFF:toStackTrace( stw, trimStackTraces ):
131      * </pre>
132      * The constructor with one argument:
133      * <ul>
134      *     <li>the opcode is "test-assumption-failure"
135      * </ul>
136      */
137     BOOTERCODE_TEST_ASSUMPTIONFAILURE("test-assumption-failure"),
138 
139     /**
140      * This is the opcode "std-out-stream". The frame is composed of segments and the separator characters ':'
141      * <pre>
142      * :maven-surefire-event:std-out-stream:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:line:
143      * </pre>
144      * The constructor with one argument:
145      * <ul>
146      *     <li>the opcode is "std-out-stream"
147      * </ul>
148      */
149     BOOTERCODE_STDOUT("std-out-stream"),
150 
151     /**
152      * This is the opcode "std-out-stream-new-line". The frame is composed of segments and the separator characters ':'
153      * <pre>
154      * :maven-surefire-event:std-out-stream-new-line:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:line:
155      * </pre>
156      * The constructor with one argument:
157      * <ul>
158      *     <li>the opcode is "std-out-stream-new-line"
159      * </ul>
160      */
161     BOOTERCODE_STDOUT_NEW_LINE("std-out-stream-new-line"),
162 
163     /**
164      * This is the opcode "std-err-stream". The frame is composed of segments and the separator characters ':'
165      * <pre>
166      * :maven-surefire-event:std-err-stream:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:line:
167      * </pre>
168      * The constructor with one argument:
169      * <ul>
170      *     <li>the opcode is "std-err-stream"
171      * </ul>
172      */
173     BOOTERCODE_STDERR("std-err-stream"),
174 
175     /**
176      * This is the opcode "std-err-stream-new-line". The frame is composed of segments and the separator characters ':'
177      * <pre>
178      * :maven-surefire-event:std-err-stream-new-line:RunMode:0x0000000100000001:5:UTF-8:0xFFFFFFFF:line:
179      * </pre>
180      * The constructor with one argument:
181      * <ul>
182      *     <li>the opcode is "std-err-stream-new-line"
183      * </ul>
184      */
185     BOOTERCODE_STDERR_NEW_LINE("std-err-stream-new-line"),
186 
187     /**
188      * This is the opcode "console-info-log". The frame is composed of segments and the separator characters ':'
189      * <pre>
190      * :maven-surefire-event:console-info-log:RunMode:5:UTF-8:0xFFFFFFFF:line:
191      * </pre>
192      * The constructor with one argument:
193      * <ul>
194      *     <li>the opcode is "console-info-log"
195      * </ul>
196      */
197     BOOTERCODE_CONSOLE_INFO("console-info-log"),
198 
199     /**
200      * This is the opcode "console-debug-log". The frame is composed of segments and the separator characters ':'
201      * <pre>
202      * :maven-surefire-event:console-debug-log:RunMode:5:UTF-8:0xFFFFFFFF:line:
203      * </pre>
204      * The constructor with one argument:
205      * <ul>
206      *     <li>the opcode is "console-debug-log"
207      * </ul>
208      */
209     BOOTERCODE_CONSOLE_DEBUG("console-debug-log"),
210 
211     /**
212      * This is the opcode "console-warning-log". The frame is composed of segments and the separator characters ':'
213      * <pre>
214      * :maven-surefire-event:console-warning-log:RunMode:5:UTF-8:0xFFFFFFFF:line:
215      * </pre>
216      * The constructor with one argument:
217      * <ul>
218      *     <li>the opcode is "console-warning-log"
219      * </ul>
220      */
221     BOOTERCODE_CONSOLE_WARNING("console-warning-log"),
222 
223     /**
224      * This is the opcode "console-error-log". The frame is composed of segments and the separator characters ':'
225      * <pre>
226      * :maven-surefire-event:console-error-log:RunMode:5:UTF-8:0xFFFFFFFF:line:
227      * </pre>
228      * The constructor with one argument:
229      * <ul>
230      *     <li>the opcode is "console-error-log"
231      * </ul>
232      */
233     BOOTERCODE_CONSOLE_ERROR("console-error-log"),
234 
235     /**
236      * This is the opcode "bye". The frame is composed of segments and the separator characters ':'
237      * <pre>
238      * :maven-surefire-event:bye:
239      * </pre>
240      * The constructor with one argument:
241      * <ul>
242      *     <li>the opcode is "bye"
243      * </ul>
244      */
245     BOOTERCODE_BYE("bye"),
246 
247     /**
248      * This is the opcode "stop-on-next-test". The frame is composed of segments and the separator characters ':'
249      * <pre>
250      * :maven-surefire-event:stop-on-next-test:
251      * </pre>
252      * The constructor with one argument:
253      * <ul>
254      *     <li>the opcode is "stop-on-next-test"
255      * </ul>
256      */
257     BOOTERCODE_STOP_ON_NEXT_TEST("stop-on-next-test"),
258 
259     /**
260      * This is the opcode "next-test". The frame is composed of segments and the separator characters ':'
261      * <pre>
262      * :maven-surefire-event:next-test:
263      * </pre>
264      * The constructor with one argument:
265      * <ul>
266      *     <li>the opcode is "next-test"
267      * </ul>
268      */
269     BOOTERCODE_NEXT_TEST("next-test"),
270 
271     /**
272      * This is the opcode "jvm-exit-error". The frame is composed of segments and the separator characters ':'
273      * <pre>
274      * :maven-surefire-event:jvm-exit-error:
275      * </pre>
276      * The constructor with one argument:
277      * <ul>
278      *     <li>the opcode is "jvm-exit-error"
279      * </ul>
280      */
281     BOOTERCODE_JVM_EXIT_ERROR("jvm-exit-error");
282 
283     private final String opcode;
284     private final byte[] opcodeBinary;
285 
286     ForkedProcessEventType(String opcode) {
287         this.opcode = opcode;
288         opcodeBinary = opcode.getBytes(US_ASCII);
289     }
290 
291     public String getOpcode() {
292         return opcode;
293     }
294 
295     public byte[] getOpcodeBinary() {
296         return opcodeBinary;
297     }
298 
299     public boolean isSysPropCategory() {
300         return this == BOOTERCODE_SYSPROPS;
301     }
302 
303     public boolean isTestCategory() {
304         return this == BOOTERCODE_TESTSET_STARTING
305                 || this == BOOTERCODE_TESTSET_COMPLETED
306                 || this == BOOTERCODE_TEST_STARTING
307                 || this == BOOTERCODE_TEST_SUCCEEDED
308                 || this == BOOTERCODE_TEST_FAILED
309                 || this == BOOTERCODE_TEST_SKIPPED
310                 || this == BOOTERCODE_TEST_ERROR
311                 || this == BOOTERCODE_TEST_ASSUMPTIONFAILURE;
312     }
313 
314     public boolean isStandardStreamCategory() {
315         return this == BOOTERCODE_STDOUT
316                 || this == BOOTERCODE_STDOUT_NEW_LINE
317                 || this == BOOTERCODE_STDERR
318                 || this == BOOTERCODE_STDERR_NEW_LINE;
319     }
320 
321     public boolean isConsoleCategory() {
322         return this == BOOTERCODE_CONSOLE_INFO
323                 || this == BOOTERCODE_CONSOLE_DEBUG
324                 || this == BOOTERCODE_CONSOLE_WARNING;
325     }
326 
327     public boolean isConsoleErrorCategory() {
328         return this == BOOTERCODE_CONSOLE_ERROR;
329     }
330 
331     public boolean isControlCategory() {
332         return this == BOOTERCODE_BYE || this == BOOTERCODE_STOP_ON_NEXT_TEST || this == BOOTERCODE_NEXT_TEST;
333     }
334 
335     public boolean isJvmExitError() {
336         return this == BOOTERCODE_JVM_EXIT_ERROR;
337     }
338 }