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 static org.apache.maven.surefire.util.internal.ObjectUtils.requireNonNull;
23 import static org.apache.maven.surefire.util.internal.StringUtils.isBlank;
24 import static org.apache.maven.surefire.booter.MasterProcessCommand.RUN_CLASS;
25 import static org.apache.maven.surefire.booter.MasterProcessCommand.SHUTDOWN;
26 import static org.apache.maven.surefire.booter.Shutdown.DEFAULT;
27
28
29
30
31
32
33
34 public final class Command
35 {
36 public static final Command TEST_SET_FINISHED = new Command( MasterProcessCommand.TEST_SET_FINISHED );
37 public static final Command SKIP_SINCE_NEXT_TEST = new Command( MasterProcessCommand.SKIP_SINCE_NEXT_TEST );
38 public static final Command NOOP = new Command( MasterProcessCommand.NOOP );
39 public static final Command BYE_ACK = new Command( MasterProcessCommand.BYE_ACK );
40
41 private final MasterProcessCommand command;
42 private final String data;
43
44 public Command( MasterProcessCommand command, String data )
45 {
46 this.command = requireNonNull( command );
47 this.data = data;
48 }
49
50 public static Command toShutdown( Shutdown shutdownType )
51 {
52 return new Command( SHUTDOWN, shutdownType.name() );
53 }
54
55 public static Command toRunClass( String runClass )
56 {
57 return new Command( RUN_CLASS, runClass );
58 }
59
60 public Command( MasterProcessCommand command )
61 {
62 this( command, null );
63 }
64
65 public MasterProcessCommand getCommandType()
66 {
67 return command;
68 }
69
70 public String getData()
71 {
72 return data;
73 }
74
75
76
77
78
79 public Shutdown toShutdownData()
80 {
81 if ( !isType( SHUTDOWN ) )
82 {
83 throw new IllegalStateException( "expected MasterProcessCommand.SHUTDOWN" );
84 }
85 return isBlank( data ) ? DEFAULT : Shutdown.valueOf( data );
86 }
87
88 public boolean isType( MasterProcessCommand command )
89 {
90 return command == this.command;
91 }
92
93 @Override
94 public boolean equals( Object o )
95 {
96 if ( this == o )
97 {
98 return true;
99 }
100
101 if ( o == null || getClass() != o.getClass() )
102 {
103 return false;
104 }
105
106 Command arg = (Command) o;
107
108 return command == arg.command && ( data == null ? arg.data == null : data.equals( arg.data ) );
109 }
110
111 @Override
112 public int hashCode()
113 {
114 int result = command.hashCode();
115 result = 31 * result + ( data != null ? data.hashCode() : 0 );
116 return result;
117 }
118 }