Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import java.io.Serializable;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -188,7 +191,7 @@ private void cancel() {
LOGGER.log(Level.WARNING, null, x);
}
}
}, MoreExecutors.sameThreadExecutor());
}, newExecutorService());
}
} else {
listener().getLogger().println("Cancelling nested steps due to timeout");
Expand All @@ -199,6 +202,30 @@ private void cancel() {
}
}

/**
* Returns an {@link ExecutorService} to be used as a parameter in other methods. It calls
* {@code MoreExecutors#newDirectExecutorService} or falls back to {@code
* MoreExecutors#sameThreadExecutor} for compatibility with older (< 18.0) versions of Guava.
*
* @since TODO
*/
private static ExecutorService newExecutorService() {
try {
try {
// Guava older than 18
Method method = MoreExecutors.class.getMethod("sameThreadExecutor");
return (ExecutorService) method.invoke(null);
} catch (NoSuchMethodException e) {
// TODO Invert this to prefer the newer Guava method once Guava is upgraded in
// Jenkins core.
Method method = MoreExecutors.class.getMethod("newDirectExecutorService");
return (ExecutorService) method.invoke(null);
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

@Override public String getStatus() {
if (killer == null) {
return "killer task nowhere to be found";
Expand Down