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 org.apache.maven.surefire.api.stream.AbstractStreamDecoder.Segment;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import static java.nio.charset.StandardCharsets.US_ASCII;
28 import static java.util.Objects.requireNonNull;
29
30
31
32
33
34
35
36 public enum MasterProcessCommand
37 {
38 RUN_CLASS( "run-testclass", String.class ),
39 TEST_SET_FINISHED( "testset-finished", Void.class ),
40 SKIP_SINCE_NEXT_TEST( "skip-since-next-test", Void.class ),
41 SHUTDOWN( "shutdown", String.class ),
42
43
44 NOOP( "noop", Void.class ),
45 BYE_ACK( "bye-ack", Void.class );
46
47
48 public static final Map<Segment, MasterProcessCommand> COMMAND_TYPES = segmentsToCmds();
49
50 private final String opcode;
51 private final byte[] opcodeBinary;
52 private final Class<?> dataType;
53
54 MasterProcessCommand( String opcode, Class<?> dataType )
55 {
56 this.opcode = requireNonNull( opcode, "value cannot be null" );
57 opcodeBinary = opcode.getBytes( US_ASCII );
58 this.dataType = requireNonNull( dataType, "dataType cannot be null" );
59 }
60
61 public byte[] getOpcodeBinary()
62 {
63 return opcodeBinary;
64 }
65
66 public int getOpcodeLength()
67 {
68 return opcodeBinary.length;
69 }
70
71 public Class<?> getDataType()
72 {
73 return dataType;
74 }
75
76 public boolean hasDataType()
77 {
78 return dataType != Void.class;
79 }
80
81 @Override
82 public String toString()
83 {
84 return opcode;
85 }
86
87 private static Map<Segment, MasterProcessCommand> segmentsToCmds()
88 {
89 Map<Segment, MasterProcessCommand> commands = new HashMap<>();
90 for ( MasterProcessCommand command : MasterProcessCommand.values() )
91 {
92 byte[] array = command.toString().getBytes( US_ASCII );
93 commands.put( new Segment( array, 0, array.length ), command );
94 }
95 return commands;
96 }
97 }