@@ -236,8 +236,8 @@ public void formatSource(CharSource input, CharSink output)
236
236
* @param timeoutForAll if true, total timeout is {@code timeout}, else timeout is {@code timeout * fileCount}
237
237
* @return the formatted java source
238
238
*/
239
- public List <String > formatSourceFile (String file , boolean useExecutor , boolean reWrite ,
240
- long timeout , TimeUnit unit , boolean timeoutForAll )
239
+ public List <String > formatSourceFile (String file , boolean useExecutor , ExecutorService executorService ,
240
+ boolean reWrite , long timeout , TimeUnit unit , boolean timeoutForAll )
241
241
throws IOException , FormatterException {
242
242
if (Strings .isNullOrEmpty (file )) {
243
243
return Collections .emptyList ();
@@ -248,6 +248,9 @@ public List<String> formatSourceFile(String file, boolean useExecutor, boolean r
248
248
unit = TimeUnit .SECONDS ;
249
249
timeoutForAll = false ;
250
250
}
251
+ if (executorService == null ) {
252
+ executorService = EXECUTOR_SERVICE ;
253
+ }
251
254
File sourceFile = new File (file );
252
255
if (sourceFile .isFile ()) {
253
256
// this is a file
@@ -262,7 +265,7 @@ public List<String> formatSourceFile(String file, boolean useExecutor, boolean r
262
265
formatted = "" ;
263
266
}
264
267
return ImmutableList .of (formatted ); // do not update the file source.
265
- }, EXECUTOR_SERVICE );
268
+ }, executorService );
266
269
try {
267
270
if (formattedFuture .get (timeout , unit ) == null ) {
268
271
return Collections .emptyList ();
@@ -298,7 +301,7 @@ public List<String> formatSourceFile(String file, boolean useExecutor, boolean r
298
301
formatted = "" ;
299
302
}
300
303
return formatted ;
301
- }, EXECUTOR_SERVICE ));
304
+ }, executorService ));
302
305
}
303
306
// check the status.
304
307
CompletableFuture <List <String >> formattedResultFuture =
0 commit comments