Skip to content

Commit ea0f260

Browse files
committed
Support for java.util.function.Function
1 parent a885a76 commit ea0f260

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/main/java/org/jenkinsci/plugins/workflow/steps/StepExecution.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jenkinsci.plugins.workflow.steps;
22

3-
import com.google.common.base.Function;
43
import com.google.common.util.concurrent.Futures;
54
import com.google.common.util.concurrent.ListenableFuture;
65
import java.io.Serializable;
@@ -10,6 +9,7 @@
109
import java.util.concurrent.Callable;
1110
import java.util.concurrent.Future;
1211
import java.util.concurrent.TimeUnit;
12+
import java.util.function.Function;
1313
import java.util.logging.Level;
1414
import java.util.logging.Logger;
1515
import edu.umd.cs.findbugs.annotations.CheckForNull;
@@ -181,6 +181,14 @@ public static ListenableFuture<?> applyAll(Function<StepExecution,Void> f) {
181181
return Futures.allAsList(futures);
182182
}
183183

184+
/**
185+
* @deprecated use {@link #applyAll(Function)}
186+
*/
187+
@Deprecated
188+
public static ListenableFuture<?> applyAll(com.google.common.base.Function<StepExecution, Void> f) {
189+
return applyAll(fromGuava(f));
190+
}
191+
184192
/**
185193
* Applies only to the specific subtypes.
186194
*/
@@ -195,5 +203,18 @@ public Void apply(StepExecution e) {
195203
});
196204
}
197205

206+
/**
207+
* @deprecated use {@link #applyAll(Class, Function)}
208+
*/
209+
@Deprecated
210+
public static <T extends StepExecution> ListenableFuture<?> applyAll(
211+
final Class<T> type, final com.google.common.base.Function<T, Void> f) {
212+
return applyAll(type, fromGuava(f));
213+
}
214+
215+
private static <T, R> Function<T, R> fromGuava(com.google.common.base.Function<T, R> func) {
216+
return func::apply;
217+
}
218+
198219
private static final long serialVersionUID = 1L;
199220
}

src/main/java/org/jenkinsci/plugins/workflow/steps/StepExecutionIterator.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.jenkinsci.plugins.workflow.steps;
22

3-
import com.google.common.base.Function;
43
import com.google.common.util.concurrent.ListenableFuture;
54
import hudson.ExtensionList;
65
import hudson.ExtensionPoint;
6+
import hudson.Util;
7+
import java.util.function.Function;
78

89
/**
910
* Enumerates active running {@link StepExecution}s in the system.
@@ -21,7 +22,31 @@ public abstract class StepExecutionIterator implements ExtensionPoint {
2122
* @return
2223
* {@link ListenableFuture} to signal the completion of the application.
2324
*/
24-
public abstract ListenableFuture<?> apply(Function<StepExecution,Void> f);
25+
public /* abstract */ ListenableFuture<?> apply(Function<StepExecution, Void> f) {
26+
return Util.ifOverridden(
27+
() -> apply(toGuava(f)),
28+
StepExecutionIterator.class,
29+
getClass(),
30+
"apply",
31+
com.google.common.base.Function.class);
32+
}
33+
34+
/**
35+
* @deprecated use {@link #apply(Function)}
36+
*/
37+
@Deprecated
38+
public /* abstract */ ListenableFuture<?> apply(com.google.common.base.Function<StepExecution, Void> f) {
39+
return Util.ifOverridden(
40+
() -> apply(fromGuava(f)), StepExecutionIterator.class, getClass(), "apply", Function.class);
41+
}
42+
43+
private static <T, R> Function<T, R> fromGuava(com.google.common.base.Function<T, R> func) {
44+
return func::apply;
45+
}
46+
47+
private static <T, R> com.google.common.base.Function<T, R> toGuava(Function<T, R> func) {
48+
return func::apply;
49+
}
2550

2651
public static ExtensionList<StepExecutionIterator> all() {
2752
return ExtensionList.lookup(StepExecutionIterator.class);

0 commit comments

Comments
 (0)