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

Commit

Permalink
[FIXED JENKINS-11718] Don't evaluate new warnings when there is
Browse files Browse the repository at this point in the history
no previous build result available.
  • Loading branch information
uhafner committed Nov 14, 2011
1 parent 2a27cd2 commit 3fd1404
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/main/java/hudson/plugins/analysis/core/BuildResult.java
Expand Up @@ -1024,7 +1024,11 @@ public void evaluateStatus(final Thresholds thresholds, final boolean useDeltaVa

BuildResultEvaluator resultEvaluator = new BuildResultEvaluator();
Result buildResult;
if (useDeltaValues) {
if (!history.hasPreviousResult()) {
logger.log("Ignore new warnings since this is the first valid build");
buildResult = resultEvaluator.evaluateBuildResult(logger, thresholds, getAnnotations());
}
else if (useDeltaValues) {
logger.log("Using delta values to compute new warnings");
buildResult = resultEvaluator.evaluateBuildResult(logger, thresholds, getAnnotations(),
getDelta(), getHighDelta(), getNormalDelta(), getLowDelta());
Expand Down
Expand Up @@ -4,7 +4,6 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.Set;

import hudson.model.Result;

Expand All @@ -18,6 +17,30 @@
* @author Ulli Hafner
*/
public class BuildResultEvaluator {
/**
* Evaluates the build result. The build is marked as unstable or failed if
* one of the thresholds has been exceeded.
*
* @param logger
* logs the results
* @param t
* the thresholds
* @param allAnnotations
* all annotations
* @return the build result
*/
public Result evaluateBuildResult(final PluginLogger logger, final Thresholds t,
final Collection<? extends FileAnnotation> allAnnotations) {
if (checkAllWarningsForFailure(logger, t, allAnnotations)) {
return Result.FAILURE;
}
if (checkAllWarningsForUnstable(logger, t, allAnnotations)) {
return Result.UNSTABLE;
}

return logSuccess(logger);
}

/**
* Evaluates the build result. The build is marked as unstable or failed if
* one of the thresholds has been exceeded.
Expand All @@ -39,17 +62,15 @@ public class BuildResultEvaluator {
* @return the build result
*/
public Result evaluateBuildResult(final PluginLogger logger, final Thresholds t,
final Set<FileAnnotation> allAnnotations,
final Collection<? extends FileAnnotation> allAnnotations,
final int delta, final int highDelta, final int normalDelta, final int lowDelta) {
if (check(logger, allAnnotations, Result.FAILURE,
t.failedTotalAll, t.failedTotalHigh, t.failedTotalNormal, t.failedTotalLow)) {
if (checkAllWarningsForFailure(logger, t, allAnnotations)) {
return Result.FAILURE;
}
if (checkFailedNew(logger, delta, highDelta, normalDelta, lowDelta, t)) {
return Result.FAILURE;
}
if (check(logger, allAnnotations, Result.UNSTABLE,
t.unstableTotalAll, t.unstableTotalHigh, t.unstableTotalNormal, t.unstableTotalLow)) {
if (checkAllWarningsForUnstable(logger, t, allAnnotations)) {
return Result.UNSTABLE;
}
if (checkUnstableNew(logger, delta, highDelta, normalDelta, lowDelta, t)) {
Expand All @@ -59,6 +80,18 @@ public Result evaluateBuildResult(final PluginLogger logger, final Thresholds t,
return logSuccess(logger);
}

protected boolean checkAllWarningsForUnstable(final PluginLogger logger, final Thresholds t,
final Collection<? extends FileAnnotation> allAnnotations) {
return check(logger, allAnnotations, Result.UNSTABLE,
t.unstableTotalAll, t.unstableTotalHigh, t.unstableTotalNormal, t.unstableTotalLow);
}

protected boolean checkAllWarningsForFailure(final PluginLogger logger, final Thresholds t,
final Collection<? extends FileAnnotation> allAnnotations) {
return check(logger, allAnnotations, Result.FAILURE,
t.failedTotalAll, t.failedTotalHigh, t.failedTotalNormal, t.failedTotalLow);
}

/**
* Evaluates the build result. The build is marked as unstable or failed if one of the
* thresholds has been exceeded.
Expand All @@ -74,17 +107,16 @@ public Result evaluateBuildResult(final PluginLogger logger, final Thresholds t,
* @return the build result
*/
public Result evaluateBuildResult(final PluginLogger logger, final Thresholds t,
final Collection<FileAnnotation> allAnnotations, final Collection<FileAnnotation> newAnnotations) {
if (check(logger, allAnnotations, Result.FAILURE,
t.failedTotalAll, t.failedTotalHigh, t.failedTotalNormal, t.failedTotalLow)) {
final Collection<? extends FileAnnotation> allAnnotations,
final Collection<FileAnnotation> newAnnotations) {
if (checkAllWarningsForFailure(logger, t, allAnnotations)) {
return Result.FAILURE;
}
if (check(logger, newAnnotations, Result.FAILURE,
t.failedNewAll, t.failedNewHigh, t.failedNewNormal, t.failedNewLow)) {
return Result.FAILURE;
}
if (check(logger, allAnnotations, Result.UNSTABLE,
t.unstableTotalAll, t.unstableTotalHigh, t.unstableTotalNormal, t.unstableTotalLow)) {
if (checkAllWarningsForUnstable(logger, t, allAnnotations)) {
return Result.UNSTABLE;
}
if (check(logger, newAnnotations, Result.UNSTABLE,
Expand All @@ -101,7 +133,7 @@ private Result logSuccess(final PluginLogger logger) {
return Result.SUCCESS;
}

private boolean check(final PluginLogger logger, final Collection<FileAnnotation> annotations,
private boolean check(final PluginLogger logger, final Collection<? extends FileAnnotation> annotations,
final Result result, final String all, final String high, final String normal, final String low) {
if (checkThresholds(logger, annotations, all, result, Priority.HIGH, Priority.NORMAL, Priority.LOW)) {
return true;
Expand Down Expand Up @@ -150,7 +182,7 @@ private boolean checkUnstableNew(final PluginLogger logger, final int delta, fin
return false;
}

private boolean checkThresholds(final PluginLogger logger, final Collection<FileAnnotation> allAnnotations,
private boolean checkThresholds(final PluginLogger logger, final Collection<? extends FileAnnotation> allAnnotations,
final String threshold, final Result result, final Priority... priorities) {
return checkThresholds(logger, countAnnotations(allAnnotations, priorities), threshold, result, priorities);
}
Expand All @@ -175,7 +207,7 @@ private boolean checkThresholds(final PluginLogger logger, final int annotationC
* the annotations to consider
* @return the number of relevant annotations
*/
private int countAnnotations(final Collection<FileAnnotation> annotations, final Priority... priorities) {
private int countAnnotations(final Collection<? extends FileAnnotation> annotations, final Priority... priorities) {
ParserResult result = new ParserResult(annotations);
int annotationCount = 0;
for (Priority priority : priorities) {
Expand Down
Expand Up @@ -114,7 +114,7 @@ public ParserResult(final Workspace workspace) {
* @param annotations
* the annotations to add
*/
public ParserResult(final Collection<FileAnnotation> annotations) {
public ParserResult(final Collection<? extends FileAnnotation> annotations) {
this(new NullWorkspace());

addAnnotations(annotations);
Expand Down

0 comments on commit 3fd1404

Please sign in to comment.