This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
TasksPublisher.java
227 lines (208 loc) · 8.54 KB
/
TasksPublisher.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package hudson.plugins.tasks;
import hudson.Launcher;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.HealthAwarePublisher;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.tasks.parser.TasksParserResult;
import hudson.plugins.tasks.parser.WorkspaceScanner;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
/**
* Publishes the results of the task scanner (freestyle project type).
*
* @author Ulli Hafner
*/
public class TasksPublisher extends HealthAwarePublisher {
/** Unique ID of this class. */
private static final long serialVersionUID = 3787892530045641806L;
/** Default files pattern. */
private static final String DEFAULT_PATTERN = "**/*.java";
/** Tag identifiers indicating high priority. */
private final String high;
/** Tag identifiers indicating normal priority. */
private final String normal;
/** Tag identifiers indicating low priority. */
private final String low;
/** Tag identifiers indicating case sensitivity. */
private final boolean ignoreCase;
/** Ant file-set pattern of files to work with. */
private final String pattern;
/** Ant file-set pattern of files to exclude from work. */
private final String excludePattern;
/**
* Creates a new instance of <code>TasksPublisher</code>.
*
* @param pattern
* Ant file-set pattern of files to scan for open tasks in
* @param excludePattern
* Ant file-set pattern of files to exclude from scan
* @param healthy
* Report health as 100% when the number of open tasks is less
* than this value
* @param unHealthy
* Report health as 0% when the number of open tasks is greater
* than this value
* @param thresholdLimit
* determines which warning priorities should be considered when
* evaluating the build stability and health
* @param useDeltaValues
* determines whether the absolute annotations delta or the
* actual annotations set difference should be used to evaluate
* the build stability
* @param unstableTotalAll
* annotation threshold
* @param unstableTotalHigh
* annotation threshold
* @param unstableTotalNormal
* annotation threshold
* @param unstableTotalLow
* annotation threshold
* @param unstableNewAll
* annotation threshold
* @param unstableNewHigh
* annotation threshold
* @param unstableNewNormal
* annotation threshold
* @param unstableNewLow
* annotation threshold
* @param failedTotalAll
* annotation threshold
* @param failedTotalHigh
* annotation threshold
* @param failedTotalNormal
* annotation threshold
* @param failedTotalLow
* annotation threshold
* @param failedNewAll
* annotation threshold
* @param failedNewHigh
* annotation threshold
* @param failedNewNormal
* annotation threshold
* @param failedNewLow
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param shouldDetectModules
* determines whether module names should be derived from Maven POM or Ant build files
* @param high
* tag identifiers indicating high priority
* @param normal
* tag identifiers indicating normal priority
* @param low
* tag identifiers indicating low priority
* @param ignoreCase
* if case should be ignored during matching
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
*/
// CHECKSTYLE:OFF
@SuppressWarnings("PMD.ExcessiveParameterList")
@DataBoundConstructor
public TasksPublisher(final String healthy, final String unHealthy, final String thresholdLimit,
final String defaultEncoding, final boolean useDeltaValues,
final String unstableTotalAll, final String unstableTotalHigh, final String unstableTotalNormal, final String unstableTotalLow,
final String unstableNewAll, final String unstableNewHigh, final String unstableNewNormal, final String unstableNewLow,
final String failedTotalAll, final String failedTotalHigh, final String failedTotalNormal, final String failedTotalLow,
final String failedNewAll, final String failedNewHigh, final String failedNewNormal, final String failedNewLow,
final boolean canRunOnFailed, final boolean shouldDetectModules, final boolean canComputeNew,
final String high, final String normal, final String low, final boolean ignoreCase,
final String pattern, final String excludePattern) {
super(healthy, unHealthy, thresholdLimit, defaultEncoding, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, shouldDetectModules, canComputeNew, "TASKS");
this.pattern = pattern;
this.excludePattern = excludePattern;
this.high = high;
this.normal = normal;
this.low = low;
this.ignoreCase = ignoreCase;
}
// CHECKSTYLE:ON
/**
* Returns the Ant file-set pattern of files to work with.
*
* @return Ant file-set pattern of files to work with
*/
public String getPattern() {
return pattern;
}
/**
* Returns the Ant file-set pattern of files to exclude from work.
*
* @return Ant file-set pattern of files to exclude from work
*/
public String getExcludePattern() {
return excludePattern;
}
/**
* Returns the high priority task identifiers.
*
* @return the high priority task identifiers
*/
public String getHigh() {
return high;
}
/**
* Returns the normal priority task identifiers.
*
* @return the normal priority task identifiers
*/
public String getNormal() {
return normal;
}
/**
* Returns the low priority task identifiers.
*
* @return the low priority task identifiers
*/
public String getLow() {
return low;
}
/**
* Returns whether case should be ignored during the scanning.
*
* @return <code>true</code> if case should be ignored during the scanning
*/
public boolean getIgnoreCase() {
return ignoreCase;
}
/** {@inheritDoc} */
@Override
public Action getProjectAction(final AbstractProject<?, ?> project) {
return new TasksProjectAction(project);
}
/** {@inheritDoc} */
@Override
protected BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger logger) throws InterruptedException, IOException {
TasksParserResult project;
WorkspaceScanner scanner = new WorkspaceScanner(StringUtils.defaultIfEmpty(getPattern(), DEFAULT_PATTERN),
getExcludePattern(), getDefaultEncoding(), high, normal, low, ignoreCase, shouldDetectModules());
project = build.getWorkspace().act(scanner);
logger.logLines(project.getLogMessages());
logger.log(String.format("Found %d open tasks.", project.getNumberOfAnnotations()));
TasksResult result = new TasksResult(build, getDefaultEncoding(), project, high, normal, low);
build.getActions().add(new TasksResultAction(build, this, result));
return result;
}
/** {@inheritDoc} */
@Override
public TasksDescriptor getDescriptor() {
return (TasksDescriptor)super.getDescriptor();
}
/** {@inheritDoc} */
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener) {
return new TasksAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding());
}
}