36
36
import hudson .util .LogTaskListener ;
37
37
import hudson .util .NamingThreadFactory ;
38
38
import java .io .IOException ;
39
- import java .io .PrintStream ;
40
39
import java .nio .charset .Charset ;
41
40
import java .util .Set ;
42
41
import java .util .concurrent .ScheduledFuture ;
@@ -196,7 +195,7 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
196
195
LOGGER .log (Level .FINE , node + " is evidently offline now" , x );
197
196
ws = null ;
198
197
if (!printedCannotContactMessage ) {
199
- logger ().println ("Cannot contact " + node + ": " + x );
198
+ listener (). getLogger ().println ("Cannot contact " + node + ": " + x );
200
199
printedCannotContactMessage = true ;
201
200
}
202
201
return null ;
@@ -207,7 +206,7 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
207
206
return ws ;
208
207
}
209
208
210
- private @ Nonnull PrintStream logger () {
209
+ private @ Nonnull TaskListener listener () {
211
210
TaskListener l ;
212
211
StepContext context = getContext ();
213
212
try {
@@ -223,7 +222,7 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
223
222
l = new LogTaskListener (LOGGER , Level .FINE );
224
223
recurrencePeriod = 0 ;
225
224
}
226
- return l . getLogger () ;
225
+ return l ;
227
226
}
228
227
229
228
private @ Nonnull Launcher launcher () throws IOException , InterruptedException {
@@ -238,21 +237,21 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
238
237
@ Override public void stop (final Throwable cause ) throws Exception {
239
238
FilePath workspace = getWorkspace ();
240
239
if (workspace != null ) {
241
- logger ().println ("Sending interrupt signal to process" );
240
+ listener (). getLogger ().println ("Sending interrupt signal to process" );
242
241
LOGGER .log (Level .FINE , "stopping process" , cause );
243
242
stopTask = Timer .get ().schedule (new Runnable () {
244
243
@ Override public void run () {
245
244
stopTask = null ;
246
245
if (recurrencePeriod > 0 ) {
247
246
recurrencePeriod = 0 ;
248
- logger ().println ("After 10s process did not stop" );
247
+ listener (). getLogger ().println ("After 10s process did not stop" );
249
248
getContext ().onFailure (cause );
250
249
}
251
250
}
252
251
}, 10 , TimeUnit .SECONDS );
253
252
controller .stop (workspace , launcher ());
254
253
} else {
255
- logger ().println ("Could not connect to " + node + " to send interrupt signal to process" );
254
+ listener (). getLogger ().println ("Could not connect to " + node + " to send interrupt signal to process" );
256
255
recurrencePeriod = 0 ;
257
256
super .stop (cause );
258
257
}
@@ -312,25 +311,26 @@ private void check() {
312
311
if (workspace == null ) {
313
312
return ; // slave not yet ready, wait for another day
314
313
}
314
+ TaskListener listener = listener ();
315
315
try (Timeout timeout = Timeout .limit (10 , TimeUnit .SECONDS )) {
316
- if (controller .writeLog (workspace , logger ())) {
316
+ if (controller .writeLog (workspace , listener . getLogger ())) {
317
317
getContext ().saveState ();
318
318
recurrencePeriod = MIN_RECURRENCE_PERIOD ; // got output, maybe we will get more soon
319
319
} else {
320
320
recurrencePeriod = Math .min ((long ) (recurrencePeriod * RECURRENCE_PERIOD_BACKOFF ), MAX_RECURRENCE_PERIOD );
321
321
}
322
- Integer exitCode = controller .exitStatus (workspace , launcher ());
322
+ Integer exitCode = controller .exitStatus (workspace , launcher (), listener );
323
323
if (exitCode == null ) {
324
324
LOGGER .log (Level .FINE , "still running in {0} on {1}" , new Object [] {remote , node });
325
325
} else {
326
- if (controller .writeLog (workspace , logger ())) {
326
+ if (controller .writeLog (workspace , listener . getLogger ())) {
327
327
LOGGER .log (Level .FINE , "last-minute output in {0} on {1}" , new Object [] {remote , node });
328
328
}
329
329
if (returnStatus || exitCode == 0 ) {
330
330
getContext ().onSuccess (returnStatus ? exitCode : returnStdout ? new String (controller .getOutput (workspace , launcher ()), encoding ) : null );
331
331
} else {
332
332
if (returnStdout ) {
333
- logger ().write (controller .getOutput (workspace , launcher ())); // diagnostic
333
+ listener . getLogger ().write (controller .getOutput (workspace , launcher ())); // diagnostic
334
334
}
335
335
getContext ().onFailure (new AbortException ("script returned exit code " + exitCode ));
336
336
}
@@ -341,7 +341,7 @@ private void check() {
341
341
LOGGER .log (Level .FINE , "could not check " + workspace , x );
342
342
ws = null ;
343
343
if (!printedCannotContactMessage ) {
344
- logger ().println ("Cannot contact " + node + ": " + x );
344
+ listener . getLogger ().println ("Cannot contact " + node + ": " + x );
345
345
printedCannotContactMessage = true ;
346
346
}
347
347
}
0 commit comments