Skip to content
This repository was archived by the owner on Feb 26, 2020. It is now read-only.

Commit fba349e

Browse files
committedSep 28, 2012
[JENKINS-15037]: Upgrade to new API in order to compute warnings only
for stable builds (if option is checked).
1 parent 6f7ca21 commit fba349e

10 files changed

+48
-58
lines changed
 

‎src/main/java/hudson/plugins/pmd/MavenPmdResultAction.java

+5-21
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import hudson.maven.MavenModuleSet;
88
import hudson.maven.MavenModuleSetBuild;
99
import hudson.model.Action;
10+
import hudson.model.AbstractBuild;
1011
import hudson.plugins.analysis.core.HealthDescriptor;
12+
import hudson.plugins.analysis.core.ParserResult;
1113

1214
import java.util.List;
1315
import java.util.Map;
@@ -25,25 +27,6 @@ public class MavenPmdResultAction extends PmdResultAction implements Aggregatabl
2527
/** The default encoding to be used when reading and parsing files. */
2628
private final String defaultEncoding;
2729

28-
/**
29-
* Creates a new instance of {@link MavenPmdResultAction}. This instance
30-
* will have no result set in the beginning. The result will be set
31-
* successively after each of the modules are build.
32-
*
33-
* @param owner
34-
* the associated build of this action
35-
* @param healthDescriptor
36-
* health descriptor to use
37-
* @param defaultEncoding
38-
* the default encoding to be used when reading and parsing files
39-
*/
40-
public MavenPmdResultAction(final MavenModuleSetBuild owner, final HealthDescriptor healthDescriptor,
41-
final String defaultEncoding) {
42-
super(owner, healthDescriptor);
43-
44-
this.defaultEncoding = defaultEncoding;
45-
}
46-
4730
/**
4831
* Creates a new instance of {@link MavenPmdResultAction}.
4932
*
@@ -56,7 +39,7 @@ public MavenPmdResultAction(final MavenModuleSetBuild owner, final HealthDescrip
5639
* @param result
5740
* the result in this build
5841
*/
59-
public MavenPmdResultAction(final MavenBuild owner, final HealthDescriptor healthDescriptor,
42+
public MavenPmdResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor,
6043
final String defaultEncoding, final PmdResult result) {
6144
super(owner, healthDescriptor, result);
6245

@@ -65,7 +48,8 @@ public MavenPmdResultAction(final MavenBuild owner, final HealthDescriptor healt
6548

6649
/** {@inheritDoc} */
6750
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
68-
return new MavenPmdResultAction(build, getHealthDescriptor(), defaultEncoding);
51+
return new MavenPmdResultAction(build, getHealthDescriptor(), defaultEncoding,
52+
new PmdResult(build, defaultEncoding, new ParserResult(), false));
6953
}
7054

7155
/** {@inheritDoc} */

‎src/main/java/hudson/plugins/pmd/PmdAnnotationsAggregator.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*
1616
* @author Ulli Hafner
1717
*/
18-
1918
public class PmdAnnotationsAggregator extends AnnotationsAggregator {
2019
/**
2120
* Creates a new instance of {@link PmdAnnotationsAggregator}.
@@ -30,16 +29,20 @@ public class PmdAnnotationsAggregator extends AnnotationsAggregator {
3029
* health descriptor
3130
* @param defaultEncoding
3231
* the default encoding to be used when reading and parsing files
32+
* @param useStableBuildAsReference
33+
* determines whether only stable builds should be used as
34+
* reference builds or not
3335
*/
3436
public PmdAnnotationsAggregator(final MatrixBuild build, final Launcher launcher,
35-
final BuildListener listener, final HealthDescriptor healthDescriptor, final String defaultEncoding) {
36-
super(build, launcher, listener, healthDescriptor, defaultEncoding);
37+
final BuildListener listener, final HealthDescriptor healthDescriptor, final String defaultEncoding,
38+
final boolean useStableBuildAsReference) {
39+
super(build, launcher, listener, healthDescriptor, defaultEncoding, useStableBuildAsReference);
3740
}
3841

3942
@Override
4043
protected Action createAction(final HealthDescriptor healthDescriptor, final String defaultEncoding, final ParserResult aggregatedResult) {
4144
return new PmdResultAction(build, healthDescriptor,
42-
new PmdResult(build, defaultEncoding, aggregatedResult));
45+
new PmdResult(build, defaultEncoding, aggregatedResult, useOnlyStableBuildsAsReference()));
4346
}
4447

4548
@Override

‎src/main/java/hudson/plugins/pmd/PmdMavenResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class PmdMavenResult extends PmdResult {
2929
@SuppressWarnings("deprecation")
3030
public PmdMavenResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
3131
final ParserResult result) {
32-
super(build, defaultEncoding, result, MavenPmdResultAction.class);
32+
super(build, defaultEncoding, result, false, MavenPmdResultAction.class);
3333
}
3434

3535
/**

‎src/main/java/hudson/plugins/pmd/PmdMavenResultAction.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public PmdMavenResultAction(final AbstractBuild<?, ?> owner, final HealthDescrip
4242
/** {@inheritDoc} */
4343
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
4444
return new PmdMavenResultAction(build, getHealthDescriptor(), getDisplayName(),
45-
new PmdResult(build, getDefaultEncoding(), new ParserResult()));
45+
new PmdResult(build, getDefaultEncoding(), new ParserResult(), false));
4646
}
4747

