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

Commit

Permalink
[FIXED JENKINS-4912] Fixed build health and threshold evaluation of m2
Browse files Browse the repository at this point in the history
jobs.
  • Loading branch information
uhafner committed May 1, 2011
1 parent a5898fe commit 128e98d
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 34 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-pom</artifactId>
<version>1.24</version>
<version>1.25-SNAPSHOT</version>
<relativePath>../analysis-pom/pom.xml</relativePath>
</parent>

Expand All @@ -17,6 +17,11 @@
<url>http://wiki.jenkins-ci.org/x/CwDgAQ</url>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>1.399</version>
</dependency>
<dependency>
<groupId>de.java2html</groupId>
<artifactId>java2html</artifactId>
Expand Down
Expand Up @@ -16,8 +16,10 @@

import hudson.model.HealthReport;
import hudson.model.HealthReportingAction;
import hudson.model.Result;
import hudson.model.AbstractBuild;

import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.analysis.util.ToolTipProvider;
import hudson.plugins.analysis.util.model.AbstractAnnotation;

Expand Down Expand Up @@ -179,7 +181,6 @@ protected ParserResult createResult() {
* @param builds
* the builds for a module
*/
// FIXME: this method is always invoked with all available builds, check this for hierarchies
@java.lang.SuppressWarnings("unchecked")
protected void addModule(final ParserResult aggregatedResult, final List<MavenBuild> builds) {
MavenBuild mavenBuild = builds.get(0);
Expand Down Expand Up @@ -211,13 +212,13 @@ protected void addModule(final ParserResult aggregatedResult, final List<MavenBu
* the build result
*/
protected void updateBuildHealth(final MavenBuild build, final BuildResult buildResult) {
// FIXME: See http://issues.hudson-ci.org/browse/HUDSON-4912
// PluginLogger logger = new PluginLogger(System.out, "[" + getDisplayName() + "] ");
// Result hudsonResult = new BuildResultEvaluator().evaluateBuildResult(
// logger, getHealthDescriptor(), buildResult.getAnnotations(), buildResult.getNewWarnings());
// if (hudsonResult != Result.SUCCESS) {
// build.setResult(hudsonResult);
// }
PluginLogger logger = new PluginLogger(System.out, "[" + getDisplayName() + "] ");
Result hudsonResult = new BuildResultEvaluator().evaluateBuildResult(
logger, getHealthDescriptor().getThresholds(),
buildResult.getAnnotations(), buildResult.getNewWarnings());
if (hudsonResult != Result.SUCCESS) {
build.getParentBuild().setResult(hudsonResult);
}
}

/** {@inheritDoc} */
Expand Down
164 changes: 140 additions & 24 deletions src/main/java/hudson/plugins/analysis/core/HealthAwareMavenReporter.java
Expand Up @@ -53,14 +53,6 @@ public abstract class HealthAwareMavenReporter extends MavenReporter implements
private static final String DEFAULT_PRIORITY_THRESHOLD_LIMIT = "low";
/** Unique identifier of this class. */
private static final long serialVersionUID = 3003791883748835331L;
/** Annotation threshold to be reached if a build should be considered as unstable. */
private final String threshold;
/** Annotation threshold to be reached if a build should be considered as failure. */
private final String failureThreshold;
/** Threshold for new annotations to be reached if a build should be considered as failure. */
private final String newFailureThreshold;
/** Annotation threshold for new warnings to be reached if a build should be considered as unstable. */
private final String newThreshold;
/** Report health as 100% when the number of warnings is less than this value. */
private final String healthy;
/** Report health as 0% when the number of warnings is greater than this value. */
Expand All @@ -74,6 +66,98 @@ public abstract class HealthAwareMavenReporter extends MavenReporter implements
/** Determines whether the plug-in should run for failed builds, too. @since 1.6 */
private final boolean canRunOnFailed;

/**
* Thresholds for build status unstable and failed, resp. and priorities
* all, high, normal, and low, resp.
*
* @since 1.20
*/
private Thresholds thresholds = new Thresholds();

/**
* Creates a new instance of <code>HealthReportingMavenReporter</code>.
*
* @param healthy
* Report health as 100% when the number of warnings is less than
* this value
* @param unHealthy
* Report health as 0% when the number of warnings is greater
* than this value
* @param thresholdLimit
* determines which warning priorities should be considered when
* evaluating the build stability and health
* @param unstableTotalAll
* annotation threshold
* @param unstableTotalHigh
* annotation threshold
* @param unstableTotalNormal
* annotation threshold
* @param unstableTotalLow
* annotation threshold
* @param unstableNewAll
* annotation threshold
* @param unstableNewHigh
* annotation threshold
* @param unstableNewNormal
* annotation threshold
* @param unstableNewLow
* annotation threshold
* @param failedTotalAll
* annotation threshold
* @param failedTotalHigh
* annotation threshold
* @param failedTotalNormal
* annotation threshold
* @param failedTotalLow
* annotation threshold
* @param failedNewAll
* annotation threshold
* @param failedNewHigh
* annotation threshold
* @param failedNewNormal
* annotation threshold
* @param failedNewLow
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param pluginName
* the name of the plug-in
*/
// CHECKSTYLE:OFF
public HealthAwareMavenReporter(final String healthy, final String unHealthy, final String thresholdLimit,
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 String pluginName) {
super();
this.healthy = healthy;
this.unHealthy = unHealthy;
this.thresholdLimit = thresholdLimit;
this.canRunOnFailed = canRunOnFailed;
this.pluginName = "[" + pluginName + "] ";

thresholds.unstableTotalAll = unstableTotalAll;
thresholds.unstableTotalHigh = unstableTotalHigh;
thresholds.unstableTotalNormal = unstableTotalNormal;
thresholds.unstableTotalLow = unstableTotalLow;
thresholds.unstableNewAll = unstableNewAll;
thresholds.unstableNewHigh = unstableNewHigh;
thresholds.unstableNewNormal = unstableNewNormal;
thresholds.unstableNewLow = unstableNewLow;
thresholds.failedTotalAll = failedTotalAll;
thresholds.failedTotalHigh = failedTotalHigh;
thresholds.failedTotalNormal = failedTotalNormal;
thresholds.failedTotalLow = failedTotalLow;
thresholds.failedNewAll = failedNewAll;
thresholds.failedNewHigh = failedNewHigh;
thresholds.failedNewNormal = failedNewNormal;
thresholds.failedNewLow = failedNewLow;

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
}
// CHECKSTYLE:ON

/**
* Creates a new instance of <code>HealthReportingMavenReporter</code>.
*
Expand Down Expand Up @@ -102,26 +186,21 @@ public abstract class HealthAwareMavenReporter extends MavenReporter implements
* determines whether the plug-in can run for failed builds, too
* @param pluginName
* the name of the plug-in
* @deprecated replaced by {@link HealthAwareMavenReporter#HealthAwareMavenReporter(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, boolean, String)}
*/
// CHECKSTYLE:OFF
@Deprecated
public HealthAwareMavenReporter(final String threshold, final String newThreshold,
final String failureThreshold, final String newFailureThreshold,
final String healthy, final String unHealthy,
final String thresholdLimit, final boolean canRunOnFailed, final String pluginName) {
super();
this.threshold = threshold;
this.newThreshold = newThreshold;
this.failureThreshold = failureThreshold;
this.newFailureThreshold = newFailureThreshold;
this.healthy = healthy;
this.unHealthy = unHealthy;
this.thresholdLimit = thresholdLimit;
this.canRunOnFailed = canRunOnFailed;
this.pluginName = "[" + pluginName + "] ";

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
this(healthy, unHealthy, thresholdLimit,
threshold, "", "", "",
newThreshold, "", "", "",
failureThreshold, "", "", "",
newFailureThreshold, "", "", "",
canRunOnFailed, pluginName);
}
// CHECKSTYLE:ON

/**
* Creates a new instance of <code>HealthReportingMavenReporter</code>.
Expand Down Expand Up @@ -149,21 +228,26 @@ public HealthAwareMavenReporter(final String threshold, final String newThreshol
* evaluating the build stability and health
* @param pluginName
* the name of the plug-in
* @deprecated replaced by {@link #HealthAwareMavenReporter(String, String, String, String, String, String, String, boolean, String)}
* @deprecated replaced by {@link HealthAwareMavenReporter#HealthAwareMavenReporter(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, boolean, String)}
*/
// CHECKSTYLE:OFF
@Deprecated
public HealthAwareMavenReporter(final String threshold, final String newThreshold,
final String failureThreshold, final String newFailureThreshold,
final String healthy, final String unHealthy,
final String thresholdLimit, final String pluginName) {
this(threshold, newThreshold, failureThreshold, newFailureThreshold, healthy, unHealthy, thresholdLimit, false, pluginName);
this(healthy, unHealthy, thresholdLimit,
threshold, "", "", "",
newThreshold, "", "", "",
failureThreshold, "", "", "",
newFailureThreshold, "", "", "",
false, pluginName);
}
// CHECKSTYLE:ON

/** {@inheritDoc} */
public Thresholds getThresholds() {
return new Thresholds(); // TODO: see issue HUDSON-4912
return thresholds;
}

/**
Expand All @@ -176,6 +260,26 @@ private Object readResolve() {
if (thresholdLimit == null) {
thresholdLimit = DEFAULT_PRIORITY_THRESHOLD_LIMIT;
}
if (thresholds == null) {
thresholds = new Thresholds();

if (threshold != null) {
thresholds.unstableTotalAll = threshold;
threshold = null; // NOPMD
}
if (newThreshold != null) {
thresholds.unstableNewAll = newThreshold;
newThreshold = null; // NOPMD
}
if (failureThreshold != null) {
thresholds.failedTotalAll = failureThreshold;
failureThreshold = null; //NOPMD
}
if (newFailureThreshold != null) {
thresholds.failedNewAll = newFailureThreshold;
newFailureThreshold = null; // NOPMD
}
}
return this;
}

Expand Down Expand Up @@ -522,5 +626,17 @@ public Result call(final MavenBuild mavenBuild) throws IOException, InterruptedE
@SuppressWarnings("unused")
@Deprecated
private transient String height;
/** Backward compatibility. @deprecated */
@Deprecated
private transient String threshold;
/** Backward compatibility. @deprecated */
@Deprecated
private transient String failureThreshold;
/** Backward compatibility. @deprecated */
@Deprecated
private transient String newFailureThreshold;
/** Backward compatibility. @deprecated */
@Deprecated
private transient String newThreshold;
}

4 changes: 3 additions & 1 deletion src/main/java/hudson/plugins/analysis/core/Thresholds.java
Expand Up @@ -2,6 +2,8 @@

import static hudson.plugins.analysis.util.ThresholdValidator.*;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

/**
Expand All @@ -12,7 +14,7 @@
// CHECKSTYLE:OFF
@edu.umd.cs.findbugs.annotations.SuppressWarnings("")
@SuppressWarnings("all")
public class Thresholds {
public class Thresholds implements Serializable {
public String unstableTotalAll = StringUtils.EMPTY;
public String unstableTotalHigh = StringUtils.EMPTY;
public String unstableTotalNormal = StringUtils.EMPTY;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/util/advancedMaven.jelly
Expand Up @@ -9,6 +9,7 @@
<u:failed/>

<u:health id="${id}"/>
<u:thresholds id="${id}"/>
<u:trend id="${id}"/>

</j:jelly>

0 comments on commit 128e98d

Please sign in to comment.