View Javadoc
1   package org.apache.maven.surefire.api.booter;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * Events sent back to the plugin process.
30   *
31   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
32   * @since 3.0.0-M4
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 }