Skip to content

Commit

Permalink
Suggesting ControllerToAgentFileCallable (#7678)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored Nov 12, 2024
1 parent 787c9c8 commit bcb46a7
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ To fix code like this:
int stuff(FilePath workspace, final String arg) throws IOException, InterruptedException {
return workspace.act(new MasterToSlaveFileCallable<Integer>() {
@Override
Integer invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
public Integer invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
return countThings(f, arg);
}
});
Expand All @@ -43,6 +43,21 @@ int stuff(FilePath workspace, final String arg) throws IOException, InterruptedE

just use a "convert anonymous to member" refactoring in your IDE, or manually:

[source,java]
----
private record ThingCounter(String arg) implements ControllerToAgentFileCallable<Integer> {
@Override
public Integer invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
return countThings(f, arg);
}
}
int stuff(FilePath workspace, String arg) throws IOException, InterruptedException {
return workspace.act(new ThingCounter(arg));
}
----

or prior to Jenkins 2.485:

[source,java]
----
private static final class ThingCounter extends MasterToSlaveFileCallable<Integer> {
Expand All @@ -51,7 +66,7 @@ private static final class ThingCounter extends MasterToSlaveFileCallable<Intege
this.arg = arg;
}
@Override
Integer invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
public Integer invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
return countThings(f, arg);
}
}
Expand Down

0 comments on commit bcb46a7

Please sign in to comment.