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 FlowNodes that precede this one or are part of an enclosing scope (within a Block).
Specifically:
- Where a
BlockEndNodeis encountered, the scanner will jump to theBlockStartNodeand 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected FlowNodejumpBlockScan(FlowNode node, Collection<FlowNode> blacklistNodes) Keeps jumping over blocks until we hit the first node preceding a blockprotected FlowNodenext(FlowNode current, Collection<FlowNode> blackList) Actual meat of the iteration, get the next node to visit, using and updating state as neededprotected voidsetHeads(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.myBlackListremoved - none of the filteredHeads are nullbooleansetup(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, visitAllMethods inherited from class org.jenkinsci.plugins.workflow.graphanalysis.AbstractFlowScanner
allNodes, allNodes, convertToFastCheckable, filter, filteredNodes, filteredNodes, findFirstMatch, hasNext, iterator, next, remove, setup, setupMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods 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:LinearScannerSet 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:
setupin 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:LinearScannerSet 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.myBlackListremoved - none of the filteredHeads are null- Overrides:
setHeadsin 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:AbstractFlowScannerActual meat of the iteration, get the next node to visit, using and updating state as needed- Overrides:
nextin 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
-