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 206c61c commit d92bd4c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 21 deletions.
33 changes: 16 additions & 17 deletions plugin/src/main/java/hudson/plugins/findbugs/FindBugsReporter.java
@@ -1,14 +1,13 @@
package hudson.plugins.findbugs;

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.model.BuildListener;
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.findbugs.parser.FindBugsParser;
Expand All @@ -29,7 +28,7 @@
* @author Ulli Hafner
*/
// CHECKSTYLE:COUPLING-OFF
public class FindBugsReporter extends HealthAwareMavenReporter {
public class FindBugsReporter extends HealthAwareReporter<FindBugsResult> {
private static final long serialVersionUID = -288391908253344862L;

/** FindBugs filename if maven findbugsXmlOutput is activated. */
Expand All @@ -49,6 +48,10 @@ public class FindBugsReporter 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 @@ -87,13 +90,13 @@ public class FindBugsReporter extends HealthAwareMavenReporter {
// CHECKSTYLE:OFF
@SuppressWarnings("PMD.ExcessiveParameterList")
@DataBoundConstructor
public FindBugsReporter(final String healthy, final String unHealthy, final String thresholdLimit,
public FindBugsReporter(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 Down Expand Up @@ -129,13 +132,11 @@ private void activateProperty(final MojoInfo mojo, final String property) {
}
}

/** {@inheritDoc} */
@Override
protected boolean acceptGoal(final String goal) {
return "findbugs".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 @@ -148,14 +149,14 @@ public ParserResult perform(final MavenBuildProxy build, final MavenProject pom,
return getTargetPath(pom).act(findBugsCollector);
}

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

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

/**
Expand All @@ -178,15 +179,13 @@ private String determineFileName(final MojoInfo mojo) {
return fileName;
}

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

/** {@inheritDoc} */
@Override
protected Class<? extends Action> getResultActionClass() {
protected Class<MavenFindBugsResultAction> getResultActionClass() {
return MavenFindBugsResultAction.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) {
FindBugsResult annotationsResult = new FindBugsResult(getOwner(), defaultEncoding, createAggregatedResult(moduleBuilds));
setResult(annotationsResult);
updateBuildHealth(newBuild, annotationsResult);
MavenFindBugsResultAction additionalAction = newBuild.getAction(MavenFindBugsResultAction.class);
if (additionalAction != null) {
FindBugsResult existingResult = getResult();
FindBugsResult 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 FindBugsResult aggregate(final FindBugsResult existingResult, final FindBugsResult additionalResult, final PluginLogger logger) {
ParserResult aggregatedAnnotations = new ParserResult();
aggregatedAnnotations.addAnnotations(existingResult.getAnnotations());
aggregatedAnnotations.addAnnotations(additionalResult.getAnnotations());

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

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

0 comments on commit d92bd4c

Please sign in to comment.