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