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

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-4912] Added build health/threshold evaluation for m2 jobs.
Totally refactored the calculation code, introduced new parent class.
  • Loading branch information
uhafner committed May 11, 2011
1 parent 3464ac5 commit ac9535e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 26 deletions.
58 changes: 49 additions & 9 deletions src/main/java/hudson/plugins/pmd/MavenPmdResultAction.java
Expand Up @@ -7,8 +7,10 @@
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.util.PluginLogger;

import java.util.List;
import java.util.Map;
Expand All @@ -25,7 +27,9 @@ public class MavenPmdResultAction extends PmdResultAction implements Aggregatabl
private final String defaultEncoding;

/**
* Creates a new instance of <code>MavenPmdResultAction</code>.
* 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
Expand All @@ -34,14 +38,15 @@ public class MavenPmdResultAction extends PmdResultAction implements Aggregatabl
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
*/
public MavenPmdResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor,
public MavenPmdResultAction(final MavenModuleSetBuild owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding) {
super(owner, healthDescriptor);

this.defaultEncoding = defaultEncoding;
}

/**
* Creates a new instance of <code>MavenPmdResultAction</code>.
* Creates a new instance of {@link MavenPmdResultAction}.
*
* @param owner
* the associated build of this action
Expand All @@ -52,9 +57,10 @@ public MavenPmdResultAction(final AbstractBuild<?, ?> owner, final HealthDescrip
* @param result
* the result in this build
*/
public MavenPmdResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor,
public MavenPmdResultAction(final MavenBuild owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding, final PmdResult result) {
super(owner, healthDescriptor, result);

this.defaultEncoding = defaultEncoding;
}

Expand All @@ -75,7 +81,7 @@ public Class<? extends AggregatableAction> getIndividualActionType() {

/**
* Called whenever a new module build is completed, to update the aggregated
* report. When multiple builds complete simultaneously, Hudson serializes
* report. When multiple builds complete simultaneously, Jenkins serializes
* the execution of this method, so this method needs not be
* concurrency-safe.
*
Expand All @@ -86,9 +92,43 @@ public Class<? extends AggregatableAction> getIndividualActionType() {
* Newly completed build.
*/
public void update(final Map<MavenModule, List<MavenBuild>> moduleBuilds, final MavenBuild newBuild) {
PmdResult annotationsResult = new PmdResult(getOwner(), defaultEncoding, createAggregatedResult(moduleBuilds));
setResult(annotationsResult);
updateBuildHealth(newBuild, annotationsResult);
MavenPmdResultAction additionalAction = newBuild.getAction(MavenPmdResultAction.class);
if (additionalAction != null) {
PmdResult existingResult = getResult();
PmdResult additionalResult = additionalAction.getResult();

log("Aggregating results of " + newBuild.getProject().getDisplayName());

if (existingResult == null) {
setResult(additionalResult);
getOwner().setResult(additionalResult.getPluginResult());
}
else {
setResult(aggregate(existingResult, additionalResult, getLogger()));
}
}
}

/**
* Creates a new instance of {@link BuildResult} that contains the aggregated
* results of this result and the provided additional result.
*
* @param existingResult
* the existing result
* @param additionalResult
* the result that will be added to the existing result
* @param logger
* the plug-in logger
* @return the aggregated result
*/
public PmdResult aggregate(final PmdResult existingResult, final PmdResult additionalResult, final PluginLogger logger) {
ParserResult aggregatedAnnotations = new ParserResult();
aggregatedAnnotations.addAnnotations(existingResult.getAnnotations());
aggregatedAnnotations.addAnnotations(additionalResult.getAnnotations());

PmdResult createdResult = new PmdResult(getOwner(), existingResult.getDefaultEncoding(), aggregatedAnnotations);
createdResult.evaluateStatus(existingResult.getThresholds(), existingResult.canUseDeltaValues(), logger);
return createdResult;
}

/** Backward compatibility. @deprecated */
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/hudson/plugins/pmd/PmdReporter.java
@@ -1,13 +1,12 @@
package hudson.plugins.pmd;

import hudson.maven.MavenAggregatedReport;
import hudson.maven.MavenBuildProxy;
import hudson.maven.MojoInfo;
import hudson.maven.MavenBuild;
import hudson.maven.MavenModule;
import hudson.model.Action;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.FilesParser;
import hudson.plugins.analysis.core.HealthAwareMavenReporter;
import hudson.plugins.analysis.core.HealthAwareReporter;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.pmd.parser.PmdParser;
Expand All @@ -24,7 +23,7 @@
*
* @author Ulli Hafner
*/
public class PmdReporter extends HealthAwareMavenReporter {
public class PmdReporter extends HealthAwareReporter<PmdResult> {
/** Unique identifier of this class. */
private static final long serialVersionUID = 2272875032054063496L;

Expand All @@ -46,6 +45,10 @@ public class PmdReporter extends HealthAwareMavenReporter {
* @param thresholdLimit
* determines which warning priorities should be considered when
* evaluating the build stability and health
* @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
Expand Down Expand Up @@ -84,13 +87,13 @@ public class PmdReporter extends HealthAwareMavenReporter {
// CHECKSTYLE:OFF
@SuppressWarnings("PMD.ExcessiveParameterList")
@DataBoundConstructor
public PmdReporter(final String healthy, final String unHealthy, final String thresholdLimit,
public PmdReporter(final String healthy, final String unHealthy, final String thresholdLimit, 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) {
super(healthy, unHealthy, thresholdLimit,
super(healthy, unHealthy, thresholdLimit, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
Expand All @@ -99,13 +102,11 @@ public PmdReporter(final String healthy, final String unHealthy, final String th
}
// CHECKSTYLE:ON

/** {@inheritDoc} */
@Override
protected boolean acceptGoal(final String goal) {
return "pmd".equals(goal) || "site".equals(goal);
}

/** {@inheritDoc} */
@Override
public ParserResult perform(final MavenBuildProxy build, final MavenProject pom, final MojoInfo mojo, final PluginLogger logger) throws InterruptedException, IOException {
FilesParser pmdCollector = new FilesParser(logger, PMD_XML_FILE,
Expand All @@ -114,25 +115,23 @@ public ParserResult perform(final MavenBuildProxy build, final MavenProject pom,
return getTargetPath(pom).act(pmdCollector);
}

/** {@inheritDoc} */
@Override
protected BuildResult persistResult(final ParserResult project, final MavenBuild build) {
PmdResult result = new PmdResult(build, getDefaultEncoding(), project);
build.getActions().add(new MavenPmdResultAction(build, this, getDefaultEncoding(), result));
build.registerAsProjectAction(PmdReporter.this);
protected PmdResult createResult(final MavenBuild build, final ParserResult project) {
return new PmdResult(build, getDefaultEncoding(), project);
}

return result;
@Override
protected MavenAggregatedReport createMavenAggregatedReport(final MavenBuild build, final PmdResult result) {
return new MavenPmdResultAction(build, this, getDefaultEncoding(), result);
}

/** {@inheritDoc} */
@Override
public List<PmdProjectAction> getProjectActions(final MavenModule module) {
return Collections.singletonList(new PmdProjectAction(module));
}

/** {@inheritDoc} */
@Override
protected Class<? extends Action> getResultActionClass() {
protected Class<MavenPmdResultAction> getResultActionClass() {
return MavenPmdResultAction.class;
}
}
Expand Down

0 comments on commit ac9535e

Please sign in to comment.