13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- package com .diffplug .spotless .changelog . gradle ;
16
+ package com .diffplug .spotless .changelog ;
17
17
18
18
import static java .util .Objects .requireNonNull ;
19
19
34
34
import java .util .concurrent .Future ;
35
35
import java .util .concurrent .TimeUnit ;
36
36
import java .util .function .BiConsumer ;
37
- import javax .annotation .Nonnull ;
38
- import javax .annotation .Nullable ;
37
+ import pl .tlinkowski .annotation .basic .NullOr ;
39
38
40
39
/**
41
40
* Shelling out to a process is harder than it ought to be in Java.
@@ -82,7 +81,7 @@ private static boolean machineIsWin() {
82
81
}
83
82
84
83
/** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */
85
- public Result shellWinUnix (@ Nullable File cwd , @ Nullable Map <String , String > environment , String cmdWin , String cmdUnix ) throws IOException , InterruptedException {
84
+ public Result shellWinUnix (@ NullOr File cwd , @ NullOr Map <String , String > environment , String cmdWin , String cmdUnix ) throws IOException , InterruptedException {
86
85
List <String > args ;
87
86
if (machineIsWin ()) {
88
87
args = Arrays .asList ("cmd" , "/c" , cmdWin );
@@ -98,7 +97,7 @@ public Result exec(String... args) throws IOException, InterruptedException {
98
97
}
99
98
100
99
/** Creates a process with the given arguments, the given byte array is written to stdin immediately. */
101
- public Result exec (@ Nullable byte [] stdin , String ... args ) throws IOException , InterruptedException {
100
+ public Result exec (@ NullOr byte [] stdin , String ... args ) throws IOException , InterruptedException {
102
101
return exec (stdin , Arrays .asList (args ));
103
102
}
104
103
@@ -108,12 +107,12 @@ public Result exec(List<String> args) throws IOException, InterruptedException {
108
107
}
109
108
110
109
/** Creates a process with the given arguments, the given byte array is written to stdin immediately. */
111
- public Result exec (@ Nullable byte [] stdin , List <String > args ) throws IOException , InterruptedException {
110
+ public Result exec (@ NullOr byte [] stdin , List <String > args ) throws IOException , InterruptedException {
112
111
return exec (null , null , stdin , args );
113
112
}
114
113
115
114
/** Creates a process with the given arguments, the given byte array is written to stdin immediately. */
116
- public Result exec (@ Nullable File cwd , @ Nullable Map <String , String > environment , @ Nullable byte [] stdin , List <String > args ) throws IOException , InterruptedException {
115
+ public Result exec (@ NullOr File cwd , @ NullOr Map <String , String > environment , @ NullOr byte [] stdin , List <String > args ) throws IOException , InterruptedException {
117
116
LongRunningProcess process = start (cwd , environment , stdin , args );
118
117
try {
119
118
// wait for the process to finish
@@ -130,7 +129,7 @@ public Result exec(@Nullable File cwd, @Nullable Map<String, String> environment
130
129
* <br>
131
130
* Delegates to {@link #start(File, Map, byte[], boolean, List)} with {@code false} for {@code redirectErrorStream}.
132
131
*/
133
- public LongRunningProcess start (@ Nullable File cwd , @ Nullable Map <String , String > environment , @ Nullable byte [] stdin , List <String > args ) throws IOException {
132
+ public LongRunningProcess start (@ NullOr File cwd , @ NullOr Map <String , String > environment , @ NullOr byte [] stdin , List <String > args ) throws IOException {
134
133
return start (cwd , environment , stdin , false , args );
135
134
}
136
135
@@ -142,7 +141,7 @@ public LongRunningProcess start(@Nullable File cwd, @Nullable Map<String, String
142
141
* To dispose this {@code ProcessRunner} instance, either call {@link #close()} or {@link LongRunningProcess#close()}. After
143
142
* {@link #close()} or {@link LongRunningProcess#close()} has been called, this {@code ProcessRunner} instance must not be used anymore.
144
143
*/
145
- public LongRunningProcess start (@ Nullable File cwd , @ Nullable Map <String , String > environment , @ Nullable byte [] stdin , boolean redirectErrorStream , List <String > args ) throws IOException {
144
+ public LongRunningProcess start (@ NullOr File cwd , @ NullOr Map <String , String > environment , @ NullOr byte [] stdin , boolean redirectErrorStream , List <String > args ) throws IOException {
146
145
checkState ();
147
146
ProcessBuilder builder = new ProcessBuilder (args );
148
147
if (cwd != null ) {
@@ -203,7 +202,7 @@ public static class Result {
203
202
private final int exitCode ;
204
203
private final byte [] stdOut , stdErr ;
205
204
206
- public Result (@ Nonnull List <String > args , int exitCode , @ Nonnull byte [] stdOut , @ Nullable byte [] stdErr ) {
205
+ public Result (List <String > args , int exitCode , byte [] stdOut , @ NullOr byte [] stdErr ) {
207
206
this .args = args ;
208
207
this .exitCode = exitCode ;
209
208
this .stdOut = stdOut ;
@@ -295,7 +294,7 @@ public class LongRunningProcess extends Process implements AutoCloseable {
295
294
private final Future <byte []> outputFut ;
296
295
private final Future <byte []> errorFut ;
297
296
298
- public LongRunningProcess (@ Nonnull Process delegate , @ Nonnull List <String > args , @ Nonnull Future <byte []> outputFut , @ Nullable Future <byte []> errorFut ) {
297
+ public LongRunningProcess (Process delegate , List <String > args , Future <byte []> outputFut , @ NullOr Future <byte []> errorFut ) {
299
298
this .delegate = requireNonNull (delegate );
300
299
this .args = args ;
301
300
this .outputFut = outputFut ;
0 commit comments