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 a5898fe commit a4b109a
Show file tree
Hide file tree
Showing 11 changed files with 940 additions and 82 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
119 changes: 81 additions & 38 deletions src/main/java/hudson/plugins/analysis/core/AbstractResultAction.java
Expand Up @@ -7,6 +7,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerProxy;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;
Expand All @@ -16,13 +17,16 @@

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.StringPluginLogger;
import hudson.plugins.analysis.util.ToolTipProvider;
import hudson.plugins.analysis.util.model.AbstractAnnotation;

/**
* Controls the live cycle of Hudson results. This action persists the results
* Controls the live cycle of the results in a job. This action persists the results
* of a build and displays them on the build page. The actual visualization of
* the results is defined in the matching <code>summary.jelly</code> file.
* <p>
Expand All @@ -42,6 +46,12 @@ public abstract class AbstractResultAction<T extends BuildResult> implements Sta
/** The actual result of this action. */
private T result;

private transient StringPluginLogger logger = createLogger();

private StringPluginLogger createLogger() {
return new StringPluginLogger("[" + StringUtils.upperCase(getDisplayName()) + "] "); //NOCHECKSTYLE
}

/**
* Creates a new instance of <code>AbstractResultAction</code>.
*
Expand Down Expand Up @@ -144,23 +154,6 @@ public String getIconFileName() {
return null;
}

/**
* Aggregates the results of the specified maven module builds.
*
* @param moduleBuilds
* the module builds to aggregate
* @return the aggregated result
*/
protected ParserResult createAggregatedResult(final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
ParserResult project = createResult();
for (List<MavenBuild> builds : moduleBuilds.values()) {
if (!builds.isEmpty()) {
addModule(project, builds);
}
}
return project;
}