4848
/** {@inheritDoc} */
@@ -57,7 +57,8 @@ public Class<? extends MavenResultAction<PmdResult>> getIndividualActionType() {
5757

5858
@Override
5959
protected PmdResult createResult(final PmdResult existingResult, final PmdResult additionalResult) {
60-
return new PmdReporterResult(getOwner(), additionalResult.getDefaultEncoding(), aggregate(existingResult, additionalResult));
60+
return new PmdReporterResult(getOwner(), additionalResult.getDefaultEncoding(),
61+
aggregate(existingResult, additionalResult), existingResult.useOnlyStableBuildsAsReference());
6162
}
6263
}
6364

‎src/main/java/hudson/plugins/pmd/PmdPublisher.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public class PmdPublisher extends HealthAwarePublisher {
8686
* annotation threshold
8787
* @param canRunOnFailed
8888
* determines whether the plug-in can run for failed builds, too
89+
* @param useStableBuildAsReference
90+
* determines whether only stable builds should be used as reference builds or not
8991
* @param canComputeNew
9092
* determines whether new warnings should be computed (with
9193
* respect to baseline)
@@ -103,14 +105,14 @@ public PmdPublisher(final String healthy, final String unHealthy, final String t
103105
final String unstableNewAll, final String unstableNewHigh, final String unstableNewNormal, final String unstableNewLow,
104106
final String failedTotalAll, final String failedTotalHigh, final String failedTotalNormal, final String failedTotalLow,
105107
final String failedNewAll, final String failedNewHigh, final String failedNewNormal, final String failedNewLow,
106-
final boolean canRunOnFailed, final boolean shouldDetectModules, final boolean canComputeNew,
107-
final String pattern) {
108+
final boolean canRunOnFailed, final boolean useStableBuildAsReference, final boolean shouldDetectModules,
109+
final boolean canComputeNew, final String pattern) {
108110
super(healthy, unHealthy, thresholdLimit, defaultEncoding, useDeltaValues,
109111
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
110112
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
111113
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
112114
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
113-
canRunOnFailed, shouldDetectModules, canComputeNew, PLUGIN_NAME);
115+
canRunOnFailed, useStableBuildAsReference, shouldDetectModules, canComputeNew, false, PLUGIN_NAME);
114116
this.pattern = pattern;
115117
}
116118
// CHECKSTYLE:ON
@@ -137,7 +139,7 @@ public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger l
137139
ParserResult project = build.getWorkspace().act(pmdCollector);
138140
logger.logLines(project.getLogMessages());
139141

140-
PmdResult result = new PmdResult(build, getDefaultEncoding(), project);
142+
PmdResult result = new PmdResult(build, getDefaultEncoding(), project, useOnlyStableBuildsAsReference());
141143
build.getActions().add(new PmdResultAction(build, this, result));
142144

143145
return result;
@@ -151,6 +153,6 @@ public PmdDescriptor getDescriptor() {
151153
/** {@inheritDoc} */
152154
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
153155
final BuildListener listener) {
154-
return new PmdAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding());
156+
return new PmdAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(), useOnlyStableBuildsAsReference());
155157
}
156158
}

‎src/main/java/hudson/plugins/pmd/PmdReporter.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public class PmdReporter extends HealthAwareReporter<PmdResult> {
8080
* annotation threshold
8181
* @param canRunOnFailed
8282
* determines whether the plug-in can run for failed builds, too
83+
* @param useStableBuildAsReference
84+
* determines whether only stable builds should be used as reference builds or not
8385
* @param canComputeNew
8486
* determines whether new warnings should be computed (with
8587
* respect to baseline)
@@ -92,13 +94,13 @@ public PmdReporter(final String healthy, final String unHealthy, final String th
9294
final String unstableNewAll, final String unstableNewHigh, final String unstableNewNormal, final String unstableNewLow,
9395
final String failedTotalAll, final String failedTotalHigh, final String failedTotalNormal, final String failedTotalLow,
9496
final String failedNewAll, final String failedNewHigh, final String failedNewNormal, final String failedNewLow,
95-
final boolean canRunOnFailed, final boolean canComputeNew) {
97+
final boolean canRunOnFailed, final boolean useStableBuildAsReference, final boolean canComputeNew) {
9698
super(healthy, unHealthy, thresholdLimit, useDeltaValues,
9799
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
98100
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
99101
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
100102
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
101-
canRunOnFailed, canComputeNew, PLUGIN_NAME);
103+
canRunOnFailed, useStableBuildAsReference, canComputeNew, PLUGIN_NAME);
102104
}
103105
// CHECKSTYLE:ON
104106

