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 31
/
CheckStylePublisher.java
101 lines (83 loc) · 3.52 KB
/
CheckStylePublisher.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
package hudson.plugins.checkstyle;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;
import net.sf.json.JSONObject;
import hudson.FilePath;
import hudson.Launcher;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
import hudson.model.BuildListener;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.FilesParser;
import hudson.plugins.analysis.core.HealthAwarePublisher;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.checkstyle.parser.CheckStyleParser;
/**
* Publishes the results of the Checkstyle analysis (freestyle project type).
*
* @author Ulli Hafner
*/
public class CheckStylePublisher extends HealthAwarePublisher {
/** Unique ID of this class. */
private static final long serialVersionUID = 6369581633551160418L;
private static final String PLUGIN_NAME = "CHECKSTYLE";
/** Default Checkstyle pattern. */
private static final String DEFAULT_PATTERN = "**/checkstyle-result.xml";
/** Ant file-set pattern of files to work with. */
private String pattern;
/**
* Constructor used from methods like {@link StaplerRequest#bindJSON(Class, JSONObject)} and
* {@link StaplerRequest#bindParameters(Class, String)}.
*/
@DataBoundConstructor
public CheckStylePublisher() {
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;
}
/**
* Sets the Ant file-set pattern of files to work with.
*/
@DataBoundSetter
public void setPattern(final String pattern) {
this.pattern = pattern;
}
@Override
public BuildResult perform(final Run<?, ?> build, final FilePath workspace, final PluginLogger logger) throws
InterruptedException, IOException {
logger.log("Collecting checkstyle analysis files...");
FilesParser parser = new FilesParser(PLUGIN_NAME,
StringUtils.defaultIfEmpty(expandFilePattern(getPattern(), build.getEnvironment(TaskListener.NULL)), DEFAULT_PATTERN),
new CheckStyleParser(getDefaultEncoding()),
shouldDetectModules(), isMavenBuild(build));
ParserResult project = workspace.act(parser);
logger.logLines(project.getLogMessages());
blame(project.getAnnotations(), build, workspace);
CheckStyleResult result = new CheckStyleResult(build, getDefaultEncoding(), project,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
build.addAction(new CheckStyleResultAction(build, this, result));
return result;
}
@Override
public CheckStyleDescriptor getDescriptor() {
return (CheckStyleDescriptor)super.getDescriptor();
}
@Override
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener) {
return new CheckStyleAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(),
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
}
}