Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[JENKINS-4912] Added build health/threshold evaluation for m2 jobs.
Browse files Browse the repository at this point in the history
Totally refactored the calculation code, introduced new parent class.
  • Loading branch information
uhafner committed May 11, 2011
1 parent 9c0529f commit e59aa3a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
32 changes: 16 additions & 16 deletions src/main/java/hudson/plugins/checkstyle/CheckStyleReporter.java
@@ -1,12 +1,12 @@
package hudson.plugins.checkstyle;

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.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.checkstyle.parser.CheckStyleParser;
Expand All @@ -23,7 +23,7 @@
*
* @author Ulli Hafner
*/
public class CheckStyleReporter extends HealthAwareMavenReporter {
public class CheckStyleReporter extends HealthAwareReporter<CheckStyleResult> {
/** Unique identifier of this class. */
private static final long serialVersionUID = 2272875032054063496L;

Expand All @@ -42,6 +42,10 @@ public class CheckStyleReporter 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 @@ -80,13 +84,13 @@ public class CheckStyleReporter extends HealthAwareMavenReporter {
// CHECKSTYLE:OFF
@SuppressWarnings("PMD.ExcessiveParameterList")
@DataBoundConstructor
public CheckStyleReporter(final String healthy, final String unHealthy, final String thresholdLimit,
public CheckStyleReporter(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 @@ -95,13 +99,11 @@ public CheckStyleReporter(final String healthy, final String unHealthy, final St
}
// CHECKSTYLE:ON

/** {@inheritDoc} */
@Override
protected boolean acceptGoal(final String goal) {
return "checkstyle".equals(goal) || "check".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 {
Expand All @@ -111,25 +113,23 @@ public ParserResult perform(final MavenBuildProxy build, final MavenProject pom,
return getTargetPath(pom).act(checkstyleCollector);
}

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

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

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

/** {@inheritDoc} */
@Override
protected Class<? extends Action> getResultActionClass() {
protected Class<MavenCheckStyleResultAction> getResultActionClass() {
return MavenCheckStyleResultAction.class;
}
}
Expand Down
Expand Up @@ -8,7 +8,10 @@
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 Down Expand Up @@ -75,7 +78,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 +89,43 @@ public Class<? extends AggregatableAction> getIndividualActionType() {
* Newly completed build.
*/
public void update(final Map<MavenModule, List<MavenBuild>> moduleBuilds, final MavenBuild newBuild) {
CheckStyleResult annotationsResult = new CheckStyleResult(getOwner(), defaultEncoding, createAggregatedResult(moduleBuilds));
setResult(annotationsResult);
updateBuildHealth(newBuild, annotationsResult);
MavenCheckStyleResultAction additionalAction = newBuild.getAction(MavenCheckStyleResultAction.class);
if (additionalAction != null) {
CheckStyleResult existingResult = getResult();
CheckStyleResult 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 CheckStyleResult aggregate(final CheckStyleResult existingResult, final CheckStyleResult additionalResult, final PluginLogger logger) {
ParserResult aggregatedAnnotations = new ParserResult();
aggregatedAnnotations.addAnnotations(existingResult.getAnnotations());
aggregatedAnnotations.addAnnotations(additionalResult.getAnnotations());

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

/** Backward compatibility. @deprecated */
Expand Down

0 comments on commit e59aa3a

Please sign in to comment.