/**
* Factory method to create the result of this action.
*
Expand All @@ -179,7 +172,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 All @@ -201,25 +193,6 @@ protected void addModule(final ParserResult aggregatedResult, final List<MavenBu
}
}

/**
* Updates the build status if the number of annotations exceeds one of the
* thresholds.
*
* @param build
* the build to change the status from
* @param buildResult
* 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);
// }
}

/** {@inheritDoc} */
public String getTooltip(final int numberOfItems) {
if (numberOfItems == 1) {
Expand Down Expand Up @@ -251,6 +224,76 @@ public boolean isSuccessful() {
return getResult().isSuccessful();
}

/**
* Aggregates the results of the specified maven module builds.
*
* @param moduleBuilds
* the module builds to aggregate
* @return the aggregated result
* @deprecated not used anymore, see MavenPmdResultAction as an example
*/
@Deprecated
protected ParserResult createAggregatedResult(final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
ParserResult project = createResult();
for (List<MavenBuild> builds : moduleBuilds.values()) {
if (!builds.isEmpty()) {
addModule(project, builds);
}
}
return project;
}

/**
* Updates the build status if the number of annotations exceeds one of the
* thresholds.
*
* @param build
* the build to change the status from
* @param buildResult
* the build result
* @deprecated not used anymore, see MavenPmdResultAction as an example
*/
@Deprecated
protected void updateBuildHealth(final MavenBuild build, final BuildResult buildResult) {
PluginLogger logger = new PluginLogger(System.out, "[" + getDisplayName() + "] "); // NOCHECKSTYLE
Result hudsonResult = new BuildResultEvaluator().evaluateBuildResult(
logger, getHealthDescriptor().getThresholds(),
buildResult.getAnnotations(), buildResult.getNewWarnings());
if (hudsonResult != Result.SUCCESS) {
build.getParentBuild().setResult(hudsonResult);
}
}

/**
* Returns the logger.
*
* @return the logger
*/
protected PluginLogger getLogger() {
if (logger == null) {
logger = createLogger();
}
return logger;
}

/**
* Returns all logging statements of this action that couldn't be printed so far.
*
* @return the logging statements
*/
public String getLog() {
return getLogger().toString();
}

/**
* Logs the specified message.
*
* @param message the message
*/
protected void log(final String message) {
getLogger().log(message);
}

/** Backward compatibility. @deprecated */
@Deprecated
@java.lang.SuppressWarnings("unused")
Expand Down
71 changes: 68 additions & 3 deletions src/main/java/hudson/plugins/analysis/core/BuildResult.java
Expand Up @@ -13,6 +13,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.kohsuke.stapler.StaplerRequest;
Expand All @@ -31,6 +32,7 @@
import hudson.model.Hudson;

import hudson.plugins.analysis.Messages;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.analysis.util.model.AnnotationContainer;
import hudson.plugins.analysis.util.model.AnnotationProvider;
import hudson.plugins.analysis.util.model.AnnotationStream;
Expand Down Expand Up @@ -175,6 +177,9 @@ public static long getDays(final long ms) {
*/
private boolean isSuccessfulStateTouched;

private transient boolean useDeltaValues;
private transient Thresholds thresholds = new Thresholds();

/**
* Creates a new instance of {@link BuildResult}.
*
Expand Down Expand Up @@ -406,6 +411,27 @@ public String getDefaultEncoding() {
return defaultEncoding;
}

/**
* Returns the thresholds used to compute the build health.
*
* @return the thresholds
*/
public Thresholds getThresholds() {
return (Thresholds)ObjectUtils.defaultIfNull(thresholds, new Thresholds());
}

/**
* Returns the whether delta values should be used to compute the new
* warnings.
*
* @return <code>true</code> if the absolute annotations delta should be
* used, <code>false</code> if the actual annotations set difference
* should be used to evaluate the build stability.
*/
public boolean canUseDeltaValues() {
return useDeltaValues;
}

/**
* Returns the serialization file.
*
Expand Down Expand Up @@ -945,11 +971,50 @@ public boolean isSuccessful() {
}

/**
* Sets the Hudson build result for the associated plug-in build result.
* Updates the build status, i.e. sets this plug-in result status field to
* the corresponding {@link Result}. Additionally, the {@link Result} of the
* build that owns this instance of {@link BuildResult} will be also
* changed.
*
* @param result the Hudson build result
* @param thresholds
* the failure thresholds
* @param useDeltaValues
* the use delta values when computing the differences
* @param logger
* the logger
*/
// CHECKSTYLE:OFF
public void evaluateStatus(final Thresholds thresholds, final boolean useDeltaValues, final PluginLogger logger) {
// CHECKSTYLE:ON
this.thresholds = thresholds;
this.useDeltaValues = useDeltaValues;

BuildResultEvaluator resultEvaluator = new BuildResultEvaluator();
Result buildResult;
if (useDeltaValues) {
logger.log("Using delta values to compute new warnings");
buildResult = resultEvaluator.evaluateBuildResult(logger, thresholds, getAnnotations(),
getDelta(), getHighDelta(), getNormalDelta(), getLowDelta());
}
else {
logger.log("Using set difference to compute new warnings");
buildResult = resultEvaluator.evaluateBuildResult(logger, thresholds,
getAnnotations(), getNewWarnings());
}
saveResult(buildResult);
}

// CHECKSTYLE:OFF
/**
* @deprecated use {@link #evaluateStatus(Thresholds, boolean, PluginLogger)}
*/
@Deprecated
public void setResult(final Result result) {
saveResult(result);
}
// CHECKSTYLE:ON

private void saveResult(final Result result) {
isSuccessfulStateTouched = true;
pluginResult = result;
owner.setResult(result);
Expand All @@ -976,7 +1041,7 @@ public void setResult(final Result result) {
}
if (!isSuccessfulHighscore) {
successfulHighScoreGap = previous.getSuccessfulHighScore()
- (owner.getTimestamp().getTimeInMillis() - successfulSinceDate);
- (owner.getTimestamp().getTimeInMillis() - successfulSinceDate);
}
}
else {
Expand Down

0 comments on commit a4b109a

Please sign in to comment.