Class LinearBlockHoppingScanner
java.lang.Object
org.jenkinsci.plugins.workflow.graphanalysis.AbstractFlowScanner
org.jenkinsci.plugins.workflow.graphanalysis.LinearScanner
org.jenkinsci.plugins.workflow.graphanalysis.LinearBlockHoppingScanner
Extension of
LinearScanner
that skips nested blocks at the current level, useful for finding enclosing blocks.
ONLY use this with nodes inside the flow graph, never the last node of a completed flow (it will jump over the whole flow).
This is useful where you only care about FlowNode
s that precede this one or are part of an enclosing scope (within a Block).
Specifically:
- Where a
BlockEndNode
is encountered, the scanner will jump to theBlockStartNode
and go to its first parent. - The only case where you visit branches of a parallel block is if you begin inside it.
Specific use cases:
- Finding out the executor workspace used to run a FlowNode
- Finding the start of the parallel block enclosing the current node
- Locating the label applying to a given FlowNode (if any) if using labelled blocks
- Author:
- Sam Van Oort
-
Field Summary
Fields inherited from class org.jenkinsci.plugins.workflow.graphanalysis.AbstractFlowScanner
MAX_LIST_CHECK_SIZE, myBlackList, myCurrent, myNext
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected FlowNode
jumpBlockScan
(FlowNode node, Collection<FlowNode> blacklistNodes) Keeps jumping over blocks until we hit the first node preceding a blockprotected FlowNode
next
(FlowNode current, Collection<FlowNode> blackList) Actual meat of the iteration, get the next node to visit, using and updating state as neededprotected void
setHeads
(Collection<FlowNode> heads) Set up to begin flow scanning using the filteredHeads as starting points This method makes several assumptions: -AbstractFlowScanner.reset()
has already been invoked to reset state - filteredHeads has already had any points inAbstractFlowScanner.myBlackList
removed - none of the filteredHeads are nullboolean
setup
(Collection<FlowNode> heads, Collection<FlowNode> blackList) Set up for iteration/analysis on a graph of nodes, initializing the internal state Includes null-checking on arguments to allow directly calling with unchecked inputs (simplifies use).Methods inherited from class org.jenkinsci.plugins.workflow.graphanalysis.LinearScanner
filteredNodes, filteredNodes, findFirstMatch, findFirstMatch, findFirstMatch, reset, setup, visitAll, visitAll
Methods inherited from class org.jenkinsci.plugins.workflow.graphanalysis.AbstractFlowScanner
allNodes, allNodes, convertToFastCheckable, filter, filteredNodes, filteredNodes, findFirstMatch, hasNext, iterator, next, remove, setup, setup
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
LinearBlockHoppingScanner
public LinearBlockHoppingScanner()
-
-
Method Details
-
setup
public boolean setup(@CheckForNull Collection<FlowNode> heads, @CheckForNull Collection<FlowNode> blackList) Description copied from class:LinearScanner
Set up for iteration/analysis on a graph of nodes, initializing the internal state Includes null-checking on arguments to allow directly calling with unchecked inputs (simplifies use).- Overrides:
setup
in classLinearScanner
- Parameters:
heads
- The head nodes we start walking from (the most recently executed nodes, i.e. FlowExecution.getCurrentHeads()blackList
- Nodes that we cannot visit or walk past (useful to limit scanning to only nodes after a specific point)- Returns:
- True if we can have nodes to work with, otherwise false
-
setHeads
Description copied from class:LinearScanner
Set up to begin flow scanning using the filteredHeads as starting points This method makes several assumptions: -AbstractFlowScanner.reset()
has already been invoked to reset state - filteredHeads has already had any points inAbstractFlowScanner.myBlackList
removed - none of the filteredHeads are null- Overrides:
setHeads
in classLinearScanner
- Parameters:
heads
- Head nodes that have been filtered against denyList. Do not pass multiple heads.
-
jumpBlockScan
@CheckForNull protected FlowNode jumpBlockScan(@CheckForNull FlowNode node, @NonNull Collection<FlowNode> blacklistNodes) Keeps jumping over blocks until we hit the first node preceding a block -
next
Description copied from class:AbstractFlowScanner
Actual meat of the iteration, get the next node to visit, using and updating state as needed- Overrides:
next
in classLinearScanner
- Parameters:
current
- Current node to use in generating next valueblackList
- Nodes that are not eligible for visiting- Returns:
- Next node to visit, or null if we've exhausted the node list
-