@@ -117,7 +119,7 @@ public ParserResult perform(final MavenBuildProxy build, final MavenProject pom,
117119

118120
@Override
119121
protected PmdResult createResult(final MavenBuild build, final ParserResult project) {
120-
return new PmdReporterResult(build, getDefaultEncoding(), project);
122+
return new PmdReporterResult(build, getDefaultEncoding(), project, useOnlyStableBuildsAsReference());
121123
}
122124

123125
@Override

‎src/main/java/hudson/plugins/pmd/PmdReporterResult.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ public class PmdReporterResult extends PmdResult {
2222
* the default encoding to be used when reading and parsing files
2323
* @param result
2424
* the parsed result with all annotations
25+
* @param useStableBuildAsReference
26+
* determines whether only stable builds should be used as
27+
* reference builds or not
2528
*/
2629
public PmdReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
27-
final ParserResult result) {
28-
super(build, defaultEncoding, result, PmdMavenResultAction.class);
30+
final ParserResult result, final boolean useStableBuildAsReference) {
31+
super(build, defaultEncoding, result, useStableBuildAsReference, PmdMavenResultAction.class);
2932
}
3033

3134
@Override

‎src/main/java/hudson/plugins/pmd/PmdResult.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ public class PmdResult extends BuildResult {
2727
* the default encoding to be used when reading and parsing files
2828
* @param result
2929
* the parsed result with all annotations
30+
* @param useStableBuildAsReference
31+
* determines whether only stable builds should be used as
32+
* reference builds or not
3033
*/
31-
public PmdResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result) {
32-
this(build, defaultEncoding, result, PmdResultAction.class);
34+
public PmdResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
35+
final boolean useStableBuildAsReference) {
36+
this(build, defaultEncoding, result, useStableBuildAsReference, PmdResultAction.class);
3337
}
3438

3539
/**
@@ -41,12 +45,15 @@ public PmdResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
4145
* the default encoding to be used when reading and parsing files
4246
* @param result
4347
* the parsed result with all annotations
48+
* @param useStableBuildAsReference
49+
* determines whether only stable builds should be used as
50+
* reference builds or not
4451
* @param actionType
4552
* the type of the result action
4653
*/
4754
protected PmdResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
48-
final Class<? extends ResultAction<PmdResult>> actionType) {
49-
this(build, new BuildHistory(build, actionType), result, defaultEncoding, true);
55+
final boolean useStableBuildAsReference, final Class<? extends ResultAction<PmdResult>> actionType) {
56+
this(build, new BuildHistory(build, actionType, useStableBuildAsReference), result, defaultEncoding, true);
5057
}
5158

5259
PmdResult(final AbstractBuild<?, ?> build, final BuildHistory history,

‎src/main/java/hudson/plugins/pmd/PmdResultAction.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package hudson.plugins.pmd;
22

33
import hudson.model.AbstractBuild;
4-
import hudson.plugins.analysis.core.AbstractResultAction;
54
import hudson.plugins.analysis.core.HealthDescriptor;
65
import hudson.plugins.analysis.core.PluginDescriptor;
6+
import hudson.plugins.analysis.core.AbstractResultAction;
77

88
/**
99
* Controls the live cycle of the PMD results. This action persists the
@@ -31,18 +31,6 @@ public PmdResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor h
3131
super(owner, new PmdHealthDescriptor(healthDescriptor), result);
3232
}
3333

34-
/**
35-
* Creates a new instance of <code>PmdResultAction</code>.
36-
*
37-
* @param owner
38-
* the associated build of this action
39-
* @param healthDescriptor
40-
* health descriptor to use
41-
*/
42-
public PmdResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor) {
43-
super(owner, new PmdHealthDescriptor(healthDescriptor));
44-
}
45-
4634
/** {@inheritDoc} */
4735
public String getDisplayName() {
4836
return Messages.PMD_ProjectAction_Name();
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?jelly escape-by-default='true'?>
2-
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
3-
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:u="/util">
2+
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
3+
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:u="/util">
44
<f:advanced>
5-
<u:advancedMaven id="pmd"/>
5+
<u:advancedMaven id="pmd" />
66
</f:advanced>
77
</j:jelly>

0 commit comments

Comments
 (0)
This repository has been archived.