-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add includeStage to allow starting check immediately for JUnit
- Loading branch information
Showing
9 changed files
with
191 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/io/jenkins/plugins/checks/utils/FlowNodeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.jenkins.plugins.checks.utils; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.jenkinsci.plugins.workflow.actions.LabelAction; | ||
import org.jenkinsci.plugins.workflow.actions.ThreadNameAction; | ||
import org.jenkinsci.plugins.workflow.graph.FlowNode; | ||
import org.jenkinsci.plugins.workflow.graph.StepNode; | ||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
/** | ||
* Utility methods for working with FlowNodes. | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
public class FlowNodeUtils { | ||
/** | ||
* Get the stage and parallel branch start node IDs (not the body nodes) for this node, innermost first. | ||
* @param node A flownode. | ||
* @return A nonnull, possibly empty list of stage/parallel branch start nodes, innermost first. | ||
*/ | ||
@NonNull | ||
public static List<FlowNode> getEnclosingStagesAndParallels(final FlowNode node) { | ||
List<FlowNode> enclosingBlocks = new ArrayList<>(); | ||
for (FlowNode enclosing : node.getEnclosingBlocks()) { | ||
if (enclosing != null && enclosing.getAction(LabelAction.class) != null | ||
&& (isStageNode(enclosing) || enclosing.getAction(ThreadNameAction.class) != null)) { | ||
enclosingBlocks.add(enclosing); | ||
} | ||
} | ||
|
||
return enclosingBlocks; | ||
} | ||
|
||
/** | ||
* Get the stage and parallel branch names for these nodes, innermost first. | ||
* @param nodes A flownode. | ||
* @return A nonnull, possibly empty list of stage/parallel branch names, innermost first. | ||
*/ | ||
@NonNull | ||
public static List<String> getEnclosingBlockNames(@NonNull final List<FlowNode> nodes) { | ||
List<String> names = new ArrayList<>(); | ||
for (FlowNode n : nodes) { | ||
ThreadNameAction threadNameAction = n.getPersistentAction(ThreadNameAction.class); | ||
LabelAction labelAction = n.getPersistentAction(LabelAction.class); | ||
if (threadNameAction != null) { | ||
// If we're on a parallel branch with the same name as the previous (inner) node, that generally | ||
// means we're in a Declarative parallel stages situation, so don't add the redundant branch name. | ||
if (names.isEmpty() || !threadNameAction.getThreadName().equals(names.get(names.size() - 1))) { | ||
names.add(threadNameAction.getThreadName()); | ||
} | ||
} | ||
else if (labelAction != null) { | ||
names.add(labelAction.getDisplayName()); | ||
} | ||
} | ||
return names; | ||
} | ||
|
||
private static boolean isStageNode(@NonNull final FlowNode node) { | ||
if (node instanceof StepNode) { | ||
StepDescriptor d = ((StepNode) node).getDescriptor(); | ||
return d != null && d.getFunctionName().equals("stage"); | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
} | ||
Check warning on line 71 in src/main/java/io/jenkins/plugins/checks/utils/FlowNodeUtils.java ci.jenkins.io / PMDUseUtilityClass
Raw output
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.