Skip to content

Commit 4d64a9c

Browse files
committed
use pattern variables
1 parent 325444a commit 4d64a9c

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

src/main/java/io/jenkins/plugins/agent_build_history/AgentBuildHistory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ public static AgentExecution loadSingleExecution(String jobName, int buildNumber
165165
LOGGER.finer("Loading run " + run.getFullDisplayName());
166166
AgentExecution execution = new AgentExecution(run);
167167

168-
if (run instanceof AbstractBuild) {
169-
Node node = ((AbstractBuild<?, ?>) run).getBuiltOn();
168+
if (run instanceof AbstractBuild<?, ?> build) {
169+
Node node = build.getBuiltOn();
170170
if (node != null) {
171171
LOGGER.finer("Loading AbstractBuild on node: " + node.getNodeName());
172172
return execution;
@@ -212,13 +212,12 @@ private static void load() {
212212
runList.forEach(run -> {
213213
LOGGER.finer("Loading run " + run.getFullDisplayName());
214214

215-
if (run instanceof AbstractBuild) {
216-
Node node = ((AbstractBuild<?, ?>) run).getBuiltOn();
215+
if (run instanceof AbstractBuild<?, ?> build) {
216+
Node node = build.getBuiltOn();
217217
if (node != null) {
218218
BuildHistoryFileManager.addRunToNodeIndex(node.getNodeName(), run, AgentBuildHistoryConfig.get().getStorageDir());
219219
}
220-
} else if (run instanceof WorkflowRun) {
221-
WorkflowRun wfr = (WorkflowRun) run;
220+
} else if (run instanceof WorkflowRun wfr) {
222221
FlowExecution flowExecution = wfr.getExecution();
223222
if (flowExecution != null) {
224223
for (FlowNode flowNode : new DepthFirstScanner().allNodes(flowExecution)) {

src/main/java/io/jenkins/plugins/agent_build_history/AgentBuildHistoryListeners.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ public static class HistoryItemListener extends ItemListener {
4141

4242
@Override
4343
public void onDeleted(Item item) {
44-
if (item instanceof Job) {
45-
Job<?, ?> job = (Job<?, ?>) item;
46-
String jobName = job.getFullName();
44+
if (item instanceof Job<?, ?>) {
45+
String jobName = item.getFullName();
4746
BuildHistoryFileManager.deleteJobSerialization(jobName, AgentBuildHistoryConfig.get().getStorageDir());
4847
}
4948
}
@@ -84,18 +83,15 @@ public static class AgentBuildHistoryExecutorListener implements ExecutorListene
8483
public void taskStarted(Executor executor, Queue.Task task) {
8584
Queue.Executable executable = executor.getCurrentExecutable();
8685
Computer c = executor.getOwner();
87-
if (executable instanceof AbstractBuild) {
88-
Run<?, ?> run = (Run<?, ?>) executable;
86+
if (executable instanceof Run<?, ?> run) {
8987
LOGGER.log(Level.FINER, () -> "Starting Job: " + run.getFullDisplayName() + " on " + c.getName());
9088
AgentBuildHistory.startJobExecution(c, run);
91-
} else if (task instanceof ExecutorStepExecution.PlaceholderTask) {
92-
ExecutorStepExecution.PlaceholderTask pht = (ExecutorStepExecution.PlaceholderTask) task;
89+
} else if (task instanceof ExecutorStepExecution.PlaceholderTask pht) {
9390
executable = task.getOwnerExecutable();
9491
try {
9592
FlowNode node = pht.getNode();
96-
if (node != null && executable instanceof WorkflowRun) {
97-
Run<?, ?> run = (Run<?, ?>) executable;
98-
AgentBuildHistory.startFlowNodeExecution(c, (WorkflowRun) run, node);
93+
if (node != null && executable instanceof WorkflowRun run) {
94+
AgentBuildHistory.startFlowNodeExecution(c, run, node);
9995
LOGGER.log(Level.FINER, () -> "Starting part of pipeline: " + run.getFullDisplayName()
10096
+ " Node id: " + node.getId() + " on " + c.getName());
10197
}

src/main/java/io/jenkins/plugins/agent_build_history/AgentExecution.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ private FlowNode getEndNode() {
115115
if (execution != null) {
116116
try {
117117
FlowNode node = execution.getNode(nodeId);
118-
if (node instanceof BlockStartNode) {
119-
return ((BlockStartNode) node).getEndNode();
118+
if (node instanceof BlockStartNode bsn) {
119+
return bsn.getEndNode();
120120
}
121121
} catch (IOException e) {
122122
return null;
@@ -180,18 +180,17 @@ public Status getFlowNodeStatus() {
180180
}
181181
if (status == null) {
182182
Run<?, ?> run = AgentExecution.this.getRun();
183-
if (!(run instanceof WorkflowRun)) {
183+
if (!(run instanceof WorkflowRun wfr)) {
184184
return Status.UNKNOWN;
185185
}
186-
WorkflowRun wfr = (WorkflowRun) run;
187186
FlowExecution flowExecution = wfr.getExecution();
188187
if (flowExecution == null) {
189188
return Status.UNKNOWN;
190189
}
191190
try {
192191
FlowNode node = flowExecution.getNode(nodeId);
193-
if (node instanceof BlockStartNode) {
194-
BlockEndNode<?> endNode = ((BlockStartNode) node).getEndNode();
192+
if (node instanceof BlockStartNode bsn) {
193+
BlockEndNode<?> endNode = bsn.getEndNode();
195194
if (endNode != null) {
196195
ErrorAction errorAction = endNode.getError();
197196
status = errorAction != null ? Status.FAILURE : Status.SUCCESS;

0 commit comments

Comments
 (0)