-
Notifications
You must be signed in to change notification settings - Fork 248
/
ModelASTStep.java
126 lines (107 loc) · 3.45 KB
/
ModelASTStep.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package org.jenkinsci.plugins.pipeline.modeldefinition.ast;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import groovy.transform.ToString;
import java.util.LinkedHashMap;
import java.util.Map;
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ModelValidator;
/**
* Represents an individual step within any of the various blocks that can contain steps.
*
* @author Kohsuke Kawaguchi
* @author Andrew Bayer
*/
@ToString(includeSuper = true, includeSuperProperties = true)
@SuppressFBWarnings(value = "SE_NO_SERIALVERSIONID")
public class ModelASTStep extends ModelASTElement {
private String name;
private ModelASTArgumentList args;
public static Map<String, String> blockedStepsBase() {
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
map.put("stage", Messages.ModelASTStep_BlockedSteps_Stage());
map.put("properties", Messages.ModelASTStep_BlockedSteps_Properties());
map.put("parallel", Messages.ModelASTStep_BlockedSteps_Parallel());
return map;
}
/**
* A map of step names which are banned from being executed within a step block.
*
* @return the map of steps that are banned from being executed within a step block, keyed by step name.
*/
public static Map<String, String> getBlockedSteps() {
return blockedStepsBase();
}
public ModelASTStep(Object sourceLocation) {
super(sourceLocation);
}
@Override
public JSONObject toJSON() {
JSONObject o = new JSONObject();
o.accumulate("name", name);
if (args != null) {
o.accumulate("arguments", args.toJSON());
}
return o;
}
@Override
public void validate(ModelValidator validator) {
validator.validateElement(this);
if (args != null) {
args.validate(validator);
}
}
@Override
public String toGroovy() {
return name + "(" + (args != null ? args.toGroovy() : "") + ")";
}
@Override
public void removeSourceLocation() {
super.removeSourceLocation();
if (args != null) {
args.removeSourceLocation();
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ModelASTArgumentList getArgs() {
return args;
}
public void setArgs(ModelASTArgumentList args) {
this.args = args;
}
@Override
public String toString() {
return "ModelASTStep{" +
"name='" + name + '\'' +
", args=" + args +
"}";
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
ModelASTStep that = (ModelASTStep) o;
if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) {
return false;
}
return getArgs() != null ? getArgs().equals(that.getArgs()) : that.getArgs() == null;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (getName() != null ? getName().hashCode() : 0);
result = 31 * result + (getArgs() != null ? getArgs().hashCode() : 0);
return result;
}
}