Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[JENKINS-15037]: Upgrade to new API in order to compute warnings only
for stable builds (if option is checked).
  • Loading branch information
uhafner committed Sep 28, 2012
1 parent 6f7ca21 commit fba349e969bfdfaebfdfaa9785dd6b9d4841c88e
@@ -7,7 +7,9 @@
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.core.ParserResult;

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

/**
* Creates a new instance of {@link MavenPmdResultAction}. This instance
* will have no result set in the beginning. The result will be set
* successively after each of the modules are build.
*
* @param owner
* the associated build of this action
* @param healthDescriptor
* health descriptor to use
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
*/
public MavenPmdResultAction(final MavenModuleSetBuild owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding) {
super(owner, healthDescriptor);

this.defaultEncoding = defaultEncoding;
}

/**
* Creates a new instance of {@link MavenPmdResultAction}.
*
@@ -56,7 +39,7 @@ public MavenPmdResultAction(final MavenModuleSetBuild owner, final HealthDescrip
* @param result
* the result in this build
*/
public MavenPmdResultAction(final MavenBuild owner, final HealthDescriptor healthDescriptor,
public MavenPmdResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding, final PmdResult result) {
super(owner, healthDescriptor, result);

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

/** {@inheritDoc} */
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new MavenPmdResultAction(build, getHealthDescriptor(), defaultEncoding);
return new MavenPmdResultAction(build, getHealthDescriptor(), defaultEncoding,
new PmdResult(build, defaultEncoding, new ParserResult(), false));
}

/** {@inheritDoc} */
@@ -15,7 +15,6 @@
*
* @author Ulli Hafner
*/

public class PmdAnnotationsAggregator extends AnnotationsAggregator {
/**
* Creates a new instance of {@link PmdAnnotationsAggregator}.
@@ -30,16 +29,20 @@ public class PmdAnnotationsAggregator extends AnnotationsAggregator {
* health descriptor
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*/
public PmdAnnotationsAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener, final HealthDescriptor healthDescriptor, final String defaultEncoding) {
super(build, launcher, listener, healthDescriptor, defaultEncoding);
final BuildListener listener, final HealthDescriptor healthDescriptor, final String defaultEncoding,
final boolean useStableBuildAsReference) {
super(build, launcher, listener, healthDescriptor, defaultEncoding, useStableBuildAsReference);
}

@Override
protected Action createAction(final HealthDescriptor healthDescriptor, final String defaultEncoding, final ParserResult aggregatedResult) {
return new PmdResultAction(build, healthDescriptor,
new PmdResult(build, defaultEncoding, aggregatedResult));
new PmdResult(build, defaultEncoding, aggregatedResult, useOnlyStableBuildsAsReference()));
}

@Override
@@ -29,7 +29,7 @@ public class PmdMavenResult extends PmdResult {
@SuppressWarnings("deprecation")
public PmdMavenResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result) {
super(build, defaultEncoding, result, MavenPmdResultAction.class);
super(build, defaultEncoding, result, false, MavenPmdResultAction.class);
}

/**
@@ -42,7 +42,7 @@ public PmdMavenResultAction(final AbstractBuild<?, ?> owner, final HealthDescrip
/** {@inheritDoc} */
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new PmdMavenResultAction(build, getHealthDescriptor(), getDisplayName(),
new PmdResult(build, getDefaultEncoding(), new ParserResult()));
new PmdResult(build, getDefaultEncoding(), new ParserResult(), false));
}

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

@Override
protected PmdResult createResult(final PmdResult existingResult, final PmdResult additionalResult) {
return new PmdReporterResult(getOwner(), additionalResult.getDefaultEncoding(), aggregate(existingResult, additionalResult));
return new PmdReporterResult(getOwner(), additionalResult.getDefaultEncoding(),
aggregate(existingResult, additionalResult), existingResult.useOnlyStableBuildsAsReference());
}
}

