@@ -48,7 +48,7 @@ public class PipelineNodeTreeScanner {
48
48
private final boolean declarative ;
49
49
50
50
private static final Logger logger = LoggerFactory .getLogger (PipelineNodeTreeScanner .class );
51
- private final boolean isDebugEnabled = logger .isDebugEnabled ();
51
+ private boolean isDebugEnabled = logger .isDebugEnabled ();
52
52
53
53
public PipelineNodeTreeScanner (@ NonNull WorkflowRun run ) {
54
54
this .run = run ;
@@ -126,7 +126,6 @@ public Map<String, List<FlowNodeWrapper>> getAllSteps() {
126
126
for (String stageId : stageNodeMap .keySet ()) {
127
127
stageNodeStepMap .put (stageId , getStageSteps (stageId ));
128
128
}
129
-
130
129
return stageNodeStepMap ;
131
130
}
132
131
@@ -208,23 +207,16 @@ protected List<FlowNodeWrapper> getNodes() {
208
207
return this .wrappedStageMap ;
209
208
}
210
209
dump ("Remapping stages" );
211
- // Find any root stages (ones without parents) that have steps - we want to return these.
212
- // This should only be FlowNodeStart nodes, but I want to be flexible - if a Stage has steps then the
213
- // step view should display it.
214
- // NOTE: In instances where this isn't the FlowNodeStart, this might add an unexpected FlowNode to the graph
215
- // view.
216
- List <FlowNodeWrapper > rootStagesWithSteps = getStagesWithChildSteps ().stream ()
217
- .filter (s -> s .getFirstParent () == null )
218
- .collect (Collectors .toList ());
219
210
Map <String , FlowNodeWrapper > stageMap = this .wrappedNodeMap .entrySet ().stream ()
220
- .filter (e -> rootStagesWithSteps . contains ( e . getValue ()) || shouldBeInStageMap (e .getValue ()))
211
+ .filter (e -> shouldBeInStageMap (e .getValue ()))
221
212
.collect (Collectors .toMap (e -> e .getKey (), e -> e .getValue ()));
222
213
List <FlowNodeWrapper > nodeList = new ArrayList <FlowNodeWrapper >(stageMap .values ());
223
214
Collections .sort (nodeList , new FlowNodeWrapper .NodeComparator ());
224
215
for (FlowNodeWrapper stage : nodeList ) {
225
216
FlowNodeWrapper firstParent = stage .getFirstParent ();
226
217
// Remap parentage of stages that aren't children of stages (e.g. allocate node
227
218
// step).
219
+ dump ("Stages has %s parents" , stage .getParents ().size ());
228
220
dump ("First parent of stage %s: %s" , stage .getId (), firstParent );
229
221
if (firstParent != null ) {
230
222
dump ("Parent exists in stage map: %s" , stageMap .containsKey (firstParent .getId ()));
@@ -237,24 +229,6 @@ protected List<FlowNodeWrapper> getNodes() {
237
229
return this .wrappedStageMap ;
238
230
}
239
231
240
- /* Filter wrappedNodes to get list of steps.
241
- */
242
- private Map <String , FlowNodeWrapper > getSteps () {
243
- return this .wrappedNodeMap .entrySet ().stream ()
244
- .filter (e -> shouldBeInStepMap (e .getValue ()))
245
- .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
246
- }
247
-
248
- /* Filter wrappedNodes to get list of steps.
249
- */
250
- private List <FlowNodeWrapper > getStagesWithChildSteps () {
251
- return getSteps ().entrySet ().stream ()
252
- .map (e -> e .getValue ().getFirstParent ())
253
- .filter (p -> p != null )
254
- .map (p -> wrappedNodeMap .get (p .getId ()))
255
- .collect (Collectors .toList ());
256
- }
257
-
258
232
private boolean shouldBeInStageMap (FlowNodeWrapper n ) {
259
233
// We also want to drop steps blocks - as the front-end doesn't expect them.
260
234
// For the future: Adding Step Blocks as stages might be a good way to handle them in the
@@ -311,10 +285,13 @@ private boolean isSuperfluousStartNode(FlowNodeWrapper n) {
311
285
}
312
286
313
287
dump ("Remapping steps" );
314
- Map <String , FlowNodeWrapper > stepMap = getSteps ();
288
+ Map <String , FlowNodeWrapper > stepMap = this .wrappedNodeMap .entrySet ().stream ()
289
+ .filter (e -> shouldBeInStepMap (e .getValue ()))
290
+ .collect (Collectors .toMap (e -> e .getKey (), e -> e .getValue ()));
291
+
315
292
Map <String , FlowNodeWrapper > stageMap = this .getStageMapping ();
316
293
List <FlowNodeWrapper > nodeList = new ArrayList <FlowNodeWrapper >(stepMap .values ());
317
- nodeList .sort (new FlowNodeWrapper .NodeComparator ());
294
+ Collections .sort (nodeList , new FlowNodeWrapper .NodeComparator ());
318
295
for (FlowNodeWrapper step : nodeList ) {
319
296
FlowNodeWrapper firstParent = step .getFirstParent ();
320
297
// Remap parentage of steps that aren't children of stages (e.g. are in Step
@@ -344,15 +321,13 @@ private boolean isExceptionStep(FlowNodeWrapper n) {
344
321
* Builds a graph from the list of nodes and relationships given to the class.
345
322
*/
346
323
private void buildGraph () {
347
- List <FlowNode > nodeList = new ArrayList <>(nodeMap .values ());
348
- nodeList .sort (new FlowNodeWrapper .FlowNodeComparator ());
324
+ List <FlowNode > nodeList = new ArrayList <FlowNode >(nodeMap .values ());
325
+ Collections .sort (nodeList , new FlowNodeWrapper .FlowNodeComparator ());
349
326
// If the Pipeline ended with an unhandled exception, then we want to catch the
350
327
// node which threw it.
351
328
BlockEndNode <?> nodeThatThrewException = null ;
352
329
if (!nodeList .isEmpty ()) {
353
- boolean hasStage = nodeList .stream ().anyMatch (PipelineNodeUtil ::isStage );
354
-
355
- nodeThatThrewException = getUnhandledException (nodeList .get (nodeList .size () - 1 ), hasStage );
330
+ nodeThatThrewException = getUnhandledException (nodeList .get (nodeList .size () - 1 ));
356
331
}
357
332
for (FlowNode node : nodeList ) {
358
333
if (nodeThatThrewException == node ) {
@@ -377,15 +352,12 @@ private void buildGraph() {
377
352
* Returns the origin of any unhandled exception for this node, or null if none
378
353
* found.
379
354
*/
380
- private @ CheckForNull BlockEndNode <?> getUnhandledException (@ NonNull FlowNode node , boolean hasStage ) {
355
+ private @ CheckForNull BlockEndNode <?> getUnhandledException (@ NonNull FlowNode node ) {
381
356
// Check for an unhandled exception.
382
357
ErrorAction errorAction = node .getAction (ErrorAction .class );
383
- if (errorAction != null ) {
384
- // If this is a Jenkins failure exception, then we don't need to add a new node
385
- // - it will come from an existing step if there is a stage for the step to be part of.
386
- if (hasStage && PipelineNodeUtil .isJenkinsFailureException (errorAction .getError ())) {
387
- return null ;
388
- }
358
+ // If this is a Jenkins failure exception, then we don't need to add a new node
359
+ // - it will come from an existing step.
360
+ if (errorAction != null && !PipelineNodeUtil .isJenkinsFailureException (errorAction .getError ())) {
389
361
dump (
390
362
"getUnhandledException => Found unhandled exception: %s" ,
391
363
errorAction .getError ().getMessage ());
@@ -400,7 +372,7 @@ private void buildGraph() {
400
372
/*
401
373
* This is a corner case for trivial graphs - ones that only have one action. In
402
374
* this case the error can be thrown by a the FlowStartNode, which would mean a
403
- * single node needs to be a stage and a step. Rather than adding a fake node
375
+ * single nodes needs to be a stage and a step. Rather than adding a fake node
404
376
* to the graph, we use the end node that we were given to act as the step
405
377
* - this might need additional logic when getting the log for the exception.
406
378
*/
0 commit comments