Skip to content

Commit 6bd6b78

Browse files
authored
Migrate pipeline-graph-analysis-plugin implementations (jenkinsci#803)
1 parent 3cba824 commit 6bd6b78

File tree

17 files changed

+2200
-18
lines changed

17 files changed

+2200
-18
lines changed

pom.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@
8181
<groupId>org.jenkins-ci.plugins</groupId>
8282
<artifactId>metrics</artifactId>
8383
</dependency>
84-
<dependency>
85-
<groupId>org.jenkins-ci.plugins</groupId>
86-
<artifactId>pipeline-graph-analysis</artifactId>
87-
</dependency>
8884
<dependency>
8985
<groupId>org.jenkins-ci.plugins</groupId>
9086
<artifactId>pipeline-input-step</artifactId>
@@ -138,6 +134,12 @@
138134
<artifactId>pipeline-build-step</artifactId>
139135
<scope>test</scope>
140136
</dependency>
137+
<dependency>
138+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
139+
<artifactId>workflow-api</artifactId>
140+
<classifier>tests</classifier>
141+
<scope>test</scope>
142+
</dependency>
141143
<dependency>
142144
<groupId>org.jenkins-ci.plugins.workflow</groupId>
143145
<artifactId>workflow-support</artifactId>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2016, CloudBees, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package io.jenkins.plugins.pipelinegraphview.analysis;
26+
27+
import hudson.model.Result;
28+
import java.util.Map;
29+
30+
/**
31+
* Statuses of a {@link org.jenkinsci.plugins.workflow.graphanalysis.FlowChunk} in increasing priority order
32+
* Note, when adding new statuses you need to add a new {@link io.jenkins.plugins.pipelinegraphview.analysis.StatusAndTiming.StatusApiVersion}
33+
* and set the value of {@link StatusAndTiming#CURRENT_API_VERSION} to that,
34+
* and update {@link StatusAndTiming#coerceStatusMap(Map)} to do coercion for new codings to protect core APIs from unknown values
35+
*/
36+
public enum GenericStatus {
37+
/**
38+
* We resumed from checkpoint or {@link Result#NOT_BUILT} status - nothing ran in the chunk.
39+
*/
40+
NOT_EXECUTED,
41+
42+
/**
43+
* Completed &amp; successful, ex {@link Result#SUCCESS}
44+
*/
45+
SUCCESS,
46+
47+
/**
48+
* Completed with recoverable failures, such as noncritical tests, ex {@link Result#UNSTABLE}
49+
*/
50+
UNSTABLE,
51+
52+
/**
53+
* Not complete: still executing, in a node block, but the node block is in queue.
54+
*/
55+
QUEUED,
56+
57+
/**
58+
* Not complete: still executing, waiting for a result
59+
*/
60+
IN_PROGRESS,
61+
62+
/**
63+
* Completed and explicitly failed, i.e. {@link Result#FAILURE}
64+
*/
65+
FAILURE,
66+
67+
/**
68+
* Aborted while running, no way to determine final outcome {@link Result#ABORTED}
69+
*/
70+
ABORTED,
71+
72+
/**
73+
* Not complete: we are waiting for user input to continue (special case of IN_PROGRESS)
74+
*/
75+
PAUSED_PENDING_INPUT;
76+
77+
/**
78+
* Create a {@link GenericStatus} from a {@link Result}
79+
*/
80+
public static GenericStatus fromResult(Result result) {
81+
if (result == Result.NOT_BUILT) {
82+
return GenericStatus.NOT_EXECUTED;
83+
} else if (result == Result.ABORTED) {
84+
return GenericStatus.ABORTED;
85+
} else if (result == Result.FAILURE) {
86+
return GenericStatus.FAILURE;
87+
} else if (result == Result.UNSTABLE) {
88+
return GenericStatus.UNSTABLE;
89+
} else if (result == Result.SUCCESS) {
90+
return GenericStatus.SUCCESS;
91+
} else {
92+
return GenericStatus.NOT_EXECUTED;
93+
}
94+
}
95+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package io.jenkins.plugins.pipelinegraphview.analysis;
2+
3+
import edu.umd.cs.findbugs.annotations.CheckForNull;
4+
import edu.umd.cs.findbugs.annotations.NonNull;
5+
import org.jenkinsci.plugins.workflow.actions.LabelAction;
6+
import org.jenkinsci.plugins.workflow.actions.StageAction;
7+
import org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode;
8+
import org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode;
9+
import org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode;
10+
import org.jenkinsci.plugins.workflow.graph.BlockEndNode;
11+
import org.jenkinsci.plugins.workflow.graph.FlowNode;
12+
import org.jenkinsci.plugins.workflow.graph.StepNode;
13+
import org.jenkinsci.plugins.workflow.graphanalysis.ChunkFinder;
14+
import org.jenkinsci.plugins.workflow.support.steps.StageStep;
15+
16+
/**
17+
* Finds both block-scoped and legacy stages
18+
* @author Sam Van Oort
19+
*/
20+
public class StageChunkFinder implements ChunkFinder {
21+
22+
@Override
23+
public boolean isStartInsideChunk() {
24+
return true;
25+
}
26+
27+
@Override
28+
public boolean isChunkStart(@NonNull FlowNode current, @CheckForNull FlowNode previous) {
29+
if ((current instanceof StepAtomNode || current instanceof StepStartNode)
30+
&& !(((StepNode) current).getDescriptor() instanceof StageStep.DescriptorImpl)) {
31+
// Faster than looking at actions
32+
return false;
33+
} else if (current instanceof BlockEndNode) {
34+
return false;
35+
} else if (current instanceof StepStartNode startNode) {
36+
if (!(startNode.getDescriptor() instanceof StageStep.DescriptorImpl)) {
37+
return false;
38+
}
39+
return startNode.getAction(LabelAction.class) != null;
40+
}
41+
return current.getAction(StageAction.class) != null;
42+
}
43+
44+
/** End is where you have a label marker before it... or */
45+
@Override
46+
public boolean isChunkEnd(@NonNull FlowNode current, @CheckForNull FlowNode previous) {
47+
// First a block-scoped stage
48+
if (current instanceof StepEndNode stepEndNode
49+
&& stepEndNode.getDescriptor() instanceof StageStep.DescriptorImpl) {
50+
// We have to look for the labelaction because block-scoped stage creates two nested blocks
51+
return stepEndNode.getStartNode().getAction(LabelAction.class) != null;
52+
}
53+
// Then a marker-scoped stage
54+
if (previous != null) {
55+
return isChunkStart(previous, null);
56+
}
57+
return false;
58+
}
59+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.jenkins.plugins.pipelinegraphview.analysis;
2+
3+
/**
4+
* Duplicates some string constants used in pipeline-stage-tags-metadata plugin to avoid introducing the dependency.
5+
* See: https://github.com/jenkinsci/pipeline-model-definition-plugin/tree/master/pipeline-stage-tags-metadata
6+
*
7+
* @author cliffmeyers
8+
*/
9+
public class StageStatus {
10+
11+
public static final String TAG_NAME = "STAGE_STATUS";
12+
13+
public String getTagName() {
14+
return TAG_NAME;
15+
}
16+
17+
public static String getSkippedForConditional() {
18+
return "SKIPPED_FOR_CONDITIONAL";
19+
}
20+
}

0 commit comments

Comments
 (0)