Skip to content
This repository has been archived by the owner on Apr 6, 2022. 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 fe174ae commit 41673a3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
31 changes: 16 additions & 15 deletions src/main/java/hudson/plugins/dry/DryReporter.java
@@ -1,13 +1,12 @@
package hudson.plugins.dry;

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

Expand All @@ -49,6 +48,10 @@ public class DryReporter 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 @@ -90,14 +93,14 @@ public class DryReporter extends HealthAwareMavenReporter {
// CHECKSTYLE:OFF
@SuppressWarnings("PMD.ExcessiveParameterList")
@DataBoundConstructor
public DryReporter(final String healthy, final String unHealthy, final String thresholdLimit,
public DryReporter(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,
final int highThreshold, final int normalThreshold) {
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 @@ -143,25 +146,23 @@ public ParserResult perform(final MavenBuildProxy build, final MavenProject pom,
return getTargetPath(pom).act(dryCollector);
}

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

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

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

/** {@inheritDoc} */
@Override
protected Class<? extends Action> getResultActionClass() {
protected Class<MavenDryResultAction> getResultActionClass() {
return MavenDryResultAction.class;
}
}
Expand Down
45 changes: 41 additions & 4 deletions src/main/java/hudson/plugins/dry/MavenDryResultAction.java
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) {
DryResult annotationsResult = new DryResult(getOwner(), defaultEncoding, createAggregatedResult(moduleBuilds));
setResult(annotationsResult);
updateBuildHealth(newBuild, annotationsResult);
MavenDryResultAction additionalAction = newBuild.getAction(MavenDryResultAction.class);
if (additionalAction != null) {
DryResult existingResult = getResult();
DryResult 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 DryResult aggregate(final DryResult existingResult, final DryResult additionalResult, final PluginLogger logger) {
ParserResult aggregatedAnnotations = new ParserResult();
aggregatedAnnotations.addAnnotations(existingResult.getAnnotations());
aggregatedAnnotations.addAnnotations(additionalResult.getAnnotations());

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

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

0 comments on commit 41673a3

Please sign in to comment.