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
322 lines (292 loc) · 11.3 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package hudson.plugins.tasks;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import hudson.FilePath;
import hudson.Launcher;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.model.Action;
import hudson.model.BuildListener;
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;
/**
* 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 String high;
/** Tag identifiers indicating normal priority. */
private String normal;
/** Tag identifiers indicating low priority. */
private String low;
/** Tag identifiers indicating case sensitivity. */
private boolean ignoreCase;
/** If the identifiers should be treated as regular expression. */
private boolean asRegexp;
/** Ant file-set pattern of files to work with. */
private String pattern;
/** Ant file-set pattern of files to exclude from work. */
private String excludePattern;
/** Plugin name */
private static final String PLUGIN_NAME = "TASKS";
/**
* Simplified default constructor.
* Use setters to initialize if required.
*/
@DataBoundConstructor
public TasksPublisher() {
super(PLUGIN_NAME);
}
/**
* 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;
}
/**
* @see {@link #getPattern()}
*/
@DataBoundSetter
public void setPattern(String pattern) {
this.pattern = 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;
}
/**
* @see {@link #getExcludePattern()}
*/
@DataBoundSetter
public void setExcludePattern(String excludePattern) {
this.excludePattern = excludePattern;
}
/**
* Returns the high priority task identifiers.
*
* @return the high priority task identifiers
*/
public String getHigh() {
return high;
}
/**
* @see {@link #getHigh()}
*/
@DataBoundSetter
public void setHigh(String high) {
this.high = high;
}
/**
* Returns the normal priority task identifiers.
*
* @return the normal priority task identifiers
*/
public String getNormal() {
return normal;
}
/**
* @see {@link #getNormal()}
*/
@DataBoundSetter
public void setNormal(String normal) {
this.normal = normal;
}
/**
* Returns the low priority task identifiers.
*
* @return the low priority task identifiers
*/
public String getLow() {
return low;
}
/**
* @see {@link #getLow()}
*/
@DataBoundSetter
public void setLow(String low) {
this.low = 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;
}
/**
* @see {@link #getIgnoreCase()}
*/
@DataBoundSetter
public void setIgnoreCase(boolean ignoreCase) {
this.ignoreCase = ignoreCase;
}
/**
* Returns whether the identifiers should be treated as regular expression.
*
* @return <code>true</code> if the identifiers should be treated as regular expression
*/
public boolean getAsRegexp() {
return asRegexp;
}
/**
* @see {@link #getAsRegexp()}
*/
@DataBoundSetter
public void setAsRegexp(boolean asRegexp) {
this.asRegexp = asRegexp;
}
@Override
public Action getProjectAction(final AbstractProject<?, ?> project) {
return new TasksProjectAction(project);
}
@Override
protected BuildResult perform(final Run<?, ?> build, FilePath workspace, final PluginLogger logger) throws InterruptedException, IOException {
TasksParserResult project;
WorkspaceScanner scanner = new WorkspaceScanner(StringUtils.defaultIfEmpty(getPattern(), DEFAULT_PATTERN),
getExcludePattern(), getDefaultEncoding(), high, normal, low, ignoreCase, shouldDetectModules(), asRegexp);
project = workspace.act(scanner);
logger.logLines(project.getLogMessages());
logger.log(String.format("Found %d open tasks.", project.getNumberOfAnnotations()));
TasksResult result = new TasksResult(build, getDefaultEncoding(), project,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference(), high, normal, low);
build.addAction(new TasksResultAction(build, this, result));
return result;
}
@Override
public TasksDescriptor getDescriptor() {
return (TasksDescriptor)super.getDescriptor();
}
@Override
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener) {
return new TasksAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(),
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
}
/**
* Creates a new instance of <code>TasksPublisher</code>.
*
* @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 defaultEncoding
* the default encoding to be used when reading and parsing files
* @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 usePreviousBuildAsReference
* determines whether to always use the previous build as the reference build
* @param useStableBuildAsReference
* determines whether only stable builds should be used as reference builds or not
* @param canComputeNew
* determines whether new warnings should be computed (with
* respect to baseline)
* @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 asRegexp
* if the identifiers should be treated as regular expression
* @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
* @deprecated This constructor is called internally only, but if you need to use it (for some strange reason), call
* {@link #TasksPublisher()} and available setters
*/
// CHECKSTYLE:OFF
@SuppressWarnings("PMD.ExcessiveParameterList")
@Deprecated
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 usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final boolean shouldDetectModules, final boolean canComputeNew, final String high, final String normal, final String low,
final boolean ignoreCase, final boolean asRegexp, 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, usePreviousBuildAsReference, useStableBuildAsReference,
shouldDetectModules, canComputeNew, true, PLUGIN_NAME);
this.pattern = pattern;
this.excludePattern = excludePattern;
this.high = high;
this.normal = normal;
this.low = low;
this.ignoreCase = ignoreCase;
this.asRegexp = asRegexp;
}
// CHECKSTYLE:ON
}