@@ -86,6 +86,8 @@ public class PmdPublisher extends HealthAwarePublisher {
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @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)
@@ -103,14 +105,14 @@ public PmdPublisher(final String healthy, final String unHealthy, final String t
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 pattern) {
final boolean canRunOnFailed, final boolean useStableBuildAsReference, final boolean shouldDetectModules,
final boolean canComputeNew, final String pattern) {
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, PLUGIN_NAME);
canRunOnFailed, useStableBuildAsReference, shouldDetectModules, canComputeNew, false, PLUGIN_NAME);
this.pattern = pattern;
}
// CHECKSTYLE:ON
@@ -137,7 +139,7 @@ public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger l
ParserResult project = build.getWorkspace().act(pmdCollector);
logger.logLines(project.getLogMessages());

PmdResult result = new PmdResult(build, getDefaultEncoding(), project);
PmdResult result = new PmdResult(build, getDefaultEncoding(), project, useOnlyStableBuildsAsReference());
build.getActions().add(new PmdResultAction(build, this, result));

return result;
@@ -151,6 +153,6 @@ public PmdDescriptor getDescriptor() {
/** {@inheritDoc} */
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener) {
return new PmdAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding());
return new PmdAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(), useOnlyStableBuildsAsReference());
}
}
@@ -80,6 +80,8 @@ public class PmdReporter extends HealthAwareReporter<PmdResult> {
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @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)
@@ -92,13 +94,13 @@ public PmdReporter(final String healthy, final String unHealthy, final String th
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 canComputeNew) {
final boolean canRunOnFailed, final boolean useStableBuildAsReference, final boolean canComputeNew) {
super(healthy, unHealthy, thresholdLimit, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, canComputeNew, PLUGIN_NAME);
canRunOnFailed, useStableBuildAsReference, canComputeNew, PLUGIN_NAME);
}
// CHECKSTYLE:ON

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

@Override
protected PmdResult createResult(final MavenBuild build, final ParserResult project) {
return new PmdReporterResult(build, getDefaultEncoding(), project);
return new PmdReporterResult(build, getDefaultEncoding(), project, useOnlyStableBuildsAsReference());
}

@Override
@@ -22,10 +22,13 @@ public class PmdReporterResult extends PmdResult {
* the default encoding to be used when reading and parsing files
* @param result
* the parsed result with all annotations
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*/
public PmdReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result) {
super(build, defaultEncoding, result, PmdMavenResultAction.class);
final ParserResult result, final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, useStableBuildAsReference, PmdMavenResultAction.class);
}

@Override
@@ -27,9 +27,13 @@ public class PmdResult extends BuildResult {
* the default encoding to be used when reading and parsing files
* @param result
* the parsed result with all annotations
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*/
public PmdResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result) {
this(build, defaultEncoding, result, PmdResultAction.class);
public PmdResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean useStableBuildAsReference) {
this(build, defaultEncoding, result, useStableBuildAsReference, PmdResultAction.class);
}

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

PmdResult(final AbstractBuild<?, ?> build, final BuildHistory history,
@@ -1,9 +1,9 @@
package hudson.plugins.pmd;

import hudson.model.AbstractBuild;
import hudson.plugins.analysis.core.AbstractResultAction;
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.core.PluginDescriptor;
import hudson.plugins.analysis.core.AbstractResultAction;

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

/**
* Creates a new instance of <code>PmdResultAction</code>.
*
* @param owner
* the associated build of this action
* @param healthDescriptor
* health descriptor to use
*/
public PmdResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor) {
super(owner, new PmdHealthDescriptor(healthDescriptor));
}

/** {@inheritDoc} */
public String getDisplayName() {
return Messages.PMD_ProjectAction_Name();
@@ -1,7 +1,7 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:u="/util">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:u="/util">
<f:advanced>
<u:advancedMaven id="pmd"/>
<u:advancedMaven id="pmd" />
</f:advanced>
</j:jelly>

0 comments on commit fba349e

Please sign in to comment.