();
94 |
95 | for (hudson.plugins.pmd.parser.File file : collection.getFiles()) {
96 | for (Violation warning : file.getViolations()) {
97 | Priority priority;
98 | if (warning.getPriority() < PMD_PRIORITY_MAPPED_TO_HIGH_PRIORITY) {
99 | priority = Priority.HIGH;
100 | }
101 | else if (warning.getPriority() > PMD_PRIORITY_MAPPED_TO_LOW_PRIORITY) {
102 | priority = Priority.LOW;
103 | }
104 | else {
105 | priority = Priority.NORMAL;
106 | }
107 | Bug bug = new Bug(priority, createMessage(warning), warning.getRuleset(), warning.getRule(),
108 | warning.getBeginline(), warning.getEndline());
109 | bug.setPackageName(warning.getPackage());
110 | bug.setModuleName(moduleName);
111 | bug.setFileName(file.getName());
112 | bug.setColumnPosition(warning.getBegincolumn(), warning.getEndcolumn());
113 | bug.setContextHashCode(createContextHashCode(file.getName(), warning.getBeginline(), warning.getRule()));
114 |
115 | annotations.add(bug);
116 | }
117 | }
118 | return annotations;
119 | }
120 |
121 | private String createMessage(final Violation warning) {
122 | String original = warning.getMessage();
123 | if (StringUtils.endsWith(original, ".")) {
124 | return original;
125 | }
126 | else {
127 | return original + ".";
128 | }
129 | }
130 | }
131 |
132 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/pmd/parser/Violation.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd.parser;
2 |
3 | /**
4 | * Java Bean class for a violation of the PMD format.
5 | *
6 | * @author Ulli Hafner
7 | */
8 | @SuppressWarnings("javadoc")
9 | public class Violation {
10 | /** Type of warning. */
11 | private String rule;
12 | /** Category of warning. */
13 | private String ruleset;
14 |
15 | private String externalInfoUrl;
16 | private String javaPackage;
17 | private int priority;
18 | private String message;
19 | private int beginline;
20 | private int endline;
21 | private int begincolumn;
22 | private int endcolumn;
23 |
24 | // CHECKSTYLE:OFF
25 | public String getRule() {
26 | return rule;
27 | }
28 | public void setRule(final String rule) {
29 | this.rule = rule;
30 | }
31 | public String getRuleset() {
32 | return ruleset;
33 | }
34 | public void setRuleset(final String ruleset) {
35 | this.ruleset = ruleset;
36 | }
37 | public String getExternalInfoUrl() {
38 | return externalInfoUrl;
39 | }
40 | public void setExternalInfoUrl(final String externalInfoUrl) {
41 | this.externalInfoUrl = externalInfoUrl;
42 | }
43 | public String getPackage() {
44 | return javaPackage;
45 | }
46 | public void setPackage(final String packageName) {
47 | javaPackage = packageName;
48 | }
49 | public int getPriority() {
50 | return priority;
51 | }
52 | public void setPriority(final int priority) {
53 | this.priority = priority;
54 | }
55 | public String getMessage() {
56 | return message;
57 | }
58 | public void setMessage(final String message) {
59 | this.message = message;
60 | }
61 | public int getBeginline() {
62 | return beginline;
63 | }
64 | public void setBeginline(final int beginline) {
65 | this.beginline = beginline;
66 | }
67 | public int getEndline() {
68 | return endline;
69 | }
70 | public void setEndline(final int endline) {
71 | this.endline = endline;
72 | }
73 | public int getEndcolumn() {
74 | return endcolumn;
75 | }
76 | public void setEndcolumn(final int endcolumn) {
77 | this.endcolumn = endcolumn;
78 | }
79 | public int getBegincolumn() {
80 | return begincolumn;
81 | }
82 | public void setBegincolumn(final int begincolumn) {
83 | this.begincolumn = begincolumn;
84 | }
85 | }
86 |
87 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/pmd/tokens/FixedPmdWarningsTokenMacro.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd.tokens;
2 |
3 | import hudson.Extension;
4 | import hudson.plugins.analysis.tokens.AbstractFixedAnnotationsTokenMacro;
5 | import hudson.plugins.pmd.PmdMavenResultAction;
6 | import hudson.plugins.pmd.PmdResultAction;
7 |
8 | /**
9 | * Provides a token that evaluates to the number of fixed PMD warnings.
10 | *
11 | * @author Ulli Hafner
12 | */
13 | @Extension(optional = true)
14 | public class FixedPmdWarningsTokenMacro extends AbstractFixedAnnotationsTokenMacro {
15 | /**
16 | * Creates a new instance of {@link FixedPmdWarningsTokenMacro}.
17 | */
18 | @SuppressWarnings("unchecked")
19 | public FixedPmdWarningsTokenMacro() {
20 | super("PMD_FIXED", PmdResultAction.class, PmdMavenResultAction.class);
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/pmd/tokens/NewPmdWarningsTokenMacro.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd.tokens;
2 |
3 | import hudson.Extension;
4 | import hudson.plugins.analysis.tokens.AbstractNewAnnotationsTokenMacro;
5 | import hudson.plugins.pmd.PmdMavenResultAction;
6 | import hudson.plugins.pmd.PmdResultAction;
7 |
8 | /**
9 | * Provides a token that evaluates to the number of new PMD warnings.
10 | *
11 | * @author Ulli Hafner
12 | */
13 | @Extension(optional = true)
14 | public class NewPmdWarningsTokenMacro extends AbstractNewAnnotationsTokenMacro {
15 | /**
16 | * Creates a new instance of {@link NewPmdWarningsTokenMacro}.
17 | */
18 | @SuppressWarnings("unchecked")
19 | public NewPmdWarningsTokenMacro() {
20 | super("PMD_NEW", PmdResultAction.class, PmdMavenResultAction.class);
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/pmd/tokens/PmdResultTokenMacro.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd.tokens;
2 |
3 | import hudson.Extension;
4 | import hudson.plugins.analysis.tokens.AbstractResultTokenMacro;
5 | import hudson.plugins.pmd.PmdMavenResultAction;
6 | import hudson.plugins.pmd.PmdResultAction;
7 |
8 | /**
9 | * Provides a token that evaluates to the PMD build result.
10 | *
11 | * @author Ulli Hafner
12 | */
13 | @Extension(optional = true)
14 | public class PmdResultTokenMacro extends AbstractResultTokenMacro {
15 | /**
16 | * Creates a new instance of {@link PmdResultTokenMacro}.
17 | */
18 | @SuppressWarnings("unchecked")
19 | public PmdResultTokenMacro() {
20 | super("PMD_RESULT", PmdResultAction.class, PmdMavenResultAction.class);
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/main/java/hudson/plugins/pmd/tokens/PmdWarningCountTokenMacro.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd.tokens;
2 |
3 | import hudson.Extension;
4 | import hudson.plugins.analysis.tokens.AbstractAnnotationsCountTokenMacro;
5 | import hudson.plugins.pmd.PmdMavenResultAction;
6 | import hudson.plugins.pmd.PmdResultAction;
7 |
8 | /**
9 | * Provides a token that evaluates to the number of PMD warnings.
10 | *
11 | * @author Ulli Hafner
12 | */
13 | @Extension(optional = true)
14 | public class PmdWarningCountTokenMacro extends AbstractAnnotationsCountTokenMacro {
15 | /**
16 | * Creates a new instance of {@link PmdWarningCountTokenMacro}.
17 | */
18 | @SuppressWarnings("unchecked")
19 | public PmdWarningCountTokenMacro() {
20 | super("PMD_COUNT", PmdResultAction.class, PmdMavenResultAction.class);
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/Messages.properties:
--------------------------------------------------------------------------------
1 | PMD.Warnings.ColumnHeader=# PMD
2 | PMD.Warnings.Column=Number of PMD warnings
3 | PMD.Publisher.Name=[Deprecated] Publish PMD analysis results
4 |
5 | PMD.ProjectAction.Name=PMD Warnings
6 |
7 | PMD.Trend.Name=PMD Trend
8 |
9 | PMD.ResultAction.Header=PMD Result
10 |
11 | PMD.ResultAction.HealthReportNoItem=PMD: no warnings found.
12 | PMD.ResultAction.HealthReportSingleItem=PMD: one warning found.
13 | PMD.ResultAction.HealthReportMultipleItem=PMD: {0} warnings found.
14 |
15 | PMD.Detail.header=PMD Warnings
16 |
17 | PMD.FixedWarnings.Detail.header=Fixed PMD Warnings
18 | PMD.NewWarnings.Detail.header=New PMD Warnings
19 |
20 | Portlet.WarningsTable=PMD warnings per project
21 | Portlet.WarningsPriorityGraph=PMD warnings trend graph (priority distribution)
22 | Portlet.WarningsNewVsFixedGraph=PMD warnings trend graph (new vs. fixed)
23 | Portlet.WarningsTotalsGraph=PMD warnings trend graph (totals)
24 | Portlet.WarningsUserGraph=PMD warnings (priority per author)
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/Messages_de.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jenkinsci/pmd-plugin/8ae81512020e8c9a58531dfdeec58b912d2dd212/src/main/resources/hudson/plugins/pmd/Messages_de.properties
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/Messages_fr.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jenkinsci/pmd-plugin/8ae81512020e8c9a58531dfdeec58b912d2dd212/src/main/resources/hudson/plugins/pmd/Messages_fr.properties
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/Messages_ja.properties:
--------------------------------------------------------------------------------
1 | PMD.ProjectAction.Name=PMD\u8B66\u544A
2 |
3 | PMD.Trend.Name=PMD\u8B66\u544A\u306E\u63A8\u79FB
4 |
5 | PMD.ResultAction.Header=PMD \u8B66\u544A
6 | PMD.ResultAction.HealthReportNoItem=PMD: \u8B66\u544A\u306F\u3042\u308A\u307E\u305B\u3093\u3002
7 | PMD.ResultAction.HealthReportSingleItem=PMD: \u8B66\u544A\u304C1\u3064\u3042\u308A\u307E\u3059\u3002
8 | PMD.ResultAction.HealthReportMultipleItem=PMD: {0} \u500B\u306E\u8B66\u544A\u304C\u3042\u308A\u307E\u3059\u3002
9 |
10 | PMD.Detail.header=PMD\u8B66\u544A
11 |
12 | PMD.FixedWarnings.Detail.header=\u4FEE\u6B63\u3055\u308C\u305FPMD\u8B66\u544A
13 | PMD.NewWarnings.Detail.header=\u65B0\u3057\u3044PMD\u8B66\u544A
14 |
15 | Portlet.WarningsTable=\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u6BCE\u306EPMD\u8B66\u544A
16 | Portlet.WarningsPriorityGraph=PMD\u8B66\u544A\u306E\u63A8\u79FB\u30B0\u30E9\u30D5 (\u512A\u5148\u5EA6\u306E\u5206\u5E03)
17 | Portlet.WarningsNewVsFixedGraph=PMD\u8B66\u544A\u306E\u63A8\u79FB\u30B0\u30E9\u30D5 (\u65B0\u898F vs. \u4FEE\u6B63\u6E08)
18 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/Messages_nl.properties:
--------------------------------------------------------------------------------
1 | PMD.ResultAction.Header=PMD Resultaat
2 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/Messages_zh_TW.properties:
--------------------------------------------------------------------------------
1 | # The MIT License
2 | #
3 | # Copyright (c) 2013, Chunghwa Telecom Co., Ltd., Pei-Tang Huang
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
6 | # of this software and associated documentation files (the "Software"), to deal
7 | # in the Software without restriction, including without limitation the rights
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | # copies of the Software, and to permit persons to whom the Software is
10 | # furnished to do so, subject to the following conditions:
11 | #
12 | # The above copyright notice and this permission notice shall be included in
13 | # all copies or substantial portions of the Software.
14 | #
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | # THE SOFTWARE.
22 |
23 | PMD.ProjectAction.Name=PMD \u8b66\u544a
24 |
25 | PMD.Trend.Name=PMD \u8da8\u52e2
26 |
27 | PMD.ResultAction.Header=PMD \u7d50\u679c
28 |
29 | PMD.ResultAction.HealthReportNoItem=PMD: \u627e\u4e0d\u5230\u8b66\u544a\u3002
30 | PMD.ResultAction.HealthReportSingleItem=PMD: \u627e\u5230 1 \u9805\u8b66\u544a\u3002
31 | PMD.ResultAction.HealthReportMultipleItem=PMD: \u627e\u5230 {0} \u9805\u8b66\u544a\u3002
32 |
33 | PMD.Detail.header=PMD \u8b66\u544a
34 |
35 | PMD.FixedWarnings.Detail.header=\u4fee\u6b63\u7684 PMD \u8b66\u544a
36 | PMD.NewWarnings.Detail.header=\u65b0\u7684 PMD \u8b66\u544a
37 |
38 | Portlet.WarningsTable=\u5404\u5225\u5c08\u6848\u7684 PMD \u8b66\u544a
39 | Portlet.WarningsPriorityGraph=PMD \u8b66\u544a\u8da8\u52e2\u5716 (\u512a\u5148\u9806\u5e8f\u5206\u4f48)
40 | Portlet.WarningsNewVsFixedGraph=PMD \u8b66\u544a\u8da8\u52e2\u5716 (\u65b0\u589e\u8207\u4fee\u6b63)
41 | Portlet.WarningsTotalsGraph=PMD \u8b66\u544a\u8da8\u52e2\u5716 (\u7e3d\u8a08)
42 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/PmdPublisher/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/PmdPublisher/config.properties:
--------------------------------------------------------------------------------
1 | description.pattern=Fileset 'includes' \
2 | setting that specifies the generated raw PMD XML report files, such as '**/pmd.xml'. \
3 | Basedir of the fileset is the workspace root. \
4 | If no value is set, then the default '**/pmd.xml' is used. Be sure not to include any \
5 | non-report files into this pattern.
6 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/PmdPublisher/config_de.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jenkinsci/pmd-plugin/8ae81512020e8c9a58531dfdeec58b912d2dd212/src/main/resources/hudson/plugins/pmd/PmdPublisher/config_de.properties
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/PmdPublisher/config_ja.properties:
--------------------------------------------------------------------------------
1 | PMD\ results=\u96C6\u8A08\u3059\u308B\u30D5\u30A1\u30A4\u30EB
2 | description.pattern=\
3 | PMD\u304C\u751F\u6210\u3059\u308BXML\u5F62\u5F0F\u306E\u30EC\u30DD\u30FC\u30C8\u30D5\u30A1\u30A4\u30EB\u3092\u3001\
4 | '**/pmd.xml'\u306E\u3088\u3046\u306BAnt\u306EFileset 'includes'\u5F62\u5F0F\u3067\u6307\u5B9A\u3057\u307E\u3059\u3002\
5 | fileset\u3067\u306E\u6307\u5B9A\u306F\u3001\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u306E\u30EB\u30FC\u30C8\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3092\u57FA\u6E96\u3068\u3057\u307E\u3059\u3002\
6 | \u4F55\u3082\u6307\u5B9A\u3057\u306A\u3051\u308C\u3070\u3001'**/pmd.xml'\u3092\u5BFE\u8C61\u3068\u3057\u307E\u3059\u3002PMD\u306E\u30EC\u30DD\u30FC\u30C8\u3067\u306F\u306A\u3044\u30D5\u30A1\u30A4\u30EB\u3092\u542B\u3081\u306A\u3044\u3088\u3046\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002
7 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/PmdPublisher/config_zh_TW.properties:
--------------------------------------------------------------------------------
1 | # The MIT License
2 | #
3 | # Copyright (c) 2013, Chunghwa Telecom Co., Ltd., Pei-Tang Huang
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
6 | # of this software and associated documentation files (the "Software"), to deal
7 | # in the Software without restriction, including without limitation the rights
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | # copies of the Software, and to permit persons to whom the Software is
10 | # furnished to do so, subject to the following conditions:
11 | #
12 | # The above copyright notice and this permission notice shall be included in
13 | # all copies or substantial portions of the Software.
14 | #
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | # THE SOFTWARE.
22 |
23 | description.pattern=\u6307\u5b9a\u5230 PMD \u7522\u51fa\u539f\u59cb XML \u5831\u544a\u6a94\u7684\u6a94\u6848\u96c6 'includes'\
24 | \u8a2d\u5b9a\uff0c\u4f8b\u5982 '**/pmd.xml'\u3002\
25 | \u6a94\u6848\u96c6\u8d77\u7b97\u76ee\u9304\u5c31\u662f\u5de5\u4f5c\u5340\u6839\u76ee\u9304\u3002\
26 | \u5982\u679c\u6c92\u6709\u8a2d\u5b9a\uff0c\u9810\u8a2d\u6703\u662f '**/pmd.xml'\u3002\
27 | \u8acb\u78ba\u8a8d\u8a2d\u5b9a\u7684\u6a21\u5f0f\u4e0d\u5305\u542b\u5831\u544a\u6a94\u4ee5\u5916\u7684\u6a94\u6848\u3002
28 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/PmdPublisher/global.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/PmdReporter/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/PmdReporter/global.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/tokens/FixedPmdWarningsTokenMacro/help.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $${PMD_FIXED}
5 |
6 | Expands to the total number of fixed PMD warnings in a build.
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/tokens/NewPmdWarningsTokenMacro/help.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $${PMD_NEW}
5 |
6 | Expands to the total number of new PMD warnings in a build.
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/tokens/PmdResultTokenMacro/help.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $${PMD_RESULT}
5 |
6 | Expands to the build result of the PMD plug-in.
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/resources/hudson/plugins/pmd/tokens/PmdWarningCountTokenMacro/help.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $${PMD_COUNT}
5 |
6 | Expands to the total number of PMD warnings in a build.
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/resources/index.jelly:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/src/main/webapp/help-m2.html:
--------------------------------------------------------------------------------
1 |
2 |
Jenkins understands PMD
3 | analysis report XML format. When this option is configured and your
4 | build runs the maven goal pmd:pmd
then Jenkins provides
5 | useful information about analysis results, such as historical result
6 | trend, module and package statistics, web UI for viewing analysis
7 | reports and warnings, and so on.
8 |
This plug-in is not invoked for failed builds, it is only called for
9 | stable or unstable builds (i.e., a build with failed tests).
10 |
--------------------------------------------------------------------------------
/src/main/webapp/help-m2_de.html:
--------------------------------------------------------------------------------
1 |
2 |
Jenkins kann PMD Reports
3 | einlesen und darstellen. Wenn dies aktiviert wird und der Build das
4 | Maven Goal pmd:pmd
ausführt, dann analysiert Jenkins nach
5 | jedem Build die erzeugten PMD Dateien und stellt deren Informationen in
6 | verschiedenen Ansichten dar: Trend Anzeige, Projekt Statistik und
7 | Package Statistik. Zudem zeigt Jenkins die jeweiligen Warnungen direkt in
8 | der betroffen Datei an.
9 |
Das Plug-in wird nicht aufgerufen, wenn der Build fehlgeschlagen
10 | ist, sondern nur für stabile bzw. instabile Builds (mit fehlgeschlagenen Tests).
11 |
--------------------------------------------------------------------------------
/src/main/webapp/help-m2_zh_TW.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Jenkins 認得 XML 格式的 PMD 分析報告。
4 | 當您啟用這個選項,而且您的建置執行了 Maven pmd:pmd
這個
5 | Goal,Jenkins 就會提供很有用的分析結果資訊,例如:
6 | 結果歷史趨勢、模組及套件統計、查看分析報告及警告的網頁等。
7 |
8 |
9 | 本外掛程式在不會在失敗的建置中執行,只有穩定或是不穩定 (測試失敗) 的建置才會呼叫。
10 |
11 |
--------------------------------------------------------------------------------
/src/main/webapp/help.html:
--------------------------------------------------------------------------------
1 |
2 |
Jenkins understands PMD
3 | analysis report XML format. When this option is configured Jenkins shows
4 | the PMD analysis results in different views: historical result
5 | trend, module and package statistics, web UI for viewing analysis
6 | reports and warnings, and so on.
7 |
You need to set up your build to run PMD in order to use
8 | this feature - this Jenkins plug-in does not perform the actual analysis!
9 | This plug-in is not invoked for failed builds, it is only called for
10 | stable or unstable builds (i.e., a build with failed tests).
11 |
Note: If you are using the maven-pmd-plugin to create the
12 | PMD analysis files please make sure to specify the pattern **/target/pmd.xml
.
13 | Otherwise you will get a wrong warning count since the maven-pmd-plugin
14 | gererates two identical output files.
15 |
--------------------------------------------------------------------------------
/src/main/webapp/help_de.html:
--------------------------------------------------------------------------------
1 |
2 |
Jenkins kann PMD Reports
3 | einlesen und darstellen. Wenn dies aktiviert wird, analysiert Jenkins
4 | nach jedem Build die erzeugten PMD Dateien und stellt deren
5 | Informationen in verschiedenen Ansichten dar: Trend Anzeige, Projekt
6 | Statistik und Package Statistik. Zudem zeigt Jenkins die jeweiligen
7 | Warnungen direkt in der betroffen Datei an.
8 |
Damit das Plug-in korrekt funktioniert, muss im Build PMD
9 | gestartet werden - das Jenkins Plug-in selbst macht dies nicht! Das
10 | Plug-in wird nicht aufgerufen, wenn der Build fehlgeschlagen ist,
11 | sondern nur für stabile bzw. instabile Builds (mit fehlgeschlagenen
12 | Tests).
13 |
--------------------------------------------------------------------------------
/src/main/webapp/help_zh_TW.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Jenkins 認得 XML 格式的 PMD 分析報告。
4 | 選用這個選項後,Jenkins 會從不同面向顯示 PMD 分析結果,包含:
5 | 結果歷史趨勢、模組及套件統計、查看分析報告及警告的網頁等。
6 |
7 |
8 | 您要在建置過程中執行 PMD 才能用這項功能,本 Jenkins 外掛程式不會實際執行分析作業!
9 | 本外掛程式在不會在失敗的建置中執行,只有穩定或是不穩定 (測試失敗) 的建置才會呼叫。
10 |
11 |
12 | 注意: 如果您是使用 maven-pmd-plugin 產生 PMD 分析結果檔,請確認您是設成
13 | **/target/pmd.xml
。
14 | 否則計算出來的警告數會是錯的,因為 maven-pmd-plugin 會產生兩個一模一樣的檔案。
15 |
16 |
--------------------------------------------------------------------------------
/src/main/webapp/icons/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2003, InfoEther, LLC
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 | * The end-user documentation included with the redistribution, if
14 | any, must include the following acknowledgement:
15 | "This product includes software developed in part by support from
16 | the Defense Advanced Research Project Agency (DARPA)"
17 | * Neither the name of InfoEther, LLC nor the names of its
18 | contributors may be used to endorse or promote products derived from
19 | this software without specific prior written permission.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/src/main/webapp/icons/pmd-24x24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jenkinsci/pmd-plugin/8ae81512020e8c9a58531dfdeec58b912d2dd212/src/main/webapp/icons/pmd-24x24.png
--------------------------------------------------------------------------------
/src/main/webapp/icons/pmd-48x48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jenkinsci/pmd-plugin/8ae81512020e8c9a58531dfdeec58b912d2dd212/src/main/webapp/icons/pmd-48x48.png
--------------------------------------------------------------------------------
/src/test/java/hudson/plugins/pmd/PmdHealthDescriptorTest.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd;
2 |
3 | import static org.junit.Assert.*;
4 | import static org.mockito.Mockito.*;
5 | import hudson.plugins.analysis.core.AbstractHealthDescriptor;
6 | import hudson.plugins.analysis.core.HealthDescriptor;
7 | import hudson.plugins.analysis.core.NullHealthDescriptor;
8 | import hudson.plugins.analysis.test.AbstractHealthDescriptorTest;
9 | import hudson.plugins.analysis.util.model.AnnotationProvider;
10 |
11 | import org.junit.Test;
12 | import org.jvnet.localizer.Localizable;
13 |
14 | /**
15 | * Tests the class {@link PmdHealthDescriptor}.
16 | *
17 | * @author Ulli Hafner
18 | */
19 | public class PmdHealthDescriptorTest extends AbstractHealthDescriptorTest {
20 | /**
21 | * Verifies the different messages if the number of items are 0, 1, and 2.
22 | */
23 | @Test
24 | public void verifyNumberOfItems() {
25 | AnnotationProvider provider = mock(AnnotationProvider.class);
26 | PmdHealthDescriptor healthDescriptor = new PmdHealthDescriptor(NullHealthDescriptor.NULL_HEALTH_DESCRIPTOR);
27 |
28 | Localizable description = healthDescriptor.createDescription(provider);
29 | assertEquals(WRONG_DESCRIPTION, Messages.PMD_ResultAction_HealthReportNoItem(), description.toString());
30 |
31 | when(provider.getNumberOfAnnotations()).thenReturn(1);
32 | description = healthDescriptor.createDescription(provider);
33 | assertEquals(WRONG_DESCRIPTION, Messages.PMD_ResultAction_HealthReportSingleItem(), description.toString());
34 |
35 | when(provider.getNumberOfAnnotations()).thenReturn(2);
36 | description = healthDescriptor.createDescription(provider);
37 | assertEquals(WRONG_DESCRIPTION, Messages.PMD_ResultAction_HealthReportMultipleItem(2), description.toString());
38 | }
39 |
40 | @Override
41 | protected AbstractHealthDescriptor createHealthDescriptor(final HealthDescriptor healthDescriptor) {
42 | return new PmdHealthDescriptor(healthDescriptor);
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/src/test/java/hudson/plugins/pmd/PmdResultTest.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd;
2 |
3 | import hudson.model.AbstractBuild;
4 | import hudson.plugins.analysis.core.BuildHistory;
5 | import hudson.plugins.analysis.core.ParserResult;
6 | import hudson.plugins.analysis.test.BuildResultTest;
7 |
8 | /**
9 | * Tests the class {@link PmdResult}.
10 | */
11 | public class PmdResultTest extends BuildResultTest {
12 | @Override
13 | protected PmdResult createBuildResult(final AbstractBuild, ?> build, final ParserResult project, final BuildHistory history) {
14 | return new PmdResult(build, history, project, "UTF8", false);
15 | }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/test/java/hudson/plugins/pmd/PmdWorkflowTest.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd;
2 |
3 | import hudson.FilePath;
4 | import hudson.model.Result;
5 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
6 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.jvnet.hudson.test.JenkinsRule;
10 |
11 | import static org.junit.Assert.assertEquals;
12 | import static org.junit.Assert.assertTrue;
13 |
14 | public class PmdWorkflowTest {
15 |
16 | @Rule
17 | public JenkinsRule jenkinsRule = new JenkinsRule();
18 |
19 | /**
20 | * Run a workflow job using {@link PmdPublisher} and check for success.
21 | */
22 | @Test
23 | public void pmdPublisherWorkflowStep() throws Exception {
24 | WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "pmdPublisherWorkflowStep");
25 | FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job);
26 | FilePath report = workspace.child("target").child("pmd.xml");
27 | report.copyFrom(PmdWorkflowTest.class.getResourceAsStream("/hudson/plugins/pmd/parser/4-pmd-warnings.xml"));
28 | job.setDefinition(new CpsFlowDefinition(""
29 | + "node {\n"
30 | + " step([$class: 'PmdPublisher'])\n"
31 | + "}\n", true)
32 | );
33 | jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
34 | PmdResultAction result = job.getLastBuild().getAction(PmdResultAction.class);
35 | assertEquals(4, result.getResult().getAnnotations().size());
36 | }
37 |
38 | /**
39 | * Run a workflow job using {@link PmdPublisher} with a failing threshold of 0, so the given example file
40 | * "/hudson/plugins/pmd/parser/4-pmd-warnings.xml" will make the build to fail.
41 | */
42 | @Test
43 | public void pmdPublisherWorkflowStepSetLimits() throws Exception {
44 | WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "pmdPublisherWorkflowStepSetLimits");
45 | FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job);
46 | FilePath report = workspace.child("target").child("pmd.xml");
47 | report.copyFrom(PmdWorkflowTest.class.getResourceAsStream("/hudson/plugins/pmd/parser/4-pmd-warnings.xml"));
48 | job.setDefinition(new CpsFlowDefinition(""
49 | + "node {\n"
50 | + " step([$class: 'PmdPublisher', pattern: '**/pmd.xml', failedTotalAll: '0', usePreviousBuildAsReference: false])\n"
51 | + "}\n", true)
52 | );
53 | jenkinsRule.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get());
54 | PmdResultAction result = job.getLastBuild().getAction(PmdResultAction.class);
55 | assertEquals(4, result.getResult().getAnnotations().size());
56 | }
57 |
58 | /**
59 | * Run a workflow job using {@link PmdPublisher} with a unstable threshold of 0, so the given example file
60 | * "/hudson/plugins/pmd/parser/4-pmd-warnings.xml" will make the build to fail.
61 | */
62 | @Test
63 | public void pmdPublisherWorkflowStepFailure() throws Exception {
64 | WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "pmdPublisherWorkflowStepFailure");
65 | FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job);
66 | FilePath report = workspace.child("target").child("pmd.xml");
67 | report.copyFrom(PmdWorkflowTest.class.getResourceAsStream("/hudson/plugins/pmd/parser/4-pmd-warnings.xml"));
68 | job.setDefinition(new CpsFlowDefinition(""
69 | + "node {\n"
70 | + " step([$class: 'PmdPublisher', pattern: '**/pmd.xml', unstableTotalAll: '0', usePreviousBuildAsReference: false])\n"
71 | + "}\n")
72 | );
73 | jenkinsRule.assertBuildStatus(Result.UNSTABLE, job.scheduleBuild2(0).get());
74 | PmdResultAction result = job.getLastBuild().getAction(PmdResultAction.class);
75 | assertEquals(4, result.getResult().getAnnotations().size());
76 | }
77 | }
78 |
79 |
--------------------------------------------------------------------------------
/src/test/java/hudson/plugins/pmd/parser/BugSerializeModelTest.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd.parser;
2 |
3 | import hudson.XmlFile;
4 | import hudson.plugins.analysis.test.AbstractSerializeModelTest;
5 | import hudson.plugins.analysis.util.model.AbstractAnnotation;
6 | import hudson.plugins.analysis.util.model.AnnotationStream;
7 | import hudson.plugins.analysis.util.model.JavaProject;
8 | import hudson.plugins.analysis.util.model.Priority;
9 |
10 | import java.io.File;
11 |
12 | import org.junit.Assert;
13 |
14 | import org.junit.Test;
15 |
16 | import com.thoughtworks.xstream.XStream;
17 |
18 | /**
19 | * Tests the serialization of the model.
20 | *
21 | * @see Testing object serialization
22 | */
23 | public class BugSerializeModelTest extends AbstractSerializeModelTest {
24 | /** Serialization provider. */
25 | private static final XStream XSTREAM = new AnnotationStream();
26 |
27 | static {
28 | XSTREAM.alias("bug", Bug.class);
29 | }
30 |
31 | /**
32 | * Verifies the first created annotation.
33 | *
34 | * @param annotation
35 | * the first created annotation
36 | */
37 | @Override
38 | protected void verifyFirstAnnotation(final AbstractAnnotation annotation) {
39 | Bug bug = (Bug)annotation;
40 | Assert.assertEquals("Wrong detail message." , TEST_TASK1, bug.getMessage());
41 | }
42 |
43 | /**
44 | * Creates an annotation.
45 | *
46 | * @param line
47 | * the line
48 | * @param message
49 | * the message
50 | * @param priority
51 | * the priority
52 | * @param fileName
53 | * the file name
54 | * @param packageName
55 | * the package name
56 | * @param moduleName
57 | * the module name
58 | * @return the annotation
59 | */
60 | @Override
61 | protected AbstractAnnotation createAnnotation(final int line, final String message, final Priority priority, final String fileName, final String packageName, final String moduleName) {
62 | Bug annotation = new Bug(priority, message, message, message, line);
63 | annotation.setFileName(fileName);
64 | annotation.setPackageName(packageName);
65 | annotation.setModuleName(moduleName);
66 |
67 | return annotation;
68 | }
69 |
70 | /**
71 | * Test whether a serialized project is the same object after
72 | * deserialization of the file format of release 2.2.
73 | */
74 | @Test
75 | public void ensureSameSerialization() {
76 | JavaProject project = deserialize("project.ser");
77 |
78 | verifyProject(project);
79 | }
80 |
81 | /**
82 | * Test whether a serialized project is the same object after
83 | * deserialization of the file format of release 2.2.
84 | */
85 | @Test
86 | public void ensureSameXmlSerialization() {
87 | ensureSerialization("project.ser.xml");
88 | }
89 |
90 | @Override
91 | protected XmlFile createXmlFile(final File file) {
92 | return new XmlFile(XSTREAM, file);
93 | }
94 | }
95 |
96 |
--------------------------------------------------------------------------------
/src/test/java/hudson/plugins/pmd/parser/BugsDifferencerTest.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd.parser;
2 |
3 | import hudson.plugins.analysis.core.IssueDifference;
4 | import hudson.plugins.analysis.test.AnnotationDifferencerTest;
5 | import hudson.plugins.analysis.util.model.FileAnnotation;
6 | import hudson.plugins.analysis.util.model.Priority;
7 |
8 | /**
9 | * Tests the {@link IssueDifference} for bugs.
10 | */
11 | public class BugsDifferencerTest extends AnnotationDifferencerTest {
12 | @Override
13 | public FileAnnotation createAnnotation(final String fileName, final Priority priority, final String message, final String category,
14 | final String type, final int start, final int end) {
15 | Bug bug = new Bug(priority, message, message, message, start, end);
16 | bug.setFileName(fileName);
17 | return bug;
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/test/java/hudson/plugins/pmd/parser/PmdMessagesTest.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd.parser;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * Tests the class {@link PmdMessages}.
9 | *
10 | * @author Ullrich Hafner
11 | */
12 | public class PmdMessagesTest {
13 | /**
14 | * Verifies that the PMD messages could be correctly read.
15 | */
16 | @Test
17 | public void shouldHaveAllMessage() {
18 | assertEquals("Wrong number of rulesets found: ", 25, PmdMessages.getInstance().initialize());
19 |
20 | assertEquals("\n" +
21 | "Empty Catch Block finds instances where an exception is caught, but nothing is done. \n" +
22 | "In most circumstances, this swallows an exception which should either be acted on \n" +
23 | "or reported.\n" +
24 | " \n" +
25 | " \n" +
26 | "public void doSomething() {\n" +
27 | " try {\n" +
28 | " FileInputStream fis = new FileInputStream(\"/tmp/bugger\");\n" +
29 | " } catch (IOException ioe) {\n" +
30 | " // not good\n" +
31 | " }\n" +
32 | "}\n" +
33 | " \n" +
34 | "
",
35 | PmdMessages.getInstance().getMessage("Empty Code", "EmptyCatchBlock"));
36 | }
37 | }
--------------------------------------------------------------------------------
/src/test/java/hudson/plugins/pmd/parser/PmdParserTest.java:
--------------------------------------------------------------------------------
1 | package hudson.plugins.pmd.parser;
2 |
3 | import java.io.InputStream;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.util.Collection;
6 |
7 | import org.apache.commons.io.IOUtils;
8 | import org.junit.Test;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | import hudson.plugins.analysis.core.ParserResult;
13 | import hudson.plugins.analysis.util.model.FileAnnotation;
14 | import hudson.plugins.analysis.util.model.MavenModule;
15 | import hudson.plugins.analysis.util.model.Priority;
16 |
17 | /**
18 | * Tests the extraction of PMD analysis results.
19 | */
20 | public class PmdParserTest {
21 | /** Error message. */
22 | private static final String WRONG_WARNING_PROPERTY = "Wrong warning property";
23 | /** Error message. */
24 | private static final String ERROR_MESSAGE = "Wrong number of warnings detected.";
25 |
26 | /**
27 | * Parses the specified file.
28 | *
29 | * @param fileName
30 | * the file to read
31 | * @return the parsed module
32 | * @throws InvocationTargetException
33 | * in case of an error
34 | */
35 | private Collection parseFile(final String fileName) throws InvocationTargetException {
36 | InputStream file = PmdParserTest.class.getResourceAsStream(fileName);
37 | try {
38 | return new PmdParser().parse(file, "module");
39 | }
40 | finally {
41 | IOUtils.closeQuietly(file);
42 | }
43 | }
44 |
45 | /**
46 | * Parses a warning log with 15 warnings.
47 | *
48 | * @throws InvocationTargetException
49 | * if the file could not be read
50 | * @see Issue 12801
51 | */
52 | @Test
53 | public void issue12801() throws InvocationTargetException {
54 | String fileName = "issue12801.xml";
55 | Collection annotations = parseFile(fileName);
56 |
57 | assertEquals(ERROR_MESSAGE, 2, annotations.size());
58 | ParserResult result = new ParserResult(annotations);
59 | assertEquals(ERROR_MESSAGE, 2, result.getNumberOfAnnotations());
60 |
61 | }
62 |
63 | /**
64 | * Checks whether we correctly detect all 669 warnings.
65 | *
66 | * @throws InvocationTargetException
67 | * indicates a test failure
68 | */
69 | @Test
70 | public void scanFileWithSeveralWarnings() throws InvocationTargetException {
71 | String fileName = "pmd.xml";
72 | Collection annotations = parseFile(fileName);
73 |
74 | assertEquals(ERROR_MESSAGE, 669, annotations.size());
75 | }
76 |
77 | /**
78 | * Checks whether we create messages with a single dot.
79 | *
80 | * @throws InvocationTargetException
81 | * indicates a test failure
82 | */
83 | @Test
84 | public void verifySingleDot() throws InvocationTargetException {
85 | String fileName = "warning-message-with-dot.xml";
86 | Collection annotations = parseFile(fileName);
87 |
88 | assertEquals(ERROR_MESSAGE, 2, annotations.size());
89 |
90 | FileAnnotation annotation = annotations.iterator().next();
91 |
92 | assertEquals("Wrong message text: ", "Avoid really long parameter lists.", annotation.getMessage());
93 | }
94 |
95 | /**
96 | * Checks whether we correctly detect an empty file.
97 | * * @throws InvocationTargetException indicates a test failure
98 |
99 | * @throws InvocationTargetException
100 | * indicates a test failure
101 | */
102 | @Test
103 | public void scanFileWithNoBugs() throws InvocationTargetException {
104 | String fileName = "empty.xml";
105 | Collection annotations = parseFile(fileName);
106 |
107 | assertEquals(ERROR_MESSAGE, 0, annotations.size());
108 | }
109 |
110 | /**
111 | * Checks whether we correctly parse a file with 4 warnings.
112 | *
113 | * @throws InvocationTargetException
114 | * indicates a test failure
115 | */
116 | @Test
117 | public void scanFileWith4Warnings() throws InvocationTargetException {
118 | PmdMessages.getInstance().initialize();
119 |
120 | String fileName = "4-pmd-warnings.xml";
121 | Collection annotations = parseFile(fileName);
122 | MavenModule module = new MavenModule();
123 | module.addAnnotations(annotations);
124 |
125 | assertEquals(ERROR_MESSAGE, 4, module.getNumberOfAnnotations());
126 |
127 | assertEquals(ERROR_MESSAGE, 1, module.getPackage("com.avaloq.adt.env.internal.ui.actions")
128 | .getNumberOfAnnotations());
129 | assertEquals(ERROR_MESSAGE, 1, module.getPackage(
130 | "com.avaloq.adt.env.internal.ui.actions.change").getNumberOfAnnotations());
131 | assertEquals(ERROR_MESSAGE, 2, module.getPackage("com.avaloq.adt.env.internal.ui.dialogs")
132 | .getNumberOfAnnotations());
133 |
134 | assertEquals(ERROR_MESSAGE, 1, module.getNumberOfAnnotations("HIGH"));
135 | assertEquals(ERROR_MESSAGE, 2, module.getNumberOfAnnotations("NORMAL"));
136 | assertEquals(ERROR_MESSAGE, 1, module.getNumberOfAnnotations("LOW"));
137 |
138 | Bug warning = (Bug)module.getPackage("com.avaloq.adt.env.internal.ui.actions")
139 | .getAnnotations().iterator().next();
140 |
141 | assertEquals(WRONG_WARNING_PROPERTY, "These nested if statements could be combined.",
142 | warning.getMessage());
143 | assertEquals(WRONG_WARNING_PROPERTY, Priority.NORMAL, warning.getPriority());
144 | assertEquals(WRONG_WARNING_PROPERTY, "Basic", warning.getCategory());
145 | assertEquals(WRONG_WARNING_PROPERTY, "CollapsibleIfStatements", warning.getType());
146 | assertEquals(WRONG_WARNING_PROPERTY, 54, warning.getPrimaryLineNumber());
147 | assertEquals(WRONG_WARNING_PROPERTY, "com.avaloq.adt.env.internal.ui.actions", warning
148 | .getPackageName());
149 | assertEquals(WRONG_WARNING_PROPERTY, 1, warning.getLineRanges().size());
150 | assertEquals(WRONG_WARNING_PROPERTY, 54, warning.getLineRanges().iterator().next()
151 | .getStart());
152 | assertEquals(WRONG_WARNING_PROPERTY, 61, warning.getLineRanges().iterator().next().getEnd());
153 | assertEquals(
154 | WRONG_WARNING_PROPERTY,
155 | "C:/Build/Results/jobs/ADT-Base/workspace/com.avaloq.adt.ui/src/main/java/com/avaloq/adt/env/internal/ui/actions/CopyToClipboard.java",
156 | warning.getFileName());
157 | assertEquals(
158 | WRONG_WARNING_PROPERTY,
159 | "\n" +
160 | "Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.\n" +
161 | " \n" +
162 | " \n" +
163 | "void bar() {\n" +
164 | "\tif (x) {\t\t\t// original implementation\n" +
165 | "\t\tif (y) {\n" +
166 | "\t\t\t// do stuff\n" +
167 | "\t\t}\n" +
168 | "\t}\n" +
169 | "}\n" +
170 | "\n" +
171 | "void bar() {\n" +
172 | "\tif (x && y) {\t\t// optimized implementation\n" +
173 | "\t\t// do stuff\n" +
174 | "\t}\n" +
175 | "}\n" +
176 | " \n" +
177 | "
", warning.getToolTip());
178 | }
179 |
180 | /**
181 | * Checks whether we correctly parse a file with 4 warnings.
182 | *
183 | * @throws InvocationTargetException
184 | * indicates a test failure
185 | */
186 | @Test
187 | public void testEquals() throws InvocationTargetException {
188 | String fileName = "equals-test.xml";
189 | Collection annotations = parseFile(fileName);
190 | MavenModule module = new MavenModule();
191 | module.addAnnotations(annotations);
192 |
193 | assertEquals(ERROR_MESSAGE, 4, module.getNumberOfAnnotations());
194 | assertEquals(ERROR_MESSAGE, 4, module.getPackage("com.avaloq.adt.env.core.db.plsqlCompletion").getNumberOfAnnotations());
195 | assertEquals(ERROR_MESSAGE, 4, module.getNumberOfAnnotations(Priority.NORMAL));
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/src/test/resources/hudson/plugins/pmd/parser/4-pmd-warnings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | These nested if statements could be combined
6 |
7 |
8 |
9 |
10 | Avoid unused imports such as 'org.eclipse.ui.IWorkbenchPart'
11 |
12 |
13 |
14 |
15 | Avoid empty catch blocks
16 |
17 |
18 | Avoid empty catch blocks
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/test/resources/hudson/plugins/pmd/parser/empty.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/test/resources/hudson/plugins/pmd/parser/equals-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | These nested if statements could be combined
6 |
7 |
8 | These nested if statements could be combined
9 |
10 |
11 | These nested if statements could be combined
12 |
13 |
14 | These nested if statements could be combined
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/test/resources/hudson/plugins/pmd/parser/issue12801.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Use equals() to compare object references.
6 |
7 |
8 | Use equals() to compare object references.
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/test/resources/hudson/plugins/pmd/parser/otherfile.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/test/resources/hudson/plugins/pmd/parser/project.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jenkinsci/pmd-plugin/8ae81512020e8c9a58531dfdeec58b912d2dd212/src/test/resources/hudson/plugins/pmd/parser/project.ser
--------------------------------------------------------------------------------
/src/test/resources/hudson/plugins/pmd/parser/project.ser.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Test Task3
5 | Test Task3
6 |
7 | Test Task3
8 | LOW
9 | 679
10 |
11 |
12 | 100
13 | 100
14 |
15 |
16 | 100
17 | Path/To/File2
18 | Module1
19 | Package1
20 |
21 |
22 | Test Task2
23 | Test Task2
24 |
25 | Test Task2
26 | LOW
27 | 678
28 |
29 |
30 | 100
31 | 100
32 |
33 |
34 | 100
35 | Path/To/File
36 | Module1
37 | Package1
38 |
39 |
40 | Test Task4
41 | Test Task4
42 |
43 | Test Task4
44 | NORMAL
45 | 680
46 |
47 |
48 | 100
49 | 100
50 |
51 |
52 | 100
53 | Path/To/File
54 | Module1
55 | Package2
56 |
57 |
58 | Test Task5
59 | Test Task5
60 |
61 | Test Task5
62 | NORMAL
63 | 681
64 |
65 |
66 | 100
67 | 100
68 |
69 |
70 | 100
71 | Path/To/File
72 | Module2
73 | Package1
74 |
75 |
76 | Test Task1
77 | Test Task1
78 |
79 | Test Task1
80 | HIGH
81 | 677
82 |
83 |
84 | 100
85 | 100
86 |
87 |
88 | 100
89 | Path/To/File
90 | Module1
91 | Package1
92 |
93 |
--------------------------------------------------------------------------------
/src/test/resources/hudson/plugins/pmd/parser/warning-message-with-dot.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Avoid really long parameter lists.
6 |
7 |
8 |
9 |
10 | A high number of imports can indicate a high degree of coupling within an object.
11 |
12 |
13 |
15 |
17 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
32 |
33 |
34 |
36 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
50 |
52 |
54 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
76 |
78 |
80 |
82 |
83 |
84 |
85 |
87 |
89 |
91 |
92 |
--------------------------------------------------------------------------------